@wordpress/block-library 8.12.1 → 8.12.3
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/build/avatar/index.js +1 -1
- package/build/buttons/edit.js +5 -1
- package/build/buttons/edit.js.map +1 -1
- package/build/image/edit.js +0 -4
- package/build/image/edit.js.map +1 -1
- package/build/image/image.js +96 -43
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +6 -0
- package/build/image/index.js.map +1 -1
- package/build/image/save.js +6 -1
- package/build/image/save.js.map +1 -1
- package/build/image/utils.js +18 -0
- package/build/image/utils.js.map +1 -1
- package/build/query-pagination-numbers/index.js +1 -1
- package/build/site-tagline/icon.js +1 -1
- package/build/site-tagline/icon.js.map +1 -1
- package/build-module/avatar/index.js +1 -1
- package/build-module/buttons/edit.js +5 -1
- package/build-module/buttons/edit.js.map +1 -1
- package/build-module/image/edit.js +0 -4
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/image.js +96 -46
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +6 -0
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/save.js +6 -1
- package/build-module/image/save.js.map +1 -1
- package/build-module/image/utils.js +16 -0
- package/build-module/image/utils.js.map +1 -1
- package/build-module/query-pagination-numbers/index.js +1 -1
- package/build-module/site-tagline/icon.js +1 -1
- package/build-module/site-tagline/icon.js.map +1 -1
- package/package.json +8 -8
- package/src/avatar/block.json +1 -1
- package/src/buttons/edit.js +2 -2
- package/src/image/block.json +6 -0
- package/src/image/edit.js +0 -4
- package/src/image/image.js +130 -62
- package/src/image/save.js +7 -1
- package/src/image/utils.js +16 -0
- package/src/latest-posts/index.php +1 -1
- package/src/navigation/index.php +24 -10
- package/src/query-pagination-numbers/block.json +1 -1
- package/src/site-tagline/icon.js +1 -1
package/build/image/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/image/index.js"],"names":["name","metadata","settings","icon","example","attributes","sizeSlug","url","caption","__experimentalLabel","context","alt","getEditWrapperProps","align","transforms","edit","save","deprecated","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAdA;AACA;AACA;;AAIA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/image/index.js"],"names":["name","metadata","settings","icon","example","attributes","sizeSlug","url","caption","__experimentalLabel","context","alt","getEditWrapperProps","align","transforms","edit","save","deprecated","init"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAdA;AACA;AACA;;AAIA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAIO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,YADuB;AAEvBC,EAAAA,OAAO,EAAE;AACRC,IAAAA,UAAU,EAAE;AACXC,MAAAA,QAAQ,EAAE,OADC;AAEXC,MAAAA,GAAG,EAAE,8CAFM;AAGX;AACAC,MAAAA,OAAO,EAAE,cAAI,8CAAJ;AAJE;AADJ,GAFc;;AAUvBC,EAAAA,mBAAmB,CAAEJ,UAAF,EAAc;AAAEK,IAAAA;AAAF,GAAd,EAA4B;AAC9C,QAAKA,OAAO,KAAK,eAAjB,EAAmC;AAClC,YAAM;AAAEF,QAAAA,OAAF;AAAWG,QAAAA,GAAX;AAAgBJ,QAAAA;AAAhB,UAAwBF,UAA9B;;AAEA,UAAK,CAAEE,GAAP,EAAa;AACZ,eAAO,cAAI,OAAJ,CAAP;AACA;;AAED,UAAK,CAAEI,GAAP,EAAa;AACZ,eAAOH,OAAO,IAAI,EAAlB;AACA,OATiC,CAWlC;AACA;;;AACA,aAAOG,GAAG,IAAKH,OAAO,GAAG,OAAOA,OAAV,GAAoB,EAAhC,CAAV;AACA;AACD,GA1BsB;;AA2BvBI,EAAAA,mBAAmB,CAAEP,UAAF,EAAe;AACjC,WAAO;AACN,oBAAcA,UAAU,CAACQ;AADnB,KAAP;AAGA,GA/BsB;;AAgCvBC,EAAAA,UAAU,EAAVA,mBAhCuB;AAiCvBC,EAAAA,IAAI,EAAJA,aAjCuB;AAkCvBC,EAAAA,IAAI,EAAJA,aAlCuB;AAmCvBC,EAAAA,UAAU,EAAVA;AAnCuB,CAAjB;;;AAsCA,MAAMC,IAAI,GAAG,MAAM,wBAAW;AAAElB,EAAAA,IAAF;AAAQC,EAAAA,QAAR;AAAkBC,EAAAA;AAAlB,CAAX,CAAnB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { image as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tsizeSlug: 'large',\n\t\t\turl: 'https://s.w.org/images/core/5.3/MtBlanc1.jpg',\n\t\t\t// translators: Caption accompanying an image of the Mont Blanc, which serves as an example for the Image block.\n\t\t\tcaption: __( 'Mont Blanc appears—still, snowy, and serene.' ),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tif ( context === 'accessibility' ) {\n\t\t\tconst { caption, alt, url } = attributes;\n\n\t\t\tif ( ! url ) {\n\t\t\t\treturn __( 'Empty' );\n\t\t\t}\n\n\t\t\tif ( ! alt ) {\n\t\t\t\treturn caption || '';\n\t\t\t}\n\n\t\t\t// This is intended to be read by a screen reader.\n\t\t\t// A period simply means a pause, no need to translate it.\n\t\t\treturn alt + ( caption ? '. ' + caption : '' );\n\t\t}\n\t},\n\tgetEditWrapperProps( attributes ) {\n\t\treturn {\n\t\t\t'data-align': attributes.align,\n\t\t};\n\t},\n\ttransforms,\n\tedit,\n\tsave,\n\tdeprecated,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"]}
|
package/build/image/save.js
CHANGED
|
@@ -33,6 +33,8 @@ function save({
|
|
|
33
33
|
linkClass,
|
|
34
34
|
width,
|
|
35
35
|
height,
|
|
36
|
+
aspectRatio,
|
|
37
|
+
scale,
|
|
36
38
|
id,
|
|
37
39
|
linkTarget,
|
|
38
40
|
sizeSlug,
|
|
@@ -53,7 +55,10 @@ function save({
|
|
|
53
55
|
src: url,
|
|
54
56
|
alt: alt,
|
|
55
57
|
className: imageClasses || undefined,
|
|
56
|
-
style: borderProps.style,
|
|
58
|
+
style: { ...borderProps.style,
|
|
59
|
+
aspectRatio,
|
|
60
|
+
objectFit: scale
|
|
61
|
+
},
|
|
57
62
|
width: width,
|
|
58
63
|
height: height,
|
|
59
64
|
title: title
|
package/build/image/save.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/image/save.js"],"names":["save","attributes","url","alt","caption","align","href","rel","linkClass","width","height","id","linkTarget","sizeSlug","title","newRel","undefined","borderProps","classes","className","style","Object","keys","length","imageClasses","image","figure","RichText","isEmpty","useBlockProps"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAQe,SAASA,IAAT,CAAe;AAAEC,EAAAA;AAAF,CAAf,EAAgC;AAC9C,QAAM;AACLC,IAAAA,GADK;AAELC,IAAAA,GAFK;AAGLC,IAAAA,OAHK;AAILC,IAAAA,KAJK;AAKLC,IAAAA,IALK;AAMLC,IAAAA,GANK;AAOLC,IAAAA,SAPK;AAQLC,IAAAA,KARK;AASLC,IAAAA,MATK;AAULC,IAAAA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/image/save.js"],"names":["save","attributes","url","alt","caption","align","href","rel","linkClass","width","height","aspectRatio","scale","id","linkTarget","sizeSlug","title","newRel","undefined","borderProps","classes","className","style","Object","keys","length","imageClasses","image","objectFit","figure","RichText","isEmpty","useBlockProps"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;AAQe,SAASA,IAAT,CAAe;AAAEC,EAAAA;AAAF,CAAf,EAAgC;AAC9C,QAAM;AACLC,IAAAA,GADK;AAELC,IAAAA,GAFK;AAGLC,IAAAA,OAHK;AAILC,IAAAA,KAJK;AAKLC,IAAAA,IALK;AAMLC,IAAAA,GANK;AAOLC,IAAAA,SAPK;AAQLC,IAAAA,KARK;AASLC,IAAAA,MATK;AAULC,IAAAA,WAVK;AAWLC,IAAAA,KAXK;AAYLC,IAAAA,EAZK;AAaLC,IAAAA,UAbK;AAcLC,IAAAA,QAdK;AAeLC,IAAAA;AAfK,MAgBFf,UAhBJ;AAkBA,QAAMgB,MAAM,GAAG,CAAEV,GAAF,GAAQW,SAAR,GAAoBX,GAAnC;AACA,QAAMY,WAAW,GAAG,0DAA2BlB,UAA3B,CAApB;AAEA,QAAMmB,OAAO,GAAG,yBAAY;AAC3B,KAAG,QAAQf,KAAO,EAAlB,GAAuBA,KADI;AAE3B,KAAG,QAAQU,QAAU,EAArB,GAA0BA,QAFC;AAG3B,kBAAcN,KAAK,IAAIC,MAHI;AAI3B,yBACC,CAAC,CAAES,WAAW,CAACE,SAAf,IACEF,WAAW,CAACG,KAAZ,IACDC,MAAM,CAACC,IAAP,CAAaL,WAAW,CAACG,KAAzB,EAAiCG,MAAjC,GAA0C;AAPjB,GAAZ,CAAhB;AAUA,QAAMC,YAAY,GAAG,yBAAYP,WAAW,CAACE,SAAxB,EAAmC;AACvD,KAAG,YAAYR,EAAI,EAAnB,GAAwB,CAAC,CAAEA;AAD4B,GAAnC,CAArB;AAIA,QAAMc,KAAK,GACV;AACC,IAAA,GAAG,EAAGzB,GADP;AAEC,IAAA,GAAG,EAAGC,GAFP;AAGC,IAAA,SAAS,EAAGuB,YAAY,IAAIR,SAH7B;AAIC,IAAA,KAAK,EAAG,EACP,GAAGC,WAAW,CAACG,KADR;AAEPX,MAAAA,WAFO;AAGPiB,MAAAA,SAAS,EAAEhB;AAHJ,KAJT;AASC,IAAA,KAAK,EAAGH,KATT;AAUC,IAAA,MAAM,EAAGC,MAVV;AAWC,IAAA,KAAK,EAAGM;AAXT,IADD;AAgBA,QAAMa,MAAM,GACX,qDACGvB,IAAI,GACL;AACC,IAAA,SAAS,EAAGE,SADb;AAEC,IAAA,IAAI,EAAGF,IAFR;AAGC,IAAA,MAAM,EAAGQ,UAHV;AAIC,IAAA,GAAG,EAAGG;AAJP,KAMGU,KANH,CADK,GAULA,KAXF,EAaG,CAAEG,sBAASC,OAAT,CAAkB3B,OAAlB,CAAF,IACD,4BAAC,qBAAD,CAAU,OAAV;AACC,IAAA,SAAS,EAAG,oDAAmC,SAAnC,CADb;AAEC,IAAA,OAAO,EAAC,YAFT;AAGC,IAAA,KAAK,EAAGA;AAHT,IAdF,CADD;AAwBA,SACC,2CAAa4B,2BAAchC,IAAd,CAAoB;AAAEqB,MAAAA,SAAS,EAAED;AAAb,KAApB;AAAb,KACGS,MADH,CADD;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tRichText,\n\tuseBlockProps,\n\t__experimentalGetElementClassName,\n\t__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,\n} from '@wordpress/block-editor';\n\nexport default function save( { attributes } ) {\n\tconst {\n\t\turl,\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\thref,\n\t\trel,\n\t\tlinkClass,\n\t\twidth,\n\t\theight,\n\t\taspectRatio,\n\t\tscale,\n\t\tid,\n\t\tlinkTarget,\n\t\tsizeSlug,\n\t\ttitle,\n\t} = attributes;\n\n\tconst newRel = ! rel ? undefined : rel;\n\tconst borderProps = getBorderClassesAndStyles( attributes );\n\n\tconst classes = classnames( {\n\t\t[ `align${ align }` ]: align,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'is-resized': width || height,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst imageClasses = classnames( borderProps.className, {\n\t\t[ `wp-image-${ id }` ]: !! id,\n\t} );\n\n\tconst image = (\n\t\t<img\n\t\t\tsrc={ url }\n\t\t\talt={ alt }\n\t\t\tclassName={ imageClasses || undefined }\n\t\t\tstyle={ {\n\t\t\t\t...borderProps.style,\n\t\t\t\taspectRatio,\n\t\t\t\tobjectFit: scale,\n\t\t\t} }\n\t\t\twidth={ width }\n\t\t\theight={ height }\n\t\t\ttitle={ title }\n\t\t/>\n\t);\n\n\tconst figure = (\n\t\t<>\n\t\t\t{ href ? (\n\t\t\t\t<a\n\t\t\t\t\tclassName={ linkClass }\n\t\t\t\t\thref={ href }\n\t\t\t\t\ttarget={ linkTarget }\n\t\t\t\t\trel={ newRel }\n\t\t\t\t>\n\t\t\t\t\t{ image }\n\t\t\t\t</a>\n\t\t\t) : (\n\t\t\t\timage\n\t\t\t) }\n\t\t\t{ ! RichText.isEmpty( caption ) && (\n\t\t\t\t<RichText.Content\n\t\t\t\t\tclassName={ __experimentalGetElementClassName( 'caption' ) }\n\t\t\t\t\ttagName=\"figcaption\"\n\t\t\t\t\tvalue={ caption }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<figure { ...useBlockProps.save( { className: classes } ) }>\n\t\t\t{ figure }\n\t\t</figure>\n\t);\n}\n"]}
|
package/build/image/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.evalAspectRatio = evalAspectRatio;
|
|
6
7
|
exports.getImageSizeAttributes = getImageSizeAttributes;
|
|
7
8
|
exports.getUpdatedLinkTargetSettings = getUpdatedLinkTargetSettings;
|
|
8
9
|
exports.removeNewTabRel = removeNewTabRel;
|
|
@@ -12,6 +13,23 @@ var _constants = require("./constants");
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Evaluates a CSS aspect-ratio property value as a number.
|
|
19
|
+
*
|
|
20
|
+
* Degenerate or invalid ratios behave as 'auto'. And 'auto' ratios return NaN.
|
|
21
|
+
*
|
|
22
|
+
* @see https://drafts.csswg.org/css-sizing-4/#aspect-ratio
|
|
23
|
+
*
|
|
24
|
+
* @param {string} value CSS aspect-ratio property value.
|
|
25
|
+
* @return {number} Numerical aspect ratio or NaN if invalid.
|
|
26
|
+
*/
|
|
27
|
+
function evalAspectRatio(value) {
|
|
28
|
+
const [width, height = 1] = value.split('/').map(Number);
|
|
29
|
+
const aspectRatio = width / height;
|
|
30
|
+
return aspectRatio === Infinity || aspectRatio === 0 ? NaN : aspectRatio;
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
function removeNewTabRel(currentRel) {
|
|
16
34
|
let newRel = currentRel;
|
|
17
35
|
|
package/build/image/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/image/utils.js"],"names":["removeNewTabRel","currentRel","newRel","undefined","NEW_TAB_REL","forEach","relVal","regExp","RegExp","replace","trim","getUpdatedLinkTargetSettings","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/image/utils.js"],"names":["evalAspectRatio","value","width","height","split","map","Number","aspectRatio","Infinity","NaN","removeNewTabRel","currentRel","newRel","undefined","NEW_TAB_REL","forEach","relVal","regExp","RegExp","replace","trim","getUpdatedLinkTargetSettings","rel","linkTarget","updatedRel","getImageSizeAttributes","image","size","url","media_details","sizes","source_url","sizeSlug"],"mappings":";;;;;;;;;;AAGA;;AAHA;AAC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AACA,GAFD,MAEO;AACNW,IAAAA,UAAU,GAAGd,eAAe,CAAEY,GAAF,CAA5B;AACA;;AAED,SAAO;AACNC,IAAAA,UADM;AAEND,IAAAA,GAAG,EAAEE;AAFC,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AACrD,QAAMC,GAAG,GAAGF,KAAK,EAAEG,aAAP,EAAsBC,KAAtB,GAA+BH,IAA/B,GAAuCI,UAAnD;;AAEA,MAAKH,GAAL,EAAW;AACV,WAAO;AAAEA,MAAAA,GAAF;AAAO1B,MAAAA,KAAK,EAAEW,SAAd;AAAyBV,MAAAA,MAAM,EAAEU,SAAjC;AAA4CmB,MAAAA,QAAQ,EAAEL;AAAtD,KAAP;AACA;;AAED,SAAO,EAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { NEW_TAB_REL } from './constants';\n\n/**\n * Evaluates a CSS aspect-ratio property value as a number.\n *\n * Degenerate or invalid ratios behave as 'auto'. And 'auto' ratios return NaN.\n *\n * @see https://drafts.csswg.org/css-sizing-4/#aspect-ratio\n *\n * @param {string} value CSS aspect-ratio property value.\n * @return {number} Numerical aspect ratio or NaN if invalid.\n */\nexport function evalAspectRatio( value ) {\n\tconst [ width, height = 1 ] = value.split( '/' ).map( Number );\n\tconst aspectRatio = width / height;\n\treturn aspectRatio === Infinity || aspectRatio === 0 ? NaN : aspectRatio;\n}\n\nexport function removeNewTabRel( currentRel ) {\n\tlet newRel = currentRel;\n\n\tif ( currentRel !== undefined && newRel ) {\n\t\tNEW_TAB_REL.forEach( ( relVal ) => {\n\t\t\tconst regExp = new RegExp( '\\\\b' + relVal + '\\\\b', 'gi' );\n\t\t\tnewRel = newRel.replace( regExp, '' );\n\t\t} );\n\n\t\t// Only trim if NEW_TAB_REL values was replaced.\n\t\tif ( newRel !== currentRel ) {\n\t\t\tnewRel = newRel.trim();\n\t\t}\n\n\t\tif ( ! newRel ) {\n\t\t\tnewRel = undefined;\n\t\t}\n\t}\n\n\treturn newRel;\n}\n\n/**\n * Helper to get the link target settings to be stored.\n *\n * @param {boolean} value The new link target value.\n * @param {Object} attributes Block attributes.\n * @param {Object} attributes.rel Image block's rel attribute.\n *\n * @return {Object} Updated link target settings.\n */\nexport function getUpdatedLinkTargetSettings( value, { rel } ) {\n\tconst linkTarget = value ? '_blank' : undefined;\n\n\tlet updatedRel;\n\tif ( ! linkTarget && ! rel ) {\n\t\tupdatedRel = undefined;\n\t} else {\n\t\tupdatedRel = removeNewTabRel( rel );\n\t}\n\n\treturn {\n\t\tlinkTarget,\n\t\trel: updatedRel,\n\t};\n}\n\n/**\n * Determines new Image block attributes size selection.\n *\n * @param {Object} image Media file object for gallery image.\n * @param {string} size Selected size slug to apply.\n */\nexport function getImageSizeAttributes( image, size ) {\n\tconst url = image?.media_details?.sizes?.[ size ]?.source_url;\n\n\tif ( url ) {\n\t\treturn { url, width: undefined, height: undefined, sizeSlug: size };\n\t}\n\n\treturn {};\n}\n"]}
|
|
@@ -17,7 +17,7 @@ var _default = (0, _element.createElement)(_components.SVG, {
|
|
|
17
17
|
width: "24",
|
|
18
18
|
height: "24"
|
|
19
19
|
}, (0, _element.createElement)(_components.Path, {
|
|
20
|
-
d: "M4
|
|
20
|
+
d: "M4 10.5h16V9H4v1.5ZM4 15h9v-1.5H4V15Z"
|
|
21
21
|
}));
|
|
22
22
|
|
|
23
23
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/site-tagline/icon.js"],"names":[],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;eAIC,4BAAC,eAAD;AAAK,EAAA,KAAK,EAAC,4BAAX;AAAwC,EAAA,KAAK,EAAC,IAA9C;AAAmD,EAAA,MAAM,EAAC;AAA1D,GACC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EADD,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\n\nexport default (\n\t<SVG xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\">\n\t\t<Path d=\"M4
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/site-tagline/icon.js"],"names":[],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;eAIC,4BAAC,eAAD;AAAK,EAAA,KAAK,EAAC,4BAAX;AAAwC,EAAA,KAAK,EAAC,IAA9C;AAAmD,EAAA,MAAM,EAAC;AAA1D,GACC,4BAAC,gBAAD;AAAM,EAAA,CAAC,EAAC;AAAR,EADD,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/components';\n\nexport default (\n\t<SVG xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\">\n\t\t<Path d=\"M4 10.5h16V9H4v1.5ZM4 15h9v-1.5H4V15Z\" />\n\t</SVG>\n);\n"]}
|
|
@@ -25,8 +25,11 @@ function ButtonsEdit({
|
|
|
25
25
|
attributes,
|
|
26
26
|
className
|
|
27
27
|
}) {
|
|
28
|
+
var _layout$orientation;
|
|
29
|
+
|
|
28
30
|
const {
|
|
29
31
|
fontSize,
|
|
32
|
+
layout,
|
|
30
33
|
style
|
|
31
34
|
} = attributes;
|
|
32
35
|
const blockProps = useBlockProps({
|
|
@@ -46,7 +49,8 @@ function ButtonsEdit({
|
|
|
46
49
|
template: [[buttonBlockName, {
|
|
47
50
|
className: preferredStyle && `is-style-${preferredStyle}`
|
|
48
51
|
}]],
|
|
49
|
-
templateInsertUpdatesSelection: true
|
|
52
|
+
templateInsertUpdatesSelection: true,
|
|
53
|
+
orientation: (_layout$orientation = layout?.orientation) !== null && _layout$orientation !== void 0 ? _layout$orientation : 'horizontal'
|
|
50
54
|
});
|
|
51
55
|
return createElement("div", { ...innerBlocksProps
|
|
52
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/buttons/edit.js"],"names":["classnames","useBlockProps","useInnerBlocksProps","store","blockEditorStore","useSelect","name","buttonBlockName","ALLOWED_BLOCKS","DEFAULT_BLOCK","attributesToCopy","ButtonsEdit","attributes","className","fontSize","style","blockProps","typography","preferredStyle","select","preferredStyleVariations","getSettings","__experimentalPreferredStyleVariations","value","innerBlocksProps","allowedBlocks","__experimentalDefaultBlock","__experimentalDirectInsert","template","templateInsertUpdatesSelection"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,aADD,EAECC,mBAFD,EAGCC,KAAK,IAAIC,gBAHV,QAIO,yBAJP;AAKA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,IAAI,IAAIC,eAAjB,QAAwC,WAAxC;AAEA,MAAMC,cAAc,GAAG,CAAED,eAAF,CAAvB;AAEA,MAAME,aAAa,GAAG;AACrBH,EAAAA,IAAI,EAAEC,eADe;AAErBG,EAAAA,gBAAgB,EAAE,CACjB,iBADiB,EAEjB,QAFiB,EAGjB,WAHiB,EAIjB,YAJiB,EAKjB,UALiB,EAMjB,UANiB,EAOjB,OAPiB,EAQjB,WARiB,EASjB,OATiB;AAFG,CAAtB;;AAeA,SAASC,WAAT,CAAsB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,CAAtB,EAAkD;AACjD,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/buttons/edit.js"],"names":["classnames","useBlockProps","useInnerBlocksProps","store","blockEditorStore","useSelect","name","buttonBlockName","ALLOWED_BLOCKS","DEFAULT_BLOCK","attributesToCopy","ButtonsEdit","attributes","className","fontSize","layout","style","blockProps","typography","preferredStyle","select","preferredStyleVariations","getSettings","__experimentalPreferredStyleVariations","value","innerBlocksProps","allowedBlocks","__experimentalDefaultBlock","__experimentalDirectInsert","template","templateInsertUpdatesSelection","orientation"],"mappings":";;AAAA;A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AA,0BAA0B,EAAE,IAH6B;AAIzDC,IAAAA,QAAQ,EAAE,CACT,CACCtB,eADD,EAEC;AAAEM,MAAAA,SAAS,EAAEM,cAAc,IAAK,YAAYA,cAAgB;AAA5D,KAFD,CADS,CAJ+C;AAUzDW,IAAAA,8BAA8B,EAAE,IAVyB;AAWzDC,IAAAA,WAAW,yBAAEhB,MAAM,EAAEgB,WAAV,qEAAyB;AAXqB,GAAd,CAA5C;AAcA,SAAO,0BAAUN;AAAV,IAAP;AACA;;AAED,eAAed,WAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { name as buttonBlockName } from '../button';\n\nconst ALLOWED_BLOCKS = [ buttonBlockName ];\n\nconst DEFAULT_BLOCK = {\n\tname: buttonBlockName,\n\tattributesToCopy: [\n\t\t'backgroundColor',\n\t\t'border',\n\t\t'className',\n\t\t'fontFamily',\n\t\t'fontSize',\n\t\t'gradient',\n\t\t'style',\n\t\t'textColor',\n\t\t'width',\n\t],\n};\n\nfunction ButtonsEdit( { attributes, className } ) {\n\tconst { fontSize, layout, style } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( className, {\n\t\t\t'has-custom-font-size': fontSize || style?.typography?.fontSize,\n\t\t} ),\n\t} );\n\tconst preferredStyle = useSelect( ( select ) => {\n\t\tconst preferredStyleVariations =\n\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t.__experimentalPreferredStyleVariations;\n\t\treturn preferredStyleVariations?.value?.[ buttonBlockName ];\n\t}, [] );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tallowedBlocks: ALLOWED_BLOCKS,\n\t\t__experimentalDefaultBlock: DEFAULT_BLOCK,\n\t\t__experimentalDirectInsert: true,\n\t\ttemplate: [\n\t\t\t[\n\t\t\t\tbuttonBlockName,\n\t\t\t\t{ className: preferredStyle && `is-style-${ preferredStyle }` },\n\t\t\t],\n\t\t],\n\t\ttemplateInsertUpdatesSelection: true,\n\t\torientation: layout?.orientation ?? 'horizontal',\n\t} );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n\nexport default ButtonsEdit;\n"]}
|
|
@@ -167,8 +167,6 @@ export function ImageEdit({
|
|
|
167
167
|
|
|
168
168
|
if (!media.id || media.id !== id) {
|
|
169
169
|
additionalAttributes = {
|
|
170
|
-
width: undefined,
|
|
171
|
-
height: undefined,
|
|
172
170
|
// Fallback to size "full" if there's no default image size.
|
|
173
171
|
// It means the image is smaller, and the block will use a full-size URL.
|
|
174
172
|
sizeSlug: hasDefaultSize(media, imageDefaultSize) ? imageDefaultSize : 'full'
|
|
@@ -234,8 +232,6 @@ export function ImageEdit({
|
|
|
234
232
|
setAttributes({
|
|
235
233
|
url: newURL,
|
|
236
234
|
id: undefined,
|
|
237
|
-
width: undefined,
|
|
238
|
-
height: undefined,
|
|
239
235
|
sizeSlug: imageDefaultSize
|
|
240
236
|
});
|
|
241
237
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/image/edit.js"],"names":["classnames","getBlobByURL","isBlobURL","revokeBlobURL","Placeholder","useDispatch","useSelect","BlockAlignmentControl","BlockControls","BlockIcon","MediaPlaceholder","useBlockProps","store","blockEditorStore","__experimentalUseBorderProps","useBorderProps","privateApis","blockEditorPrivateApis","useEffect","useRef","useState","__","image","icon","noticesStore","Image","unlock","LINK_DESTINATION_ATTACHMENT","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_NONE","ALLOWED_MEDIA_TYPES","useBlockEditingMode","pickRelevantMediaFiles","size","imageProps","Object","fromEntries","entries","filter","key","includes","url","sizes","media_details","source_url","isTemporaryImage","id","isExternalImage","hasDefaultSize","defaultSize","ImageEdit","attributes","setAttributes","isSelected","className","insertBlocksAfter","onReplace","context","clientId","alt","caption","align","width","height","sizeSlug","temporaryURL","setTemporaryURL","altRef","current","captionRef","ref","imageDefaultSize","mediaUpload","select","getSettings","settings","blockEditingMode","createErrorNotice","onUploadError","message","type","src","undefined","onSelectImage","media","title","mediaAttributes","omittedCaption","restMediaAttributes","additionalAttributes","linkDestination","window","wp","view","defaultProps","link","href","onSelectURL","newURL","updateAlignment","nextAlign","extraUpdatedAttributes","isTemp","file","filesList","onFileChange","img","allowedTypes","onError","isExternal","mediaPreview","borderProps","classes","style","keys","length","blockProps","placeholder","content"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,YAAT,EAAuBC,SAAvB,EAAkCC,aAAlC,QAAuD,iBAAvD;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,qBADD,EAECC,aAFD,EAGCC,SAHD,EAICC,gBAJD,EAKCC,aALD,EAMCC,KAAK,IAAIC,gBANV,EAOCC,4BAA4B,IAAIC,cAPjC,EAQCC,WAAW,IAAIC,sBARhB,QASO,yBATP;AAUA,SAASC,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,oBAA5C;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAK,IAAIC,IAAlB,QAA8B,kBAA9B;AACA,SAASX,KAAK,IAAIY,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,MAAT,QAAuB,gBAAvB;AAEA;AACA;AACA;;AACA,SACCC,2BADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,qBAJD,EAKCC,mBALD,QAMO,aANP;AAQA,MAAM;AAAEC,EAAAA;AAAF,IAA0BN,MAAM,CAAET,sBAAF,CAAtC;AAEA,OAAO,MAAMgB,sBAAsB,GAAG,CAAE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W,EAAGc,WAHf;AAIC,IAAA,OAAO,EAAGnB,aAJX;AAKC,IAAA,WAAW,EAAGuC,WALf;AAMC,IAAA,MAAM,EAAC,SANR;AAOC,IAAA,YAAY,EAAGvF,mBAPhB;AAQC,IAAA,KAAK,EAAG;AAAEgB,MAAAA,EAAF;AAAMmC,MAAAA;AAAN,KART;AASC,IAAA,YAAY,EAAG6B,YAThB;AAUC,IAAA,mBAAmB,EAAG7C,YAAY,IAAIxB;AAVvC,IA1BD,CADD;AAyCA;AAED,eAAeS,SAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';\nimport { Placeholder } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tBlockAlignmentControl,\n\tBlockControls,\n\tBlockIcon,\n\tMediaPlaceholder,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBorderProps as useBorderProps,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { image as icon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport Image from './image';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Module constants\n */\nimport {\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_CUSTOM,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_NONE,\n\tALLOWED_MEDIA_TYPES,\n} from './constants';\n\nconst { useBlockEditingMode } = unlock( blockEditorPrivateApis );\n\nexport const pickRelevantMediaFiles = ( image, size ) => {\n\tconst imageProps = Object.fromEntries(\n\t\tObject.entries( image ?? {} ).filter( ( [ key ] ) =>\n\t\t\t[ 'alt', 'id', 'link', 'caption' ].includes( key )\n\t\t)\n\t);\n\n\timageProps.url =\n\t\timage?.sizes?.[ size ]?.url ||\n\t\timage?.media_details?.sizes?.[ size ]?.source_url ||\n\t\timage.url;\n\treturn imageProps;\n};\n\n/**\n * Is the URL a temporary blob URL? A blob URL is one that is used temporarily\n * while the image is being uploaded and will not have an id yet allocated.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the URL a Blob URL\n */\nconst isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );\n\n/**\n * Is the url for the image hosted externally. An externally hosted image has no\n * id and is not a blob url.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the url an externally hosted url?\n */\nexport const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );\n\n/**\n * Checks if WP generated default image size. Size generation is skipped\n * when the image is smaller than the said size.\n *\n * @param {Object} image\n * @param {string} defaultSize\n *\n * @return {boolean} Whether or not it has default image size.\n */\nfunction hasDefaultSize( image, defaultSize ) {\n\treturn (\n\t\t'url' in ( image?.sizes?.[ defaultSize ] ?? {} ) ||\n\t\t'source_url' in ( image?.media_details?.sizes?.[ defaultSize ] ?? {} )\n\t);\n}\n\nexport function ImageEdit( {\n\tattributes,\n\tsetAttributes,\n\tisSelected,\n\tclassName,\n\tinsertBlocksAfter,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst {\n\t\turl = '',\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\tid,\n\t\twidth,\n\t\theight,\n\t\tsizeSlug,\n\t} = attributes;\n\tconst [ temporaryURL, setTemporaryURL ] = useState();\n\n\tconst altRef = useRef();\n\tuseEffect( () => {\n\t\taltRef.current = alt;\n\t}, [ alt ] );\n\n\tconst captionRef = useRef();\n\tuseEffect( () => {\n\t\tcaptionRef.current = caption;\n\t}, [ caption ] );\n\n\tconst ref = useRef();\n\tconst { imageDefaultSize, mediaUpload } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\t\treturn {\n\t\t\timageDefaultSize: settings.imageDefaultSize,\n\t\t\tmediaUpload: settings.mediaUpload,\n\t\t};\n\t}, [] );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t\tsetAttributes( {\n\t\t\tsrc: undefined,\n\t\t\tid: undefined,\n\t\t\turl: undefined,\n\t\t} );\n\t\tsetTemporaryURL( undefined );\n\t}\n\n\tfunction onSelectImage( media ) {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: undefined,\n\t\t\t\talt: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\ttitle: undefined,\n\t\t\t\tcaption: undefined,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tsetTemporaryURL( media.url );\n\t\t\treturn;\n\t\t}\n\n\t\tsetTemporaryURL();\n\n\t\tlet mediaAttributes = pickRelevantMediaFiles( media, imageDefaultSize );\n\n\t\t// If a caption text was meanwhile written by the user,\n\t\t// make sure the text is not overwritten by empty captions.\n\t\tif ( captionRef.current && ! mediaAttributes.caption ) {\n\t\t\tconst { caption: omittedCaption, ...restMediaAttributes } =\n\t\t\t\tmediaAttributes;\n\t\t\tmediaAttributes = restMediaAttributes;\n\t\t}\n\n\t\tlet additionalAttributes;\n\t\t// Reset the dimension attributes if changing to a different image.\n\t\tif ( ! media.id || media.id !== id ) {\n\t\t\tadditionalAttributes = {\n\t\t\t\twidth: undefined,\n\t\t\t\theight: undefined,\n\t\t\t\t// Fallback to size \"full\" if there's no default image size.\n\t\t\t\t// It means the image is smaller, and the block will use a full-size URL.\n\t\t\t\tsizeSlug: hasDefaultSize( media, imageDefaultSize )\n\t\t\t\t\t? imageDefaultSize\n\t\t\t\t\t: 'full',\n\t\t\t};\n\t\t} else {\n\t\t\t// Keep the same url when selecting the same file, so \"Resolution\"\n\t\t\t// option is not changed.\n\t\t\tadditionalAttributes = { url };\n\t\t}\n\n\t\t// Check if default link setting should be used.\n\t\tlet linkDestination = attributes.linkDestination;\n\t\tif ( ! linkDestination ) {\n\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\t// TODO: fix this in a follow up PR, requires updating media-text and ui component.\n\t\t\tswitch (\n\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t) {\n\t\t\t\tcase 'file':\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'post':\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_CUSTOM:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_CUSTOM;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Check if the image is linked to it's media.\n\t\tlet href;\n\t\tswitch ( linkDestination ) {\n\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\thref = media.url;\n\t\t\t\tbreak;\n\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\thref = media.link;\n\t\t\t\tbreak;\n\t\t}\n\t\tmediaAttributes.href = href;\n\n\t\tsetAttributes( {\n\t\t\t...mediaAttributes,\n\t\t\t...additionalAttributes,\n\t\t\tlinkDestination,\n\t\t} );\n\t}\n\n\tfunction onSelectURL( newURL ) {\n\t\tif ( newURL !== url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: newURL,\n\t\t\t\tid: undefined,\n\t\t\t\twidth: undefined,\n\t\t\t\theight: undefined,\n\t\t\t\tsizeSlug: imageDefaultSize,\n\t\t\t} );\n\t\t}\n\t}\n\n\tfunction updateAlignment( nextAlign ) {\n\t\tconst extraUpdatedAttributes = [ 'wide', 'full' ].includes( nextAlign )\n\t\t\t? { width: undefined, height: undefined }\n\t\t\t: {};\n\t\tsetAttributes( {\n\t\t\t...extraUpdatedAttributes,\n\t\t\talign: nextAlign,\n\t\t} );\n\t}\n\n\tlet isTemp = isTemporaryImage( id, url );\n\n\t// Upload a temporary image on mount.\n\tuseEffect( () => {\n\t\tif ( ! isTemp ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst file = getBlobByURL( url );\n\n\t\tif ( file ) {\n\t\t\tmediaUpload( {\n\t\t\t\tfilesList: [ file ],\n\t\t\t\tonFileChange: ( [ img ] ) => {\n\t\t\t\t\tonSelectImage( img );\n\t\t\t\t},\n\t\t\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\t\t\tonError: ( message ) => {\n\t\t\t\t\tisTemp = false;\n\t\t\t\t\tonUploadError( message );\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\t// If an image is temporary, revoke the Blob url when it is uploaded (and is\n\t// no longer temporary).\n\tuseEffect( () => {\n\t\tif ( isTemp ) {\n\t\t\tsetTemporaryURL( url );\n\t\t\treturn;\n\t\t}\n\t\trevokeBlobURL( temporaryURL );\n\t}, [ isTemp, url ] );\n\n\tconst isExternal = isExternalImage( id, url );\n\tconst src = isExternal ? url : undefined;\n\tconst mediaPreview = !! url && (\n\t\t<img\n\t\t\talt={ __( 'Edit image' ) }\n\t\t\ttitle={ __( 'Edit image' ) }\n\t\t\tclassName={ 'edit-image-preview' }\n\t\t\tsrc={ url }\n\t\t/>\n\t);\n\n\tconst borderProps = useBorderProps( attributes );\n\n\tconst classes = classnames( className, {\n\t\t'is-transient': temporaryURL,\n\t\t'is-resized': !! width || !! height,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tref,\n\t\tclassName: classes,\n\t} );\n\n\t// Much of this description is duplicated from MediaPlaceholder.\n\tconst placeholder = ( content ) => {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\tclassName={ classnames( 'block-editor-media-placeholder', {\n\t\t\t\t\t[ borderProps.className ]:\n\t\t\t\t\t\t!! borderProps.className && ! isSelected,\n\t\t\t\t} ) }\n\t\t\t\twithIllustration={ true }\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ __( 'Image' ) }\n\t\t\t\tinstructions={ __(\n\t\t\t\t\t'Upload an image file, pick one from your media library, or add one with a URL.'\n\t\t\t\t) }\n\t\t\t\tstyle={ isSelected ? undefined : borderProps.style }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\n\treturn (\n\t\t<figure { ...blockProps }>\n\t\t\t{ ( temporaryURL || url ) && (\n\t\t\t\t<Image\n\t\t\t\t\ttemporaryURL={ temporaryURL }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonSelectImage={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonUploadError={ onUploadError }\n\t\t\t\t\tcontainerRef={ ref }\n\t\t\t\t\tcontext={ context }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! url && blockEditingMode === 'default' && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<BlockAlignmentControl\n\t\t\t\t\t\tvalue={ align }\n\t\t\t\t\t\tonChange={ updateAlignment }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<MediaPlaceholder\n\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\tonSelect={ onSelectImage }\n\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\tonError={ onUploadError }\n\t\t\t\tplaceholder={ placeholder }\n\t\t\t\taccept=\"image/*\"\n\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\tvalue={ { id, src } }\n\t\t\t\tmediaPreview={ mediaPreview }\n\t\t\t\tdisableMediaButtons={ temporaryURL || url }\n\t\t\t/>\n\t\t</figure>\n\t);\n}\n\nexport default ImageEdit;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/image/edit.js"],"names":["classnames","getBlobByURL","isBlobURL","revokeBlobURL","Placeholder","useDispatch","useSelect","BlockAlignmentControl","BlockControls","BlockIcon","MediaPlaceholder","useBlockProps","store","blockEditorStore","__experimentalUseBorderProps","useBorderProps","privateApis","blockEditorPrivateApis","useEffect","useRef","useState","__","image","icon","noticesStore","Image","unlock","LINK_DESTINATION_ATTACHMENT","LINK_DESTINATION_CUSTOM","LINK_DESTINATION_MEDIA","LINK_DESTINATION_NONE","ALLOWED_MEDIA_TYPES","useBlockEditingMode","pickRelevantMediaFiles","size","imageProps","Object","fromEntries","entries","filter","key","includes","url","sizes","media_details","source_url","isTemporaryImage","id","isExternalImage","hasDefaultSize","defaultSize","ImageEdit","attributes","setAttributes","isSelected","className","insertBlocksAfter","onReplace","context","clientId","alt","caption","align","width","height","sizeSlug","temporaryURL","setTemporaryURL","altRef","current","captionRef","ref","imageDefaultSize","mediaUpload","select","getSettings","settings","blockEditingMode","createErrorNotice","onUploadError","message","type","src","undefined","onSelectImage","media","title","mediaAttributes","omittedCaption","restMediaAttributes","additionalAttributes","linkDestination","window","wp","view","defaultProps","link","href","onSelectURL","newURL","updateAlignment","nextAlign","extraUpdatedAttributes","isTemp","file","filesList","onFileChange","img","allowedTypes","onError","isExternal","mediaPreview","borderProps","classes","style","keys","length","blockProps","placeholder","content"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,YAAT,EAAuBC,SAAvB,EAAkCC,aAAlC,QAAuD,iBAAvD;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,qBADD,EAECC,aAFD,EAGCC,SAHD,EAICC,gBAJD,EAKCC,aALD,EAMCC,KAAK,IAAIC,gBANV,EAOCC,4BAA4B,IAAIC,cAPjC,EAQCC,WAAW,IAAIC,sBARhB,QASO,yBATP;AAUA,SAASC,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,oBAA5C;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAK,IAAIC,IAAlB,QAA8B,kBAA9B;AACA,SAASX,KAAK,IAAIY,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,MAAT,QAAuB,gBAAvB;AAEA;AACA;AACA;;AACA,SACCC,2BADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,qBAJD,EAKCC,mBALD,QAMO,aANP;AAQA,MAAM;AAAEC,EAAAA;AAAF,IAA0BN,MAAM,CAAET,sBAAF,CAAtC;AAEA,OAAO,MAAMgB,sBAAsB,GAAG,CAAEX,KAAF,EAASY,IAAT,KAAmB;AACxD,QAAMC,UAAU,GAAGC,MAAM,CAACC,WAAP,CAClBD,MAAM,CAACE,OAAP,CAAgBhB,KAAhB,aAAgBA,KAAhB,cAAgBA,KAAhB,GAAyB,EAAzB,EAA8BiB,MAA9B,CAAsC,CAAE,CAAEC,GAAF,CAAF,KACrC,CAAE,KAAF,EAAS,IAAT,EAAe,MAAf,EAAuB,SAAvB,EAAm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Ab,KACG,CAAEnD,YAAY,IAAIxB,GAAlB,KACD,cAAC,KAAD;AACC,IAAA,YAAY,EAAGwB,YADhB;AAEC,IAAA,UAAU,EAAGd,UAFd;AAGC,IAAA,aAAa,EAAGC,aAHjB;AAIC,IAAA,UAAU,EAAGC,UAJd;AAKC,IAAA,iBAAiB,EAAGE,iBALrB;AAMC,IAAA,SAAS,EAAGC,SANb;AAOC,IAAA,aAAa,EAAG2B,aAPjB;AAQC,IAAA,WAAW,EAAGc,WARf;AASC,IAAA,aAAa,EAAGnB,aATjB;AAUC,IAAA,YAAY,EAAGR,GAVhB;AAWC,IAAA,OAAO,EAAGb,OAXX;AAYC,IAAA,QAAQ,EAAGC,QAZZ;AAaC,IAAA,gBAAgB,EAAGkB;AAbpB,IAFF,EAkBG,CAAEnC,GAAF,IAASmC,gBAAgB,KAAK,SAA9B,IACD,cAAC,aAAD;AAAe,IAAA,KAAK,EAAC;AAArB,KACC,cAAC,qBAAD;AACC,IAAA,KAAK,EAAGf,KADT;AAEC,IAAA,QAAQ,EAAGsC;AAFZ,IADD,CAnBF,EA0BC,cAAC,gBAAD;AACC,IAAA,IAAI,EAAG,cAAC,SAAD;AAAW,MAAA,IAAI,EAAG7E;AAAlB,MADR;AAEC,IAAA,QAAQ,EAAG6D,aAFZ;AAGC,IAAA,WAAW,EAAGc,WAHf;AAIC,IAAA,OAAO,EAAGnB,aAJX;AAKC,IAAA,WAAW,EAAGuC,WALf;AAMC,IAAA,MAAM,EAAC,SANR;AAOC,IAAA,YAAY,EAAGvF,mBAPhB;AAQC,IAAA,KAAK,EAAG;AAAEgB,MAAAA,EAAF;AAAMmC,MAAAA;AAAN,KART;AASC,IAAA,YAAY,EAAG6B,YAThB;AAUC,IAAA,mBAAmB,EAAG7C,YAAY,IAAIxB;AAVvC,IA1BD,CADD;AAyCA;AAED,eAAeS,SAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';\nimport { Placeholder } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tBlockAlignmentControl,\n\tBlockControls,\n\tBlockIcon,\n\tMediaPlaceholder,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalUseBorderProps as useBorderProps,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { image as icon } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport Image from './image';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Module constants\n */\nimport {\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_CUSTOM,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_NONE,\n\tALLOWED_MEDIA_TYPES,\n} from './constants';\n\nconst { useBlockEditingMode } = unlock( blockEditorPrivateApis );\n\nexport const pickRelevantMediaFiles = ( image, size ) => {\n\tconst imageProps = Object.fromEntries(\n\t\tObject.entries( image ?? {} ).filter( ( [ key ] ) =>\n\t\t\t[ 'alt', 'id', 'link', 'caption' ].includes( key )\n\t\t)\n\t);\n\n\timageProps.url =\n\t\timage?.sizes?.[ size ]?.url ||\n\t\timage?.media_details?.sizes?.[ size ]?.source_url ||\n\t\timage.url;\n\treturn imageProps;\n};\n\n/**\n * Is the URL a temporary blob URL? A blob URL is one that is used temporarily\n * while the image is being uploaded and will not have an id yet allocated.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the URL a Blob URL\n */\nconst isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );\n\n/**\n * Is the url for the image hosted externally. An externally hosted image has no\n * id and is not a blob url.\n *\n * @param {number=} id The id of the image.\n * @param {string=} url The url of the image.\n *\n * @return {boolean} Is the url an externally hosted url?\n */\nexport const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );\n\n/**\n * Checks if WP generated default image size. Size generation is skipped\n * when the image is smaller than the said size.\n *\n * @param {Object} image\n * @param {string} defaultSize\n *\n * @return {boolean} Whether or not it has default image size.\n */\nfunction hasDefaultSize( image, defaultSize ) {\n\treturn (\n\t\t'url' in ( image?.sizes?.[ defaultSize ] ?? {} ) ||\n\t\t'source_url' in ( image?.media_details?.sizes?.[ defaultSize ] ?? {} )\n\t);\n}\n\nexport function ImageEdit( {\n\tattributes,\n\tsetAttributes,\n\tisSelected,\n\tclassName,\n\tinsertBlocksAfter,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst {\n\t\turl = '',\n\t\talt,\n\t\tcaption,\n\t\talign,\n\t\tid,\n\t\twidth,\n\t\theight,\n\t\tsizeSlug,\n\t} = attributes;\n\tconst [ temporaryURL, setTemporaryURL ] = useState();\n\n\tconst altRef = useRef();\n\tuseEffect( () => {\n\t\taltRef.current = alt;\n\t}, [ alt ] );\n\n\tconst captionRef = useRef();\n\tuseEffect( () => {\n\t\tcaptionRef.current = caption;\n\t}, [ caption ] );\n\n\tconst ref = useRef();\n\tconst { imageDefaultSize, mediaUpload } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\t\treturn {\n\t\t\timageDefaultSize: settings.imageDefaultSize,\n\t\t\tmediaUpload: settings.mediaUpload,\n\t\t};\n\t}, [] );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tfunction onUploadError( message ) {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t\tsetAttributes( {\n\t\t\tsrc: undefined,\n\t\t\tid: undefined,\n\t\t\turl: undefined,\n\t\t} );\n\t\tsetTemporaryURL( undefined );\n\t}\n\n\tfunction onSelectImage( media ) {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: undefined,\n\t\t\t\talt: undefined,\n\t\t\t\tid: undefined,\n\t\t\t\ttitle: undefined,\n\t\t\t\tcaption: undefined,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tsetTemporaryURL( media.url );\n\t\t\treturn;\n\t\t}\n\n\t\tsetTemporaryURL();\n\n\t\tlet mediaAttributes = pickRelevantMediaFiles( media, imageDefaultSize );\n\n\t\t// If a caption text was meanwhile written by the user,\n\t\t// make sure the text is not overwritten by empty captions.\n\t\tif ( captionRef.current && ! mediaAttributes.caption ) {\n\t\t\tconst { caption: omittedCaption, ...restMediaAttributes } =\n\t\t\t\tmediaAttributes;\n\t\t\tmediaAttributes = restMediaAttributes;\n\t\t}\n\n\t\tlet additionalAttributes;\n\t\t// Reset the dimension attributes if changing to a different image.\n\t\tif ( ! media.id || media.id !== id ) {\n\t\t\tadditionalAttributes = {\n\t\t\t\t// Fallback to size \"full\" if there's no default image size.\n\t\t\t\t// It means the image is smaller, and the block will use a full-size URL.\n\t\t\t\tsizeSlug: hasDefaultSize( media, imageDefaultSize )\n\t\t\t\t\t? imageDefaultSize\n\t\t\t\t\t: 'full',\n\t\t\t};\n\t\t} else {\n\t\t\t// Keep the same url when selecting the same file, so \"Resolution\"\n\t\t\t// option is not changed.\n\t\t\tadditionalAttributes = { url };\n\t\t}\n\n\t\t// Check if default link setting should be used.\n\t\tlet linkDestination = attributes.linkDestination;\n\t\tif ( ! linkDestination ) {\n\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\t// TODO: fix this in a follow up PR, requires updating media-text and ui component.\n\t\t\tswitch (\n\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t) {\n\t\t\t\tcase 'file':\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'post':\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_CUSTOM:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_CUSTOM;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tlinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Check if the image is linked to it's media.\n\t\tlet href;\n\t\tswitch ( linkDestination ) {\n\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\thref = media.url;\n\t\t\t\tbreak;\n\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\thref = media.link;\n\t\t\t\tbreak;\n\t\t}\n\t\tmediaAttributes.href = href;\n\n\t\tsetAttributes( {\n\t\t\t...mediaAttributes,\n\t\t\t...additionalAttributes,\n\t\t\tlinkDestination,\n\t\t} );\n\t}\n\n\tfunction onSelectURL( newURL ) {\n\t\tif ( newURL !== url ) {\n\t\t\tsetAttributes( {\n\t\t\t\turl: newURL,\n\t\t\t\tid: undefined,\n\t\t\t\tsizeSlug: imageDefaultSize,\n\t\t\t} );\n\t\t}\n\t}\n\n\tfunction updateAlignment( nextAlign ) {\n\t\tconst extraUpdatedAttributes = [ 'wide', 'full' ].includes( nextAlign )\n\t\t\t? { width: undefined, height: undefined }\n\t\t\t: {};\n\t\tsetAttributes( {\n\t\t\t...extraUpdatedAttributes,\n\t\t\talign: nextAlign,\n\t\t} );\n\t}\n\n\tlet isTemp = isTemporaryImage( id, url );\n\n\t// Upload a temporary image on mount.\n\tuseEffect( () => {\n\t\tif ( ! isTemp ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst file = getBlobByURL( url );\n\n\t\tif ( file ) {\n\t\t\tmediaUpload( {\n\t\t\t\tfilesList: [ file ],\n\t\t\t\tonFileChange: ( [ img ] ) => {\n\t\t\t\t\tonSelectImage( img );\n\t\t\t\t},\n\t\t\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\t\t\tonError: ( message ) => {\n\t\t\t\t\tisTemp = false;\n\t\t\t\t\tonUploadError( message );\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [] );\n\n\t// If an image is temporary, revoke the Blob url when it is uploaded (and is\n\t// no longer temporary).\n\tuseEffect( () => {\n\t\tif ( isTemp ) {\n\t\t\tsetTemporaryURL( url );\n\t\t\treturn;\n\t\t}\n\t\trevokeBlobURL( temporaryURL );\n\t}, [ isTemp, url ] );\n\n\tconst isExternal = isExternalImage( id, url );\n\tconst src = isExternal ? url : undefined;\n\tconst mediaPreview = !! url && (\n\t\t<img\n\t\t\talt={ __( 'Edit image' ) }\n\t\t\ttitle={ __( 'Edit image' ) }\n\t\t\tclassName={ 'edit-image-preview' }\n\t\t\tsrc={ url }\n\t\t/>\n\t);\n\n\tconst borderProps = useBorderProps( attributes );\n\n\tconst classes = classnames( className, {\n\t\t'is-transient': temporaryURL,\n\t\t'is-resized': !! width || !! height,\n\t\t[ `size-${ sizeSlug }` ]: sizeSlug,\n\t\t'has-custom-border':\n\t\t\t!! borderProps.className ||\n\t\t\t( borderProps.style &&\n\t\t\t\tObject.keys( borderProps.style ).length > 0 ),\n\t} );\n\n\tconst blockProps = useBlockProps( {\n\t\tref,\n\t\tclassName: classes,\n\t} );\n\n\t// Much of this description is duplicated from MediaPlaceholder.\n\tconst placeholder = ( content ) => {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\tclassName={ classnames( 'block-editor-media-placeholder', {\n\t\t\t\t\t[ borderProps.className ]:\n\t\t\t\t\t\t!! borderProps.className && ! isSelected,\n\t\t\t\t} ) }\n\t\t\t\twithIllustration={ true }\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ __( 'Image' ) }\n\t\t\t\tinstructions={ __(\n\t\t\t\t\t'Upload an image file, pick one from your media library, or add one with a URL.'\n\t\t\t\t) }\n\t\t\t\tstyle={ isSelected ? undefined : borderProps.style }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t</Placeholder>\n\t\t);\n\t};\n\n\treturn (\n\t\t<figure { ...blockProps }>\n\t\t\t{ ( temporaryURL || url ) && (\n\t\t\t\t<Image\n\t\t\t\t\ttemporaryURL={ temporaryURL }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\tonSelectImage={ onSelectImage }\n\t\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\t\tonUploadError={ onUploadError }\n\t\t\t\t\tcontainerRef={ ref }\n\t\t\t\t\tcontext={ context }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! url && blockEditingMode === 'default' && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<BlockAlignmentControl\n\t\t\t\t\t\tvalue={ align }\n\t\t\t\t\t\tonChange={ updateAlignment }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<MediaPlaceholder\n\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\tonSelect={ onSelectImage }\n\t\t\t\tonSelectURL={ onSelectURL }\n\t\t\t\tonError={ onUploadError }\n\t\t\t\tplaceholder={ placeholder }\n\t\t\t\taccept=\"image/*\"\n\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\tvalue={ { id, src } }\n\t\t\t\tmediaPreview={ mediaPreview }\n\t\t\t\tdisableMediaButtons={ temporaryURL || url }\n\t\t\t/>\n\t\t</figure>\n\t);\n}\n\nexport default ImageEdit;\n"]}
|
|
@@ -4,12 +4,12 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { isBlobURL } from '@wordpress/blob';
|
|
7
|
-
import { ExternalLink,
|
|
7
|
+
import { ExternalLink, ResizableBox, Spinner, TextareaControl, TextControl, ToolbarButton, ToolbarGroup, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';
|
|
8
8
|
import { useViewportMatch, usePrevious } from '@wordpress/compose';
|
|
9
9
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
10
|
-
import { BlockControls, InspectorControls, RichText,
|
|
10
|
+
import { BlockControls, InspectorControls, RichText, __experimentalImageURLInputUI as ImageURLInputUI, MediaReplaceFlow, store as blockEditorStore, BlockAlignmentControl, __experimentalImageEditor as ImageEditor, __experimentalGetElementClassName, __experimentalUseBorderProps as useBorderProps, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
11
11
|
import { useEffect, useMemo, useState, useRef, useCallback } from '@wordpress/element';
|
|
12
|
-
import { __, sprintf, isRTL } from '@wordpress/i18n';
|
|
12
|
+
import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
|
|
13
13
|
import { getFilename } from '@wordpress/url';
|
|
14
14
|
import { createBlock, getDefaultBlockName, switchToBlockType } from '@wordpress/blocks';
|
|
15
15
|
import { crop, overlayText, upload, caption as captionIcon } from '@wordpress/icons';
|
|
@@ -19,6 +19,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
19
19
|
* Internal dependencies
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
import { unlock } from '../lock-unlock';
|
|
22
23
|
import { createUpgradedEmbedBlock } from '../embed/util';
|
|
23
24
|
import useClientWidth from './use-client-width';
|
|
24
25
|
import { isExternalImage } from './edit';
|
|
@@ -27,6 +28,20 @@ import { isExternalImage } from './edit';
|
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
30
|
import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';
|
|
31
|
+
import { evalAspectRatio } from './utils';
|
|
32
|
+
const {
|
|
33
|
+
DimensionsTool,
|
|
34
|
+
ResolutionTool
|
|
35
|
+
} = unlock(blockEditorPrivateApis);
|
|
36
|
+
const scaleOptions = [{
|
|
37
|
+
value: 'cover',
|
|
38
|
+
label: _x('Cover', 'Scale option for dimensions control'),
|
|
39
|
+
help: __('Image covers the space evenly.')
|
|
40
|
+
}, {
|
|
41
|
+
value: 'contain',
|
|
42
|
+
label: _x('Contain', 'Scale option for dimensions control'),
|
|
43
|
+
help: __('Image is contained without distortion.')
|
|
44
|
+
}];
|
|
30
45
|
export default function Image({
|
|
31
46
|
temporaryURL,
|
|
32
47
|
attributes,
|
|
@@ -55,6 +70,8 @@ export default function Image({
|
|
|
55
70
|
title,
|
|
56
71
|
width,
|
|
57
72
|
height,
|
|
73
|
+
aspectRatio,
|
|
74
|
+
scale,
|
|
58
75
|
linkTarget,
|
|
59
76
|
sizeSlug
|
|
60
77
|
} = attributes;
|
|
@@ -227,8 +244,6 @@ export default function Image({
|
|
|
227
244
|
|
|
228
245
|
setAttributes({
|
|
229
246
|
url: newUrl,
|
|
230
|
-
width: undefined,
|
|
231
|
-
height: undefined,
|
|
232
247
|
sizeSlug: newSizeSlug
|
|
233
248
|
});
|
|
234
249
|
}
|
|
@@ -285,8 +300,14 @@ export default function Image({
|
|
|
285
300
|
|
|
286
301
|
function switchToCover() {
|
|
287
302
|
replaceBlocks(clientId, switchToBlockType(getBlock(clientId), 'core/cover'));
|
|
288
|
-
}
|
|
303
|
+
} // TODO: Can allow more units after figuring out how they should interact
|
|
304
|
+
// with the ResizableBox and ImageEditor components. Calculations later on
|
|
305
|
+
// for those components are currently assuming px units.
|
|
306
|
+
|
|
289
307
|
|
|
308
|
+
const dimensionsUnitsOptions = useCustomUnits({
|
|
309
|
+
availableUnits: ['px']
|
|
310
|
+
});
|
|
290
311
|
const controls = createElement(Fragment, null, createElement(BlockControls, {
|
|
291
312
|
group: "block"
|
|
292
313
|
}, hasNonContentControls && createElement(BlockAlignmentControl, {
|
|
@@ -336,27 +357,55 @@ export default function Image({
|
|
|
336
357
|
onClick: uploadExternal,
|
|
337
358
|
icon: upload,
|
|
338
359
|
label: __('Upload external image')
|
|
339
|
-
}))), createElement(InspectorControls, null, createElement(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
360
|
+
}))), createElement(InspectorControls, null, createElement(ToolsPanel, {
|
|
361
|
+
label: __('Settings'),
|
|
362
|
+
resetAll: () => setAttributes({
|
|
363
|
+
width: undefined,
|
|
364
|
+
height: undefined,
|
|
365
|
+
scale: undefined,
|
|
366
|
+
aspectRatio: undefined
|
|
367
|
+
})
|
|
368
|
+
}, !multiImageSelection && createElement(ToolsPanelItem, {
|
|
369
|
+
label: __('Alternative text'),
|
|
370
|
+
isShownByDefault: true,
|
|
371
|
+
hasValue: () => alt !== '',
|
|
372
|
+
onDeselect: () => setAttributes({
|
|
373
|
+
alt: undefined
|
|
374
|
+
})
|
|
375
|
+
}, createElement(TextareaControl, {
|
|
343
376
|
label: __('Alternative text'),
|
|
344
377
|
value: alt,
|
|
345
378
|
onChange: updateAlt,
|
|
346
379
|
help: createElement(Fragment, null, createElement(ExternalLink, {
|
|
347
380
|
href: "https://www.w3.org/WAI/tutorials/images/decision-tree"
|
|
348
|
-
}, __('Describe the purpose of the image.')), createElement("br", null), __('Leave empty if decorative.'))
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
381
|
+
}, __('Describe the purpose of the image.')), createElement("br", null), __('Leave empty if decorative.')),
|
|
382
|
+
__nextHasNoMarginBottom: true
|
|
383
|
+
})), createElement(DimensionsTool, {
|
|
384
|
+
value: {
|
|
385
|
+
width: width && `${width}px`,
|
|
386
|
+
height: height && `${height}px`,
|
|
387
|
+
scale,
|
|
388
|
+
aspectRatio
|
|
389
|
+
},
|
|
390
|
+
onChange: newValue => {
|
|
391
|
+
// Rebuilding the object forces setting `undefined`
|
|
392
|
+
// for values that are removed since setAttributes
|
|
393
|
+
// doesn't do anything with keys that aren't set.
|
|
394
|
+
setAttributes({
|
|
395
|
+
width: newValue.width && parseInt(newValue.width, 10),
|
|
396
|
+
height: newValue.height && parseInt(newValue.height, 10),
|
|
397
|
+
scale: newValue.scale,
|
|
398
|
+
aspectRatio: newValue.aspectRatio
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
defaultScale: "cover",
|
|
402
|
+
defaultAspectRatio: "auto",
|
|
403
|
+
scaleOptions: scaleOptions,
|
|
404
|
+
unitsOptions: dimensionsUnitsOptions
|
|
405
|
+
}), createElement(ResolutionTool, {
|
|
406
|
+
value: sizeSlug,
|
|
407
|
+
onChange: updateImage,
|
|
408
|
+
options: imageSizeOptions
|
|
360
409
|
}))), createElement(InspectorControls, {
|
|
361
410
|
group: "advanced"
|
|
362
411
|
}, createElement(TextControl, {
|
|
@@ -383,7 +432,6 @@ export default function Image({
|
|
|
383
432
|
|
|
384
433
|
const borderProps = useBorderProps(attributes);
|
|
385
434
|
const isRounded = attributes.className?.includes('is-style-rounded');
|
|
386
|
-
const hasCustomBorder = !!borderProps.className || borderProps.style && Object.keys(borderProps.style).length > 0;
|
|
387
435
|
let img = // Disable reason: Image itself is not meant to be interactive, but
|
|
388
436
|
// should direct focus to block.
|
|
389
437
|
|
|
@@ -400,22 +448,17 @@ export default function Image({
|
|
|
400
448
|
},
|
|
401
449
|
ref: imageRef,
|
|
402
450
|
className: borderProps.className,
|
|
403
|
-
style:
|
|
451
|
+
style: {
|
|
452
|
+
width: width && height || aspectRatio ? '100%' : 'inherit',
|
|
453
|
+
height: width && height || aspectRatio ? '100%' : 'inherit',
|
|
454
|
+
objectFit: scale,
|
|
455
|
+
...borderProps.style
|
|
456
|
+
}
|
|
404
457
|
}), temporaryURL && createElement(Spinner, null))
|
|
405
458
|
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
406
|
-
;
|
|
407
|
-
let imageWidthWithinContainer;
|
|
408
|
-
let imageHeightWithinContainer;
|
|
409
|
-
|
|
410
|
-
if (clientWidth && naturalWidth && naturalHeight) {
|
|
411
|
-
const exceedMaxWidth = naturalWidth > clientWidth;
|
|
412
|
-
const ratio = naturalHeight / naturalWidth;
|
|
413
|
-
imageWidthWithinContainer = exceedMaxWidth ? clientWidth : naturalWidth;
|
|
414
|
-
imageHeightWithinContainer = exceedMaxWidth ? clientWidth * ratio : naturalHeight;
|
|
415
|
-
} // clientWidth needs to be a number for the image Cropper to work, but sometimes it's 0
|
|
459
|
+
; // clientWidth needs to be a number for the image Cropper to work, but sometimes it's 0
|
|
416
460
|
// So we try using the imageRef width first and fallback to clientWidth.
|
|
417
461
|
|
|
418
|
-
|
|
419
462
|
const fallbackClientWidth = imageRef.current?.width || clientWidth;
|
|
420
463
|
|
|
421
464
|
if (canEditImage && isEditingImage) {
|
|
@@ -433,17 +476,18 @@ export default function Image({
|
|
|
433
476
|
},
|
|
434
477
|
borderProps: isRounded ? undefined : borderProps
|
|
435
478
|
});
|
|
436
|
-
} else if (!isResizable
|
|
479
|
+
} else if (!isResizable) {
|
|
437
480
|
img = createElement("div", {
|
|
438
481
|
style: {
|
|
439
482
|
width,
|
|
440
|
-
height
|
|
483
|
+
height,
|
|
484
|
+
aspectRatio
|
|
441
485
|
}
|
|
442
486
|
}, img);
|
|
443
487
|
} else {
|
|
444
|
-
const
|
|
445
|
-
const
|
|
446
|
-
const
|
|
488
|
+
const ratio = aspectRatio && evalAspectRatio(aspectRatio) || width && height && width / height || naturalWidth / naturalHeight;
|
|
489
|
+
const currentWidth = !width && height ? height * ratio : width;
|
|
490
|
+
const currentHeight = !height && width ? width / ratio : height;
|
|
447
491
|
const minWidth = naturalWidth < naturalHeight ? MIN_SIZE : MIN_SIZE * ratio;
|
|
448
492
|
const minHeight = naturalHeight < naturalWidth ? MIN_SIZE : MIN_SIZE / ratio; // With the current implementation of ResizableBox, an image needs an
|
|
449
493
|
// explicit pixel value for the max-width. In absence of being able to
|
|
@@ -487,16 +531,21 @@ export default function Image({
|
|
|
487
531
|
|
|
488
532
|
|
|
489
533
|
img = createElement(ResizableBox, {
|
|
534
|
+
style: {
|
|
535
|
+
display: 'block',
|
|
536
|
+
objectFit: scale,
|
|
537
|
+
aspectRatio: !width && !height && aspectRatio ? aspectRatio : undefined
|
|
538
|
+
},
|
|
490
539
|
size: {
|
|
491
|
-
width:
|
|
492
|
-
height:
|
|
540
|
+
width: currentWidth !== null && currentWidth !== void 0 ? currentWidth : 'auto',
|
|
541
|
+
height: currentHeight !== null && currentHeight !== void 0 ? currentHeight : 'auto'
|
|
493
542
|
},
|
|
494
543
|
showHandle: isSelected,
|
|
495
544
|
minWidth: minWidth,
|
|
496
545
|
maxWidth: maxWidthBuffer,
|
|
497
546
|
minHeight: minHeight,
|
|
498
547
|
maxHeight: maxWidthBuffer / ratio,
|
|
499
|
-
lockAspectRatio:
|
|
548
|
+
lockAspectRatio: ratio,
|
|
500
549
|
enable: {
|
|
501
550
|
top: false,
|
|
502
551
|
right: showRightHandle,
|
|
@@ -504,11 +553,12 @@ export default function Image({
|
|
|
504
553
|
left: showLeftHandle
|
|
505
554
|
},
|
|
506
555
|
onResizeStart: onResizeStart,
|
|
507
|
-
onResizeStop: (event, direction, elt
|
|
556
|
+
onResizeStop: (event, direction, elt) => {
|
|
508
557
|
onResizeStop();
|
|
509
558
|
setAttributes({
|
|
510
|
-
width:
|
|
511
|
-
height:
|
|
559
|
+
width: elt.offsetWidth,
|
|
560
|
+
height: elt.offsetHeight,
|
|
561
|
+
aspectRatio: undefined
|
|
512
562
|
});
|
|
513
563
|
},
|
|
514
564
|
resizeRatio: align === 'center' ? 2 : 1
|