@wordpress/media-editor 0.23.0 → 0.24.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.
- package/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +157 -107
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +18 -8
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +9 -7
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +9 -7
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +9 -7
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +32 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-preview/index.cjs +143 -36
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +2 -2
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +9 -7
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +142 -95
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +9 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +32 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-preview/index.mjs +123 -40
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +2 -2
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +18 -30
- package/build-style/style.css +18 -30
- package/build-types/components/media-editor/index.d.ts +8 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +7 -2
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/components/media-editor/index.tsx +209 -114
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +55 -63
- package/src/components/media-editor-modal/index.tsx +3 -0
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-preview/index.tsx +195 -36
- package/src/components/media-preview/style.scss +11 -32
- package/src/state/README.md +3 -1
- package/src/state/use-media-editor-state.ts +7 -2
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
|
@@ -7,6 +7,7 @@ let _wordpress_components = require("@wordpress/components");
|
|
|
7
7
|
let _wordpress_element = require("@wordpress/element");
|
|
8
8
|
let _wordpress_i18n = require("@wordpress/i18n");
|
|
9
9
|
let _wordpress_keycodes = require("@wordpress/keycodes");
|
|
10
|
+
let _wordpress_ui = require("@wordpress/ui");
|
|
10
11
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
12
|
// packages/media-editor/src/components/media-editor-keyboard-shortcuts-modal/index.tsx
|
|
12
13
|
const SHORTCUTS = [
|
|
@@ -26,15 +27,13 @@ const SHORTCUTS = [
|
|
|
26
27
|
},
|
|
27
28
|
{
|
|
28
29
|
description: (0, _wordpress_i18n.__)("Pan"),
|
|
29
|
-
keyCombination: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
ariaLabel: (0, _wordpress_i18n.__)("Arrow keys")
|
|
37
|
-
}
|
|
30
|
+
keyCombination: { character: [
|
|
31
|
+
"↑",
|
|
32
|
+
"↓",
|
|
33
|
+
"←",
|
|
34
|
+
"→"
|
|
35
|
+
] },
|
|
36
|
+
label: (0, _wordpress_i18n.__)("Arrow keys")
|
|
38
37
|
},
|
|
39
38
|
{
|
|
40
39
|
description: (0, _wordpress_i18n.__)("Zoom in"),
|
|
@@ -72,31 +71,31 @@ const SHORTCUTS = [
|
|
|
72
71
|
"↓",
|
|
73
72
|
"←",
|
|
74
73
|
"→"
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
label: (0, _wordpress_i18n.__)("Shift + Arrow keys")
|
|
78
77
|
}
|
|
79
78
|
];
|
|
80
|
-
function KeyCombinationDisplay({ keyCombination }) {
|
|
81
|
-
const {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
let label;
|
|
89
|
-
if (ariaLabel) label = ariaLabel;
|
|
90
|
-
else if (modifier) label = _wordpress_keycodes.shortcutAriaLabel[modifier](charString);
|
|
91
|
-
else label = charString;
|
|
92
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("kbd", {
|
|
79
|
+
function KeyCombinationDisplay({ keyCombination, label }) {
|
|
80
|
+
const { character, modifier } = keyCombination;
|
|
81
|
+
const normalizedModifier = modifier ?? "undefined";
|
|
82
|
+
const characters = Array.isArray(character) ? character : [character];
|
|
83
|
+
const formatted = _wordpress_keycodes.displayShortcutList[normalizedModifier](characters[0] ?? "");
|
|
84
|
+
const prefix = formatted.slice(0, -1);
|
|
85
|
+
const keys = Array.isArray(character) ? [...prefix, ...character] : formatted;
|
|
86
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("kbd", {
|
|
93
87
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-term",
|
|
94
88
|
dir: "ltr",
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.VisuallyHidden, {
|
|
90
|
+
render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {}),
|
|
91
|
+
children: label || _wordpress_keycodes.shortcutAriaLabel[normalizedModifier](characters.join(""))
|
|
92
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
93
|
+
"aria-hidden": "true",
|
|
94
|
+
children: keys.map((key, keyIndex) => key === "+" && keyIndex < prefix.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_element.Fragment, { children: key }, keyIndex) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("kbd", {
|
|
95
|
+
className: "media-editor-keyboard-shortcuts-modal__shortcut-key",
|
|
96
|
+
children: key
|
|
97
|
+
}, keyIndex))
|
|
98
|
+
})]
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
function MediaEditorKeyboardShortcutsModal({ onClose }) {
|
|
@@ -110,12 +109,12 @@ function MediaEditorKeyboardShortcutsModal({ onClose }) {
|
|
|
110
109
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
|
|
111
110
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-list",
|
|
112
111
|
role: "list",
|
|
113
|
-
children: SHORTCUTS.map((
|
|
112
|
+
children: SHORTCUTS.map((shortcut, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
114
113
|
className: "media-editor-keyboard-shortcuts-modal__shortcut",
|
|
115
114
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
116
115
|
className: "media-editor-keyboard-shortcuts-modal__shortcut-description",
|
|
117
|
-
children: description
|
|
118
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KeyCombinationDisplay, {
|
|
116
|
+
children: shortcut.description
|
|
117
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KeyCombinationDisplay, { ...shortcut })]
|
|
119
118
|
}, index))
|
|
120
119
|
})]
|
|
121
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__","displayShortcutList","shortcutAriaLabel","Fragment","Modal"],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["__","displayShortcutList","VisuallyHidden","shortcutAriaLabel","Fragment","Modal"],"sources":["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\nimport { VisuallyHidden } from '@wordpress/ui';\n\ntype KeyCombinationDisplayProps =\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string;\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel?: string;\n\t }\n\t| {\n\t\t\tkeyCombination: {\n\t\t\t\tcharacter: string[];\n\t\t\t\tmodifier?: WPKeycodeModifier | null;\n\t\t\t};\n\t\t\tlabel: string;\n\t };\n\ntype ShortcutEntry = KeyCombinationDisplayProps & {\n\tdescription: string;\n};\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Arrow keys' ),\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t},\n\t\tlabel: __( 'Shift + Arrow keys' ),\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n\tlabel,\n}: KeyCombinationDisplayProps ) {\n\tconst { character, modifier } = keyCombination;\n\tconst normalizedModifier = modifier ?? 'undefined';\n\tconst characters = Array.isArray( character ) ? character : [ character ];\n\tconst formatted = displayShortcutList[ normalizedModifier ](\n\t\tcharacters[ 0 ] ?? ''\n\t);\n\tconst prefix = formatted.slice( 0, -1 );\n\tconst keys = Array.isArray( character )\n\t\t? [ ...prefix, ...character ]\n\t\t: formatted;\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\tdir=\"ltr\"\n\t\t>\n\t\t\t<VisuallyHidden render={ <span /> }>\n\t\t\t\t{ label ||\n\t\t\t\t\tshortcutAriaLabel[ normalizedModifier ](\n\t\t\t\t\t\tcharacters.join( '' )\n\t\t\t\t\t) }\n\t\t\t</VisuallyHidden>\n\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t{ keys.map( ( key, keyIndex ) =>\n\t\t\t\t\tkey === '+' && keyIndex < prefix.length ? (\n\t\t\t\t\t\t<Fragment key={ keyIndex }>{ key }</Fragment>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<kbd\n\t\t\t\t\t\t\tkey={ keyIndex }\n\t\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ key }\n\t\t\t\t\t\t</kbd>\n\t\t\t\t\t)\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( shortcut, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ shortcut.description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay { ...shortcut } />\n\t\t\t\t\t</li>\n\t\t\t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,GAAAA,CACD,uDACD;EACE,CAAA,GAMH,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD;GACC,WAAU;GACV,MAAK;GAEH,UAAA,UAAU,KAAO,UAAU,UAC5B,iBAAA,GAAA,kBAAA,KAAA,CAAC,MAAD;IAEC,WAAU;IAFX,UAAA,CAIC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAAM,WAAU;KACb,UAAA,SAAS;IACN,CAAA,GACN,iBAAA,GAAA,kBAAA,IAAA,CAAC,uBAAD,EAAuB,GAAK,SAAY,CAAA,CACrC;GAPG,GAAA,KAOH,CACH;EACC,CAAA,CAEE;;AAET"}
|
|
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
11
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
15
|
-
key
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return to;
|
|
22
24
|
};
|
|
@@ -30,9 +32,9 @@ let _wordpress_i18n = require("@wordpress/i18n");
|
|
|
30
32
|
let _wordpress_keyboard_shortcuts = require("@wordpress/keyboard-shortcuts");
|
|
31
33
|
let _wordpress_notices = require("@wordpress/notices");
|
|
32
34
|
let ___media_editor_index_tsx = require("../media-editor/index.cjs");
|
|
33
|
-
___media_editor_index_tsx = __toESM(___media_editor_index_tsx);
|
|
34
35
|
let ______store_index_ts = require("../../store/index.cjs");
|
|
35
36
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
___media_editor_index_tsx = __toESM(___media_editor_index_tsx);
|
|
36
38
|
// packages/media-editor/src/components/media-editor-modal/index.tsx
|
|
37
39
|
/**
|
|
38
40
|
* The modal's footer chrome. The fine-rotation ruler and the image controls
|
|
@@ -78,6 +80,7 @@ function MediaEditorModal({ fields = [], form, aspectRatioPresets }) {
|
|
|
78
80
|
shouldCloseOnEsc: true,
|
|
79
81
|
noticesClassName: "media-editor-modal__snackbar",
|
|
80
82
|
noticesPortalElement: portalElement,
|
|
83
|
+
defaultPanel: "core/crop",
|
|
81
84
|
onClose: handleClose,
|
|
82
85
|
onSaved: ({ id: savedId, url, previous }) => {
|
|
83
86
|
if (savedId && onUpdate) onUpdate({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__","MediaEditor","useSelect","mediaEditorStore","useDispatch","noticesStore","ShortcutProvider","Modal"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["__","MediaEditor","useSelect","mediaEditorStore","useDispatch","noticesStore","ShortcutProvider","Modal"],"sources":["../../../src/components/media-editor-modal/index.tsx"],"sourcesContent":["import { Modal } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Field, Form } from '@wordpress/dataviews';\nimport type { KeyboardEvent as ReactKeyboardEvent } from 'react';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport MediaEditor from '../media-editor';\nimport type { Media } from '../media-editor-provider';\nimport { store as mediaEditorStore } from '../../store';\nimport type { MediaEditorModalUpdate } from '../../store/actions';\n\ninterface MediaEditorModalProps {\n\t/**\n\t * Attachment fields to render in the Details tab.\n\t *\n\t * Passed from the editor layer (which owns the `usePostFields` hook),\n\t * since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.\n\t */\n\tfields?: Field< Media >[];\n\t/**\n\t * Form the fields are laid out with in the Details tab. When omitted,\n\t * a default layout of the core attachment fields is used.\n\t */\n\tform?: Form;\n\t/**\n\t * Fixed aspect-ratio presets for image cropping. Free and Original are\n\t * always provided by the media editor.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * The modal's footer chrome. The fine-rotation ruler and the image controls\n * both live under the canvas (in `media-editor__content`), never here, so the\n * footer has one layout at every width: History on the left, Cancel/Save on\n * the right.\n */\nfunction ModalFooter() {\n\treturn (\n\t\t<div\n\t\t\tclassName=\"media-editor-modal__footer\"\n\t\t\trole=\"region\"\n\t\t\taria-label={ __( 'Editor actions' ) }\n\t\t>\n\t\t\t<MediaEditor.HistoryActions />\n\t\t\t<MediaEditor.SaveActions />\n\t\t</div>\n\t);\n}\n\nexport function MediaEditorModal( {\n\tfields = [],\n\tform,\n\taspectRatioPresets,\n}: MediaEditorModalProps ) {\n\tconst { isModalOpen, id, onUpdate, onUndo, onClose } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isOpen, getId, getOnUpdate, getOnUndo, getOnClose } =\n\t\t\t\tselect( mediaEditorStore );\n\t\t\treturn {\n\t\t\t\tisModalOpen: isOpen(),\n\t\t\t\tid: getId(),\n\t\t\t\tonUpdate: getOnUpdate(),\n\t\t\t\tonUndo: getOnUndo(),\n\t\t\t\tonClose: getOnClose(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst { closeMediaEditorModal } = useDispatch( mediaEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tif ( ! isModalOpen || ! id ) {\n\t\treturn null;\n\t}\n\n\tconst portalElement =\n\t\ttypeof document === 'undefined' ? null : document.body;\n\n\t// React synthetic events bubble through the React tree, not the DOM tree,\n\t// so a host `ShortcutProvider` higher up still receives keydown events\n\t// from inside this portaled modal. Stop propagation at the modal boundary\n\t// so host shortcuts (undo/redo, save, etc.) don't fire from within.\n\tconst stopKeyDownPropagation = (\n\t\tevent: ReactKeyboardEvent< HTMLDivElement >\n\t) => {\n\t\tevent.stopPropagation();\n\t};\n\n\tconst handleClose = () => {\n\t\tcloseMediaEditorModal();\n\t\tonClose?.();\n\t};\n\n\treturn (\n\t\t<MediaEditor\n\t\t\tid={ id }\n\t\t\tfields={ fields }\n\t\t\tform={ form }\n\t\t\taspectRatioPresets={ aspectRatioPresets }\n\t\t\tshouldCloseOnEsc\n\t\t\tnoticesClassName=\"media-editor-modal__snackbar\"\n\t\t\tnoticesPortalElement={ portalElement }\n\t\t\t// Rotate, flip and aspect ratio are only in the Crop panel for now.\n\t\t\t// This can go once they move under the canvas (#87282).\n\t\t\tdefaultPanel=\"core/crop\"\n\t\t\tonClose={ handleClose }\n\t\t\tonSaved={ ( { id: savedId, url, previous } ) => {\n\t\t\t\tif ( savedId && onUpdate ) {\n\t\t\t\t\tconst update: MediaEditorModalUpdate = {\n\t\t\t\t\t\tid: savedId,\n\t\t\t\t\t\turl,\n\t\t\t\t\t};\n\t\t\t\t\tonUpdate( update );\n\t\t\t\t}\n\t\t\t\thandleClose();\n\t\t\t\tif ( previous && savedId !== previous.id && onUpdate ) {\n\t\t\t\t\t// Intentionally unscoped: the modal is closing, so the\n\t\t\t\t\t// snackbar surfaces in the host editor (not the media\n\t\t\t\t\t// editor's `MEDIA_EDITOR_NOTICES_CONTEXT` region).\n\t\t\t\t\tcreateSuccessNotice( __( 'Image edited.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\t\tonClick: () => {\n\t\t\t\t\t\t\t\t\tif ( onUndo ) {\n\t\t\t\t\t\t\t\t\t\tonUndo();\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonUpdate( {\n\t\t\t\t\t\t\t\t\t\tid: previous.id,\n\t\t\t\t\t\t\t\t\t\turl: previous.url,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} }\n\t\t\trenderFrame={ ( {\n\t\t\t\tchildren,\n\t\t\t\tonRequestClose,\n\t\t\t\tonKeyDown,\n\t\t\t\tshouldCloseOnClickOutside,\n\t\t\t} ) => (\n\t\t\t\t<ShortcutProvider\n\t\t\t\t\tclassName=\"media-editor-modal__shortcut-scope\"\n\t\t\t\t\tonKeyDown={ stopKeyDownPropagation }\n\t\t\t\t>\n\t\t\t\t\t<Modal\n\t\t\t\t\t\tclassName=\"media-editor-modal\"\n\t\t\t\t\t\ttitle={ __( 'Edit media' ) }\n\t\t\t\t\t\tsize=\"fill\"\n\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\tshouldCloseOnClickOutside={ shouldCloseOnClickOutside }\n\t\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t\t\tonRequestClose={ onRequestClose }\n\t\t\t\t\t\theaderActions={\n\t\t\t\t\t\t\t<MediaEditor.HeaderActions showCloseButton />\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t<ModalFooter />\n\t\t\t\t\t</Modal>\n\t\t\t\t</ShortcutProvider>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default MediaEditorModal;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,cAAc;CACtB,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EACC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AqBD,gBAAAA,GAAAA,CAAI,eAAgB,GAAG;IAC3C,MAAM;IACN,SAAS,CACR;KACC,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,MAAO;KAClB,eAAe;MACd,IAAK,QAAS;OACb,OAAO;OACP;MACD;MACA,SAAU;OACT,IAAI,SAAS;OACb,KAAK,SAAS;MACf,CAAE;KACH;IACD,CACD;GACD,CAAE;EAEJ;EACA,cAAgB,EACf,UACA,gBACA,WACA,gCAEA,iBAAA,GAAA,kBAAA,IAAA,CAACM,8BAAAA,kBAAD;GACC,WAAU;GACV,WAAY;GAEZ,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,OAAD;IACC,WAAU;IACV,QAAA,GAAQP,gBAAAA,GAAAA,CAAI,YAAa;IACzB,MAAK;IACL,eAAgB;IACY;IAChB;IACK;IACjB,eACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,0BAAAA,QAAY,eAAb,EAA2B,iBAAA,KAAiB,CAAA;IAT9C,UAAA,CAYG,UACF,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAD,CAAc,CAAA,CACR;;EACU,CAAA;CAEnB,CAAA;AAEH"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
let _wordpress_element = require("@wordpress/element");
|
|
7
|
+
let _wordpress_a11y = require("@wordpress/a11y");
|
|
8
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
9
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
10
|
+
let _wordpress_ui = require("@wordpress/ui");
|
|
11
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
|
+
// packages/media-editor/src/components/media-editor-panel/error-boundary.tsx
|
|
13
|
+
function getMessage(title) {
|
|
14
|
+
return {
|
|
15
|
+
title: (0, _wordpress_i18n.sprintf)(
|
|
16
|
+
/** translators: %s: the panel's title. */
|
|
17
|
+
(0, _wordpress_i18n.__)("The \"%s\" panel could not be shown"),
|
|
18
|
+
title
|
|
19
|
+
),
|
|
20
|
+
description: (0, _wordpress_i18n.__)("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function CopyErrorButton({ error }) {
|
|
24
|
+
const ref = (0, _wordpress_compose.useCopyToClipboard)(() => {
|
|
25
|
+
const { message, stack } = error ?? {};
|
|
26
|
+
return [[error, message].find((part) => typeof part === "string" && part) ?? "An unknown error occurred.", stack].filter((part) => typeof part === "string" && part).join("\n\n");
|
|
27
|
+
});
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.ActionButton, {
|
|
29
|
+
variant: "outline",
|
|
30
|
+
ref,
|
|
31
|
+
children: (0, _wordpress_i18n._x)("Copy error", "button label")
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Keeps a panel's failure inside its tab, so the rest of the editor stays
|
|
36
|
+
* usable.
|
|
37
|
+
*/
|
|
38
|
+
var MediaEditorPanelErrorBoundary = class extends _wordpress_element.Component {
|
|
39
|
+
state = {
|
|
40
|
+
hasError: false,
|
|
41
|
+
error: null
|
|
42
|
+
};
|
|
43
|
+
static getDerivedStateFromError(error) {
|
|
44
|
+
return {
|
|
45
|
+
hasError: true,
|
|
46
|
+
error
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
componentDidCatch() {
|
|
50
|
+
const { title, description } = getMessage(this.props.title);
|
|
51
|
+
(0, _wordpress_a11y.speak)(`${title}. ${description}`, "assertive");
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
if (!this.state.hasError) return this.props.children;
|
|
55
|
+
const { title, description } = getMessage(this.props.title);
|
|
56
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Notice.Root, {
|
|
57
|
+
intent: "error",
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Title, { children: title }),
|
|
60
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Description, { children: description }),
|
|
61
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Actions, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyErrorButton, { error: this.state.error }) })
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
exports.default = MediaEditorPanelErrorBoundary;
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=error-boundary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.cjs","names":["sprintf","__","useCopyToClipboard","Notice","_x","Component","speak"],"sources":["../../../src/components/media-editor-panel/error-boundary.tsx"],"sourcesContent":["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { Notice } from '@wordpress/ui';\nimport type { ReactNode } from 'react';\n\ninterface Props {\n\ttitle: string;\n\tchildren: ReactNode;\n}\n\ninterface State {\n\t/** Separate from `error`: a panel can throw a falsy value. */\n\thasError: boolean;\n\terror: unknown;\n}\n\nfunction getMessage( title: string ) {\n\treturn {\n\t\ttitle: sprintf(\n\t\t\t/* translators: %s: the panel's title. */\n\t\t\t__( 'The \"%s\" panel could not be shown' ),\n\t\t\ttitle\n\t\t),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A component, because the copy hook cannot run in the class below.\nfunction CopyErrorButton( { error }: { error: unknown } ) {\n\tconst ref = useCopyToClipboard< HTMLButtonElement >( () => {\n\t\t// A boundary catches whatever was thrown, which is not always an `Error`.\n\t\tconst { message, stack } = ( error ?? {} ) as {\n\t\t\tmessage?: unknown;\n\t\t\tstack?: unknown;\n\t\t};\n\t\tconst text = [ error, message ].find(\n\t\t\t( part ) => typeof part === 'string' && part\n\t\t);\n\t\treturn [ text ?? 'An unknown error occurred.', stack ]\n\t\t\t.filter( ( part ) => typeof part === 'string' && part )\n\t\t\t.join( '\\n\\n' );\n\t} );\n\treturn (\n\t\t<Notice.ActionButton variant=\"outline\" ref={ ref }>\n\t\t\t{ _x( 'Copy error', 'button label' ) }\n\t\t</Notice.ActionButton>\n\t);\n}\n\n/**\n * Keeps a panel's failure inside its tab, so the rest of the editor stays\n * usable.\n */\nexport default class MediaEditorPanelErrorBoundary extends Component<\n\tProps,\n\tState\n> {\n\tstate: State = { hasError: false, error: null };\n\n\tstatic getDerivedStateFromError( error: unknown ): State {\n\t\treturn { hasError: true, error };\n\t}\n\n\tcomponentDidCatch() {\n\t\tconst { title, description } = getMessage( this.props.title );\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t}\n\n\trender() {\n\t\tif ( ! this.state.hasError ) {\n\t\t\treturn this.props.children;\n\t\t}\n\t\tconst { title, description } = getMessage( this.props.title );\n\t\treturn (\n\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t<Notice.Actions>\n\t\t\t\t\t<CopyErrorButton error={ this.state.error } />\n\t\t\t\t</Notice.Actions>\n\t\t\t</Notice.Root>\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAS,WAAY,OAAgB;CACpC,OAAO;EACN,QAAA,GAAOA,gBAAAA,QAAAA;;IAENC,GAAAA,gBAAAA,GAAAA,CAAI,qCAAoC;GACxC;EACD;EACA,cAAA,GAAaA,gBAAAA,GAAAA,CACZ,iHACD;CACD;AACD;AAGA,SAAS,gBAAiB,EAAE,SAA8B;CACzD,MAAM,OAAA,G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,OAAQ,KAAK,MAAM,MAAS,CAAA,EAC9B,CAAA;GACJ;;CAEf;AACD"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
let fast_deep_equal_es6_index_js = require("fast-deep-equal/es6/index.js");
|
|
30
|
+
let _wordpress_components = require("@wordpress/components");
|
|
31
|
+
let _wordpress_element = require("@wordpress/element");
|
|
32
|
+
let _wordpress_warning = require("@wordpress/warning");
|
|
33
|
+
let ______utils_index_ts = require("../../utils/index.cjs");
|
|
34
|
+
let __error_boundary_tsx = require("./error-boundary.cjs");
|
|
35
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
fast_deep_equal_es6_index_js = __toESM(fast_deep_equal_es6_index_js);
|
|
37
|
+
_wordpress_warning = __toESM(_wordpress_warning);
|
|
38
|
+
__error_boundary_tsx = __toESM(__error_boundary_tsx);
|
|
39
|
+
// packages/media-editor/src/components/media-editor-panel/index.tsx
|
|
40
|
+
const MediaEditorPanelsContext = (0, _wordpress_element.createContext)(null);
|
|
41
|
+
const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;
|
|
42
|
+
/** The `registerPlugin` scope the editor mounts. */
|
|
43
|
+
const MEDIA_EDITOR_PLUGIN_SCOPE = "media-editor";
|
|
44
|
+
/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */
|
|
45
|
+
const PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
|
|
46
|
+
function getPanelSlotName(name) {
|
|
47
|
+
return `MediaEditorPanel/${name}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The mounted panels of one editor.
|
|
51
|
+
*
|
|
52
|
+
* @return The panels, in the order they mounted, and the context value to provide to them.
|
|
53
|
+
*/
|
|
54
|
+
function useMediaEditorPanels() {
|
|
55
|
+
const [panels, setPanels] = (0, _wordpress_element.useState)({});
|
|
56
|
+
const ownersRef = (0, _wordpress_element.useRef)(/* @__PURE__ */ new Map());
|
|
57
|
+
const register = (0, _wordpress_element.useCallback)((panel, instance) => {
|
|
58
|
+
const owner = ownersRef.current.get(panel.name);
|
|
59
|
+
if (owner && owner !== instance) {
|
|
60
|
+
(0, _wordpress_warning.default)(`A media editor panel named "${panel.name}" is already registered, so this one is not shown. Give each panel a unique name.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
ownersRef.current.set(panel.name, instance);
|
|
64
|
+
setPanels((current) => {
|
|
65
|
+
const entry = current[panel.name];
|
|
66
|
+
if (entry?.owner === instance && (0, fast_deep_equal_es6_index_js.default)(entry.registration, panel)) return current;
|
|
67
|
+
return {
|
|
68
|
+
...current,
|
|
69
|
+
[panel.name]: {
|
|
70
|
+
registration: panel,
|
|
71
|
+
owner: instance
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}, []);
|
|
76
|
+
const unregister = (0, _wordpress_element.useCallback)((name, instance) => {
|
|
77
|
+
if (ownersRef.current.get(name) !== instance) return;
|
|
78
|
+
ownersRef.current.delete(name);
|
|
79
|
+
setPanels((current) => {
|
|
80
|
+
if (!Object.hasOwn(current, name)) return current;
|
|
81
|
+
const next = { ...current };
|
|
82
|
+
delete next[name];
|
|
83
|
+
return next;
|
|
84
|
+
});
|
|
85
|
+
}, []);
|
|
86
|
+
const owners = (0, _wordpress_element.useMemo)(() => Object.fromEntries(Object.entries(panels).map(([name, { owner }]) => [name, owner])), [panels]);
|
|
87
|
+
const contextValue = (0, _wordpress_element.useMemo)(() => ({
|
|
88
|
+
register,
|
|
89
|
+
unregister,
|
|
90
|
+
owners
|
|
91
|
+
}), [
|
|
92
|
+
register,
|
|
93
|
+
unregister,
|
|
94
|
+
owners
|
|
95
|
+
]);
|
|
96
|
+
return {
|
|
97
|
+
panels: (0, _wordpress_element.useMemo)(() => Object.values(panels).map(({ registration }) => registration), [panels]),
|
|
98
|
+
contextValue
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** A tab in the media editor's sidebar, filled with its children. */
|
|
102
|
+
function MediaEditorPanel({ name, title, mediaTypes, children }) {
|
|
103
|
+
const context = (0, _wordpress_element.useContext)(MediaEditorPanelsContext);
|
|
104
|
+
if (!context) throw new Error("MediaEditorPanel is rendered outside the media editor.");
|
|
105
|
+
const { register, unregister, owners } = context;
|
|
106
|
+
const [instance] = (0, _wordpress_element.useState)(() => ({}));
|
|
107
|
+
const owner = owners[name];
|
|
108
|
+
(0, _wordpress_element.useLayoutEffect)(() => {
|
|
109
|
+
if (!PANEL_NAME_PATTERN.test(name)) (0, _wordpress_warning.default)(`The media editor panel name "${name}" should be namespaced, like "my-plugin/my-panel": lowercase letters, digits and dashes, with one slash.`);
|
|
110
|
+
mediaTypes?.forEach((type) => {
|
|
111
|
+
if (!______utils_index_ts.MEDIA_TYPES.includes(type)) (0, _wordpress_warning.default)(`The media editor panel "${name}" lists the media type "${type}", which the editor does not know, so the panel would never show for it. Known types: ${______utils_index_ts.MEDIA_TYPES.join(", ")}.`);
|
|
112
|
+
});
|
|
113
|
+
register({
|
|
114
|
+
name,
|
|
115
|
+
title,
|
|
116
|
+
mediaTypes
|
|
117
|
+
}, instance);
|
|
118
|
+
}, [
|
|
119
|
+
name,
|
|
120
|
+
title,
|
|
121
|
+
mediaTypes,
|
|
122
|
+
register,
|
|
123
|
+
owner,
|
|
124
|
+
instance
|
|
125
|
+
]);
|
|
126
|
+
(0, _wordpress_element.useLayoutEffect)(() => {
|
|
127
|
+
return () => unregister(name, instance);
|
|
128
|
+
}, [
|
|
129
|
+
name,
|
|
130
|
+
unregister,
|
|
131
|
+
instance
|
|
132
|
+
]);
|
|
133
|
+
if (owner !== instance) return null;
|
|
134
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Fill, {
|
|
135
|
+
name: getPanelSlotName(name),
|
|
136
|
+
children: (fillProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__error_boundary_tsx.default, {
|
|
137
|
+
title,
|
|
138
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaEditorPanelContent, {
|
|
139
|
+
fillProps,
|
|
140
|
+
children
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Calls a function child inside the error boundary, so one that throws is
|
|
147
|
+
* caught there.
|
|
148
|
+
*/
|
|
149
|
+
function MediaEditorPanelContent({ fillProps, children }) {
|
|
150
|
+
return typeof children === "function" ? children(fillProps) : children;
|
|
151
|
+
}
|
|
152
|
+
exports.MEDIA_EDITOR_PLUGIN_SCOPE = MEDIA_EDITOR_PLUGIN_SCOPE;
|
|
153
|
+
exports.MediaEditorPanelsProvider = MediaEditorPanelsProvider;
|
|
154
|
+
exports.default = MediaEditorPanel;
|
|
155
|
+
exports.getPanelSlotName = getPanelSlotName;
|
|
156
|
+
exports.useMediaEditorPanels = useMediaEditorPanels;
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useState","useRef","useCallback","warning","fastDeepEqual","useMemo","useContext","useLayoutEffect","MEDIA_TYPES","Fill","MediaEditorPanelErrorBoundary"],"sources":["../../../src/components/media-editor-panel/index.tsx"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport { Fill } from '@wordpress/components';\nimport {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport warning from '@wordpress/warning';\nimport type { ReactNode } from 'react';\nimport { MEDIA_TYPES, type MediaType } from '../../utils';\nimport MediaEditorPanelErrorBoundary from './error-boundary';\n\nexport interface MediaEditorPanelFillProps {\n\t/** `true` while a save is running. */\n\tdisabled: boolean;\n}\n\nexport interface MediaEditorPanelRegistration {\n\t/** Unique, namespaced name, for example `core/crop`. */\n\tname: string;\n\t/** Tab label. */\n\ttitle: string;\n\t/** Omitted means every type. */\n\tmediaTypes?: readonly MediaType[ 'type' ][];\n}\n\nexport interface MediaEditorPanelProps extends MediaEditorPanelRegistration {\n\tchildren:\n\t\tReactNode | ( ( fillProps: MediaEditorPanelFillProps ) => ReactNode );\n}\n\ninterface MediaEditorPanelsContextValue {\n\tregister: ( panel: MediaEditorPanelRegistration, instance: object ) => void;\n\tunregister: ( name: string, instance: object ) => void;\n\t/** Panel name to the mounted panel that has it. */\n\towners: Record< string, object >;\n}\n\nconst MediaEditorPanelsContext =\n\tcreateContext< MediaEditorPanelsContextValue | null >( null );\n\nexport const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;\n\n/** The `registerPlugin` scope the editor mounts. */\nexport const MEDIA_EDITOR_PLUGIN_SCOPE = 'media-editor';\n\n/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */\nconst PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\\/[a-z][a-z0-9-]*$/;\n\nexport function getPanelSlotName( name: string ) {\n\treturn `MediaEditorPanel/${ name }`;\n}\n\n/**\n * The mounted panels of one editor.\n *\n * @return The panels, in the order they mounted, and the context value to provide to them.\n */\nexport function useMediaEditorPanels() {\n\tconst [ panels, setPanels ] = useState<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t{ registration: MediaEditorPanelRegistration; owner: object }\n\t\t>\n\t>( {} );\n\t// The first panel to announce a name keeps it. A ref, so panels\n\t// announcing in the same commit see each other.\n\tconst ownersRef = useRef( new Map< string, object >() );\n\tconst register = useCallback(\n\t\t( panel: MediaEditorPanelRegistration, instance: object ) => {\n\t\t\tconst owner = ownersRef.current.get( panel.name );\n\t\t\tif ( owner && owner !== instance ) {\n\t\t\t\twarning(\n\t\t\t\t\t`A media editor panel named \"${ panel.name }\" is already registered, so this one is not shown. Give each panel a unique name.`\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\townersRef.current.set( panel.name, instance );\n\t\t\tsetPanels( ( current ) => {\n\t\t\t\t// Skip unchanged details: an inline `mediaTypes` array would\n\t\t\t\t// otherwise re-render the editor and the panel in a loop.\n\t\t\t\tconst entry = current[ panel.name ];\n\t\t\t\tif (\n\t\t\t\t\tentry?.owner === instance &&\n\t\t\t\t\tfastDeepEqual( entry.registration, panel )\n\t\t\t\t) {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...current,\n\t\t\t\t\t[ panel.name ]: { registration: panel, owner: instance },\n\t\t\t\t};\n\t\t\t} );\n\t\t},\n\t\t[]\n\t);\n\tconst unregister = useCallback( ( name: string, instance: object ) => {\n\t\tif ( ownersRef.current.get( name ) !== instance ) {\n\t\t\treturn;\n\t\t}\n\t\townersRef.current.delete( name );\n\t\tsetPanels( ( current ) => {\n\t\t\tif ( ! Object.hasOwn( current, name ) ) {\n\t\t\t\treturn current;\n\t\t\t}\n\t\t\tconst next = { ...current };\n\t\t\tdelete next[ name ];\n\t\t\treturn next;\n\t\t} );\n\t}, [] );\n\tconst owners = useMemo(\n\t\t() =>\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( panels ).map( ( [ name, { owner } ] ) => [\n\t\t\t\t\tname,\n\t\t\t\t\towner,\n\t\t\t\t] )\n\t\t\t),\n\t\t[ panels ]\n\t);\n\tconst contextValue = useMemo(\n\t\t() => ( { register, unregister, owners } ),\n\t\t[ register, unregister, owners ]\n\t);\n\tconst registrations = useMemo(\n\t\t() =>\n\t\t\tObject.values( panels ).map( ( { registration } ) => registration ),\n\t\t[ panels ]\n\t);\n\treturn { panels: registrations, contextValue };\n}\n\n/** A tab in the media editor's sidebar, filled with its children. */\nexport default function MediaEditorPanel( {\n\tname,\n\ttitle,\n\tmediaTypes,\n\tchildren,\n}: MediaEditorPanelProps ) {\n\tconst context = useContext( MediaEditorPanelsContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'MediaEditorPanel is rendered outside the media editor.'\n\t\t);\n\t}\n\tconst { register, unregister, owners } = context;\n\t// Identifies this mounted panel.\n\tconst [ instance ] = useState( () => ( {} ) );\n\tconst owner = owners[ name ];\n\t// Layout effects, so the tab exists before the sidebar paints. Two of\n\t// them: details may change on any render, but the tab only goes when\n\t// the panel unmounts or changes its name.\n\tuseLayoutEffect( () => {\n\t\tif ( ! PANEL_NAME_PATTERN.test( name ) ) {\n\t\t\twarning(\n\t\t\t\t`The media editor panel name \"${ name }\" should be namespaced, like \"my-plugin/my-panel\": lowercase letters, digits and dashes, with one slash.`\n\t\t\t);\n\t\t}\n\t\tmediaTypes?.forEach( ( type ) => {\n\t\t\tif ( ! MEDIA_TYPES.includes( type ) ) {\n\t\t\t\twarning(\n\t\t\t\t\t`The media editor panel \"${ name }\" lists the media type \"${ type }\", which the editor does not know, so the panel would never show for it. Known types: ${ MEDIA_TYPES.join( ', ' ) }.`\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t\tregister( { name, title, mediaTypes }, instance );\n\t\t// When two panels share a name, the second waits for the first to\n\t\t// unmount. `owner` changes at that point, which re-runs this effect\n\t\t// and gives the second panel the tab.\n\t}, [ name, title, mediaTypes, register, owner, instance ] );\n\tuseLayoutEffect( () => {\n\t\treturn () => unregister( name, instance );\n\t}, [ name, unregister, instance ] );\n\n\tif ( owner !== instance ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Fill name={ getPanelSlotName( name ) }>\n\t\t\t{ ( fillProps ) => (\n\t\t\t\t<MediaEditorPanelErrorBoundary title={ title }>\n\t\t\t\t\t<MediaEditorPanelContent\n\t\t\t\t\t\t// The slot passes exactly these props; `Fill` types them loosely.\n\t\t\t\t\t\tfillProps={ fillProps as MediaEditorPanelFillProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</MediaEditorPanelContent>\n\t\t\t\t</MediaEditorPanelErrorBoundary>\n\t\t\t) }\n\t\t</Fill>\n\t);\n}\n\n/**\n * Calls a function child inside the error boundary, so one that throws is\n * caught there.\n */\nfunction MediaEditorPanelContent( {\n\tfillProps,\n\tchildren,\n}: {\n\tfillProps: MediaEditorPanelFillProps;\n\tchildren: MediaEditorPanelProps[ 'children' ];\n} ) {\n\treturn typeof children === 'function' ? children( fillProps ) : children;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,4BAAA,GACLA,mBAAAA,cAAAA,CAAuD,IAAK;AAE7D,MAAa,4BAA4B,yBAAyB;;AAGlE,MAAa,4BAA4B;;AAGzC,MAAM,qBAAq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