@wordpress/block-editor 10.0.3 → 10.0.5
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/components/block-inspector/index.js +3 -4
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +72 -14
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-parent-selector/index.js +2 -2
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +3 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +19 -16
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/image-editor/use-transform-image.js +2 -2
- package/build/components/image-editor/use-transform-image.js.map +1 -1
- package/build/components/inserter/search-items.js +2 -17
- package/build/components/inserter/search-items.js.map +1 -1
- package/build/components/spacing-sizes-control/index.js +10 -2
- package/build/components/spacing-sizes-control/index.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +5 -4
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/hooks/index.js +13 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +76 -23
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/margin.js +4 -4
- package/build/hooks/margin.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +3 -4
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +72 -14
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +2 -2
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +3 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +19 -16
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/image-editor/use-transform-image.js +2 -2
- package/build-module/components/image-editor/use-transform-image.js.map +1 -1
- package/build-module/components/inserter/search-items.js +3 -17
- package/build-module/components/inserter/search-items.js.map +1 -1
- package/build-module/components/spacing-sizes-control/index.js +10 -3
- package/build-module/components/spacing-sizes-control/index.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +6 -5
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +73 -23
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/margin.js +4 -4
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +85 -125
- package/build-style/style.css +85 -125
- package/package.json +9 -10
- package/src/components/block-inspector/index.js +4 -7
- package/src/components/block-list/block.js +111 -7
- package/src/components/block-list/style.scss +85 -133
- package/src/components/block-parent-selector/index.js +2 -2
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +36 -21
- package/src/components/button-block-appender/style.scss +3 -1
- package/src/components/image-editor/use-transform-image.js +2 -2
- package/src/components/inserter/search-items.js +3 -15
- package/src/components/inserter/test/search-items.js +4 -0
- package/src/components/spacing-sizes-control/index.js +15 -3
- package/src/components/spacing-sizes-control/spacing-input-control.js +8 -7
- package/src/components/spacing-sizes-control/style.scss +28 -24
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +64 -21
- package/src/hooks/margin.js +4 -4
- package/src/index.js +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/index.js"],"names":["MAX_POPOVER_RECOMPUTE_COUNTER","Number","MAX_SAFE_INTEGER","BlockPopover","ref","clientId","bottomClientId","children","__unstableRefreshSize","__unstableCoverTarget","__unstablePopoverSlot","__unstableContentRef","props","selectedElement","lastSelectedElement","mergedRefs","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-popover/index.js"],"names":["MAX_POPOVER_RECOMPUTE_COUNTER","Number","MAX_SAFE_INTEGER","BlockPopover","ref","clientId","bottomClientId","children","__unstableRefreshSize","__unstableCoverTarget","__unstablePopoverSlot","__unstableContentRef","props","selectedElement","lastSelectedElement","mergedRefs","popoverDimensionsRecomputeCounter","forceRecomputePopoverDimensions","s","observer","window","MutationObserver","observe","attributes","disconnect","style","position","width","offsetWidth","height","offsetHeight","popoverAnchor","undefined","getBoundingClientRect","selectedBCR","lastSelectedBCR","left","Math","min","Infinity","top","right","max","bottom","DOMRect","ownerDocument","className"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AAKA;;AACA;;AAWA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;AAIA,MAAMA,6BAA6B,GAAGC,MAAM,CAACC,gBAA7C;;AAEA,SAASC,YAAT,OAWCC,GAXD,EAYE;AAAA,MAXD;AACCC,IAAAA,QADD;AAECC,IAAAA,cAFD;AAGCC,IAAAA,QAHD;AAICC,IAAAA,qBAJD;AAKCC,IAAAA,qBAAqB,GAAG,KALzB;AAMCC,IAAAA,qBAND;AAOCC,IAAAA,oBAPD;AAQC,OAAGC;AARJ,GAWC;AACD,QAAMC,eAAe,GAAG,6CAAiBR,QAAjB,CAAxB;AACA,QAAMS,mBAAmB,GAAG,6CAAiBR,cAAjB,aAAiBA,cAAjB,cAAiBA,cAAjB,GAAmCD,QAAnC,CAA5B;AACA,QAAMU,UAAU,GAAG,2BAAc,CAChCX,GADgC,EAEhC,+BAAkBO,oBAAlB,CAFgC,CAAd,CAAnB;AAKA,QAAM,CACLK,iCADK,EAELC,+BAFK,IAGF,0BACH;AACEC,EAAAA,CAAF,IAAS,CAAEA,CAAC,GAAG,CAAN,IAAYlB,6BAFlB,EAGH,CAHG,CAHJ,CARC,CAiBD;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,gCAAiB,MAAM;AACtB,QAAK,CAAEa,eAAP,EAAyB;AACxB;AACA;;AAED,UAAMM,QAAQ,GAAG,IAAIC,MAAM,CA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KAAK,EAAGgB;AAAb,KAAuBlB,QAAvB,CAlB5B,EAmBG,CAAEE,qBAAF,IAA2BF,QAnB9B,CADD;AAuBA;;eAEc,yBAAYJ,YAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { Popover } from '@wordpress/components';\nimport {\n\tforwardRef,\n\tuseMemo,\n\tuseReducer,\n\tuseLayoutEffect,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';\nimport usePopoverScroll from './use-popover-scroll';\n\nconst MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;\n\nfunction BlockPopover(\n\t{\n\t\tclientId,\n\t\tbottomClientId,\n\t\tchildren,\n\t\t__unstableRefreshSize,\n\t\t__unstableCoverTarget = false,\n\t\t__unstablePopoverSlot,\n\t\t__unstableContentRef,\n\t\t...props\n\t},\n\tref\n) {\n\tconst selectedElement = useBlockElement( clientId );\n\tconst lastSelectedElement = useBlockElement( bottomClientId ?? clientId );\n\tconst mergedRefs = useMergeRefs( [\n\t\tref,\n\t\tusePopoverScroll( __unstableContentRef ),\n\t] );\n\n\tconst [\n\t\tpopoverDimensionsRecomputeCounter,\n\t\tforceRecomputePopoverDimensions,\n\t] = useReducer(\n\t\t// Module is there to make sure that the counter doesn't overflow.\n\t\t( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,\n\t\t0\n\t);\n\n\t// When blocks are moved up/down, they are animated to their new position by\n\t// updating the `transform` property manually (i.e. without using CSS\n\t// transitions or animations). The animation, which can also scroll the block\n\t// editor, can sometimes cause the position of the Popover to get out of sync.\n\t// A MutationObserver is therefore used to make sure that changes to the\n\t// selectedElement's attribute (i.e. `transform`) can be tracked and used to\n\t// trigger the Popover to rerender.\n\tuseLayoutEffect( () => {\n\t\tif ( ! selectedElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst observer = new window.MutationObserver(\n\t\t\tforceRecomputePopoverDimensions\n\t\t);\n\t\tobserver.observe( selectedElement, { attributes: true } );\n\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [ selectedElement ] );\n\n\tconst style = useMemo( () => {\n\t\tif (\n\t\t\t// popoverDimensionsRecomputeCounter is by definition always equal or greater\n\t\t\t// than 0. This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverDimensionsRecomputeCounter < 0 ||\n\t\t\t! selectedElement ||\n\t\t\tlastSelectedElement !== selectedElement\n\t\t) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn {\n\t\t\tposition: 'absolute',\n\t\t\twidth: selectedElement.offsetWidth,\n\t\t\theight: selectedElement.offsetHeight,\n\t\t};\n\t}, [\n\t\tselectedElement,\n\t\tlastSelectedElement,\n\t\t__unstableRefreshSize,\n\t\tpopoverDimensionsRecomputeCounter,\n\t] );\n\n\tconst popoverAnchor = useMemo( () => {\n\t\tif (\n\t\t\t// popoverDimensionsRecomputeCounter is by definition always equal or greater\n\t\t\t// than 0. This check is only there to satisfy the correctness of the\n\t\t\t// exhaustive-deps rule for the `useMemo` hook.\n\t\t\tpopoverDimensionsRecomputeCounter < 0 ||\n\t\t\t! selectedElement ||\n\t\t\t( bottomClientId && ! lastSelectedElement )\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst selectedBCR = selectedElement.getBoundingClientRect();\n\t\t\t\tconst lastSelectedBCR =\n\t\t\t\t\tlastSelectedElement?.getBoundingClientRect();\n\n\t\t\t\t// Get the biggest rectangle that encompasses completely the currently\n\t\t\t\t// selected element and the last selected element:\n\t\t\t\t// - for top/left coordinates, use the smaller numbers\n\t\t\t\t// - for the bottom/right coordinates, use the largest numbers\n\t\t\t\tconst left = Math.min(\n\t\t\t\t\tselectedBCR.left,\n\t\t\t\t\tlastSelectedBCR?.left ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst top = Math.min(\n\t\t\t\t\tselectedBCR.top,\n\t\t\t\t\tlastSelectedBCR?.top ?? Infinity\n\t\t\t\t);\n\t\t\t\tconst right = Math.max(\n\t\t\t\t\tselectedBCR.right,\n\t\t\t\t\tlastSelectedBCR.right ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst bottom = Math.max(\n\t\t\t\t\tselectedBCR.bottom,\n\t\t\t\t\tlastSelectedBCR.bottom ?? -Infinity\n\t\t\t\t);\n\t\t\t\tconst width = right - left;\n\t\t\t\tconst height = bottom - top;\n\n\t\t\t\treturn new window.DOMRect( left, top, width, height );\n\t\t\t},\n\t\t\townerDocument: selectedElement.ownerDocument,\n\t\t};\n\t}, [\n\t\tbottomClientId,\n\t\tlastSelectedElement,\n\t\tselectedElement,\n\t\tpopoverDimensionsRecomputeCounter,\n\t] );\n\n\tif ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ mergedRefs }\n\t\t\tanimate={ false }\n\t\t\tposition=\"top right left\"\n\t\t\tfocusOnMount={ false }\n\t\t\tanchor={ popoverAnchor }\n\t\t\t// Render in the old slot if needed for backward compatibility,\n\t\t\t// otherwise render in place (not in the default popover slot).\n\t\t\t__unstableSlotName={ __unstablePopoverSlot || null }\n\t\t\tresize={ false }\n\t\t\tflip={ false }\n\t\t\tshift\n\t\t\t{ ...props }\n\t\t\tclassName={ classnames(\n\t\t\t\t'block-editor-block-popover',\n\t\t\t\tprops.className\n\t\t\t) }\n\t\t>\n\t\t\t{ __unstableCoverTarget && <div style={ style }>{ children }</div> }\n\t\t\t{ ! __unstableCoverTarget && children }\n\t\t</Popover>\n\t);\n}\n\nexport default forwardRef( BlockPopover );\n"]}
|
|
@@ -49,7 +49,7 @@ function useTransformState(_ref) {
|
|
|
49
49
|
if (angle === 0) {
|
|
50
50
|
setEditedUrl();
|
|
51
51
|
setRotation(angle);
|
|
52
|
-
setAspect(
|
|
52
|
+
setAspect(naturalWidth / naturalHeight);
|
|
53
53
|
setPosition({
|
|
54
54
|
x: -(position.y * naturalAspectRatio),
|
|
55
55
|
y: position.x * naturalAspectRatio
|
|
@@ -85,7 +85,7 @@ function useTransformState(_ref) {
|
|
|
85
85
|
canvas.toBlob(blob => {
|
|
86
86
|
setEditedUrl(URL.createObjectURL(blob));
|
|
87
87
|
setRotation(angle);
|
|
88
|
-
setAspect(
|
|
88
|
+
setAspect(canvas.width / canvas.height);
|
|
89
89
|
setPosition({
|
|
90
90
|
x: -(position.y * naturalAspectRatio),
|
|
91
91
|
y: position.x * naturalAspectRatio
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-transform-image.js"],"names":["useTransformState","url","naturalWidth","naturalHeight","editedUrl","setEditedUrl","crop","setCrop","position","setPosition","x","y","zoom","setZoom","rotation","setRotation","aspect","setAspect","defaultAspect","setDefaultAspect","initializeTransformValues","rotateClockwise","angle","naturalAspectRatio","editImage","event","canvas","document","createElement","translateX","translateY","width","target","height","context","getContext","translate","rotate","Math","PI","drawImage","toBlob","blob","URL","createObjectURL","el","window","Image","src","onload","imgCrossOrigin","undefined","crossOrigin","useTransformImage","imageProperties","isEditing","transformState"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA,SAASA,iBAAT,OAAmE;AAAA,MAAvC;AAAEC,IAAAA,GAAF;AAAOC,IAAAA,YAAP;AAAqBC,IAAAA;AAArB,GAAuC;AAClE,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,wBAApC;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,wBAA1B;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,uBAAU;AAAEC,IAAAA,CAAC,EAAE,CAAL;AAAQC,IAAAA,CAAC,EAAE;AAAX,GAAV,CAAlC;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,wBAA1B;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,wBAAlC;AACA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,wBAA9B;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,wBAA5C;AAEA,QAAMC,yBAAyB,GAAG,0BAAa,MAAM;AACpDX,IAAAA,WAAW,CAAE;AAAEC,MAAAA,CAAC,EAAE,CAAL;AAAQC,MAAAA,CAAC,EAAE;AAAX,KAAF,CAAX;AACAE,IAAAA,OAAO,CAAE,GAAF,CAAP;AACAE,IAAAA,WAAW,CAAE,CAAF,CAAX;AACAE,IAAAA,SAAS,CAAEf,YAAY,GAAGC,aAAjB,CAAT;AACAgB,IAAAA,gBAAgB,CAAEjB,YAAY,GAAGC,aAAjB,CAAhB;AACA,GANiC,EAM/B,CACFD,YADE,EAEFC,aAFE,EAGFM,WAHE,EAIFI,OAJE,EAKFE,WALE,EAMFE,SANE,EAOFE,gBAPE,CAN+B,CAAlC;AAgBA,QAAME,eAAe,GAAG,0BAAa,MAAM;AAC1C,UAAMC,KAAK,GAAG,CAAER,QAAQ,GAAG,EAAb,IAAoB,GAAlC;AAEA,QAAIS,kBAAkB,GAAGrB,YAAY,GAAGC,aAAxC;;AAEA,QAAKW,QAAQ,GAAG,GAAX,KAAmB,EAAxB,EAA6B;AAC5BS,MAAAA,kBAAkB,GAAGpB,aAAa,GAAGD,YAArC;AACA;;AAED,QAAKoB,KAAK,KAAK,CAAf,EAAmB;AAClBjB,MAAAA,YAAY;AACZU,MAAAA,WAAW,CAAEO,KAAF,CAAX;AACAL,MAAAA,SAAS,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-transform-image.js"],"names":["useTransformState","url","naturalWidth","naturalHeight","editedUrl","setEditedUrl","crop","setCrop","position","setPosition","x","y","zoom","setZoom","rotation","setRotation","aspect","setAspect","defaultAspect","setDefaultAspect","initializeTransformValues","rotateClockwise","angle","naturalAspectRatio","editImage","event","canvas","document","createElement","translateX","translateY","width","target","height","context","getContext","translate","rotate","Math","PI","drawImage","toBlob","blob","URL","createObjectURL","el","window","Image","src","onload","imgCrossOrigin","undefined","crossOrigin","useTransformImage","imageProperties","isEditing","transformState"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA,SAASA,iBAAT,OAAmE;AAAA,MAAvC;AAAEC,IAAAA,GAAF;AAAOC,IAAAA,YAAP;AAAqBC,IAAAA;AAArB,GAAuC;AAClE,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,wBAApC;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,wBAA1B;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,uBAAU;AAAEC,IAAAA,CAAC,EAAE,CAAL;AAAQC,IAAAA,CAAC,EAAE;AAAX,GAAV,CAAlC;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,wBAA1B;AACA,QAAM,CAAEC,QAAF,EAAYC,WAAZ,IAA4B,wBAAlC;AACA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,wBAA9B;AACA,QAAM,CAAEC,aAAF,EAAiBC,gBAAjB,IAAsC,wBAA5C;AAEA,QAAMC,yBAAyB,GAAG,0BAAa,MAAM;AACpDX,IAAAA,WAAW,CAAE;AAAEC,MAAAA,CAAC,EAAE,CAAL;AAAQC,MAAAA,CAAC,EAAE;AAAX,KAAF,CAAX;AACAE,IAAAA,OAAO,CAAE,GAAF,CAAP;AACAE,IAAAA,WAAW,CAAE,CAAF,CAAX;AACAE,IAAAA,SAAS,CAAEf,YAAY,GAAGC,aAAjB,CAAT;AACAgB,IAAAA,gBAAgB,CAAEjB,YAAY,GAAGC,aAAjB,CAAhB;AACA,GANiC,EAM/B,CACFD,YADE,EAEFC,aAFE,EAGFM,WAHE,EAIFI,OAJE,EAKFE,WALE,EA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;AACA;AACD,GAvEuB,EAuErB,CACFpC,QADE,EAEFZ,YAFE,EAGFC,aAHE,EAIFE,YAJE,EAKFU,WALE,EAMFE,SANE,EAOFR,WAPE,CAvEqB,CAAxB;AAiFA,SAAO,sBACN,OAAQ;AACPL,IAAAA,SADO;AAEPC,IAAAA,YAFO;AAGPC,IAAAA,IAHO;AAIPC,IAAAA,OAJO;AAKPC,IAAAA,QALO;AAMPC,IAAAA,WANO;AAOPG,IAAAA,IAPO;AAQPC,IAAAA,OARO;AASPC,IAAAA,QATO;AAUPC,IAAAA,WAVO;AAWPM,IAAAA,eAXO;AAYPL,IAAAA,MAZO;AAaPC,IAAAA,SAbO;AAcPC,IAAAA,aAdO;AAePE,IAAAA;AAfO,GAAR,CADM,EAkBN,CACChB,SADD,EAECC,YAFD,EAGCC,IAHD,EAICC,OAJD,EAKCC,QALD,EAMCC,WAND,EAOCG,IAPD,EAQCC,OARD,EASCC,QATD,EAUCC,WAVD,EAWCM,eAXD,EAYCL,MAZD,EAaCC,SAbD,EAcCC,aAdD,EAeCE,yBAfD,CAlBM,CAAP;AAoCA;;AAEc,SAASiC,iBAAT,CAA4BC,eAA5B,EAA6CC,SAA7C,EAAyD;AACvE,QAAMC,cAAc,GAAGxD,iBAAiB,CAAEsD,eAAF,CAAxC;AACA,QAAM;AAAElC,IAAAA;AAAF,MAAgCoC,cAAtC;AAEA,0BAAW,MAAM;AAChB,QAAKD,SAAL,EAAiB;AAChBnC,MAAAA,yBAAyB;AACzB;AACD,GAJD,EAIG,CAAEmC,SAAF,EAAanC,yBAAb,CAJH;AAMA,SAAOoC,cAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { applyFilters } from '@wordpress/hooks';\n\nfunction useTransformState( { url, naturalWidth, naturalHeight } ) {\n\tconst [ editedUrl, setEditedUrl ] = useState();\n\tconst [ crop, setCrop ] = useState();\n\tconst [ position, setPosition ] = useState( { x: 0, y: 0 } );\n\tconst [ zoom, setZoom ] = useState();\n\tconst [ rotation, setRotation ] = useState();\n\tconst [ aspect, setAspect ] = useState();\n\tconst [ defaultAspect, setDefaultAspect ] = useState();\n\n\tconst initializeTransformValues = useCallback( () => {\n\t\tsetPosition( { x: 0, y: 0 } );\n\t\tsetZoom( 100 );\n\t\tsetRotation( 0 );\n\t\tsetAspect( naturalWidth / naturalHeight );\n\t\tsetDefaultAspect( naturalWidth / naturalHeight );\n\t}, [\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tsetPosition,\n\t\tsetZoom,\n\t\tsetRotation,\n\t\tsetAspect,\n\t\tsetDefaultAspect,\n\t] );\n\n\tconst rotateClockwise = useCallback( () => {\n\t\tconst angle = ( rotation + 90 ) % 360;\n\n\t\tlet naturalAspectRatio = naturalWidth / naturalHeight;\n\n\t\tif ( rotation % 180 === 90 ) {\n\t\t\tnaturalAspectRatio = naturalHeight / naturalWidth;\n\t\t}\n\n\t\tif ( angle === 0 ) {\n\t\t\tsetEditedUrl();\n\t\t\tsetRotation( angle );\n\t\t\tsetAspect( naturalWidth / naturalHeight );\n\t\t\tsetPosition( {\n\t\t\t\tx: -( position.y * naturalAspectRatio ),\n\t\t\t\ty: position.x * naturalAspectRatio,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tfunction editImage( event ) {\n\t\t\tconst canvas = document.createElement( 'canvas' );\n\n\t\t\tlet translateX = 0;\n\t\t\tlet translateY = 0;\n\n\t\t\tif ( angle % 180 ) {\n\t\t\t\tcanvas.width = event.target.height;\n\t\t\t\tcanvas.height = event.target.width;\n\t\t\t} else {\n\t\t\t\tcanvas.width = event.target.width;\n\t\t\t\tcanvas.height = event.target.height;\n\t\t\t}\n\n\t\t\tif ( angle === 90 || angle === 180 ) {\n\t\t\t\ttranslateX = canvas.width;\n\t\t\t}\n\n\t\t\tif ( angle === 270 || angle === 180 ) {\n\t\t\t\ttranslateY = canvas.height;\n\t\t\t}\n\n\t\t\tconst context = canvas.getContext( '2d' );\n\n\t\t\tcontext.translate( translateX, translateY );\n\t\t\tcontext.rotate( ( angle * Math.PI ) / 180 );\n\t\t\tcontext.drawImage( event.target, 0, 0 );\n\n\t\t\tcanvas.toBlob( ( blob ) => {\n\t\t\t\tsetEditedUrl( URL.createObjectURL( blob ) );\n\t\t\t\tsetRotation( angle );\n\t\t\t\tsetAspect( canvas.width / canvas.height );\n\t\t\t\tsetPosition( {\n\t\t\t\t\tx: -( position.y * naturalAspectRatio ),\n\t\t\t\t\ty: position.x * naturalAspectRatio,\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\tconst el = new window.Image();\n\t\tel.src = url;\n\t\tel.onload = editImage;\n\n\t\tconst imgCrossOrigin = applyFilters(\n\t\t\t'media.crossOrigin',\n\t\t\tundefined,\n\t\t\turl\n\t\t);\n\t\tif ( typeof imgCrossOrigin === 'string' ) {\n\t\t\tel.crossOrigin = imgCrossOrigin;\n\t\t}\n\t}, [\n\t\trotation,\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tsetEditedUrl,\n\t\tsetRotation,\n\t\tsetAspect,\n\t\tsetPosition,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\teditedUrl,\n\t\t\tsetEditedUrl,\n\t\t\tcrop,\n\t\t\tsetCrop,\n\t\t\tposition,\n\t\t\tsetPosition,\n\t\t\tzoom,\n\t\t\tsetZoom,\n\t\t\trotation,\n\t\t\tsetRotation,\n\t\t\trotateClockwise,\n\t\t\taspect,\n\t\t\tsetAspect,\n\t\t\tdefaultAspect,\n\t\t\tinitializeTransformValues,\n\t\t} ),\n\t\t[\n\t\t\teditedUrl,\n\t\t\tsetEditedUrl,\n\t\t\tcrop,\n\t\t\tsetCrop,\n\t\t\tposition,\n\t\t\tsetPosition,\n\t\t\tzoom,\n\t\t\tsetZoom,\n\t\t\trotation,\n\t\t\tsetRotation,\n\t\t\trotateClockwise,\n\t\t\taspect,\n\t\t\tsetAspect,\n\t\t\tdefaultAspect,\n\t\t\tinitializeTransformValues,\n\t\t]\n\t);\n}\n\nexport default function useTransformImage( imageProperties, isEditing ) {\n\tconst transformState = useTransformState( imageProperties );\n\tconst { initializeTransformValues } = transformState;\n\n\tuseEffect( () => {\n\t\tif ( isEditing ) {\n\t\t\tinitializeTransformValues();\n\t\t}\n\t}, [ isEditing, initializeTransformValues ] );\n\n\treturn transformState;\n}\n"]}
|
|
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.getItemSearchRank = getItemSearchRank;
|
|
9
9
|
exports.searchItems = exports.searchBlockItems = exports.getNormalizedSearchTerms = void 0;
|
|
10
10
|
|
|
11
|
-
var _changeCase = require("change-case");
|
|
12
|
-
|
|
13
11
|
var _removeAccents = _interopRequireDefault(require("remove-accents"));
|
|
14
12
|
|
|
15
13
|
var _lodash = require("lodash");
|
|
@@ -51,19 +49,6 @@ function normalizeSearchInput() {
|
|
|
51
49
|
input = input.toLowerCase();
|
|
52
50
|
return input;
|
|
53
51
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts words from an input string.
|
|
56
|
-
*
|
|
57
|
-
* @param {string} input The input string.
|
|
58
|
-
*
|
|
59
|
-
* @return {Array} Words, extracted from the input string.
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
function extractWords() {
|
|
64
|
-
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
65
|
-
return (0, _changeCase.noCase)(input).split(' ').filter(Boolean);
|
|
66
|
-
}
|
|
67
52
|
/**
|
|
68
53
|
* Converts the search term into a list of normalized terms.
|
|
69
54
|
*
|
|
@@ -75,7 +60,7 @@ function extractWords() {
|
|
|
75
60
|
|
|
76
61
|
const getNormalizedSearchTerms = function () {
|
|
77
62
|
let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
78
|
-
return
|
|
63
|
+
return (0, _lodash.words)(normalizeSearchInput(input));
|
|
79
64
|
};
|
|
80
65
|
|
|
81
66
|
exports.getNormalizedSearchTerms = getNormalizedSearchTerms;
|
|
@@ -189,7 +174,7 @@ function getItemSearchRank(item, searchTerm) {
|
|
|
189
174
|
rank += 20;
|
|
190
175
|
} else {
|
|
191
176
|
const terms = [name, title, description, ...keywords, category, collection].join(' ');
|
|
192
|
-
const normalizedSearchTerms =
|
|
177
|
+
const normalizedSearchTerms = (0, _lodash.words)(normalizedSearchInput);
|
|
193
178
|
const unmatchedTerms = removeMatchingTerms(normalizedSearchTerms, terms);
|
|
194
179
|
|
|
195
180
|
if (unmatchedTerms.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-items.js"],"names":["defaultGetName","item","name","defaultGetTitle","title","defaultGetDescription","description","defaultGetKeywords","keywords","defaultGetCategory","category","defaultGetCollection","normalizeSearchInput","input","replace","toLowerCase","extractWords","split","filter","Boolean","getNormalizedSearchTerms","removeMatchingTerms","unmatchedTerms","unprocessedTerms","term","some","unprocessedTerm","includes","searchBlockItems","items","categories","collections","searchInput","normalizedSearchTerms","length","config","getCategory","slug","getCollection","searchItems","rankedItems","map","getItemSearchRank","rank","sort","rank1","rank2","searchTerm","getName","getTitle","getDescription","getKeywords","collection","normalizedSearchInput","normalizedTitle","startsWith","terms","join","isCoreBlockVariation","id"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;AAKA;AACA,MAAMA,cAAc,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,IAAa,EAAhD;;AACA,MAAMC,eAAe,GAAKF,IAAF,IAAYA,IAAI,CAACG,KAAzC;;AACA,MAAMC,qBAAqB,GAAKJ,IAAF,IAAYA,IAAI,CAACK,WAAL,IAAoB,EAA9D;;AACA,MAAMC,kBAAkB,GAAKN,IAAF,IAAYA,IAAI,CAACO,QAAL,IAAiB,EAAxD;;AACA,MAAMC,kBAAkB,GAAKR,IAAF,IAAYA,IAAI,CAACS,QAA5C;;AACA,M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AMa,KAAK,GAAG,CACbtD,IADa,EAEbE,KAFa,EAGbE,WAHa,EAIb,GAAGE,QAJU,EAKbE,QALa,EAMb0C,UANa,EAOZK,IAPY,CAON,GAPM,CAAd;AAQA,UAAMxB,qBAAqB,GAAGjB,YAAY,CAAEqC,qBAAF,CAA1C;AACA,UAAM/B,cAAc,GAAGD,mBAAmB,CACzCY,qBADyC,EAEzCuB,KAFyC,CAA1C;;AAKA,QAAKlC,cAAc,CAACY,MAAf,KAA0B,CAA/B,EAAmC;AAClCS,MAAAA,IAAI,IAAI,EAAR;AACA;AACD,GA/CiE,CAiDlE;;;AACA,MAAKA,IAAI,KAAK,CAAT,IAAczC,IAAI,CAACqD,UAAL,CAAiB,OAAjB,CAAnB,EAAgD;AAC/C,UAAMG,oBAAoB,GAAGxD,IAAI,KAAKD,IAAI,CAAC0D,EAA3C,CAD+C,CAE/C;;AACAhB,IAAAA,IAAI,IAAIe,oBAAoB,GAAG,CAAH,GAAO,CAAnC;AACA;;AAED,SAAOf,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { noCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport { find } from 'lodash';\n\n// Default search helpers.\nconst defaultGetName = ( item ) => item.name || '';\nconst defaultGetTitle = ( item ) => item.title;\nconst defaultGetDescription = ( item ) => item.description || '';\nconst defaultGetKeywords = ( item ) => item.keywords || [];\nconst defaultGetCategory = ( item ) => item.category;\nconst defaultGetCollection = () => null;\n\n/**\n * Sanitizes the search input string.\n *\n * @param {string} input The search input to normalize.\n *\n * @return {string} The normalized search input.\n */\nfunction normalizeSearchInput( input = '' ) {\n\t// Disregard diacritics.\n\t// Input: \"média\"\n\tinput = removeAccents( input );\n\n\t// Accommodate leading slash, matching autocomplete expectations.\n\t// Input: \"/media\"\n\tinput = input.replace( /^\\//, '' );\n\n\t// Lowercase.\n\t// Input: \"MEDIA\"\n\tinput = input.toLowerCase();\n\n\treturn input;\n}\n\n/**\n * Extracts words from an input string.\n *\n * @param {string} input The input string.\n *\n * @return {Array} Words, extracted from the input string.\n */\nfunction extractWords( input = '' ) {\n\treturn noCase( input ).split( ' ' ).filter( Boolean );\n}\n\n/**\n * Converts the search term into a list of normalized terms.\n *\n * @param {string} input The search term to normalize.\n *\n * @return {string[]} The normalized list of search terms.\n */\nexport const getNormalizedSearchTerms = ( input = '' ) => {\n\treturn extractWords( normalizeSearchInput( input ) );\n};\n\nconst removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {\n\treturn unmatchedTerms.filter(\n\t\t( term ) =>\n\t\t\t! getNormalizedSearchTerms( unprocessedTerms ).some(\n\t\t\t\t( unprocessedTerm ) => unprocessedTerm.includes( term )\n\t\t\t)\n\t);\n};\n\nexport const searchBlockItems = (\n\titems,\n\tcategories,\n\tcollections,\n\tsearchInput\n) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst config = {\n\t\tgetCategory: ( item ) =>\n\t\t\tfind( categories, { slug: item.category } )?.title,\n\t\tgetCollection: ( item ) =>\n\t\t\tcollections[ item.name.split( '/' )[ 0 ] ]?.title,\n\t};\n\n\treturn searchItems( items, searchInput, config );\n};\n\n/**\n * Filters an item list given a search term.\n *\n * @param {Array} items Item list\n * @param {string} searchInput Search input.\n * @param {Object} config Search Config.\n *\n * @return {Array} Filtered item list.\n */\nexport const searchItems = ( items = [], searchInput = '', config = {} ) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst rankedItems = items\n\t\t.map( ( item ) => {\n\t\t\treturn [ item, getItemSearchRank( item, searchInput, config ) ];\n\t\t} )\n\t\t.filter( ( [ , rank ] ) => rank > 0 );\n\n\trankedItems.sort( ( [ , rank1 ], [ , rank2 ] ) => rank2 - rank1 );\n\treturn rankedItems.map( ( [ item ] ) => item );\n};\n\n/**\n * Get the search rank for a given item and a specific search term.\n * The better the match, the higher the rank.\n * If the rank equals 0, it should be excluded from the results.\n *\n * @param {Object} item Item to filter.\n * @param {string} searchTerm Search term.\n * @param {Object} config Search Config.\n *\n * @return {number} Search Rank.\n */\nexport function getItemSearchRank( item, searchTerm, config = {} ) {\n\tconst {\n\t\tgetName = defaultGetName,\n\t\tgetTitle = defaultGetTitle,\n\t\tgetDescription = defaultGetDescription,\n\t\tgetKeywords = defaultGetKeywords,\n\t\tgetCategory = defaultGetCategory,\n\t\tgetCollection = defaultGetCollection,\n\t} = config;\n\n\tconst name = getName( item );\n\tconst title = getTitle( item );\n\tconst description = getDescription( item );\n\tconst keywords = getKeywords( item );\n\tconst category = getCategory( item );\n\tconst collection = getCollection( item );\n\n\tconst normalizedSearchInput = normalizeSearchInput( searchTerm );\n\tconst normalizedTitle = normalizeSearchInput( title );\n\n\tlet rank = 0;\n\n\t// Prefers exact matches\n\t// Then prefers if the beginning of the title matches the search term\n\t// name, keywords, categories, collection, variations match come later.\n\tif ( normalizedSearchInput === normalizedTitle ) {\n\t\trank += 30;\n\t} else if ( normalizedTitle.startsWith( normalizedSearchInput ) ) {\n\t\trank += 20;\n\t} else {\n\t\tconst terms = [\n\t\t\tname,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\t...keywords,\n\t\t\tcategory,\n\t\t\tcollection,\n\t\t].join( ' ' );\n\t\tconst normalizedSearchTerms = extractWords( normalizedSearchInput );\n\t\tconst unmatchedTerms = removeMatchingTerms(\n\t\t\tnormalizedSearchTerms,\n\t\t\tterms\n\t\t);\n\n\t\tif ( unmatchedTerms.length === 0 ) {\n\t\t\trank += 10;\n\t\t}\n\t}\n\n\t// Give a better rank to \"core\" namespaced items.\n\tif ( rank !== 0 && name.startsWith( 'core/' ) ) {\n\t\tconst isCoreBlockVariation = name !== item.id;\n\t\t// Give a bit better rank to \"core\" blocks over \"core\" block variations.\n\t\trank += isCoreBlockVariation ? 1 : 2;\n\t}\n\n\treturn rank;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-items.js"],"names":["defaultGetName","item","name","defaultGetTitle","title","defaultGetDescription","description","defaultGetKeywords","keywords","defaultGetCategory","category","defaultGetCollection","normalizeSearchInput","input","replace","toLowerCase","getNormalizedSearchTerms","removeMatchingTerms","unmatchedTerms","unprocessedTerms","filter","term","some","unprocessedTerm","includes","searchBlockItems","items","categories","collections","searchInput","normalizedSearchTerms","length","config","getCategory","slug","getCollection","split","searchItems","rankedItems","map","getItemSearchRank","rank","sort","rank1","rank2","searchTerm","getName","getTitle","getDescription","getKeywords","collection","normalizedSearchInput","normalizedTitle","startsWith","terms","join","isCoreBlockVariation","id"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA;AACA,MAAMA,cAAc,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,IAAa,EAAhD;;AACA,MAAMC,eAAe,GAAKF,IAAF,IAAYA,IAAI,CAACG,KAAzC;;AACA,MAAMC,qBAAqB,GAAKJ,IAAF,IAAYA,IAAI,CAACK,WAAL,IAAoB,EAA9D;;AACA,MAAMC,kBAAkB,GAAKN,IAAF,IAAYA,IAAI,CAACO,QAAL,IAAiB,EAAxD;;AACA,MAAMC,kBAAkB,GAAKR,IAAF,IAAYA,IAAI,CAACS,QAA5C;;AACA,MAAMC,oBAAoB,GAAG,MAAM,IAAnC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,GAA4C;AAAA,MAAbC,KAAa,uEAAL,EAAK;AAC3C;AACA;AACAA,EAAAA,KAAK,GAAG,4BAAeA,KAAf,CAAR,CAH2C,CAK3C;AACA;;AACAA,EAAAA,KAAK,GAAGA,KAAK,CAACC,OAAN,CAAe,KAAf,EAAsB,EAAtB,CAAR,CAP2C,CAS3C;AACA;;AACAD,EAAAA,KAAK,GAAGA,KAAK,CAACE,WAAN,EAAR;AAEA,SAAOF,KAAP;AACA;AAED;AACA;AACA;AACA;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CAAnC;AACA;;AAED,SAAOf,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\nimport { find, words } from 'lodash';\n\n// Default search helpers.\nconst defaultGetName = ( item ) => item.name || '';\nconst defaultGetTitle = ( item ) => item.title;\nconst defaultGetDescription = ( item ) => item.description || '';\nconst defaultGetKeywords = ( item ) => item.keywords || [];\nconst defaultGetCategory = ( item ) => item.category;\nconst defaultGetCollection = () => null;\n\n/**\n * Sanitizes the search input string.\n *\n * @param {string} input The search input to normalize.\n *\n * @return {string} The normalized search input.\n */\nfunction normalizeSearchInput( input = '' ) {\n\t// Disregard diacritics.\n\t// Input: \"média\"\n\tinput = removeAccents( input );\n\n\t// Accommodate leading slash, matching autocomplete expectations.\n\t// Input: \"/media\"\n\tinput = input.replace( /^\\//, '' );\n\n\t// Lowercase.\n\t// Input: \"MEDIA\"\n\tinput = input.toLowerCase();\n\n\treturn input;\n}\n\n/**\n * Converts the search term into a list of normalized terms.\n *\n * @param {string} input The search term to normalize.\n *\n * @return {string[]} The normalized list of search terms.\n */\nexport const getNormalizedSearchTerms = ( input = '' ) => {\n\treturn words( normalizeSearchInput( input ) );\n};\n\nconst removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {\n\treturn unmatchedTerms.filter(\n\t\t( term ) =>\n\t\t\t! getNormalizedSearchTerms( unprocessedTerms ).some(\n\t\t\t\t( unprocessedTerm ) => unprocessedTerm.includes( term )\n\t\t\t)\n\t);\n};\n\nexport const searchBlockItems = (\n\titems,\n\tcategories,\n\tcollections,\n\tsearchInput\n) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst config = {\n\t\tgetCategory: ( item ) =>\n\t\t\tfind( categories, { slug: item.category } )?.title,\n\t\tgetCollection: ( item ) =>\n\t\t\tcollections[ item.name.split( '/' )[ 0 ] ]?.title,\n\t};\n\n\treturn searchItems( items, searchInput, config );\n};\n\n/**\n * Filters an item list given a search term.\n *\n * @param {Array} items Item list\n * @param {string} searchInput Search input.\n * @param {Object} config Search Config.\n *\n * @return {Array} Filtered item list.\n */\nexport const searchItems = ( items = [], searchInput = '', config = {} ) => {\n\tconst normalizedSearchTerms = getNormalizedSearchTerms( searchInput );\n\tif ( normalizedSearchTerms.length === 0 ) {\n\t\treturn items;\n\t}\n\n\tconst rankedItems = items\n\t\t.map( ( item ) => {\n\t\t\treturn [ item, getItemSearchRank( item, searchInput, config ) ];\n\t\t} )\n\t\t.filter( ( [ , rank ] ) => rank > 0 );\n\n\trankedItems.sort( ( [ , rank1 ], [ , rank2 ] ) => rank2 - rank1 );\n\treturn rankedItems.map( ( [ item ] ) => item );\n};\n\n/**\n * Get the search rank for a given item and a specific search term.\n * The better the match, the higher the rank.\n * If the rank equals 0, it should be excluded from the results.\n *\n * @param {Object} item Item to filter.\n * @param {string} searchTerm Search term.\n * @param {Object} config Search Config.\n *\n * @return {number} Search Rank.\n */\nexport function getItemSearchRank( item, searchTerm, config = {} ) {\n\tconst {\n\t\tgetName = defaultGetName,\n\t\tgetTitle = defaultGetTitle,\n\t\tgetDescription = defaultGetDescription,\n\t\tgetKeywords = defaultGetKeywords,\n\t\tgetCategory = defaultGetCategory,\n\t\tgetCollection = defaultGetCollection,\n\t} = config;\n\n\tconst name = getName( item );\n\tconst title = getTitle( item );\n\tconst description = getDescription( item );\n\tconst keywords = getKeywords( item );\n\tconst category = getCategory( item );\n\tconst collection = getCollection( item );\n\n\tconst normalizedSearchInput = normalizeSearchInput( searchTerm );\n\tconst normalizedTitle = normalizeSearchInput( title );\n\n\tlet rank = 0;\n\n\t// Prefers exact matches\n\t// Then prefers if the beginning of the title matches the search term\n\t// name, keywords, categories, collection, variations match come later.\n\tif ( normalizedSearchInput === normalizedTitle ) {\n\t\trank += 30;\n\t} else if ( normalizedTitle.startsWith( normalizedSearchInput ) ) {\n\t\trank += 20;\n\t} else {\n\t\tconst terms = [\n\t\t\tname,\n\t\t\ttitle,\n\t\t\tdescription,\n\t\t\t...keywords,\n\t\t\tcategory,\n\t\t\tcollection,\n\t\t].join( ' ' );\n\t\tconst normalizedSearchTerms = words( normalizedSearchInput );\n\t\tconst unmatchedTerms = removeMatchingTerms(\n\t\t\tnormalizedSearchTerms,\n\t\t\tterms\n\t\t);\n\n\t\tif ( unmatchedTerms.length === 0 ) {\n\t\t\trank += 10;\n\t\t}\n\t}\n\n\t// Give a better rank to \"core\" namespaced items.\n\tif ( rank !== 0 && name.startsWith( 'core/' ) ) {\n\t\tconst isCoreBlockVariation = name !== item.id;\n\t\t// Give a bit better rank to \"core\" blocks over \"core\" block variations.\n\t\trank += isCoreBlockVariation ? 1 : 2;\n\t}\n\n\treturn rank;\n}\n"]}
|
|
@@ -11,6 +11,8 @@ var _element = require("@wordpress/element");
|
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
+
|
|
14
16
|
var _i18n = require("@wordpress/i18n");
|
|
15
17
|
|
|
16
18
|
var _components = require("@wordpress/components");
|
|
@@ -27,6 +29,10 @@ var _utils = require("./utils");
|
|
|
27
29
|
|
|
28
30
|
var _useSetting = _interopRequireDefault(require("../use-setting"));
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* External dependencies
|
|
34
|
+
*/
|
|
35
|
+
|
|
30
36
|
/**
|
|
31
37
|
* WordPress dependencies
|
|
32
38
|
*/
|
|
@@ -87,8 +93,10 @@ function SpacingSizesControl(_ref) {
|
|
|
87
93
|
};
|
|
88
94
|
return (0, _element.createElement)("fieldset", {
|
|
89
95
|
role: "region",
|
|
90
|
-
className:
|
|
91
|
-
|
|
96
|
+
className: (0, _classnames.default)('component-spacing-sizes-control', {
|
|
97
|
+
'is-unlinked': !isLinked
|
|
98
|
+
})
|
|
99
|
+
}, (0, _element.createElement)(_components.BaseControl.VisualLabel, {
|
|
92
100
|
as: "legend"
|
|
93
101
|
}, label), !hasOneSide && (0, _element.createElement)(_linkedButton.default, {
|
|
94
102
|
onClick: toggleLinked,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/index.js"],"names":["SpacingSizesControl","inputProps","onChange","label","values","sides","splitOnAxis","useSelect","minimumCustomValue","spacingSizes","name","slug","size","length","unshift","undefined","inputValues","DEFAULT_VALUES","hasInitialValue","hasOneSide","isLinked","setIsLinked","toggleLinked","handleOnChange","nextValue","newValues","inputControlProps","type"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/index.js"],"names":["SpacingSizesControl","inputProps","onChange","label","values","sides","splitOnAxis","useSelect","minimumCustomValue","spacingSizes","name","slug","size","length","unshift","undefined","inputValues","DEFAULT_VALUES","hasInitialValue","hasOneSide","isLinked","setIsLinked","toggleLinked","handleOnChange","nextValue","newValues","inputControlProps","type"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAQe,SAASA,mBAAT,OASX;AAAA,MATyC;AAC5CC,IAAAA,UAD4C;AAE5CC,IAAAA,QAF4C;AAG5CC,IAAAA,KAAK,GAAG,cAAI,iBAAJ,CAHoC;AAI5CC,IAAAA,MAJ4C;AAK5CC,IAAAA,KAL4C;AAM5CC,IAAAA,WAAW,GAAG,KAN8B;AAO5CC,IAAAA,SAP4C;AAQ5CC,IAAAA,kBAAkB,GAAG;AARuB,GASzC;AACH,QAAMC,YAAY,GAAG,CACpB;AAAEC,IAAAA,IAAI,EAAE,CAAR;AAAWC,IAAAA,IAAI,EAAE,GAAjB;AAAsBC,IAAAA,IAAI,EAAE;AAA5B,GADoB,EAEpB,IAAK,yBAAY,sBAAZ,KAAwC,EAA7C,C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AAFb,KAMC,4BAAC,uBAAD,CAAa,WAAb;AAAyB,IAAA,EAAE,EAAC;AAA5B,KACGjB,KADH,CAND,EASG,CAAEgB,UAAF,IACD,4BAAC,qBAAD;AAAc,IAAA,OAAO,EAAGG,YAAxB;AAAuC,IAAA,QAAQ,EAAGF;AAAlD,IAVF,EAYGA,QAAQ,IACT,4BAAC,wBAAD;AACC,kBAAajB;AADd,KAEMuB,iBAFN,EAbF,EAmBG,CAAEN,QAAF,IAAcd,WAAd,IACD,4BAAC,2BAAD,EAAyBoB,iBAAzB,CApBF,EAsBG,CAAEN,QAAF,IAAc,CAAEd,WAAhB,IACD,4BAAC,sBAAD,EAAoBoB,iBAApB,CAvBF,CADD;AA4BA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { BaseControl } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport AllInputControl from './all-input-control';\nimport InputControls from './input-controls';\nimport AxialInputControls from './axial-input-controls';\nimport LinkedButton from './linked-button';\nimport { DEFAULT_VALUES, isValuesMixed, isValuesDefined } from './utils';\nimport useSetting from '../use-setting';\n\nexport default function SpacingSizesControl( {\n\tinputProps,\n\tonChange,\n\tlabel = __( 'Spacing Control' ),\n\tvalues,\n\tsides,\n\tsplitOnAxis = false,\n\tuseSelect,\n\tminimumCustomValue = 0,\n} ) {\n\tconst spacingSizes = [\n\t\t{ name: 0, slug: '0', size: 0 },\n\t\t...( useSetting( 'spacing.spacingSizes' ) || [] ),\n\t];\n\n\tif ( spacingSizes.length > 8 ) {\n\t\tspacingSizes.unshift( {\n\t\t\tname: __( 'Default' ),\n\t\t\tslug: 'default',\n\t\t\tsize: undefined,\n\t\t} );\n\t}\n\n\tconst inputValues = values || DEFAULT_VALUES;\n\tconst hasInitialValue = isValuesDefined( values );\n\tconst hasOneSide = sides?.length === 1;\n\n\tconst [ isLinked, setIsLinked ] = useState(\n\t\t! hasInitialValue || ! isValuesMixed( inputValues, sides ) || hasOneSide\n\t);\n\n\tconst toggleLinked = () => {\n\t\tsetIsLinked( ! isLinked );\n\t};\n\n\tconst handleOnChange = ( nextValue ) => {\n\t\tconst newValues = { ...values, ...nextValue };\n\t\tonChange( newValues );\n\t};\n\n\tconst inputControlProps = {\n\t\t...inputProps,\n\t\tonChange: handleOnChange,\n\t\tisLinked,\n\t\tsides,\n\t\tvalues: inputValues,\n\t\tspacingSizes,\n\t\tuseSelect,\n\t\ttype: label,\n\t\tminimumCustomValue,\n\t};\n\n\treturn (\n\t\t<fieldset\n\t\t\trole=\"region\"\n\t\t\tclassName={ classnames( 'component-spacing-sizes-control', {\n\t\t\t\t'is-unlinked': ! isLinked,\n\t\t\t} ) }\n\t\t>\n\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t{ label }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t{ ! hasOneSide && (\n\t\t\t\t<LinkedButton onClick={ toggleLinked } isLinked={ isLinked } />\n\t\t\t) }\n\t\t\t{ isLinked && (\n\t\t\t\t<AllInputControl\n\t\t\t\t\taria-label={ label }\n\t\t\t\t\t{ ...inputControlProps }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ ! isLinked && splitOnAxis && (\n\t\t\t\t<AxialInputControls { ...inputControlProps } />\n\t\t\t) }\n\t\t\t{ ! isLinked && ! splitOnAxis && (\n\t\t\t\t<InputControls { ...inputControlProps } />\n\t\t\t) }\n\t\t</fieldset>\n\t);\n}\n"]}
|
|
@@ -136,11 +136,11 @@ function SpacingInputControl(_ref) {
|
|
|
136
136
|
const showHint = showRangeControl && !showCustomValueControl && currentValueHint !== undefined;
|
|
137
137
|
return (0, _element.createElement)(_element.Fragment, null, side !== 'all' && (0, _element.createElement)(_components.__experimentalHStack, {
|
|
138
138
|
className: "components-spacing-sizes-control__side-labels"
|
|
139
|
-
}, (0, _element.createElement)(_components.
|
|
139
|
+
}, (0, _element.createElement)(_components.BaseControl.VisualLabel, {
|
|
140
140
|
className: "components-spacing-sizes-control__side-label"
|
|
141
|
-
}, _utils.LABELS[side]), showHint && (0, _element.createElement)(_components.
|
|
141
|
+
}, _utils.LABELS[side]), showHint && (0, _element.createElement)(_components.BaseControl.VisualLabel, {
|
|
142
142
|
className: "components-spacing-sizes-control__hint-single"
|
|
143
|
-
}, currentValueHint)), side === 'all' && showHint && (0, _element.createElement)(_components.
|
|
143
|
+
}, currentValueHint)), side === 'all' && showHint && (0, _element.createElement)(_components.BaseControl.VisualLabel, {
|
|
144
144
|
className: "components-spacing-sizes-control__hint-all"
|
|
145
145
|
}, currentValueHint), !disableCustomSpacingSizes && (0, _element.createElement)(_components.Button, {
|
|
146
146
|
label: showCustomValueControl ? (0, _i18n.__)('Use size preset') : (0, _i18n.__)('Set custom size'),
|
|
@@ -196,7 +196,8 @@ function SpacingInputControl(_ref) {
|
|
|
196
196
|
max: spacingSizes.length - 1,
|
|
197
197
|
marks: marks,
|
|
198
198
|
label: ariaLabel,
|
|
199
|
-
hideLabelFromVision: true
|
|
199
|
+
hideLabelFromVision: true,
|
|
200
|
+
__nextHasNoMarginBottom: true
|
|
200
201
|
}), !showRangeControl && !showCustomValueControl && (0, _element.createElement)(_components.CustomSelectControl, {
|
|
201
202
|
className: "components-spacing-sizes-control__custom-select-control",
|
|
202
203
|
value: options.find(option => option.key === currentValue) || '' // passing undefined here causes a downshift controlled/uncontrolled warning
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/spacing-input-control.js"],"names":["SpacingInputControl","spacingSizes","value","side","onChange","isMixed","type","minimumCustomValue","selectListSizes","showRangeControl","length","disableCustomSpacingSizes","select","editorSettings","blockEditorStore","getSettings","showCustomValueControl","setShowCustomValueControl","undefined","units","availableUnits","currentValue","showCustomValueInSelectList","name","slug","size","selectedUnit","setInitialValue","customTooltipContent","newValue","customRangeValue","parseInt","getNewCustomValue","newSize","isNumeric","isNaN","parseFloat","nextValue","getNewPresetValue","controlType","handleCustomValueSliderChange","next","join","allPlaceholder","currentValueHint","options","map","index","key","marks","label","ariaLabel","LABELS","toLowerCase","showHint","settings","gridColumn","event","nativeEvent","offsetX","find","option","selection","selectedItem"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAUA;;AACA;;AAKA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAWe,SAASA,mBAAT,OAQX;AAAA;;AAAA,MARyC;AAC5CC,IAAAA,YAD4C;AAE5CC,IAAAA,KAF4C;AAG5CC,IAAAA,IAH4C;AAI5CC,IAAAA,QAJ4C;AAK5CC,IAAAA,OAAO,GAAG,KALkC;AAM5CC,IAAAA,IAN4C;AAO5CC,IAAAA;AAP4C,GAQzC;AACH;AACAL,EAAAA,KAAK,GAAG,0CAA+BA,KAA/B,EAAsCD,YAAtC,CAAR;AAEA,MAAIO,eAAe,GAAGP,YAAtB;AACA,QAAMQ,gBAAgB,GAAGR,YAAY,CAACS,MAAb,IAAuB,CAAhD;AAEA,QAAMC,yBAAyB,GAAG,qBAAaC,MAAF,IAAc;AAC1D,UAAMC,cAAc,GAAGD,MAAM,CAAEE,YAAF,CAAN,CAA2BC,WAA3B,EAAvB;AACA,WAAOF,cAAP,aAAOA,cAAP,uBAAOA,cAAc,CAAEF,yBAAvB;AACA,GAHiC,CAAlC;AAKA,QAAM,CAAEK,sBAAF,EAA0BC,yBAA1B,IAAwD,uBAC7D,CAAEN,yBAAF,IACCT,KAAK,KAAKgB,SADX,IAEC,CAAE,iCAAsBhB,KAAtB,CAH0D,CAA9D;AAMA,QAAMiB,KAAK,GAAG,8CAAgB;AAC7BC,IAAAA,cAAc,EAAE,yBAAY,eAAZ,KAAiC,CAAE,IAAF,EAAQ,IAAR,EAAc,KAAd;AADpB,GAAhB,CAAd;AAIA,MAAIC,YAAY,GAAG,IAAnB;AAEA,QAAMC,2BAA2B,GAChC,C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IAAA,GAAG,EAAG,CAjBP;AAkBC,IAAA,GAAG,EAAG3B,YAAY,CAACS,MAAb,GAAsB,CAlB7B;AAmBC,IAAA,KAAK,EAAGuC,KAnBT;AAoBC,IAAA,KAAK,EAAGE,SApBT;AAqBC,IAAA,mBAAmB,EAAG;AArBvB,IAtEF,EA8FG,CAAE1C,gBAAF,IAAsB,CAAEO,sBAAxB,IACD,4BAAC,+BAAD;AACC,IAAA,SAAS,EAAC,yDADX;AAEC,IAAA,KAAK,EACJ6B,OAAO,CAACe,IAAR,CACGC,MAAF,IAAcA,MAAM,CAACb,GAAP,KAAe3B,YAD9B,KAEK,EAHD,CAGI;AALV;AAOC,IAAA,QAAQ,EAAKyC,SAAF,IAAiB;AAC3B1D,MAAAA,QAAQ,CACPkC,iBAAiB,CAChBwB,SAAS,CAACC,YAAV,CAAuBf,GADP,EAEhB,YAFgB,CADV,CAAR;AAMA,KAdF;AAeC,IAAA,OAAO,EAAGH,OAfX;AAgBC,IAAA,KAAK,EAAGM,SAhBT;AAiBC,IAAA,mBAAmB,EAAG,IAjBvB;AAkBC,IAAA,wBAAwB,EAAG;AAlB5B,IA/FF,CADD;AAuHA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tButton,\n\tRangeControl,\n\tCustomSelectControl,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalHStack as HStack,\n\t__experimentalText as Text,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\nimport { store as blockEditorStore } from '../../store';\nimport {\n\tLABELS,\n\tgetSliderValueFromPreset,\n\tgetCustomValueFromPreset,\n\tgetPresetValueFromCustomValue,\n\tisValueSpacingPreset,\n} from './utils';\n\nexport default function SpacingInputControl( {\n\tspacingSizes,\n\tvalue,\n\tside,\n\tonChange,\n\tisMixed = false,\n\ttype,\n\tminimumCustomValue,\n} ) {\n\t// Treat value as a preset value if the passed in value matches the value of one of the spacingSizes.\n\tvalue = getPresetValueFromCustomValue( value, spacingSizes );\n\n\tlet selectListSizes = spacingSizes;\n\tconst showRangeControl = spacingSizes.length <= 8;\n\n\tconst disableCustomSpacingSizes = useSelect( ( select ) => {\n\t\tconst editorSettings = select( blockEditorStore ).getSettings();\n\t\treturn editorSettings?.disableCustomSpacingSizes;\n\t} );\n\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomSpacingSizes &&\n\t\t\tvalue !== undefined &&\n\t\t\t! isValueSpacingPreset( value )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tlet currentValue = null;\n\n\tconst showCustomValueInSelectList =\n\t\t! showRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tvalue !== undefined &&\n\t\t( ! isValueSpacingPreset( value ) ||\n\t\t\t( isValueSpacingPreset( value ) && isMixed ) );\n\n\tif ( showCustomValueInSelectList ) {\n\t\tselectListSizes = [\n\t\t\t...spacingSizes,\n\t\t\t{\n\t\t\t\tname: ! isMixed\n\t\t\t\t\t? // translators: A custom measurement, eg. a number followed by a unit like 12px.\n\t\t\t\t\t sprintf( __( 'Custom (%s)' ), value )\n\t\t\t\t\t: __( 'Mixed' ),\n\t\t\t\tslug: 'custom',\n\t\t\t\tsize: value,\n\t\t\t},\n\t\t];\n\t\tcurrentValue = selectListSizes.length - 1;\n\t} else if ( ! isMixed ) {\n\t\tcurrentValue = ! showCustomValueControl\n\t\t\t? getSliderValueFromPreset( value, spacingSizes )\n\t\t\t: getCustomValueFromPreset( value, spacingSizes );\n\t}\n\n\tconst selectedUnit =\n\t\tuseMemo(\n\t\t\t() => parseQuantityAndUnitFromRawValue( currentValue ),\n\t\t\t[ currentValue ]\n\t\t)[ 1 ] || units[ 0 ].value;\n\n\tconst setInitialValue = () => {\n\t\tif ( value === undefined ) {\n\t\t\tonChange( '0' );\n\t\t}\n\t};\n\n\tconst customTooltipContent = ( newValue ) =>\n\t\tvalue === undefined ? undefined : spacingSizes[ newValue ]?.name;\n\n\tconst customRangeValue = parseInt( currentValue, 10 );\n\n\tconst getNewCustomValue = ( newSize ) => {\n\t\tconst isNumeric = ! isNaN( parseFloat( newSize ) );\n\t\tconst nextValue = isNumeric ? newSize : undefined;\n\t\treturn nextValue;\n\t};\n\n\tconst getNewPresetValue = ( newSize, controlType ) => {\n\t\tconst size = parseInt( newSize, 10 );\n\n\t\tif ( controlType === 'selectList' ) {\n\t\t\tif ( size === 0 ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ( size === 1 ) {\n\t\t\t\treturn '0';\n\t\t\t}\n\t\t} else if ( size === 0 ) {\n\t\t\treturn '0';\n\t\t}\n\t\treturn `var:preset|spacing|${ spacingSizes[ newSize ]?.slug }`;\n\t};\n\n\tconst handleCustomValueSliderChange = ( next ) => {\n\t\tonChange( [ next, selectedUnit ].join( '' ) );\n\t};\n\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\tconst currentValueHint = ! isMixed\n\t\t? customTooltipContent( currentValue )\n\t\t: __( 'Mixed' );\n\n\tconst options = selectListSizes.map( ( size, index ) => ( {\n\t\tkey: index,\n\t\tname: size.name,\n\t} ) );\n\n\tconst marks = spacingSizes.map( ( newValue, index ) => ( {\n\t\tvalue: index,\n\t\tlabel: undefined,\n\t} ) );\n\n\tconst ariaLabel = sprintf(\n\t\t// translators: 1: The side of the block being modified (top, bottom, left, etc.). 2. Type of spacing being modified (Padding, margin, etc)\n\t\t__( '%1$s %2$s' ),\n\t\tLABELS[ side ],\n\t\ttype?.toLowerCase()\n\t);\n\n\tconst showHint =\n\t\tshowRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tcurrentValueHint !== undefined;\n\n\treturn (\n\t\t<>\n\t\t\t{ side !== 'all' && (\n\t\t\t\t<HStack className=\"components-spacing-sizes-control__side-labels\">\n\t\t\t\t\t<Text className=\"components-spacing-sizes-control__side-label\">\n\t\t\t\t\t\t{ LABELS[ side ] }\n\t\t\t\t\t</Text>\n\n\t\t\t\t\t{ showHint && (\n\t\t\t\t\t\t<Text className=\"components-spacing-sizes-control__hint-single\">\n\t\t\t\t\t\t\t{ currentValueHint }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t) }\n\t\t\t{ side === 'all' && showHint && (\n\t\t\t\t<Text className=\"components-spacing-sizes-control__hint-all\">\n\t\t\t\t\t{ currentValueHint }\n\t\t\t\t</Text>\n\t\t\t) }\n\n\t\t\t{ ! disableCustomSpacingSizes && (\n\t\t\t\t<Button\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t}\n\t\t\t\t\ticon={ settings }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetShowCustomValueControl( ! showCustomValueControl );\n\t\t\t\t\t} }\n\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\tisSmall\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-all':\n\t\t\t\t\t\t\tside === 'all',\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-single':\n\t\t\t\t\t\t\tside !== 'all',\n\t\t\t\t\t} ) }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomValueControl && (\n\t\t\t\t<>\n\t\t\t\t\t<UnitControl\n\t\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\t\tonChange( getNewCustomValue( newSize ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tmin={ minimumCustomValue }\n\t\t\t\t\t\tplaceholder={ allPlaceholder }\n\t\t\t\t\t\tdisableUnits={ isMixed }\n\t\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-input\"\n\t\t\t\t\t\tstyle={ { gridColumn: '1' } }\n\t\t\t\t\t/>\n\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\tvalue={ customRangeValue }\n\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\tmax={ 100 }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\tonChange={ handleCustomValueSliderChange }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-range\"\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<RangeControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__range-control\"\n\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\tonChange( getNewPresetValue( newSize ) )\n\t\t\t\t\t}\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// If mouse down is near start of range set initial value to 0, which\n\t\t\t\t\t\t// prevents the user have to drag right then left to get 0 setting.\n\t\t\t\t\t\tif ( event?.nativeEvent?.offsetX < 35 ) {\n\t\t\t\t\t\t\tsetInitialValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\twithInputField={ false }\n\t\t\t\t\taria-valuenow={ currentValue }\n\t\t\t\t\taria-valuetext={ spacingSizes[ currentValue ]?.name }\n\t\t\t\t\trenderTooltipContent={ customTooltipContent }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tmax={ spacingSizes.length - 1 }\n\t\t\t\t\tmarks={ marks }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<CustomSelectControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-select-control\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\toptions.find(\n\t\t\t\t\t\t\t( option ) => option.key === currentValue\n\t\t\t\t\t\t) || '' // passing undefined here causes a downshift controlled/uncontrolled warning\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( selection ) => {\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tgetNewPresetValue(\n\t\t\t\t\t\t\t\tselection.selectedItem.key,\n\t\t\t\t\t\t\t\t'selectList'\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\toptions={ options }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextUnconstrainedWidth={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/spacing-sizes-control/spacing-input-control.js"],"names":["SpacingInputControl","spacingSizes","value","side","onChange","isMixed","type","minimumCustomValue","selectListSizes","showRangeControl","length","disableCustomSpacingSizes","select","editorSettings","blockEditorStore","getSettings","showCustomValueControl","setShowCustomValueControl","undefined","units","availableUnits","currentValue","showCustomValueInSelectList","name","slug","size","selectedUnit","setInitialValue","customTooltipContent","newValue","customRangeValue","parseInt","getNewCustomValue","newSize","isNumeric","isNaN","parseFloat","nextValue","getNewPresetValue","controlType","handleCustomValueSliderChange","next","join","allPlaceholder","currentValueHint","options","map","index","key","marks","label","ariaLabel","LABELS","toLowerCase","showHint","settings","gridColumn","event","nativeEvent","offsetX","find","option","selection","selectedItem"],"mappings":";;;;;;;;;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GE,SApBT;AAqBC,IAAA,mBAAmB,EAAG,IArBvB;AAsBC,IAAA,uBAAuB,EAAG;AAtB3B,IAtEF,EA+FG,CAAE1C,gBAAF,IAAsB,CAAEO,sBAAxB,IACD,4BAAC,+BAAD;AACC,IAAA,SAAS,EAAC,yDADX;AAEC,IAAA,KAAK,EACJ6B,OAAO,CAACe,IAAR,CACGC,MAAF,IAAcA,MAAM,CAACb,GAAP,KAAe3B,YAD9B,KAEK,EAHD,CAGI;AALV;AAOC,IAAA,QAAQ,EAAKyC,SAAF,IAAiB;AAC3B1D,MAAAA,QAAQ,CACPkC,iBAAiB,CAChBwB,SAAS,CAACC,YAAV,CAAuBf,GADP,EAEhB,YAFgB,CADV,CAAR;AAMA,KAdF;AAeC,IAAA,OAAO,EAAGH,OAfX;AAgBC,IAAA,KAAK,EAAGM,SAhBT;AAiBC,IAAA,mBAAmB,EAAG,IAjBvB;AAkBC,IAAA,wBAAwB,EAAG;AAlB5B,IAhGF,CADD;AAwHA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tBaseControl,\n\tButton,\n\tRangeControl,\n\tCustomSelectControl,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalHStack as HStack,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { settings } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../use-setting';\nimport { store as blockEditorStore } from '../../store';\nimport {\n\tLABELS,\n\tgetSliderValueFromPreset,\n\tgetCustomValueFromPreset,\n\tgetPresetValueFromCustomValue,\n\tisValueSpacingPreset,\n} from './utils';\n\nexport default function SpacingInputControl( {\n\tspacingSizes,\n\tvalue,\n\tside,\n\tonChange,\n\tisMixed = false,\n\ttype,\n\tminimumCustomValue,\n} ) {\n\t// Treat value as a preset value if the passed in value matches the value of one of the spacingSizes.\n\tvalue = getPresetValueFromCustomValue( value, spacingSizes );\n\n\tlet selectListSizes = spacingSizes;\n\tconst showRangeControl = spacingSizes.length <= 8;\n\n\tconst disableCustomSpacingSizes = useSelect( ( select ) => {\n\t\tconst editorSettings = select( blockEditorStore ).getSettings();\n\t\treturn editorSettings?.disableCustomSpacingSizes;\n\t} );\n\n\tconst [ showCustomValueControl, setShowCustomValueControl ] = useState(\n\t\t! disableCustomSpacingSizes &&\n\t\t\tvalue !== undefined &&\n\t\t\t! isValueSpacingPreset( value )\n\t);\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],\n\t} );\n\n\tlet currentValue = null;\n\n\tconst showCustomValueInSelectList =\n\t\t! showRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tvalue !== undefined &&\n\t\t( ! isValueSpacingPreset( value ) ||\n\t\t\t( isValueSpacingPreset( value ) && isMixed ) );\n\n\tif ( showCustomValueInSelectList ) {\n\t\tselectListSizes = [\n\t\t\t...spacingSizes,\n\t\t\t{\n\t\t\t\tname: ! isMixed\n\t\t\t\t\t? // translators: A custom measurement, eg. a number followed by a unit like 12px.\n\t\t\t\t\t sprintf( __( 'Custom (%s)' ), value )\n\t\t\t\t\t: __( 'Mixed' ),\n\t\t\t\tslug: 'custom',\n\t\t\t\tsize: value,\n\t\t\t},\n\t\t];\n\t\tcurrentValue = selectListSizes.length - 1;\n\t} else if ( ! isMixed ) {\n\t\tcurrentValue = ! showCustomValueControl\n\t\t\t? getSliderValueFromPreset( value, spacingSizes )\n\t\t\t: getCustomValueFromPreset( value, spacingSizes );\n\t}\n\n\tconst selectedUnit =\n\t\tuseMemo(\n\t\t\t() => parseQuantityAndUnitFromRawValue( currentValue ),\n\t\t\t[ currentValue ]\n\t\t)[ 1 ] || units[ 0 ].value;\n\n\tconst setInitialValue = () => {\n\t\tif ( value === undefined ) {\n\t\t\tonChange( '0' );\n\t\t}\n\t};\n\n\tconst customTooltipContent = ( newValue ) =>\n\t\tvalue === undefined ? undefined : spacingSizes[ newValue ]?.name;\n\n\tconst customRangeValue = parseInt( currentValue, 10 );\n\n\tconst getNewCustomValue = ( newSize ) => {\n\t\tconst isNumeric = ! isNaN( parseFloat( newSize ) );\n\t\tconst nextValue = isNumeric ? newSize : undefined;\n\t\treturn nextValue;\n\t};\n\n\tconst getNewPresetValue = ( newSize, controlType ) => {\n\t\tconst size = parseInt( newSize, 10 );\n\n\t\tif ( controlType === 'selectList' ) {\n\t\t\tif ( size === 0 ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif ( size === 1 ) {\n\t\t\t\treturn '0';\n\t\t\t}\n\t\t} else if ( size === 0 ) {\n\t\t\treturn '0';\n\t\t}\n\t\treturn `var:preset|spacing|${ spacingSizes[ newSize ]?.slug }`;\n\t};\n\n\tconst handleCustomValueSliderChange = ( next ) => {\n\t\tonChange( [ next, selectedUnit ].join( '' ) );\n\t};\n\n\tconst allPlaceholder = isMixed ? __( 'Mixed' ) : null;\n\n\tconst currentValueHint = ! isMixed\n\t\t? customTooltipContent( currentValue )\n\t\t: __( 'Mixed' );\n\n\tconst options = selectListSizes.map( ( size, index ) => ( {\n\t\tkey: index,\n\t\tname: size.name,\n\t} ) );\n\n\tconst marks = spacingSizes.map( ( newValue, index ) => ( {\n\t\tvalue: index,\n\t\tlabel: undefined,\n\t} ) );\n\n\tconst ariaLabel = sprintf(\n\t\t// translators: 1: The side of the block being modified (top, bottom, left, etc.). 2. Type of spacing being modified (Padding, margin, etc)\n\t\t__( '%1$s %2$s' ),\n\t\tLABELS[ side ],\n\t\ttype?.toLowerCase()\n\t);\n\n\tconst showHint =\n\t\tshowRangeControl &&\n\t\t! showCustomValueControl &&\n\t\tcurrentValueHint !== undefined;\n\n\treturn (\n\t\t<>\n\t\t\t{ side !== 'all' && (\n\t\t\t\t<HStack className=\"components-spacing-sizes-control__side-labels\">\n\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__side-label\">\n\t\t\t\t\t\t{ LABELS[ side ] }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\n\t\t\t\t\t{ showHint && (\n\t\t\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-single\">\n\t\t\t\t\t\t\t{ currentValueHint }\n\t\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t) }\n\t\t\t{ side === 'all' && showHint && (\n\t\t\t\t<BaseControl.VisualLabel className=\"components-spacing-sizes-control__hint-all\">\n\t\t\t\t\t{ currentValueHint }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t) }\n\n\t\t\t{ ! disableCustomSpacingSizes && (\n\t\t\t\t<Button\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tshowCustomValueControl\n\t\t\t\t\t\t\t? __( 'Use size preset' )\n\t\t\t\t\t\t\t: __( 'Set custom size' )\n\t\t\t\t\t}\n\t\t\t\t\ticon={ settings }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetShowCustomValueControl( ! showCustomValueControl );\n\t\t\t\t\t} }\n\t\t\t\t\tisPressed={ showCustomValueControl }\n\t\t\t\t\tisSmall\n\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-all':\n\t\t\t\t\t\t\tside === 'all',\n\t\t\t\t\t\t'components-spacing-sizes-control__custom-toggle-single':\n\t\t\t\t\t\t\tside !== 'all',\n\t\t\t\t\t} ) }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomValueControl && (\n\t\t\t\t<>\n\t\t\t\t\t<UnitControl\n\t\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\t\tonChange( getNewCustomValue( newSize ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tmin={ minimumCustomValue }\n\t\t\t\t\t\tplaceholder={ allPlaceholder }\n\t\t\t\t\t\tdisableUnits={ isMixed }\n\t\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-input\"\n\t\t\t\t\t\tstyle={ { gridColumn: '1' } }\n\t\t\t\t\t/>\n\n\t\t\t\t\t<RangeControl\n\t\t\t\t\t\tvalue={ customRangeValue }\n\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\tmax={ 100 }\n\t\t\t\t\t\twithInputField={ false }\n\t\t\t\t\t\tonChange={ handleCustomValueSliderChange }\n\t\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-value-range\"\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<RangeControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__range-control\"\n\t\t\t\t\tvalue={ currentValue }\n\t\t\t\t\tonChange={ ( newSize ) =>\n\t\t\t\t\t\tonChange( getNewPresetValue( newSize ) )\n\t\t\t\t\t}\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// If mouse down is near start of range set initial value to 0, which\n\t\t\t\t\t\t// prevents the user have to drag right then left to get 0 setting.\n\t\t\t\t\t\tif ( event?.nativeEvent?.offsetX < 35 ) {\n\t\t\t\t\t\t\tsetInitialValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\twithInputField={ false }\n\t\t\t\t\taria-valuenow={ currentValue }\n\t\t\t\t\taria-valuetext={ spacingSizes[ currentValue ]?.name }\n\t\t\t\t\trenderTooltipContent={ customTooltipContent }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tmax={ spacingSizes.length - 1 }\n\t\t\t\t\tmarks={ marks }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextHasNoMarginBottom={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! showRangeControl && ! showCustomValueControl && (\n\t\t\t\t<CustomSelectControl\n\t\t\t\t\tclassName=\"components-spacing-sizes-control__custom-select-control\"\n\t\t\t\t\tvalue={\n\t\t\t\t\t\toptions.find(\n\t\t\t\t\t\t\t( option ) => option.key === currentValue\n\t\t\t\t\t\t) || '' // passing undefined here causes a downshift controlled/uncontrolled warning\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( selection ) => {\n\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\tgetNewPresetValue(\n\t\t\t\t\t\t\t\tselection.selectedItem.key,\n\t\t\t\t\t\t\t\t'selectList'\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\toptions={ options }\n\t\t\t\t\tlabel={ ariaLabel }\n\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t__nextUnconstrainedWidth={ true }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
package/build/hooks/index.js
CHANGED
|
@@ -57,6 +57,18 @@ Object.defineProperty(exports, "useCustomSides", {
|
|
|
57
57
|
return _dimensions.useCustomSides;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "useLayoutClasses", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _layout.useLayoutClasses;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "useLayoutStyles", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _layout.useLayoutStyles;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
60
72
|
|
|
61
73
|
require("./compat");
|
|
62
74
|
|
|
@@ -84,7 +96,7 @@ require("./font-size");
|
|
|
84
96
|
|
|
85
97
|
require("./border");
|
|
86
98
|
|
|
87
|
-
require("./layout");
|
|
99
|
+
var _layout = require("./layout");
|
|
88
100
|
|
|
89
101
|
require("./content-lock-ui");
|
|
90
102
|
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport './compat';\nimport './align';\nimport './lock';\nimport './anchor';\nimport './aria-label';\nimport './custom-class-name';\nimport './generated-class-name';\nimport './style';\nimport './settings';\nimport './color';\nimport './duotone';\nimport './font-size';\nimport './border';\nimport './layout';\nimport './content-lock-ui';\nimport './metadata';\nimport './metadata-name';\n\nexport { useCustomSides } from './dimensions';\nexport { useLayoutClasses, useLayoutStyles } from './layout';\nexport { getBorderClassesAndStyles, useBorderProps } from './use-border-props';\nexport { getColorClassesAndStyles, useColorProps } from './use-color-props';\nexport { getSpacingClassesAndStyles } from './use-spacing-props';\nexport { getTypographyClassesAndStyles } from './use-typography-props';\nexport { getGapCSSValue } from './gap';\nexport { useCachedTruthy } from './use-cached-truthy';\n"]}
|
package/build/hooks/layout.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.addAttribute = addAttribute;
|
|
9
|
+
exports.useLayoutClasses = useLayoutClasses;
|
|
10
|
+
exports.useLayoutStyles = useLayoutStyles;
|
|
9
11
|
exports.withLayoutStyles = exports.withInspectorControls = void 0;
|
|
10
12
|
|
|
11
13
|
var _element = require("@wordpress/element");
|
|
@@ -53,22 +55,17 @@ var _layouts = require("../layouts");
|
|
|
53
55
|
*/
|
|
54
56
|
const layoutBlockSupportKey = '__experimentalLayout';
|
|
55
57
|
/**
|
|
56
|
-
* Generates the utility classnames for the given
|
|
57
|
-
* This method was primarily added to reintroduce classnames that were removed
|
|
58
|
-
* in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather
|
|
59
|
-
* than providing an extensive list of all possible layout classes. The plan is to
|
|
60
|
-
* have the style engine generate a more extensive list of utility classnames which
|
|
61
|
-
* will then replace this method.
|
|
58
|
+
* Generates the utility classnames for the given block's layout attributes.
|
|
62
59
|
*
|
|
63
|
-
* @param { Object }
|
|
64
|
-
* @param { Object } layoutDefinitions An object containing layout definitions, stored in theme.json.
|
|
60
|
+
* @param { Object } block Block object.
|
|
65
61
|
*
|
|
66
62
|
* @return { Array } Array of CSS classname strings.
|
|
67
63
|
*/
|
|
68
64
|
|
|
69
|
-
function useLayoutClasses(
|
|
70
|
-
var
|
|
65
|
+
function useLayoutClasses() {
|
|
66
|
+
var _globalLayoutSettings, _globalLayoutSettings2;
|
|
71
67
|
|
|
68
|
+
let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
72
69
|
const rootPaddingAlignment = (0, _data.useSelect)(select => {
|
|
73
70
|
var _getSettings$__experi;
|
|
74
71
|
|
|
@@ -77,32 +74,87 @@ function useLayoutClasses(layout, layoutDefinitions) {
|
|
|
77
74
|
} = select(_store.store);
|
|
78
75
|
return (_getSettings$__experi = getSettings().__experimentalFeatures) === null || _getSettings$__experi === void 0 ? void 0 : _getSettings$__experi.useRootPaddingAwareAlignments;
|
|
79
76
|
}, []);
|
|
77
|
+
const globalLayoutSettings = (0, _useSetting.default)('layout') || {};
|
|
78
|
+
const {
|
|
79
|
+
attributes = {},
|
|
80
|
+
name
|
|
81
|
+
} = block;
|
|
82
|
+
const {
|
|
83
|
+
layout
|
|
84
|
+
} = attributes;
|
|
85
|
+
const {
|
|
86
|
+
default: defaultBlockLayout
|
|
87
|
+
} = (0, _blocks.getBlockSupport)(name, layoutBlockSupportKey) || {};
|
|
88
|
+
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
89
|
+
type: 'constrained'
|
|
90
|
+
} : layout || defaultBlockLayout || {};
|
|
80
91
|
const layoutClassnames = [];
|
|
81
92
|
|
|
82
|
-
if (
|
|
83
|
-
var
|
|
93
|
+
if (globalLayoutSettings !== null && globalLayoutSettings !== void 0 && (_globalLayoutSettings = globalLayoutSettings.definitions) !== null && _globalLayoutSettings !== void 0 && (_globalLayoutSettings2 = _globalLayoutSettings[(usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default']) !== null && _globalLayoutSettings2 !== void 0 && _globalLayoutSettings2.className) {
|
|
94
|
+
var _globalLayoutSettings3, _globalLayoutSettings4;
|
|
84
95
|
|
|
85
|
-
layoutClassnames.push(
|
|
96
|
+
layoutClassnames.push(globalLayoutSettings === null || globalLayoutSettings === void 0 ? void 0 : (_globalLayoutSettings3 = globalLayoutSettings.definitions) === null || _globalLayoutSettings3 === void 0 ? void 0 : (_globalLayoutSettings4 = _globalLayoutSettings3[(usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default']) === null || _globalLayoutSettings4 === void 0 ? void 0 : _globalLayoutSettings4.className);
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
if ((
|
|
99
|
+
if ((usedLayout !== null && usedLayout !== void 0 && usedLayout.inherit || usedLayout !== null && usedLayout !== void 0 && usedLayout.contentSize || (usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) === 'constrained') && rootPaddingAlignment) {
|
|
89
100
|
layoutClassnames.push('has-global-padding');
|
|
90
101
|
}
|
|
91
102
|
|
|
92
|
-
if (
|
|
93
|
-
layoutClassnames.push(`is-${(0, _lodash.kebabCase)(
|
|
103
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.orientation) {
|
|
104
|
+
layoutClassnames.push(`is-${(0, _lodash.kebabCase)(usedLayout.orientation)}`);
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
if (
|
|
97
|
-
layoutClassnames.push(`is-content-justification-${(0, _lodash.kebabCase)(
|
|
107
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.justifyContent) {
|
|
108
|
+
layoutClassnames.push(`is-content-justification-${(0, _lodash.kebabCase)(usedLayout.justifyContent)}`);
|
|
98
109
|
}
|
|
99
110
|
|
|
100
|
-
if (
|
|
111
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.flexWrap && usedLayout.flexWrap === 'nowrap') {
|
|
101
112
|
layoutClassnames.push('is-nowrap');
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
return layoutClassnames;
|
|
105
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Generates a CSS rule with the given block's layout styles.
|
|
119
|
+
*
|
|
120
|
+
* @param { Object } block Block object.
|
|
121
|
+
* @param { string } selector A selector to use in generating the CSS rule.
|
|
122
|
+
*
|
|
123
|
+
* @return { string } CSS rule.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
function useLayoutStyles() {
|
|
128
|
+
var _fullLayoutType$getLa;
|
|
129
|
+
|
|
130
|
+
let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
131
|
+
let selector = arguments.length > 1 ? arguments[1] : undefined;
|
|
132
|
+
const {
|
|
133
|
+
attributes = {},
|
|
134
|
+
name
|
|
135
|
+
} = block;
|
|
136
|
+
const {
|
|
137
|
+
layout = {},
|
|
138
|
+
style = {}
|
|
139
|
+
} = attributes; // Update type for blocks using legacy layouts.
|
|
140
|
+
|
|
141
|
+
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
142
|
+
type: 'constrained'
|
|
143
|
+
} : layout || {};
|
|
144
|
+
const fullLayoutType = (0, _layouts.getLayoutType)((usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default');
|
|
145
|
+
const globalLayoutSettings = (0, _useSetting.default)('layout') || {};
|
|
146
|
+
const blockGapSupport = (0, _useSetting.default)('spacing.blockGap');
|
|
147
|
+
const hasBlockGapSupport = blockGapSupport !== null;
|
|
148
|
+
const css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$getLa = fullLayoutType.getLayoutStyle) === null || _fullLayoutType$getLa === void 0 ? void 0 : _fullLayoutType$getLa.call(fullLayoutType, {
|
|
149
|
+
blockName: name,
|
|
150
|
+
selector,
|
|
151
|
+
layout,
|
|
152
|
+
layoutDefinitions: globalLayoutSettings === null || globalLayoutSettings === void 0 ? void 0 : globalLayoutSettings.definitions,
|
|
153
|
+
style,
|
|
154
|
+
hasBlockGapSupport
|
|
155
|
+
});
|
|
156
|
+
return css;
|
|
157
|
+
}
|
|
106
158
|
|
|
107
159
|
function LayoutPanel(_ref) {
|
|
108
160
|
let {
|
|
@@ -272,7 +324,8 @@ exports.withInspectorControls = withInspectorControls;
|
|
|
272
324
|
const withLayoutStyles = (0, _compose.createHigherOrderComponent)(BlockListBlock => props => {
|
|
273
325
|
const {
|
|
274
326
|
name,
|
|
275
|
-
attributes
|
|
327
|
+
attributes,
|
|
328
|
+
block
|
|
276
329
|
} = props;
|
|
277
330
|
const hasLayoutBlockSupport = (0, _blocks.hasBlockSupport)(name, layoutBlockSupportKey);
|
|
278
331
|
const disableLayoutStyles = (0, _data.useSelect)(select => {
|
|
@@ -294,7 +347,7 @@ const withLayoutStyles = (0, _compose.createHigherOrderComponent)(BlockListBlock
|
|
|
294
347
|
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
295
348
|
type: 'constrained'
|
|
296
349
|
} : layout || defaultBlockLayout || {};
|
|
297
|
-
const layoutClasses = hasLayoutBlockSupport ? useLayoutClasses(
|
|
350
|
+
const layoutClasses = hasLayoutBlockSupport ? useLayoutClasses(block) : null;
|
|
298
351
|
const selector = `.${(0, _blocks.getBlockDefaultClassName)(name)}.wp-container-${id}`;
|
|
299
352
|
const blockGapSupport = (0, _useSetting.default)('spacing.blockGap');
|
|
300
353
|
const hasBlockGapSupport = blockGapSupport !== null; // Get CSS string for the current layout type.
|
|
@@ -303,10 +356,10 @@ const withLayoutStyles = (0, _compose.createHigherOrderComponent)(BlockListBlock
|
|
|
303
356
|
let css;
|
|
304
357
|
|
|
305
358
|
if (shouldRenderLayoutStyles) {
|
|
306
|
-
var _fullLayoutType$
|
|
359
|
+
var _fullLayoutType$getLa2;
|
|
307
360
|
|
|
308
361
|
const fullLayoutType = (0, _layouts.getLayoutType)((usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default');
|
|
309
|
-
css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$
|
|
362
|
+
css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$getLa2 = fullLayoutType.getLayoutStyle) === null || _fullLayoutType$getLa2 === void 0 ? void 0 : _fullLayoutType$getLa2.call(fullLayoutType, {
|
|
310
363
|
blockName: name,
|
|
311
364
|
selector,
|
|
312
365
|
layout: usedLayout,
|