@wordpress/block-editor 10.0.4 → 10.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +40 -0
  3. package/build/components/block-inspector/index.js +3 -4
  4. package/build/components/block-inspector/index.js.map +1 -1
  5. package/build/components/block-list/block.js +72 -14
  6. package/build/components/block-list/block.js.map +1 -1
  7. package/build/components/font-sizes/fluid-utils.js +208 -0
  8. package/build/components/font-sizes/fluid-utils.js.map +1 -0
  9. package/build/components/font-sizes/index.js +8 -0
  10. package/build/components/font-sizes/index.js.map +1 -1
  11. package/build/components/inserter/search-items.js +2 -17
  12. package/build/components/inserter/search-items.js.map +1 -1
  13. package/build/hooks/font-size.js +60 -0
  14. package/build/hooks/font-size.js.map +1 -1
  15. package/build/hooks/margin.js +4 -4
  16. package/build/hooks/margin.js.map +1 -1
  17. package/build/hooks/use-typography-props.js +17 -3
  18. package/build/hooks/use-typography-props.js.map +1 -1
  19. package/build-module/components/block-inspector/index.js +3 -4
  20. package/build-module/components/block-inspector/index.js.map +1 -1
  21. package/build-module/components/block-list/block.js +72 -14
  22. package/build-module/components/block-list/block.js.map +1 -1
  23. package/build-module/components/font-sizes/fluid-utils.js +197 -0
  24. package/build-module/components/font-sizes/fluid-utils.js.map +1 -0
  25. package/build-module/components/font-sizes/index.js +1 -0
  26. package/build-module/components/font-sizes/index.js.map +1 -1
  27. package/build-module/components/inserter/search-items.js +3 -17
  28. package/build-module/components/inserter/search-items.js.map +1 -1
  29. package/build-module/hooks/font-size.js +59 -1
  30. package/build-module/hooks/font-size.js.map +1 -1
  31. package/build-module/hooks/margin.js +4 -4
  32. package/build-module/hooks/margin.js.map +1 -1
  33. package/build-module/hooks/use-typography-props.js +17 -4
  34. package/build-module/hooks/use-typography-props.js.map +1 -1
  35. package/build-style/style-rtl.css +61 -106
  36. package/build-style/style.css +61 -106
  37. package/package.json +3 -4
  38. package/src/components/block-inspector/index.js +4 -7
  39. package/src/components/block-list/block.js +111 -7
  40. package/src/components/block-list/style.scss +85 -133
  41. package/src/components/button-block-appender/style.scss +3 -1
  42. package/src/components/font-sizes/fluid-utils.js +221 -0
  43. package/src/components/font-sizes/index.js +1 -0
  44. package/src/components/font-sizes/test/fluid-utils.js +168 -0
  45. package/src/components/inserter/search-items.js +3 -15
  46. package/src/components/inserter/test/search-items.js +4 -0
  47. package/src/hooks/font-size.js +75 -0
  48. package/src/hooks/margin.js +4 -4
  49. package/src/hooks/test/use-typography-props.js +22 -0
  50. package/src/hooks/use-typography-props.js +18 -3
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getComputedFluidTypographyValue = getComputedFluidTypographyValue;
7
+ exports.getTypographyValueAndUnit = getTypographyValueAndUnit;
8
+ exports.roundToPrecision = roundToPrecision;
9
+
10
+ /**
11
+ * The fluid utilities must match the backend equivalent.
12
+ * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php
13
+ * ---------------------------------------------------------------
14
+ */
15
+ // Defaults.
16
+ const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
17
+ const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';
18
+ const DEFAULT_SCALE_FACTOR = 1;
19
+ const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;
20
+ const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
21
+ /**
22
+ * Computes a fluid font-size value that uses clamp(). A minimum and maxinmum
23
+ * font size OR a single font size can be specified.
24
+ *
25
+ * If a single font size is specified, it is scaled up and down by
26
+ * minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and
27
+ * maximum sizes.
28
+ *
29
+ * @example
30
+ * ```js
31
+ * // Calculate fluid font-size value from a minimum and maximum value.
32
+ * const fontSize = getComputedFluidTypographyValue( {
33
+ * minimumFontSize: '20px',
34
+ * maximumFontSize: '45px'
35
+ * } );
36
+ * // Calculate fluid font-size value from a single font size.
37
+ * const fontSize = getComputedFluidTypographyValue( {
38
+ * fontSize: '30px',
39
+ * } );
40
+ * ```
41
+ *
42
+ * @param {Object} args
43
+ * @param {?string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.
44
+ * @param {?string} args.maximumViewPortWidth Maximum size up to which type will have fluidity. Optional if fontSize is specified.
45
+ * @param {string|number} [args.fontSize] Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.
46
+ * @param {?string} args.maximumFontSize Maximum font size for any clamp() calculation. Optional.
47
+ * @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.
48
+ * @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.
49
+ * @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.
50
+ * @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.
51
+ *
52
+ * @return {string|null} A font-size value using clamp().
53
+ */
54
+
55
+ function getComputedFluidTypographyValue(_ref) {
56
+ let {
57
+ minimumFontSize,
58
+ maximumFontSize,
59
+ fontSize,
60
+ minimumViewPortWidth = DEFAULT_MINIMUM_VIEWPORT_WIDTH,
61
+ maximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
62
+ scaleFactor = DEFAULT_SCALE_FACTOR,
63
+ minimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,
64
+ maximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR
65
+ } = _ref;
66
+
67
+ // Calculate missing minimumFontSize and maximumFontSize from
68
+ // defaultFontSize if provided.
69
+ if (fontSize && (!minimumFontSize || !maximumFontSize)) {
70
+ // Parse default font size.
71
+ const fontSizeParsed = getTypographyValueAndUnit(fontSize); // Protect against invalid units.
72
+
73
+ if (!(fontSizeParsed !== null && fontSizeParsed !== void 0 && fontSizeParsed.unit)) {
74
+ return null;
75
+ } // If no minimumFontSize is provided, derive using min scale factor.
76
+
77
+
78
+ if (!minimumFontSize) {
79
+ minimumFontSize = fontSizeParsed.value * minimumFontSizeFactor + fontSizeParsed.unit;
80
+ } // If no maximumFontSize is provided, derive using max scale factor.
81
+
82
+
83
+ if (!maximumFontSize) {
84
+ maximumFontSize = fontSizeParsed.value * maximumFontSizeFactor + fontSizeParsed.unit;
85
+ }
86
+ } // Return early if one of the provided inputs is not provided.
87
+
88
+
89
+ if (!minimumFontSize || !maximumFontSize) {
90
+ return null;
91
+ } // Grab the minimum font size and normalize it in order to use the value for calculations.
92
+
93
+
94
+ const minimumFontSizeParsed = getTypographyValueAndUnit(minimumFontSize); // We get a 'preferred' unit to keep units consistent when calculating,
95
+ // otherwise the result will not be accurate.
96
+
97
+ const fontSizeUnit = (minimumFontSizeParsed === null || minimumFontSizeParsed === void 0 ? void 0 : minimumFontSizeParsed.unit) || 'rem'; // Grab the maximum font size and normalize it in order to use the value for calculations.
98
+
99
+ const maximumFontSizeParsed = getTypographyValueAndUnit(maximumFontSize, {
100
+ coerceTo: fontSizeUnit
101
+ }); // Protect against unsupported units.
102
+
103
+ if (!minimumFontSizeParsed || !maximumFontSizeParsed) {
104
+ return null;
105
+ } // Use rem for accessible fluid target font scaling.
106
+
107
+
108
+ const minimumFontSizeRem = getTypographyValueAndUnit(minimumFontSize, {
109
+ coerceTo: 'rem'
110
+ }); // Viewport widths defined for fluid typography. Normalize units
111
+
112
+ const maximumViewPortWidthParsed = getTypographyValueAndUnit(maximumViewPortWidth, {
113
+ coerceTo: fontSizeUnit
114
+ });
115
+ const minumumViewPortWidthParsed = getTypographyValueAndUnit(minimumViewPortWidth, {
116
+ coerceTo: fontSizeUnit
117
+ }); // Protect against unsupported units.
118
+
119
+ if (!maximumViewPortWidthParsed || !minumumViewPortWidthParsed || !minimumFontSizeRem) {
120
+ return null;
121
+ } // Build CSS rule.
122
+ // Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
123
+
124
+
125
+ const minViewPortWidthOffsetValue = roundToPrecision(minumumViewPortWidthParsed.value / 100, 3);
126
+ const viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;
127
+ let linearFactor = 100 * ((maximumFontSizeParsed.value - minimumFontSizeParsed.value) / (maximumViewPortWidthParsed.value - minumumViewPortWidthParsed.value));
128
+ linearFactor = roundToPrecision(linearFactor, 3) || 1;
129
+ const linearFactorScaled = linearFactor * scaleFactor;
130
+ const fluidTargetFontSize = `${minimumFontSizeRem.value}${minimumFontSizeRem.unit} + ((1vw - ${viewPortWidthOffset}) * ${linearFactorScaled})`;
131
+ return `clamp(${minimumFontSize}, ${fluidTargetFontSize}, ${maximumFontSize})`;
132
+ }
133
+ /**
134
+ * Internal method that checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].
135
+ * A raw font size of `value + unit` is expected. If the value is an integer, it will convert to `value + 'px'`.
136
+ *
137
+ * @param {string|number} rawValue Raw size value from theme.json.
138
+ * @param {Object|undefined} options Calculation options.
139
+ *
140
+ * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.
141
+ */
142
+
143
+
144
+ function getTypographyValueAndUnit(rawValue) {
145
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
146
+
147
+ if (typeof rawValue !== 'string' && typeof rawValue !== 'number') {
148
+ return null;
149
+ } // Converts numeric values to pixel values by default.
150
+
151
+
152
+ if (isFinite(rawValue)) {
153
+ rawValue = `${rawValue}px`;
154
+ }
155
+
156
+ const {
157
+ coerceTo,
158
+ rootSizeValue,
159
+ acceptableUnits
160
+ } = {
161
+ coerceTo: '',
162
+ // Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
163
+ rootSizeValue: 16,
164
+ acceptableUnits: ['rem', 'px', 'em'],
165
+ ...options
166
+ };
167
+ const acceptableUnitsGroup = acceptableUnits === null || acceptableUnits === void 0 ? void 0 : acceptableUnits.join('|');
168
+ const regexUnits = new RegExp(`^(\\d*\\.?\\d+)(${acceptableUnitsGroup}){1,1}$`);
169
+ const matches = rawValue.match(regexUnits); // We need a number value and a unit.
170
+
171
+ if (!matches || matches.length < 3) {
172
+ return null;
173
+ }
174
+
175
+ let [, value, unit] = matches;
176
+ let returnValue = parseFloat(value);
177
+
178
+ if ('px' === coerceTo && ('em' === unit || 'rem' === unit)) {
179
+ returnValue = returnValue * rootSizeValue;
180
+ unit = coerceTo;
181
+ }
182
+
183
+ if ('px' === unit && ('em' === coerceTo || 'rem' === coerceTo)) {
184
+ returnValue = returnValue / rootSizeValue;
185
+ unit = coerceTo;
186
+ }
187
+
188
+ return {
189
+ value: returnValue,
190
+ unit
191
+ };
192
+ }
193
+ /**
194
+ * Returns a value rounded to defined precision.
195
+ * Returns `undefined` if the value is not a valid finite number.
196
+ *
197
+ * @param {number} value Raw value.
198
+ * @param {number} digits The number of digits to appear after the decimal point
199
+ *
200
+ * @return {number|undefined} Value rounded to standard precision.
201
+ */
202
+
203
+
204
+ function roundToPrecision(value) {
205
+ let digits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
206
+ return Number.isFinite(value) ? parseFloat(value.toFixed(digits)) : undefined;
207
+ }
208
+ //# sourceMappingURL=fluid-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/fluid-utils.js"],"names":["DEFAULT_MAXIMUM_VIEWPORT_WIDTH","DEFAULT_MINIMUM_VIEWPORT_WIDTH","DEFAULT_SCALE_FACTOR","DEFAULT_MINIMUM_FONT_SIZE_FACTOR","DEFAULT_MAXIMUM_FONT_SIZE_FACTOR","getComputedFluidTypographyValue","minimumFontSize","maximumFontSize","fontSize","minimumViewPortWidth","maximumViewPortWidth","scaleFactor","minimumFontSizeFactor","maximumFontSizeFactor","fontSizeParsed","getTypographyValueAndUnit","unit","value","minimumFontSizeParsed","fontSizeUnit","maximumFontSizeParsed","coerceTo","minimumFontSizeRem","maximumViewPortWidthParsed","minumumViewPortWidthParsed","minViewPortWidthOffsetValue","roundToPrecision","viewPortWidthOffset","linearFactor","linearFactorScaled","fluidTargetFontSize","rawValue","options","isFinite","rootSizeValue","acceptableUnits","acceptableUnitsGroup","join","regexUnits","RegExp","matches","match","length","returnValue","parseFloat","digits","Number","toFixed","undefined"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA,MAAMA,8BAA8B,GAAG,QAAvC;AACA,MAAMC,8BAA8B,GAAG,OAAvC;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,gCAAgC,GAAG,IAAzC;AACA,MAAMC,gCAAgC,GAAG,GAAzC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,+BAAT,OASH;AAAA,MAT6C;AAChDC,IAAAA,eADgD;AAEhDC,IAAAA,eAFgD;AAGhDC,IAAAA,QAHgD;AAIhDC,IAAAA,oBAAoB,GAAGR,8BAJyB;AAKhDS,IAAAA,oBAAoB,GAAGV,8BALyB;AAMhDW,IAAAA,WAAW,GAAGT,oBANkC;AAOhDU,IAAAA,qBAAqB,GAAGT,gCAPwB;AAQhDU,IAAAA,qBAAqB,GAAGT;AARwB,GAS7C;;AACH;AACA;AACA,MAAKI,QAAQ,KAAM,CAAEF,eAAF,IAAqB,CAAEC,eAA7B,CAAb,EAA8D;AAC7D;AACA,UAAMO,cAAc,GAAGC,yBAAyB,CAAEP,QAAF,CAAhD,CAF6D,CAI7D;;AACA,QAAK,EAAEM,cAAF,aAAEA,cAAF,eAAEA,cAAc,CAAEE,IAAlB,CAAL,EAA8B;AAC7B,aAAO,IAAP;AACA,KAP4D,CAS7D;;;AACA,QAAK,CAAEV,eAAP,EAA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;AAQA,QAAMI,oBAAoB,GAAGD,eAAH,aAAGA,eAAH,uBAAGA,eAAe,CAAEE,IAAjB,CAAuB,GAAvB,CAA7B;AACA,QAAMC,UAAU,GAAG,IAAIC,MAAJ,CACjB,mBAAmBH,oBAAsB,SADxB,CAAnB;AAIA,QAAMI,OAAO,GAAGT,QAAQ,CAACU,KAAT,CAAgBH,UAAhB,CAAhB,CAvBmE,CAyBnE;;AACA,MAAK,CAAEE,OAAF,IAAaA,OAAO,CAACE,MAAR,GAAiB,CAAnC,EAAuC;AACtC,WAAO,IAAP;AACA;;AAED,MAAI,GAAIzB,KAAJ,EAAWD,IAAX,IAAoBwB,OAAxB;AAEA,MAAIG,WAAW,GAAGC,UAAU,CAAE3B,KAAF,CAA5B;;AAEA,MAAK,SAASI,QAAT,KAAuB,SAASL,IAAT,IAAiB,UAAUA,IAAlD,CAAL,EAAgE;AAC/D2B,IAAAA,WAAW,GAAGA,WAAW,GAAGT,aAA5B;AACAlB,IAAAA,IAAI,GAAGK,QAAP;AACA;;AAED,MAAK,SAASL,IAAT,KAAmB,SAASK,QAAT,IAAqB,UAAUA,QAAlD,CAAL,EAAoE;AACnEsB,IAAAA,WAAW,GAAGA,WAAW,GAAGT,aAA5B;AACAlB,IAAAA,IAAI,GAAGK,QAAP;AACA;;AAED,SAAO;AACNJ,IAAAA,KAAK,EAAE0B,WADD;AAEN3B,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,gBAAT,CAA2BT,KAA3B,EAA+C;AAAA,MAAb4B,MAAa,uEAAJ,CAAI;AACrD,SAAOC,MAAM,CAACb,QAAP,CAAiBhB,KAAjB,IACJ2B,UAAU,CAAE3B,KAAK,CAAC8B,OAAN,CAAeF,MAAf,CAAF,CADN,GAEJG,SAFH;AAGA","sourcesContent":["/**\n * The fluid utilities must match the backend equivalent.\n * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php\n * ---------------------------------------------------------------\n */\n\n// Defaults.\nconst DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';\nconst DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';\nconst DEFAULT_SCALE_FACTOR = 1;\nconst DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;\nconst DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;\n\n/**\n * Computes a fluid font-size value that uses clamp(). A minimum and maxinmum\n * font size OR a single font size can be specified.\n *\n * If a single font size is specified, it is scaled up and down by\n * minimumFontSizeFactor and maximumFontSizeFactor to arrive at the minimum and\n * maximum sizes.\n *\n * @example\n * ```js\n * // Calculate fluid font-size value from a minimum and maximum value.\n * const fontSize = getComputedFluidTypographyValue( {\n * minimumFontSize: '20px',\n * maximumFontSize: '45px'\n * } );\n * // Calculate fluid font-size value from a single font size.\n * const fontSize = getComputedFluidTypographyValue( {\n * fontSize: '30px',\n * } );\n * ```\n *\n * @param {Object} args\n * @param {?string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity. Optional if fontSize is specified.\n * @param {?string} args.maximumViewPortWidth Maximum size up to which type will have fluidity. Optional if fontSize is specified.\n * @param {string|number} [args.fontSize] Size to derive maximumFontSize and minimumFontSize from, if necessary. Optional if minimumFontSize and maximumFontSize are specified.\n * @param {?string} args.maximumFontSize Maximum font size for any clamp() calculation. Optional.\n * @param {?string} args.minimumFontSize Minimum font size for any clamp() calculation. Optional.\n * @param {?number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.\n * @param {?number} args.minimumFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.\n * @param {?number} args.maximumFontSizeFactor How much to scale defaultFontSize by to derive maximumFontSize. Optional.\n *\n * @return {string|null} A font-size value using clamp().\n */\nexport function getComputedFluidTypographyValue( {\n\tminimumFontSize,\n\tmaximumFontSize,\n\tfontSize,\n\tminimumViewPortWidth = DEFAULT_MINIMUM_VIEWPORT_WIDTH,\n\tmaximumViewPortWidth = DEFAULT_MAXIMUM_VIEWPORT_WIDTH,\n\tscaleFactor = DEFAULT_SCALE_FACTOR,\n\tminimumFontSizeFactor = DEFAULT_MINIMUM_FONT_SIZE_FACTOR,\n\tmaximumFontSizeFactor = DEFAULT_MAXIMUM_FONT_SIZE_FACTOR,\n} ) {\n\t// Calculate missing minimumFontSize and maximumFontSize from\n\t// defaultFontSize if provided.\n\tif ( fontSize && ( ! minimumFontSize || ! maximumFontSize ) ) {\n\t\t// Parse default font size.\n\t\tconst fontSizeParsed = getTypographyValueAndUnit( fontSize );\n\n\t\t// Protect against invalid units.\n\t\tif ( ! fontSizeParsed?.unit ) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// If no minimumFontSize is provided, derive using min scale factor.\n\t\tif ( ! minimumFontSize ) {\n\t\t\tminimumFontSize =\n\t\t\t\tfontSizeParsed.value * minimumFontSizeFactor +\n\t\t\t\tfontSizeParsed.unit;\n\t\t}\n\n\t\t// If no maximumFontSize is provided, derive using max scale factor.\n\t\tif ( ! maximumFontSize ) {\n\t\t\tmaximumFontSize =\n\t\t\t\tfontSizeParsed.value * maximumFontSizeFactor +\n\t\t\t\tfontSizeParsed.unit;\n\t\t}\n\t}\n\n\t// Return early if one of the provided inputs is not provided.\n\tif ( ! minimumFontSize || ! maximumFontSize ) {\n\t\treturn null;\n\t}\n\n\t// Grab the minimum font size and normalize it in order to use the value for calculations.\n\tconst minimumFontSizeParsed = getTypographyValueAndUnit( minimumFontSize );\n\n\t// We get a 'preferred' unit to keep units consistent when calculating,\n\t// otherwise the result will not be accurate.\n\tconst fontSizeUnit = minimumFontSizeParsed?.unit || 'rem';\n\n\t// Grab the maximum font size and normalize it in order to use the value for calculations.\n\tconst maximumFontSizeParsed = getTypographyValueAndUnit( maximumFontSize, {\n\t\tcoerceTo: fontSizeUnit,\n\t} );\n\n\t// Protect against unsupported units.\n\tif ( ! minimumFontSizeParsed || ! maximumFontSizeParsed ) {\n\t\treturn null;\n\t}\n\n\t// Use rem for accessible fluid target font scaling.\n\tconst minimumFontSizeRem = getTypographyValueAndUnit( minimumFontSize, {\n\t\tcoerceTo: 'rem',\n\t} );\n\n\t// Viewport widths defined for fluid typography. Normalize units\n\tconst maximumViewPortWidthParsed = getTypographyValueAndUnit(\n\t\tmaximumViewPortWidth,\n\t\t{ coerceTo: fontSizeUnit }\n\t);\n\tconst minumumViewPortWidthParsed = getTypographyValueAndUnit(\n\t\tminimumViewPortWidth,\n\t\t{ coerceTo: fontSizeUnit }\n\t);\n\n\t// Protect against unsupported units.\n\tif (\n\t\t! maximumViewPortWidthParsed ||\n\t\t! minumumViewPortWidthParsed ||\n\t\t! minimumFontSizeRem\n\t) {\n\t\treturn null;\n\t}\n\n\t// Build CSS rule.\n\t// Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.\n\tconst minViewPortWidthOffsetValue = roundToPrecision(\n\t\tminumumViewPortWidthParsed.value / 100,\n\t\t3\n\t);\n\n\tconst viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;\n\tlet linearFactor =\n\t\t100 *\n\t\t( ( maximumFontSizeParsed.value - minimumFontSizeParsed.value ) /\n\t\t\t( maximumViewPortWidthParsed.value -\n\t\t\t\tminumumViewPortWidthParsed.value ) );\n\tlinearFactor = roundToPrecision( linearFactor, 3 ) || 1;\n\tconst linearFactorScaled = linearFactor * scaleFactor;\n\tconst fluidTargetFontSize = `${ minimumFontSizeRem.value }${ minimumFontSizeRem.unit } + ((1vw - ${ viewPortWidthOffset }) * ${ linearFactorScaled })`;\n\n\treturn `clamp(${ minimumFontSize }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;\n}\n\n/**\n * Internal method that checks a string for a unit and value and returns an array consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].\n * A raw font size of `value + unit` is expected. If the value is an integer, it will convert to `value + 'px'`.\n *\n * @param {string|number} rawValue Raw size value from theme.json.\n * @param {Object|undefined} options Calculation options.\n *\n * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.\n */\nexport function getTypographyValueAndUnit( rawValue, options = {} ) {\n\tif ( typeof rawValue !== 'string' && typeof rawValue !== 'number' ) {\n\t\treturn null;\n\t}\n\n\t// Converts numeric values to pixel values by default.\n\tif ( isFinite( rawValue ) ) {\n\t\trawValue = `${ rawValue }px`;\n\t}\n\n\tconst { coerceTo, rootSizeValue, acceptableUnits } = {\n\t\tcoerceTo: '',\n\t\t// Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( \"html\" ) ).fontSize`.\n\t\trootSizeValue: 16,\n\t\tacceptableUnits: [ 'rem', 'px', 'em' ],\n\t\t...options,\n\t};\n\n\tconst acceptableUnitsGroup = acceptableUnits?.join( '|' );\n\tconst regexUnits = new RegExp(\n\t\t`^(\\\\d*\\\\.?\\\\d+)(${ acceptableUnitsGroup }){1,1}$`\n\t);\n\n\tconst matches = rawValue.match( regexUnits );\n\n\t// We need a number value and a unit.\n\tif ( ! matches || matches.length < 3 ) {\n\t\treturn null;\n\t}\n\n\tlet [ , value, unit ] = matches;\n\n\tlet returnValue = parseFloat( value );\n\n\tif ( 'px' === coerceTo && ( 'em' === unit || 'rem' === unit ) ) {\n\t\treturnValue = returnValue * rootSizeValue;\n\t\tunit = coerceTo;\n\t}\n\n\tif ( 'px' === unit && ( 'em' === coerceTo || 'rem' === coerceTo ) ) {\n\t\treturnValue = returnValue / rootSizeValue;\n\t\tunit = coerceTo;\n\t}\n\n\treturn {\n\t\tvalue: returnValue,\n\t\tunit,\n\t};\n}\n\n/**\n * Returns a value rounded to defined precision.\n * Returns `undefined` if the value is not a valid finite number.\n *\n * @param {number} value Raw value.\n * @param {number} digits The number of digits to appear after the decimal point\n *\n * @return {number|undefined} Value rounded to standard precision.\n */\nexport function roundToPrecision( value, digits = 3 ) {\n\treturn Number.isFinite( value )\n\t\t? parseFloat( value.toFixed( digits ) )\n\t\t: undefined;\n}\n"]}
@@ -11,6 +11,12 @@ Object.defineProperty(exports, "FontSizePicker", {
11
11
  return _fontSizePicker.default;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "getComputedFluidTypographyValue", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _fluidUtils.getComputedFluidTypographyValue;
18
+ }
19
+ });
14
20
  Object.defineProperty(exports, "getFontSize", {
15
21
  enumerable: true,
16
22
  get: function () {
@@ -38,6 +44,8 @@ Object.defineProperty(exports, "withFontSizes", {
38
44
 
39
45
  var _utils = require("./utils");
40
46
 
47
+ var _fluidUtils = require("./fluid-utils");
48
+
41
49
  var _fontSizePicker = _interopRequireDefault(require("./font-size-picker"));
42
50
 
43
51
  var _withFontSizes = _interopRequireDefault(require("./with-font-sizes"));
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAKA;;AACA","sourcesContent":["export {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n} from './utils';\nexport { default as FontSizePicker } from './font-size-picker';\nexport { default as withFontSizes } from './with-font-sizes';\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/font-sizes/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAKA;;AACA;;AACA","sourcesContent":["export {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n} from './utils';\nexport { getComputedFluidTypographyValue } from './fluid-utils';\nexport { default as FontSizePicker } from './font-size-picker';\nexport { default as withFontSizes } from './with-font-sizes';\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 extractWords(normalizeSearchInput(input));
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 = extractWords(normalizedSearchInput);
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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IAAF,CAA5B;AACA,QAAMmD,UAAU,GAAGd,aAAa,CAAErC,IAAF,CAAhC;AAEA,QAAMoD,qBAAqB,GAAGzC,oBAAoB,CAAEmC,UAAF,CAAlD;AACA,QAAMO,eAAe,GAAG1C,oBAAoB,CAAER,KAAF,CAA5C;AAEA,MAAIuC,IAAI,GAAG,CAAX,CApBkE,CAsBlE;AACA;AACA;;AACA,MAAKU,qBAAqB,KAAKC,eAA/B,EAAiD;AAChDX,IAAAA,IAAI,IAAI,EAAR;AACA,GAFD,MAEO,IAAKW,eAAe,CAACC,UAAhB,CAA4BF,qBAA5B,CAAL,EAA2D;AACjEV,IAAAA,IAAI,IAAI,EAAR;AACA,GAFM,MAEA;AACN,UAAMa,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,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G,mBAAOqB,qBAAP,CAA9B;AACA,UAAMjC,cAAc,GAAGD,mBAAmB,CACzCa,qBADyC,EAEzCwB,KAFyC,CAA1C;;AAKA,QAAKpC,cAAc,CAACa,MAAf,KAA0B,CAA/B,EAAmC;AAClCU,MAAAA,IAAI,IAAI,EAAR;AACA;AACD,GA/CiE,CAiDlE;;;AACA,MAAKA,IAAI,KAAK,CAAT,IAAcvC,IAAI,CAACmD,UAAL,CAAiB,OAAjB,CAAnB,EAAgD;AAC/C,UAAMG,oBAAoB,GAAGtD,IAAI,KAAKD,IAAI,CAACwD,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 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"]}
@@ -22,6 +22,8 @@ var _tokenList = _interopRequireDefault(require("@wordpress/token-list"));
22
22
 
23
23
  var _compose = require("@wordpress/compose");
24
24
 
25
+ var _data = require("@wordpress/data");
26
+
25
27
  var _fontSizes = require("../components/font-sizes");
26
28
 
27
29
  var _typography = require("./typography");
@@ -30,6 +32,8 @@ var _utils = require("./utils");
30
32
 
31
33
  var _useSetting = _interopRequireDefault(require("../components/use-setting"));
32
34
 
35
+ var _store = require("../store");
36
+
33
37
  /**
34
38
  * WordPress dependencies
35
39
  */
@@ -278,10 +282,66 @@ function addTransforms(result, source, index, results) {
278
282
  };
279
283
  return (0, _utils.transformStyles)(activeSupports, MIGRATION_PATHS, result, source, index, results);
280
284
  }
285
+ /**
286
+ * Allow custom font sizes to appear fluid when fluid typography is enabled at
287
+ * the theme level.
288
+ *
289
+ * Adds a custom getEditWrapperProps() callback to all block types that support
290
+ * font sizes. Then, if fluid typography is enabled, this callback will swap any
291
+ * custom font size in style.fontSize with a fluid font size (i.e. one that uses
292
+ * clamp()).
293
+ *
294
+ * It's important that this hook runs after 'core/style/addEditProps' sets
295
+ * style.fontSize as otherwise fontSize will be overwritten.
296
+ *
297
+ * @param {Object} blockType Block settings object.
298
+ */
299
+
300
+
301
+ function addEditPropsForFluidCustomFontSizes(blockType) {
302
+ if (!(0, _blocks.hasBlockSupport)(blockType, FONT_SIZE_SUPPORT_KEY) || (0, _utils.shouldSkipSerialization)(blockType, _typography.TYPOGRAPHY_SUPPORT_KEY, 'fontSize')) {
303
+ return blockType;
304
+ }
305
+
306
+ const existingGetEditWrapperProps = blockType.getEditWrapperProps;
307
+
308
+ blockType.getEditWrapperProps = attributes => {
309
+ var _wrapperProps$style, _select$getSettings$_, _select$getSettings$_2;
310
+
311
+ const wrapperProps = existingGetEditWrapperProps ? existingGetEditWrapperProps(attributes) : {};
312
+ const fontSize = wrapperProps === null || wrapperProps === void 0 ? void 0 : (_wrapperProps$style = wrapperProps.style) === null || _wrapperProps$style === void 0 ? void 0 : _wrapperProps$style.fontSize; // TODO: This sucks! We should be using useSetting( 'typography.fluid' )
313
+ // or even useSelect( blockEditorStore ). We can't do either here
314
+ // because getEditWrapperProps is a plain JavaScript function called by
315
+ // BlockListBlock and not a React component rendered within
316
+ // BlockListContext.Provider. If we set fontSize using editor.
317
+ // BlockListBlock instead of using getEditWrapperProps then the value is
318
+ // clobbered when the core/style/addEditProps filter runs.
319
+
320
+ const isFluidTypographyEnabled = !!((_select$getSettings$_ = (0, _data.select)(_store.store).getSettings().__experimentalFeatures) !== null && _select$getSettings$_ !== void 0 && (_select$getSettings$_2 = _select$getSettings$_.typography) !== null && _select$getSettings$_2 !== void 0 && _select$getSettings$_2.fluid);
321
+ const newFontSize = fontSize && isFluidTypographyEnabled ? (0, _fontSizes.getComputedFluidTypographyValue)({
322
+ fontSize
323
+ }) : null;
324
+
325
+ if (newFontSize === null) {
326
+ return wrapperProps;
327
+ }
328
+
329
+ return { ...wrapperProps,
330
+ style: { ...(wrapperProps === null || wrapperProps === void 0 ? void 0 : wrapperProps.style),
331
+ fontSize: newFontSize
332
+ }
333
+ };
334
+ };
335
+
336
+ return blockType;
337
+ }
281
338
 
282
339
  (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font/addAttribute', addAttributes);
283
340
  (0, _hooks.addFilter)('blocks.getSaveContent.extraProps', 'core/font/addSaveProps', addSaveProps);
284
341
  (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font/addEditProps', addEditProps);
285
342
  (0, _hooks.addFilter)('editor.BlockListBlock', 'core/font-size/with-font-size-inline-styles', withFontSizeInlineStyles);
286
343
  (0, _hooks.addFilter)('blocks.switchToBlockType.transformedBlock', 'core/font-size/addTransforms', addTransforms);
344
+ (0, _hooks.addFilter)('blocks.registerBlockType', 'core/font-size/addEditPropsForFluidCustomFontSizes', addEditPropsForFluidCustomFontSizes, // Run after 'core/style/addEditProps' so that the style object has already
345
+ // been translated into inline CSS.
346
+ 11);
287
347
  //# sourceMappingURL=font-size.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/hooks/font-size.js"],"names":["FONT_SIZE_SUPPORT_KEY","addAttributes","settings","attributes","fontSize","Object","assign","type","addSaveProps","props","blockType","TYPOGRAPHY_SUPPORT_KEY","classes","TokenList","className","add","newClassName","value","undefined","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","FontSizeEdit","style","setAttributes","fontSizes","onChange","fontSizeSlug","slug","typography","fontSizeObject","fontSizeValue","size","hasFontSizeValue","resetFontSize","useIsFontSizeDisabled","name","blockName","hasFontSizes","length","withFontSizeInlineStyles","BlockListBlock","wrapperProps","newProps","MIGRATION_PATHS","addTransforms","result","source","index","results","destinationBlockType","activeSupports"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAMA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAMA;AACA;AACA;AAeO,MAAMA,qBAAqB,GAAG,qBAA9B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,aAAT,CAAwBC,QAAxB,EAAmC;AAClC,MAAK,CAAE,6BAAiBA,QAAjB,EAA2BF,qBAA3B,CAAP,EAA4D;AAC3D,WAAOE,QAAP;AACA,GAHiC,CAKlC;;;AACA,MAAK,CAAEA,QAAQ,CAACC,UAAT,CAAoBC,QAA3B,EAAsC;AACrCC,IAAAA,MAAM,CAACC,MAAP,CAAeJ,QAAQ,CAACC,UAAxB,EAAoC;AACnCC,MAAAA,QAAQ,EAAE;AACTG,QAAAA,IAAI,EAAE;AADG;AADyB,KAApC;AAKA;;AAED,SAAOL,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CAAuBC,KAAvB,EAA8BC,SAA9B,EAAyCP,UAAzC,EAAsD;AACrD,MAAK,CAAE,6BAAiBO,SAAjB,EAA4BV,qBAA5B,CAAP,EAA6D;AAC5D,WAAOS,KAAP;AACA;;AAED,MACC,oCAAyBC,SAAzB,EAAoCC,kCAApC,EAA4D,UAA5D,CADD,EAEE;AACD,WAAOF,KAAP;AACA,GAToD,CAWrD;;;AACA,QAAMG,OAAO,GAAG,IAAIC,kBAAJ,CAAeJ,KAAK,CAACK,SAArB,CAAhB;AACAF,EAAAA,OAAO,CAACG,GAAR,CAAa,iCAAkBZ,UAAU,CAACC,QAA7B,CAAb;AACA,QAAMY,YAAY,GAAGJ,OAAO,CAACK,KAA7B;AACAR,EAAAA,KAAK,CAACK,SAAN,GAAkBE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GAAG,EAChB,GAAGlC,KADa;AAEhBiC,IAAAA,YAAY,EAAE,EACb,GAAGA,YADU;AAEbnB,MAAAA,KAAK,EAAE;AACNnB,QAAAA,QAAQ,EAAE2B,aADJ;AAEN,YAAGW,YAAH,aAAGA,YAAH,uBAAGA,YAAY,CAAEnB,KAAjB;AAFM;AAFM;AAFE,GAAjB;AAWA,SAAO,4BAAC,cAAD,EAAqBoB,QAArB,CAAP;AACA,CA5C+B,EA6ChC,0BA7CgC,CAAjC;AAgDA,MAAMC,eAAe,GAAG;AACvBxC,EAAAA,QAAQ,EAAE,CAAE,CAAE,UAAF,CAAF,EAAkB,CAAE,OAAF,EAAW,YAAX,EAAyB,UAAzB,CAAlB;AADa,CAAxB;;AAIO,SAASyC,aAAT,CAAwBC,MAAxB,EAAgCC,MAAhC,EAAwCC,KAAxC,EAA+CC,OAA/C,EAAyD;AAC/D,QAAMC,oBAAoB,GAAGJ,MAAM,CAACV,IAApC;AACA,QAAMe,cAAc,GAAG;AACtB/C,IAAAA,QAAQ,EAAE,6BACT8C,oBADS,EAETlD,qBAFS;AADY,GAAvB;AAMA,SAAO,4BACNmD,cADM,EAENP,eAFM,EAGNE,MAHM,EAINC,MAJM,EAKNC,KALM,EAMNC,OANM,CAAP;AAQA;;AAED,sBACC,0BADD,EAEC,wBAFD,EAGChD,aAHD;AAMA,sBACC,kCADD,EAEC,wBAFD,EAGCO,YAHD;AAMA,sBAAW,0BAAX,EAAuC,wBAAvC,EAAiEW,YAAjE;AAEA,sBACC,uBADD,EAEC,6CAFD,EAGCqB,wBAHD;AAMA,sBACC,2CADD,EAEC,8BAFD,EAGCK,aAHD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport TokenList from '@wordpress/token-list';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n\tFontSizePicker,\n} from '../components/font-sizes';\nimport { TYPOGRAPHY_SUPPORT_KEY } from './typography';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport useSetting from '../components/use-setting';\n\nexport const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\n\n/**\n * Filters registered block settings, extending attributes to include\n * `fontSize` and `fontWeight` attributes.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify a default value if needed.\n\tif ( ! settings.attributes.fontSize ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tfontSize: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject font size.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tif (\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn props;\n\t}\n\n\t// Use TokenList to dedupe classes.\n\tconst classes = new TokenList( props.className );\n\tclasses.add( getFontSizeClass( attributes.fontSize ) );\n\tconst newClassName = classes.value;\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to expand the block edit wrapper\n * by applying the desired styles and classnames.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * Inspector control panel containing the font size related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Font size edit element.\n */\nexport function FontSizeEdit( props ) {\n\tconst {\n\t\tattributes: { fontSize, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\n\tconst onChange = ( value ) => {\n\t\tconst fontSizeSlug = getFontSizeObjectByValue( fontSizes, value ).slug;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\tfontSize: fontSizeSlug ? undefined : value,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\tfontSize: fontSizeSlug,\n\t\t} );\n\t};\n\n\tconst fontSizeObject = getFontSize(\n\t\tfontSizes,\n\t\tfontSize,\n\t\tstyle?.typography?.fontSize\n\t);\n\n\tconst fontSizeValue =\n\t\tfontSizeObject?.size || style?.typography?.fontSize || fontSize;\n\n\treturn (\n\t\t<FontSizePicker\n\t\t\tonChange={ onChange }\n\t\t\tvalue={ fontSizeValue }\n\t\t\twithReset={ false }\n\t\t\tsize=\"__unstable-large\"\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value set for the font size block support.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a font size value set.\n */\nexport function hasFontSizeValue( props ) {\n\tconst { fontSize, style } = props.attributes;\n\treturn !! fontSize || !! style?.typography?.fontSize;\n}\n\n/**\n * Resets the font size block support attribute. This can be used when\n * disabling the font size support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetFontSize( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tfontSize: undefined,\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\ttypography: {\n\t\t\t\t...style?.typography,\n\t\t\t\tfontSize: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if font-size settings have been disabled.\n *\n * @param {string} name The name of the block.\n * @return {boolean} Whether setting is disabled.\n */\nexport function useIsFontSizeDisabled( { name: blockName } = {} ) {\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst hasFontSizes = !! fontSizes?.length;\n\n\treturn (\n\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) || ! hasFontSizes\n\t);\n}\n\n/**\n * Add inline styles for font sizes.\n * Ideally, this is not needed and themes load the font-size classes on the\n * editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nconst withFontSizeInlineStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\t\tconst {\n\t\t\tname: blockName,\n\t\t\tattributes: { fontSize, style },\n\t\t\twrapperProps,\n\t\t} = props;\n\n\t\t// Only add inline styles if the block supports font sizes,\n\t\t// doesn't skip serialization of font sizes,\n\t\t// doesn't already have an inline font size,\n\t\t// and does have a class to extract the font size from.\n\t\tif (\n\t\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) ||\n\t\t\tshouldSkipSerialization(\n\t\t\t\tblockName,\n\t\t\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t\t\t'fontSize'\n\t\t\t) ||\n\t\t\t! fontSize ||\n\t\t\tstyle?.typography?.fontSize\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst fontSizeValue = getFontSize(\n\t\t\tfontSizes,\n\t\t\tfontSize,\n\t\t\tstyle?.typography?.fontSize\n\t\t).size;\n\n\t\tconst newProps = {\n\t\t\t...props,\n\t\t\twrapperProps: {\n\t\t\t\t...wrapperProps,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontSize: fontSizeValue,\n\t\t\t\t\t...wrapperProps?.style,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...newProps } />;\n\t},\n\t'withFontSizeInlineStyles'\n);\n\nconst MIGRATION_PATHS = {\n\tfontSize: [ [ 'fontSize' ], [ 'style', 'typography', 'fontSize' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tfontSize: hasBlockSupport(\n\t\t\tdestinationBlockType,\n\t\t\tFONT_SIZE_SUPPORT_KEY\n\t\t),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/font/addSaveProps',\n\taddSaveProps\n);\n\naddFilter( 'blocks.registerBlockType', 'core/font/addEditProps', addEditProps );\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/font-size/with-font-size-inline-styles',\n\twithFontSizeInlineStyles\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/font-size/addTransforms',\n\taddTransforms\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/font-size.js"],"names":["FONT_SIZE_SUPPORT_KEY","addAttributes","settings","attributes","fontSize","Object","assign","type","addSaveProps","props","blockType","TYPOGRAPHY_SUPPORT_KEY","classes","TokenList","className","add","newClassName","value","undefined","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","FontSizeEdit","style","setAttributes","fontSizes","onChange","fontSizeSlug","slug","typography","fontSizeObject","fontSizeValue","size","hasFontSizeValue","resetFontSize","useIsFontSizeDisabled","name","blockName","hasFontSizes","length","withFontSizeInlineStyles","BlockListBlock","wrapperProps","newProps","MIGRATION_PATHS","addTransforms","result","source","index","results","destinationBlockType","activeSupports","addEditPropsForFluidCustomFontSizes","isFluidTypographyEnabled","blockEditorStore","getSettings","__experimentalFeatures","fluid","newFontSize"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAOA;;AACA;;AAKA;;AACA;;AA1BA;AACA;AACA;;AAOA;AACA;AACA;AAiBO,MAAMA,qBAAqB,GAAG,qBAA9B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,aAAT,CAAwBC,QAAxB,EAAmC;AAClC,MAAK,CAAE,6BAAiBA,QAAjB,EAA2BF,qBAA3B,CAAP,EAA4D;AAC3D,WAAOE,QAAP;AACA,GAHiC,CAKlC;;;AACA,MAAK,CAAEA,QAAQ,CAACC,UAAT,CAAoBC,QAA3B,EAAsC;AACrCC,IAAAA,MAAM,CAACC,MAAP,CAAeJ,QAAQ,CAACC,UAAxB,EAAoC;AACnCC,MAAAA,QAAQ,EAAE;AACTG,QAAAA,IAAI,EAAE;AADG;AADyB,KAApC;AAKA;;AAED,SAAOL,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CAAuBC,KAAvB,EAA8BC,SAA9B,EAAyCP,UAAzC,EAAsD;AACrD,MAAK,CAAE,6BAAiBO,SAAjB,EAA4BV,qBAA5B,CAAP,EAA6D;AAC5D,WAAOS,KAAP;AACA;;AAED,MACC,oCAAyBC,SAAzB,EAAoCC,kCAApC,EAA4D,UAA5D,CADD,EAEE;AACD,WAAOF,KAAP;AACA,GAToD,CAWrD;;;AACA,QAAMG,OAAO,GAAG,IAAIC,kBAAJ,CAAe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lockSupport } from '@wordpress/blocks';\nimport TokenList from '@wordpress/token-list';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { select } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetFontSize,\n\tgetFontSizeClass,\n\tgetFontSizeObjectByValue,\n\tFontSizePicker,\n\tgetComputedFluidTypographyValue,\n} from '../components/font-sizes';\nimport { TYPOGRAPHY_SUPPORT_KEY } from './typography';\nimport {\n\tcleanEmptyObject,\n\ttransformStyles,\n\tshouldSkipSerialization,\n} from './utils';\nimport useSetting from '../components/use-setting';\nimport { store as blockEditorStore } from '../store';\n\nexport const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\n\n/**\n * Filters registered block settings, extending attributes to include\n * `fontSize` and `fontWeight` attributes.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify a default value if needed.\n\tif ( ! settings.attributes.fontSize ) {\n\t\tObject.assign( settings.attributes, {\n\t\t\tfontSize: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override props assigned to save component to inject font size.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tif (\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn props;\n\t}\n\n\t// Use TokenList to dedupe classes.\n\tconst classes = new TokenList( props.className );\n\tclasses.add( getFontSizeClass( attributes.fontSize ) );\n\tconst newClassName = classes.value;\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters registered block settings to expand the block edit wrapper\n * by applying the desired styles and classnames.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif ( ! hasBlockSupport( settings, FONT_SIZE_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * Inspector control panel containing the font size related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Font size edit element.\n */\nexport function FontSizeEdit( props ) {\n\tconst {\n\t\tattributes: { fontSize, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\n\tconst onChange = ( value ) => {\n\t\tconst fontSizeSlug = getFontSizeObjectByValue( fontSizes, value ).slug;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\ttypography: {\n\t\t\t\t\t...style?.typography,\n\t\t\t\t\tfontSize: fontSizeSlug ? undefined : value,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\tfontSize: fontSizeSlug,\n\t\t} );\n\t};\n\n\tconst fontSizeObject = getFontSize(\n\t\tfontSizes,\n\t\tfontSize,\n\t\tstyle?.typography?.fontSize\n\t);\n\n\tconst fontSizeValue =\n\t\tfontSizeObject?.size || style?.typography?.fontSize || fontSize;\n\n\treturn (\n\t\t<FontSizePicker\n\t\t\tonChange={ onChange }\n\t\t\tvalue={ fontSizeValue }\n\t\t\twithReset={ false }\n\t\t\tsize=\"__unstable-large\"\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value set for the font size block support.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a font size value set.\n */\nexport function hasFontSizeValue( props ) {\n\tconst { fontSize, style } = props.attributes;\n\treturn !! fontSize || !! style?.typography?.fontSize;\n}\n\n/**\n * Resets the font size block support attribute. This can be used when\n * disabling the font size support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetFontSize( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tfontSize: undefined,\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\ttypography: {\n\t\t\t\t...style?.typography,\n\t\t\t\tfontSize: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if font-size settings have been disabled.\n *\n * @param {string} name The name of the block.\n * @return {boolean} Whether setting is disabled.\n */\nexport function useIsFontSizeDisabled( { name: blockName } = {} ) {\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst hasFontSizes = !! fontSizes?.length;\n\n\treturn (\n\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) || ! hasFontSizes\n\t);\n}\n\n/**\n * Add inline styles for font sizes.\n * Ideally, this is not needed and themes load the font-size classes on the\n * editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nconst withFontSizeInlineStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\t\tconst {\n\t\t\tname: blockName,\n\t\t\tattributes: { fontSize, style },\n\t\t\twrapperProps,\n\t\t} = props;\n\n\t\t// Only add inline styles if the block supports font sizes,\n\t\t// doesn't skip serialization of font sizes,\n\t\t// doesn't already have an inline font size,\n\t\t// and does have a class to extract the font size from.\n\t\tif (\n\t\t\t! hasBlockSupport( blockName, FONT_SIZE_SUPPORT_KEY ) ||\n\t\t\tshouldSkipSerialization(\n\t\t\t\tblockName,\n\t\t\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t\t\t'fontSize'\n\t\t\t) ||\n\t\t\t! fontSize ||\n\t\t\tstyle?.typography?.fontSize\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst fontSizeValue = getFontSize(\n\t\t\tfontSizes,\n\t\t\tfontSize,\n\t\t\tstyle?.typography?.fontSize\n\t\t).size;\n\n\t\tconst newProps = {\n\t\t\t...props,\n\t\t\twrapperProps: {\n\t\t\t\t...wrapperProps,\n\t\t\t\tstyle: {\n\t\t\t\t\tfontSize: fontSizeValue,\n\t\t\t\t\t...wrapperProps?.style,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...newProps } />;\n\t},\n\t'withFontSizeInlineStyles'\n);\n\nconst MIGRATION_PATHS = {\n\tfontSize: [ [ 'fontSize' ], [ 'style', 'typography', 'fontSize' ] ],\n};\n\nexport function addTransforms( result, source, index, results ) {\n\tconst destinationBlockType = result.name;\n\tconst activeSupports = {\n\t\tfontSize: hasBlockSupport(\n\t\t\tdestinationBlockType,\n\t\t\tFONT_SIZE_SUPPORT_KEY\n\t\t),\n\t};\n\treturn transformStyles(\n\t\tactiveSupports,\n\t\tMIGRATION_PATHS,\n\t\tresult,\n\t\tsource,\n\t\tindex,\n\t\tresults\n\t);\n}\n\n/**\n * Allow custom font sizes to appear fluid when fluid typography is enabled at\n * the theme level.\n *\n * Adds a custom getEditWrapperProps() callback to all block types that support\n * font sizes. Then, if fluid typography is enabled, this callback will swap any\n * custom font size in style.fontSize with a fluid font size (i.e. one that uses\n * clamp()).\n *\n * It's important that this hook runs after 'core/style/addEditProps' sets\n * style.fontSize as otherwise fontSize will be overwritten.\n *\n * @param {Object} blockType Block settings object.\n */\nfunction addEditPropsForFluidCustomFontSizes( blockType ) {\n\tif (\n\t\t! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ||\n\t\tshouldSkipSerialization( blockType, TYPOGRAPHY_SUPPORT_KEY, 'fontSize' )\n\t) {\n\t\treturn blockType;\n\t}\n\n\tconst existingGetEditWrapperProps = blockType.getEditWrapperProps;\n\n\tblockType.getEditWrapperProps = ( attributes ) => {\n\t\tconst wrapperProps = existingGetEditWrapperProps\n\t\t\t? existingGetEditWrapperProps( attributes )\n\t\t\t: {};\n\n\t\tconst fontSize = wrapperProps?.style?.fontSize;\n\n\t\t// TODO: This sucks! We should be using useSetting( 'typography.fluid' )\n\t\t// or even useSelect( blockEditorStore ). We can't do either here\n\t\t// because getEditWrapperProps is a plain JavaScript function called by\n\t\t// BlockListBlock and not a React component rendered within\n\t\t// BlockListContext.Provider. If we set fontSize using editor.\n\t\t// BlockListBlock instead of using getEditWrapperProps then the value is\n\t\t// clobbered when the core/style/addEditProps filter runs.\n\t\tconst isFluidTypographyEnabled =\n\t\t\t!! select( blockEditorStore ).getSettings().__experimentalFeatures\n\t\t\t\t?.typography?.fluid;\n\n\t\tconst newFontSize =\n\t\t\tfontSize && isFluidTypographyEnabled\n\t\t\t\t? getComputedFluidTypographyValue( { fontSize } )\n\t\t\t\t: null;\n\n\t\tif ( newFontSize === null ) {\n\t\t\treturn wrapperProps;\n\t\t}\n\n\t\treturn {\n\t\t\t...wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...wrapperProps?.style,\n\t\t\t\tfontSize: newFontSize,\n\t\t\t},\n\t\t};\n\t};\n\n\treturn blockType;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font/addAttribute',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/font/addSaveProps',\n\taddSaveProps\n);\n\naddFilter( 'blocks.registerBlockType', 'core/font/addEditProps', addEditProps );\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/font-size/with-font-size-inline-styles',\n\twithFontSizeInlineStyles\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/font-size/addTransforms',\n\taddTransforms\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/font-size/addEditPropsForFluidCustomFontSizes',\n\taddEditPropsForFluidCustomFontSizes,\n\t// Run after 'core/style/addEditProps' so that the style object has already\n\t// been translated into inline CSS.\n\t11\n);\n"]}
@@ -191,10 +191,10 @@ function MarginVisualizer(_ref2) {
191
191
  borderRightWidth: marginRight,
192
192
  borderBottomWidth: marginBottom,
193
193
  borderLeftWidth: marginLeft,
194
- top: marginTop !== 0 ? `-${marginTop}` : 0,
195
- right: marginRight !== 0 ? `-${marginRight}` : 0,
196
- bottom: marginBottom !== 0 ? `-${marginBottom}` : 0,
197
- left: marginLeft !== 0 ? `-${marginLeft}` : 0
194
+ top: marginTop !== 0 ? `calc(${marginTop} * -1)` : 0,
195
+ right: marginRight !== 0 ? `calc(${marginRight} * -1)` : 0,
196
+ bottom: marginBottom !== 0 ? `calc(${marginBottom} * -1)` : 0,
197
+ left: marginLeft !== 0 ? `calc(${marginLeft} * -1)` : 0
198
198
  };
199
199
  }, [margin]);
200
200
  const [isActive, setIsActive] = (0, _element.useState)(false);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["hasMarginSupport","blockType","support","SPACING_SUPPORT_KEY","margin","hasMarginValue","props","attributes","style","spacing","undefined","resetMargin","setAttributes","useIsMarginDisabled","name","blockName","isDisabled","isInvalid","MarginEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","MarginVisualizer","clientId","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;;AADA;;AAQA;;AACA;;AAIA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;A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AQ,GAAG,qBAAQhD,MAAR,CAAjB;AACA,QAAMiD,UAAU,GAAG,sBAAnB;;AAEA,QAAMC,UAAU,GAAG,MAAM;AACxB,QAAKD,UAAU,CAACE,OAAhB,EAA0B;AACzBC,MAAAA,MAAM,CAACC,YAAP,CAAqBJ,UAAU,CAACE,OAAhC;AACA;AACD,GAJD;;AAMA,0BAAW,MAAM;AAChB,QAAK,CAAE,6BAAgBnD,MAAhB,EAAwBgD,QAAQ,CAACG,OAAjC,CAAP,EAAoD;AACnDJ,MAAAA,WAAW,CAAE,IAAF,CAAX;AACAC,MAAAA,QAAQ,CAACG,OAAT,GAAmBnD,MAAnB;AAEAkD,MAAAA,UAAU;AAEVD,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAElD,MAAF,CAbH;;AAeA,MAAK,CAAE8C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGb,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC;AAHzB,KAKC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IALD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getCustomValueFromPreset } from '../components/spacing-sizes-control/utils';\n\n/**\n * Determines if there is margin support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasMarginSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.margin );\n}\n\n/**\n * Checks if there is a current value in the margin block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a margin value set.\n */\nexport function hasMarginValue( props ) {\n\treturn props.attributes.style?.spacing?.margin !== undefined;\n}\n\n/**\n * Resets the margin block support attributes. This can be used when disabling\n * the margin support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetMargin( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if margin settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether margin setting is disabled.\n */\nexport function useIsMarginDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.margin' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );\n\n\treturn ! hasMarginSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the margin related configuration\n *\n * @param {Object} props Block props.\n *\n * @return {WPElement} Margin edit element.\n */\nexport function MarginEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'margin' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsMarginDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function MarginVisualizer( { clientId, attributes } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getCustomValueFromPreset( margin?.top, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getCustomValueFromPreset( margin?.right, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getCustomValueFromPreset( margin?.bottom, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getCustomValueFromPreset( margin?.left, spacingSizes )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop !== 0 ? `-${ marginTop }` : 0,\n\t\t\tright: marginRight !== 0 ? `-${ marginRight }` : 0,\n\t\t\tbottom: marginBottom !== 0 ? `-${ marginBottom }` : 0,\n\t\t\tleft: marginLeft !== 0 ? `-${ marginLeft }` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ margin ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["hasMarginSupport","blockType","support","SPACING_SUPPORT_KEY","margin","hasMarginValue","props","attributes","style","spacing","undefined","resetMargin","setAttributes","useIsMarginDisabled","name","blockName","isDisabled","isInvalid","MarginEdit","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","AXIAL_SIDES","includes","onChange","next","newStyle","Platform","select","web","length","native","MarginVisualizer","clientId","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;AAIA;;AADA;;AAQA;;AACA;;AAIA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAgBA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAT,CAA2BC,SAA3B,EAAuC;AAC7C,QAAMC,OAAO,GAAG,6BAAiBD,SAAjB,EAA4BE,+BAA5B,CAAhB;AACA,SAAO,CAAC,EAAI,SAASD,OAAT,IAAoBA,OAApB,aAAoBA,OAApB,eAAoBA,OAAO,CAAEE,MAAjC,CAAR;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,cAAT,CAAyBC,KAAzB,EAAiC;AAAA;;AACvC,SAAO,0BAAAA,KAAK,CAACC,UAAN,CAAiBC,KAAjB,0GAAwBC,OAAxB,kFAAiCL,MAAjC,MAA4CM,SAAnD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,OAA2D;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F8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAElD,MAAF,CAbH;;AAeA,MAAK,CAAE8C,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,qBAAD;AACC,IAAA,QAAQ,EAAGb,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC;AAHzB,KAKC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IALD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getCustomValueFromPreset } from '../components/spacing-sizes-control/utils';\n\n/**\n * Determines if there is margin support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasMarginSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.margin );\n}\n\n/**\n * Checks if there is a current value in the margin block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a margin value set.\n */\nexport function hasMarginValue( props ) {\n\treturn props.attributes.style?.spacing?.margin !== undefined;\n}\n\n/**\n * Resets the margin block support attributes. This can be used when disabling\n * the margin support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetMargin( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if margin settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether margin setting is disabled.\n */\nexport function useIsMarginDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.margin' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );\n\n\treturn ! hasMarginSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the margin related configuration\n *\n * @param {Object} props Block props.\n *\n * @return {WPElement} Margin edit element.\n */\nexport function MarginEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'margin' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsMarginDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function MarginVisualizer( { clientId, attributes } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getCustomValueFromPreset( margin?.top, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getCustomValueFromPreset( margin?.right, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getCustomValueFromPreset( margin?.bottom, spacingSizes )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getCustomValueFromPreset( margin?.left, spacingSizes )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop !== 0 ? `calc(${ marginTop } * -1)` : 0,\n\t\t\tright: marginRight !== 0 ? `calc(${ marginRight } * -1)` : 0,\n\t\t\tbottom: marginBottom !== 0 ? `calc(${ marginBottom } * -1)` : 0,\n\t\t\tleft: marginLeft !== 0 ? `calc(${ marginLeft } * -1)` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ margin ] );\n\n\tif ( ! isActive ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}