@wordpress/block-library 9.33.1 → 9.33.2

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 (117) hide show
  1. package/build/accordion/block.json +1 -1
  2. package/build/accordion/edit.js +11 -9
  3. package/build/accordion/edit.js.map +2 -2
  4. package/build/accordion-heading/block.json +1 -1
  5. package/build/accordion-item/block.json +1 -1
  6. package/build/accordion-panel/block.json +1 -1
  7. package/build/buttons/transforms.js +1 -0
  8. package/build/buttons/transforms.js.map +2 -2
  9. package/build/code/transforms.js +2 -0
  10. package/build/code/transforms.js.map +2 -2
  11. package/build/home-link/block.json +2 -1
  12. package/build/image/view.js +4 -1
  13. package/build/image/view.js.map +2 -2
  14. package/build/math/edit.js +1 -0
  15. package/build/math/edit.js.map +2 -2
  16. package/build/navigation/menu-items-to-blocks.js +8 -3
  17. package/build/navigation/menu-items-to-blocks.js.map +2 -2
  18. package/build/navigation/view.js +2 -2
  19. package/build/navigation/view.js.map +2 -2
  20. package/build/post-date/block.json +1 -1
  21. package/build/post-date/deprecated.js +1 -1
  22. package/build/post-date/deprecated.js.map +2 -2
  23. package/build/post-date/edit.js +11 -5
  24. package/build/post-date/edit.js.map +3 -3
  25. package/build/post-date/variations.js +4 -7
  26. package/build/post-date/variations.js.map +2 -2
  27. package/build/post-template/edit.js +13 -1
  28. package/build/post-template/edit.js.map +2 -2
  29. package/build/query/index.js +11 -1
  30. package/build/query/index.js.map +2 -2
  31. package/build/query/variations.js +16 -11
  32. package/build/query/variations.js.map +2 -2
  33. package/build/search/view.js +4 -4
  34. package/build/search/view.js.map +2 -2
  35. package/build/terms-query/edit/inspector-controls/index.js +1 -1
  36. package/build/terms-query/edit/inspector-controls/index.js.map +2 -2
  37. package/build/terms-query/edit/inspector-controls/inherit-control.js +2 -4
  38. package/build/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
  39. package/build/utils/get-transformed-attributes.js +1 -10
  40. package/build/utils/get-transformed-attributes.js.map +2 -2
  41. package/build-module/accordion/block.json +1 -1
  42. package/build-module/accordion/edit.js +11 -9
  43. package/build-module/accordion/edit.js.map +2 -2
  44. package/build-module/accordion-heading/block.json +1 -1
  45. package/build-module/accordion-item/block.json +1 -1
  46. package/build-module/accordion-panel/block.json +1 -1
  47. package/build-module/buttons/transforms.js +1 -0
  48. package/build-module/buttons/transforms.js.map +2 -2
  49. package/build-module/code/transforms.js +2 -0
  50. package/build-module/code/transforms.js.map +2 -2
  51. package/build-module/home-link/block.json +2 -1
  52. package/build-module/image/view.js +4 -1
  53. package/build-module/image/view.js.map +2 -2
  54. package/build-module/math/edit.js +1 -0
  55. package/build-module/math/edit.js.map +2 -2
  56. package/build-module/navigation/menu-items-to-blocks.js +8 -3
  57. package/build-module/navigation/menu-items-to-blocks.js.map +2 -2
  58. package/build-module/navigation/view.js +2 -2
  59. package/build-module/navigation/view.js.map +2 -2
  60. package/build-module/post-date/block.json +1 -1
  61. package/build-module/post-date/deprecated.js +1 -1
  62. package/build-module/post-date/deprecated.js.map +2 -2
  63. package/build-module/post-date/edit.js +11 -5
  64. package/build-module/post-date/edit.js.map +2 -2
  65. package/build-module/post-date/variations.js +4 -7
  66. package/build-module/post-date/variations.js.map +2 -2
  67. package/build-module/post-template/edit.js +13 -1
  68. package/build-module/post-template/edit.js.map +2 -2
  69. package/build-module/query/index.js +11 -1
  70. package/build-module/query/index.js.map +2 -2
  71. package/build-module/query/variations.js +16 -11
  72. package/build-module/query/variations.js.map +2 -2
  73. package/build-module/search/view.js +4 -4
  74. package/build-module/search/view.js.map +2 -2
  75. package/build-module/terms-query/edit/inspector-controls/index.js +1 -1
  76. package/build-module/terms-query/edit/inspector-controls/index.js.map +2 -2
  77. package/build-module/terms-query/edit/inspector-controls/inherit-control.js +2 -4
  78. package/build-module/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
  79. package/build-module/utils/get-transformed-attributes.js +1 -10
  80. package/build-module/utils/get-transformed-attributes.js.map +2 -2
  81. package/build-style/editor-rtl.css +5 -0
  82. package/build-style/editor.css +6 -0
  83. package/build-style/math/editor-rtl.css +49 -0
  84. package/build-style/math/editor.css +50 -0
  85. package/package.json +37 -37
  86. package/src/accordion/block.json +1 -1
  87. package/src/accordion/edit.js +16 -16
  88. package/src/accordion-heading/block.json +1 -1
  89. package/src/accordion-item/block.json +1 -1
  90. package/src/accordion-panel/block.json +1 -1
  91. package/src/buttons/transforms.js +1 -0
  92. package/src/code/transforms.js +2 -0
  93. package/src/editor.scss +1 -0
  94. package/src/home-link/block.json +2 -1
  95. package/src/image/index.php +9 -9
  96. package/src/image/view.js +11 -1
  97. package/src/math/edit.js +1 -0
  98. package/src/math/editor.scss +7 -0
  99. package/src/navigation/index.php +7 -7
  100. package/src/navigation/menu-items-to-blocks.js +12 -2
  101. package/src/navigation/test/menu-items-to-blocks.js +144 -0
  102. package/src/navigation/view.js +2 -2
  103. package/src/post-date/block.json +1 -1
  104. package/src/post-date/deprecated.js +5 -1
  105. package/src/post-date/edit.js +15 -10
  106. package/src/post-date/variations.js +2 -5
  107. package/src/post-template/edit.js +13 -1
  108. package/src/query/index.js +10 -0
  109. package/src/query/variations.js +17 -11
  110. package/src/query-pagination-next/index.php +1 -1
  111. package/src/query-pagination-previous/index.php +1 -1
  112. package/src/search/index.php +2 -2
  113. package/src/search/view.js +4 -4
  114. package/src/term-template/index.php +8 -2
  115. package/src/terms-query/edit/inspector-controls/index.js +2 -2
  116. package/src/terms-query/edit/inspector-controls/inherit-control.js +1 -3
  117. package/src/utils/get-transformed-attributes.js +5 -16
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/terms-query/edit/inspector-controls/inherit-control.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport default function InheritControl( { value, onChange, label } ) {\n\treturn (\n\t\t<ToggleGroupControl\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\tisBlock\n\t\t\tonChange={ ( newValue ) => {\n\t\t\t\tonChange( {\n\t\t\t\t\tinherit: newValue === 'default',\n\t\t\t\t\t// When enabling inherit, hierarchical is not supported.\n\t\t\t\t\t...( newValue === 'default' ? { showNested: false } : {} ),\n\t\t\t\t} );\n\t\t\t} }\n\t\t\thelp={\n\t\t\t\tvalue\n\t\t\t\t\t? __(\n\t\t\t\t\t\t\t'Display terms based on the current taxonomy archive. For hierarchical taxonomies, shows direct children of the current term. For non-hierarchical taxonomies, shows all terms.'\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Display terms based on specific criteria.' )\n\t\t\t}\n\t\t\tvalue={ value ? 'default' : 'custom' }\n\t\t>\n\t\t\t<ToggleGroupControlOption\n\t\t\t\tvalue=\"default\"\n\t\t\t\tlabel={ __( 'Default' ) }\n\t\t\t/>\n\t\t\t<ToggleGroupControlOption value=\"custom\" label={ __( 'Custom' ) } />\n\t\t</ToggleGroupControl>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWE;AARF,wBAGO;AACP,kBAAmB;AAEJ,SAAR,eAAiC,EAAE,OAAO,UAAU,MAAM,GAAI;AACpE,SACC;AAAA,IAAC,kBAAAA;AAAA,IAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,yBAAuB;AAAA,MACvB;AAAA,MACA,SAAO;AAAA,MACP,UAAW,CAAE,aAAc;AAC1B,iBAAU;AAAA,UACT,SAAS,aAAa;AAAA;AAAA,UAEtB,GAAK,aAAa,YAAY,EAAE,YAAY,MAAM,IAAI,CAAC;AAAA,QACxD,CAAE;AAAA,MACH;AAAA,MACA,MACC,YACG;AAAA,QACA;AAAA,MACA,QACA,gBAAI,2CAA4C;AAAA,MAEpD,OAAQ,QAAQ,YAAY;AAAA,MAE5B;AAAA;AAAA,UAAC,kBAAAC;AAAA,UAAA;AAAA,YACA,OAAM;AAAA,YACN,WAAQ,gBAAI,SAAU;AAAA;AAAA,QACvB;AAAA,QACA,4CAAC,kBAAAA,wCAAA,EAAyB,OAAM,UAAS,WAAQ,gBAAI,QAAS,GAAI;AAAA;AAAA;AAAA,EACnE;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport default function InheritControl( { value, onChange, label } ) {\n\treturn (\n\t\t<ToggleGroupControl\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\tisBlock\n\t\t\tonChange={ ( newValue ) => {\n\t\t\t\tonChange( {\n\t\t\t\t\tinherit: newValue === 'default',\n\t\t\t\t} );\n\t\t\t} }\n\t\t\thelp={\n\t\t\t\tvalue\n\t\t\t\t\t? __(\n\t\t\t\t\t\t\t'Display terms based on the current taxonomy archive. For hierarchical taxonomies, shows children of the current term. For non-hierarchical taxonomies, shows all terms.'\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Display terms based on specific criteria.' )\n\t\t\t}\n\t\t\tvalue={ value ? 'default' : 'custom' }\n\t\t>\n\t\t\t<ToggleGroupControlOption\n\t\t\t\tvalue=\"default\"\n\t\t\t\tlabel={ __( 'Default' ) }\n\t\t\t/>\n\t\t\t<ToggleGroupControlOption value=\"custom\" label={ __( 'Custom' ) } />\n\t\t</ToggleGroupControl>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWE;AARF,wBAGO;AACP,kBAAmB;AAEJ,SAAR,eAAiC,EAAE,OAAO,UAAU,MAAM,GAAI;AACpE,SACC;AAAA,IAAC,kBAAAA;AAAA,IAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,yBAAuB;AAAA,MACvB;AAAA,MACA,SAAO;AAAA,MACP,UAAW,CAAE,aAAc;AAC1B,iBAAU;AAAA,UACT,SAAS,aAAa;AAAA,QACvB,CAAE;AAAA,MACH;AAAA,MACA,MACC,YACG;AAAA,QACA;AAAA,MACA,QACA,gBAAI,2CAA4C;AAAA,MAEpD,OAAQ,QAAQ,YAAY;AAAA,MAE5B;AAAA;AAAA,UAAC,kBAAAC;AAAA,UAAA;AAAA,YACA,OAAM;AAAA,YACN,WAAQ,gBAAI,SAAU;AAAA;AAAA,QACvB;AAAA,QACA,4CAAC,kBAAAA,wCAAA,EAAyB,OAAM,UAAS,WAAQ,gBAAI,QAAS,GAAI;AAAA;AAAA;AAAA,EACnE;AAEF;",
6
6
  "names": ["ToggleGroupControl", "ToggleGroupControlOption"]
7
7
  }
@@ -40,20 +40,11 @@ function getTransformedAttributes(attributes, newBlockName, bindingsCallback = n
40
40
  if ((0, import_blocks.hasBlockSupport)(newBlockType, "ariaLabel") && attributes.ariaLabel) {
41
41
  transformedAttributes.ariaLabel = attributes.ariaLabel;
42
42
  }
43
- if ((0, import_blocks.hasBlockSupport)(newBlockType, "className") && attributes.className) {
44
- transformedAttributes.className = attributes.className;
45
- }
46
43
  if (attributes.metadata) {
47
- const transformedMetadata = ["noteId"];
44
+ const transformedMetadata = [];
48
45
  if (bindingsCallback) {
49
46
  transformedMetadata.push("id", "bindings");
50
47
  }
51
- if ((0, import_blocks.hasBlockSupport)(newBlockType, "renaming", true)) {
52
- transformedMetadata.push("name");
53
- }
54
- if ((0, import_blocks.hasBlockSupport)(newBlockType, "blockVisibility", true)) {
55
- transformedMetadata.push("blockVisibility");
56
- }
57
48
  if (transformedMetadata.length > 0) {
58
49
  const newMetadata = Object.entries(attributes.metadata).reduce(
59
50
  (obj, [prop, value]) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/get-transformed-attributes.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockType, hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Transform block support attributes and metadata during block transforms.\n *\n * @param {Object} attributes Original attributes from the block being transformed.\n * @param {string} newBlockName Name of the target block after transformation.\n * @param {Function} bindingsCallback Optional callback to transform the `bindings` property object.\n * @return {Object} New attributes object with preserved block support attributes and metadata.\n */\nexport function getTransformedAttributes(\n\tattributes,\n\tnewBlockName,\n\tbindingsCallback = null\n) {\n\tif ( ! attributes ) {\n\t\treturn undefined;\n\t}\n\n\tconst newBlockType = getBlockType( newBlockName );\n\tif ( ! newBlockType ) {\n\t\treturn undefined;\n\t}\n\n\tconst transformedAttributes = {};\n\n\t// Handle attributes derived from block support.\n\tif (\n\t\thasBlockSupport( newBlockType, 'allowedBlocks' ) &&\n\t\tattributes.allowedBlocks\n\t) {\n\t\ttransformedAttributes.allowedBlocks = attributes.allowedBlocks;\n\t}\n\tif ( hasBlockSupport( newBlockType, 'anchor' ) && attributes.anchor ) {\n\t\ttransformedAttributes.anchor = attributes.anchor;\n\t}\n\tif (\n\t\thasBlockSupport( newBlockType, 'ariaLabel' ) &&\n\t\tattributes.ariaLabel\n\t) {\n\t\ttransformedAttributes.ariaLabel = attributes.ariaLabel;\n\t}\n\tif (\n\t\thasBlockSupport( newBlockType, 'className' ) &&\n\t\tattributes.className\n\t) {\n\t\ttransformedAttributes.className = attributes.className;\n\t}\n\n\t// Handle metadata transformation.\n\tif ( attributes.metadata ) {\n\t\t// The metadata properties that should be preserved after the transform.\n\t\tconst transformedMetadata = [ 'noteId' ];\n\n\t\t// If there is a transform bindings callback, add the `id` and `bindings` properties.\n\t\tif ( bindingsCallback ) {\n\t\t\ttransformedMetadata.push( 'id', 'bindings' );\n\t\t}\n\n\t\t// Handle metadata properties derived from block support.\n\t\tif ( hasBlockSupport( newBlockType, 'renaming', true ) ) {\n\t\t\ttransformedMetadata.push( 'name' );\n\t\t}\n\t\tif ( hasBlockSupport( newBlockType, 'blockVisibility', true ) ) {\n\t\t\ttransformedMetadata.push( 'blockVisibility' );\n\t\t}\n\n\t\t// Only process metadata if there are supported properties.\n\t\tif ( transformedMetadata.length > 0 ) {\n\t\t\tconst newMetadata = Object.entries( attributes.metadata ).reduce(\n\t\t\t\t( obj, [ prop, value ] ) => {\n\t\t\t\t\t// If prop is not supported, don't add it to the new metadata object.\n\t\t\t\t\tif ( ! transformedMetadata.includes( prop ) ) {\n\t\t\t\t\t\treturn obj;\n\t\t\t\t\t}\n\t\t\t\t\tobj[ prop ] =\n\t\t\t\t\t\tprop === 'bindings' ? bindingsCallback( value ) : value;\n\t\t\t\t\treturn obj;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\t// Only add metadata if object is not empty.\n\t\t\tif ( Object.keys( newMetadata ).length > 0 ) {\n\t\t\t\ttransformedAttributes.metadata = newMetadata;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( Object.keys( transformedAttributes ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\n\treturn transformedAttributes;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA8C;AAUvC,SAAS,yBACf,YACA,cACA,mBAAmB,MAClB;AACD,MAAK,CAAE,YAAa;AACnB,WAAO;AAAA,EACR;AAEA,QAAM,mBAAe,4BAAc,YAAa;AAChD,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,QAAM,wBAAwB,CAAC;AAG/B,UACC,+BAAiB,cAAc,eAAgB,KAC/C,WAAW,eACV;AACD,0BAAsB,gBAAgB,WAAW;AAAA,EAClD;AACA,UAAK,+BAAiB,cAAc,QAAS,KAAK,WAAW,QAAS;AACrE,0BAAsB,SAAS,WAAW;AAAA,EAC3C;AACA,UACC,+BAAiB,cAAc,WAAY,KAC3C,WAAW,WACV;AACD,0BAAsB,YAAY,WAAW;AAAA,EAC9C;AACA,UACC,+BAAiB,cAAc,WAAY,KAC3C,WAAW,WACV;AACD,0BAAsB,YAAY,WAAW;AAAA,EAC9C;AAGA,MAAK,WAAW,UAAW;AAE1B,UAAM,sBAAsB,CAAE,QAAS;AAGvC,QAAK,kBAAmB;AACvB,0BAAoB,KAAM,MAAM,UAAW;AAAA,IAC5C;AAGA,YAAK,+BAAiB,cAAc,YAAY,IAAK,GAAI;AACxD,0BAAoB,KAAM,MAAO;AAAA,IAClC;AACA,YAAK,+BAAiB,cAAc,mBAAmB,IAAK,GAAI;AAC/D,0BAAoB,KAAM,iBAAkB;AAAA,IAC7C;AAGA,QAAK,oBAAoB,SAAS,GAAI;AACrC,YAAM,cAAc,OAAO,QAAS,WAAW,QAAS,EAAE;AAAA,QACzD,CAAE,KAAK,CAAE,MAAM,KAAM,MAAO;AAE3B,cAAK,CAAE,oBAAoB,SAAU,IAAK,GAAI;AAC7C,mBAAO;AAAA,UACR;AACA,cAAK,IAAK,IACT,SAAS,aAAa,iBAAkB,KAAM,IAAI;AACnD,iBAAO;AAAA,QACR;AAAA,QACA,CAAC;AAAA,MACF;AAGA,UAAK,OAAO,KAAM,WAAY,EAAE,SAAS,GAAI;AAC5C,8BAAsB,WAAW;AAAA,MAClC;AAAA,IACD;AAAA,EACD;AAEA,MAAK,OAAO,KAAM,qBAAsB,EAAE,WAAW,GAAI;AACxD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { getBlockType, hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Transform block support attributes and metadata during block transforms.\n *\n * @param {Object} attributes Original attributes from the block being transformed.\n * @param {string} newBlockName Name of the target block after transformation.\n * @param {Function} bindingsCallback Optional callback to transform the `bindings` property object.\n * @return {Object} New attributes object with preserved block support attributes and metadata.\n */\nexport function getTransformedAttributes(\n\tattributes,\n\tnewBlockName,\n\tbindingsCallback = null\n) {\n\tif ( ! attributes ) {\n\t\treturn undefined;\n\t}\n\n\tconst newBlockType = getBlockType( newBlockName );\n\tif ( ! newBlockType ) {\n\t\treturn undefined;\n\t}\n\n\tconst transformedAttributes = {};\n\n\t// Handle attributes derived from block support. The custom class name\n\t// attribute is handled in the `core/customClassName/addTransforms` hook.\n\tif (\n\t\thasBlockSupport( newBlockType, 'allowedBlocks' ) &&\n\t\tattributes.allowedBlocks\n\t) {\n\t\ttransformedAttributes.allowedBlocks = attributes.allowedBlocks;\n\t}\n\tif ( hasBlockSupport( newBlockType, 'anchor' ) && attributes.anchor ) {\n\t\ttransformedAttributes.anchor = attributes.anchor;\n\t}\n\tif (\n\t\thasBlockSupport( newBlockType, 'ariaLabel' ) &&\n\t\tattributes.ariaLabel\n\t) {\n\t\ttransformedAttributes.ariaLabel = attributes.ariaLabel;\n\t}\n\n\t// Handle metadata transformation.\n\tif ( attributes.metadata ) {\n\t\t// The metadata properties that should be preserved after the transform.\n\t\t// The noteId, name, and blockVisibility properties are separately handled\n\t\t// in the `core/metadata/addTransforms` hook.\n\t\tconst transformedMetadata = [];\n\n\t\t// If there is a transform bindings callback, add the `id` and `bindings` properties.\n\t\tif ( bindingsCallback ) {\n\t\t\ttransformedMetadata.push( 'id', 'bindings' );\n\t\t}\n\n\t\t// Only process metadata if there are supported properties.\n\t\tif ( transformedMetadata.length > 0 ) {\n\t\t\tconst newMetadata = Object.entries( attributes.metadata ).reduce(\n\t\t\t\t( obj, [ prop, value ] ) => {\n\t\t\t\t\t// If prop is not supported, don't add it to the new metadata object.\n\t\t\t\t\tif ( ! transformedMetadata.includes( prop ) ) {\n\t\t\t\t\t\treturn obj;\n\t\t\t\t\t}\n\t\t\t\t\tobj[ prop ] =\n\t\t\t\t\t\tprop === 'bindings' ? bindingsCallback( value ) : value;\n\t\t\t\t\treturn obj;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\t// Only add metadata if object is not empty.\n\t\t\tif ( Object.keys( newMetadata ).length > 0 ) {\n\t\t\t\ttransformedAttributes.metadata = newMetadata;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( Object.keys( transformedAttributes ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\n\treturn transformedAttributes;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA8C;AAUvC,SAAS,yBACf,YACA,cACA,mBAAmB,MAClB;AACD,MAAK,CAAE,YAAa;AACnB,WAAO;AAAA,EACR;AAEA,QAAM,mBAAe,4BAAc,YAAa;AAChD,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,QAAM,wBAAwB,CAAC;AAI/B,UACC,+BAAiB,cAAc,eAAgB,KAC/C,WAAW,eACV;AACD,0BAAsB,gBAAgB,WAAW;AAAA,EAClD;AACA,UAAK,+BAAiB,cAAc,QAAS,KAAK,WAAW,QAAS;AACrE,0BAAsB,SAAS,WAAW;AAAA,EAC3C;AACA,UACC,+BAAiB,cAAc,WAAY,KAC3C,WAAW,WACV;AACD,0BAAsB,YAAY,WAAW;AAAA,EAC9C;AAGA,MAAK,WAAW,UAAW;AAI1B,UAAM,sBAAsB,CAAC;AAG7B,QAAK,kBAAmB;AACvB,0BAAoB,KAAM,MAAM,UAAW;AAAA,IAC5C;AAGA,QAAK,oBAAoB,SAAS,GAAI;AACrC,YAAM,cAAc,OAAO,QAAS,WAAW,QAAS,EAAE;AAAA,QACzD,CAAE,KAAK,CAAE,MAAM,KAAM,MAAO;AAE3B,cAAK,CAAE,oBAAoB,SAAU,IAAK,GAAI;AAC7C,mBAAO;AAAA,UACR;AACA,cAAK,IAAK,IACT,SAAS,aAAa,iBAAkB,KAAM,IAAI;AACnD,iBAAO;AAAA,QACR;AAAA,QACA,CAAC;AAAA,MACF;AAGA,UAAK,OAAO,KAAM,WAAY,EAAE,SAAS,GAAI;AAC5C,8BAAsB,WAAW;AAAA,MAClC;AAAA,IACD;AAAA,EACD;AAEA,MAAK,OAAO,KAAM,qBAAsB,EAAE,WAAW,GAAI;AACxD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -4,7 +4,7 @@
4
4
  "name": "core/accordion",
5
5
  "title": "Accordion",
6
6
  "category": "design",
7
- "description": "Displays a group of accordion headings and associated expandable content.",
7
+ "description": "Displays a foldable layout that groups content in collapsible sections.",
8
8
  "example": {},
9
9
  "supports": {
10
10
  "anchor": true,
@@ -77,15 +77,17 @@ function Edit({
77
77
  });
78
78
  };
79
79
  return /* @__PURE__ */ jsxs(Fragment, { children: [
80
- isSingleSelected && !isContentOnlyMode && /* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(
81
- HeadingLevelDropdown,
82
- {
83
- value: headingLevel,
84
- options: levelOptions,
85
- onChange: updateHeadingLevel
86
- }
87
- ) }) }),
88
- isSingleSelected && /* @__PURE__ */ jsx(BlockControls, { group: "other", children: /* @__PURE__ */ jsx(ToolbarButton, { onClick: addAccordionItemBlock, children: __("Add") }) }),
80
+ isSingleSelected && !isContentOnlyMode && /* @__PURE__ */ jsxs(Fragment, { children: [
81
+ /* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(
82
+ HeadingLevelDropdown,
83
+ {
84
+ value: headingLevel,
85
+ options: levelOptions,
86
+ onChange: updateHeadingLevel
87
+ }
88
+ ) }) }),
89
+ /* @__PURE__ */ jsx(BlockControls, { group: "other", children: /* @__PURE__ */ jsx(ToolbarButton, { onClick: addAccordionItemBlock, children: __("Add") }) })
90
+ ] }),
89
91
  /* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsxs(
90
92
  ToolsPanel,
91
93
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/accordion/edit.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tBlockControls,\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst ACCORDION_BLOCK_NAME = 'core/accordion-item';\nconst ACCORDION_HEADING_BLOCK_NAME = 'core/accordion-heading';\nconst ACCORDION_BLOCK = {\n\tname: ACCORDION_BLOCK_NAME,\n};\n\nexport default function Edit( {\n\tattributes: {\n\t\tautoclose,\n\t\ticonPosition,\n\t\tshowIcon,\n\t\theadingLevel,\n\t\tlevelOptions,\n\t},\n\tclientId,\n\tsetAttributes,\n\tisSelected: isSingleSelected,\n} ) {\n\tconst registry = useRegistry();\n\tconst { getBlockOrder } = useSelect( blockEditorStore );\n\tconst blockProps = useBlockProps( {\n\t\trole: 'group',\n\t} );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst { updateBlockAttributes, insertBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isContentOnlyMode = blockEditingMode === 'contentOnly';\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: [ [ ACCORDION_BLOCK_NAME ] ],\n\t\tdefaultBlock: ACCORDION_BLOCK,\n\t\tdirectInsert: true,\n\t\ttemplateInsertUpdatesSelection: true,\n\t} );\n\n\tconst addAccordionItemBlock = () => {\n\t\t// When adding, set the header's level to current headingLevel\n\t\tconst newAccordionItem = createBlock( ACCORDION_BLOCK_NAME, {}, [\n\t\t\tcreateBlock( ACCORDION_HEADING_BLOCK_NAME, {\n\t\t\t\tlevel: headingLevel,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/accordion-panel', {} ),\n\t\t] );\n\t\tinsertBlock( newAccordionItem, undefined, clientId );\n\t};\n\n\t/**\n\t * Update all child Accordion Header blocks with a new heading level\n\t * based on the accordion group setting.\n\t * @param {number} newHeadingLevel The new heading level to set\n\t */\n\tconst updateHeadingLevel = ( newHeadingLevel ) => {\n\t\tconst innerBlockClientIds = getBlockOrder( clientId );\n\n\t\t// Get all accordion-header blocks from all accordion-content blocks.\n\t\tconst accordionHeaderClientIds = [];\n\t\tinnerBlockClientIds.forEach( ( contentClientId ) => {\n\t\t\tconst headerClientIds = getBlockOrder( contentClientId );\n\t\t\taccordionHeaderClientIds.push( ...headerClientIds );\n\t\t} );\n\n\t\t// Update own and child block heading levels.\n\t\tregistry.batch( () => {\n\t\t\tsetAttributes( { headingLevel: newHeadingLevel } );\n\t\t\tupdateBlockAttributes( accordionHeaderClientIds, {\n\t\t\t\tlevel: newHeadingLevel,\n\t\t\t} );\n\t\t} );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ isSingleSelected && ! isContentOnlyMode && (\n\t\t\t\t<BlockControls>\n\t\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\t\t\tvalue={ headingLevel }\n\t\t\t\t\t\t\toptions={ levelOptions }\n\t\t\t\t\t\t\tonChange={ updateHeadingLevel }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t{ isSingleSelected && (\n\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t<ToolbarButton onClick={ addAccordionItemBlock }>\n\t\t\t\t\t\t{ __( 'Add' ) }\n\t\t\t\t\t</ToolbarButton>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<InspectorControls key=\"setting\">\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tautoclose: false,\n\t\t\t\t\t\t\tshowIcon: true,\n\t\t\t\t\t\t\ticonPosition: 'right',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Auto-close' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! autoclose }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { autoclose: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Auto-close' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tautoclose: value,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tchecked={ autoclose }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Automatically close accordions when a new one is opened.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Show icon' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => ! showIcon }\n\t\t\t\t\t\tonDeselect={ () => setAttributes( { showIcon: true } ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Show icon' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowIcon: value,\n\t\t\t\t\t\t\t\t\ticonPosition: value\n\t\t\t\t\t\t\t\t\t\t? iconPosition\n\t\t\t\t\t\t\t\t\t\t: 'right',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tchecked={ showIcon }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Display a plus icon next to the accordion header.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ showIcon && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\tlabel={ __( 'Icon Position' ) }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t\thasValue={ () => iconPosition !== 'right' }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { iconPosition: 'right' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\tlabel={ __( 'Icon Position' ) }\n\t\t\t\t\t\t\t\tvalue={ iconPosition }\n\t\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( { iconPosition: value } );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Left' ) }\n\t\t\t\t\t\t\t\t\tvalue=\"left\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Right' ) }\n\t\t\t\t\t\t\t\t\tvalue=\"right\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"],
5
- "mappings": "AAsGE,mBAII,KAmFC,YAvFL;AAnGF;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,oCAAoC;AAAA,EACpC,0CAA0C;AAAA,EAC1C,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,WAAW,mBAAmB;AACpD,SAAS,mBAAmB;AAK5B,SAAS,sCAAsC;AAE/C,MAAM,uBAAuB;AAC7B,MAAM,+BAA+B;AACrC,MAAM,kBAAkB;AAAA,EACvB,MAAM;AACP;AAEe,SAAR,KAAuB;AAAA,EAC7B,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AACb,GAAI;AACH,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,cAAc,IAAI,UAAW,gBAAiB;AACtD,QAAM,aAAa,cAAe;AAAA,IACjC,MAAM;AAAA,EACP,CAAE;AACF,QAAM,oBAAoB,+BAA+B;AACzD,QAAM,EAAE,uBAAuB,YAAY,IAC1C,YAAa,gBAAiB;AAC/B,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,oBAAoB,qBAAqB;AAE/C,QAAM,mBAAmB,oBAAqB,YAAY;AAAA,IACzD,UAAU,CAAE,CAAE,oBAAqB,CAAE;AAAA,IACrC,cAAc;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BACxC;AAAA,kBAEA;AAAA;AAAA,sBAAC;AAAA;AAAA,wBACA,OAAQ,GAAI,MAAO;AAAA,wBACnB,OAAM;AAAA;AAAA,oBACP;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,OAAQ,GAAI,OAAQ;AAAA,wBACpB,OAAM;AAAA;AAAA,oBACP;AAAA;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA;AAAA;AAAA,IAEF,KAzFsB,SA0FvB;AAAA,IACA,oBAAC,SAAM,GAAG,kBAAmB;AAAA,KAC9B;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tBlockControls,\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst ACCORDION_BLOCK_NAME = 'core/accordion-item';\nconst ACCORDION_HEADING_BLOCK_NAME = 'core/accordion-heading';\nconst ACCORDION_BLOCK = {\n\tname: ACCORDION_BLOCK_NAME,\n};\n\nexport default function Edit( {\n\tattributes: {\n\t\tautoclose,\n\t\ticonPosition,\n\t\tshowIcon,\n\t\theadingLevel,\n\t\tlevelOptions,\n\t},\n\tclientId,\n\tsetAttributes,\n\tisSelected: isSingleSelected,\n} ) {\n\tconst registry = useRegistry();\n\tconst { getBlockOrder } = useSelect( blockEditorStore );\n\tconst blockProps = useBlockProps( {\n\t\trole: 'group',\n\t} );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst { updateBlockAttributes, insertBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isContentOnlyMode = blockEditingMode === 'contentOnly';\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: [ [ ACCORDION_BLOCK_NAME ] ],\n\t\tdefaultBlock: ACCORDION_BLOCK,\n\t\tdirectInsert: true,\n\t\ttemplateInsertUpdatesSelection: true,\n\t} );\n\n\tconst addAccordionItemBlock = () => {\n\t\t// When adding, set the header's level to current headingLevel\n\t\tconst newAccordionItem = createBlock( ACCORDION_BLOCK_NAME, {}, [\n\t\t\tcreateBlock( ACCORDION_HEADING_BLOCK_NAME, {\n\t\t\t\tlevel: headingLevel,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/accordion-panel', {} ),\n\t\t] );\n\t\tinsertBlock( newAccordionItem, undefined, clientId );\n\t};\n\n\t/**\n\t * Update all child Accordion Header blocks with a new heading level\n\t * based on the accordion group setting.\n\t * @param {number} newHeadingLevel The new heading level to set\n\t */\n\tconst updateHeadingLevel = ( newHeadingLevel ) => {\n\t\tconst innerBlockClientIds = getBlockOrder( clientId );\n\n\t\t// Get all accordion-header blocks from all accordion-content blocks.\n\t\tconst accordionHeaderClientIds = [];\n\t\tinnerBlockClientIds.forEach( ( contentClientId ) => {\n\t\t\tconst headerClientIds = getBlockOrder( contentClientId );\n\t\t\taccordionHeaderClientIds.push( ...headerClientIds );\n\t\t} );\n\n\t\t// Update own and child block heading levels.\n\t\tregistry.batch( () => {\n\t\t\tsetAttributes( { headingLevel: newHeadingLevel } );\n\t\t\tupdateBlockAttributes( accordionHeaderClientIds, {\n\t\t\t\tlevel: newHeadingLevel,\n\t\t\t} );\n\t\t} );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ isSingleSelected && ! isContentOnlyMode && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\t\t\t\tvalue={ headingLevel }\n\t\t\t\t\t\t\t\toptions={ levelOptions }\n\t\t\t\t\t\t\t\tonChange={ updateHeadingLevel }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t<ToolbarButton onClick={ addAccordionItemBlock }>\n\t\t\t\t\t\t\t{ __( 'Add' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<InspectorControls key=\"setting\">\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tautoclose: false,\n\t\t\t\t\t\t\tshowIcon: true,\n\t\t\t\t\t\t\ticonPosition: 'right',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Auto-close' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! autoclose }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { autoclose: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Auto-close' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tautoclose: value,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tchecked={ autoclose }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Automatically close accordions when a new one is opened.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Show icon' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => ! showIcon }\n\t\t\t\t\t\tonDeselect={ () => setAttributes( { showIcon: true } ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Show icon' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowIcon: value,\n\t\t\t\t\t\t\t\t\ticonPosition: value\n\t\t\t\t\t\t\t\t\t\t? iconPosition\n\t\t\t\t\t\t\t\t\t\t: 'right',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tchecked={ showIcon }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Display a plus icon next to the accordion header.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ showIcon && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\tlabel={ __( 'Icon Position' ) }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t\thasValue={ () => iconPosition !== 'right' }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { iconPosition: 'right' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\tlabel={ __( 'Icon Position' ) }\n\t\t\t\t\t\t\t\tvalue={ iconPosition }\n\t\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( { iconPosition: value } );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Left' ) }\n\t\t\t\t\t\t\t\t\tvalue=\"left\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Right' ) }\n\t\t\t\t\t\t\t\t\tvalue=\"right\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"],
5
+ "mappings": "AAwGI,mBAGG,KAHH;AArGJ;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,oCAAoC;AAAA,EACpC,0CAA0C;AAAA,EAC1C,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,WAAW,mBAAmB;AACpD,SAAS,mBAAmB;AAK5B,SAAS,sCAAsC;AAE/C,MAAM,uBAAuB;AAC7B,MAAM,+BAA+B;AACrC,MAAM,kBAAkB;AAAA,EACvB,MAAM;AACP;AAEe,SAAR,KAAuB;AAAA,EAC7B,Y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AAAA,kBACH;AAAA,kBACA,SAAU;AAAA,kBACV,MAAO;AAAA,oBACN;AAAA,kBACD;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA,UACE,YACD;AAAA,YAAC;AAAA;AAAA,cACA,OAAQ,GAAI,eAAgB;AAAA,cAC5B,kBAAgB;AAAA,cAChB,UAAW,MAAM,iBAAiB;AAAA,cAClC,YAAa,MACZ,cAAe,EAAE,cAAc,QAAQ,CAAE;AAAA,cAG1C;AAAA,gBAAC;AAAA;AAAA,kBACA,yBAAuB;AAAA,kBACvB,uBAAqB;AAAA,kBACrB,SAAO;AAAA,kBACP,OAAQ,GAAI,eAAgB;AAAA,kBAC5B,OAAQ;AAAA,kBACR,UAAW,CAAE,UAAW;AACvB,kCAAe,EAAE,cAAc,MAAM,CAAE;AAAA,kBACxC;AAAA,kBAEA;AAAA;AAAA,sBAAC;AAAA;AAAA,wBACA,OAAQ,GAAI,MAAO;AAAA,wBACnB,OAAM;AAAA;AAAA,oBACP;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,OAAQ,GAAI,OAAQ;AAAA,wBACpB,OAAM;AAAA;AAAA,oBACP;AAAA;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA;AAAA;AAAA,IAEF,KAzFsB,SA0FvB;AAAA,IACA,oBAAC,SAAM,GAAG,kBAAmB;AAAA,KAC9B;AAEF;",
6
6
  "names": []
7
7
  }
@@ -4,7 +4,7 @@
4
4
  "name": "core/accordion-heading",
5
5
  "title": "Accordion Heading",
6
6
  "category": "design",
7
- "description": "Displays an accordion heading.",
7
+ "description": "Toggles the accordion panel.",
8
8
  "parent": [ "core/accordion-item" ],
9
9
  "usesContext": [
10
10
  "core/accordion-icon-position",
@@ -4,7 +4,7 @@
4
4
  "name": "core/accordion-item",
5
5
  "title": "Accordion Item",
6
6
  "category": "design",
7
- "description": "Displays a section of content in an accordion, including a heading and expandable content.",
7
+ "description": "Wraps the heading and panel in one unit.",
8
8
  "parent": [ "core/accordion" ],
9
9
  "allowedBlocks": [ "core/accordion-heading", "core/accordion-panel" ],
10
10
  "supports": {
@@ -4,7 +4,7 @@
4
4
  "name": "core/accordion-panel",
5
5
  "title": "Accordion Panel",
6
6
  "category": "design",
7
- "description": "Displays an accordion panel.",
7
+ "description": "Contains the hidden or revealed content beneath the heading.",
8
8
  "parent": [ "core/accordion-item" ],
9
9
  "supports": {
10
10
  "html": false,
@@ -39,6 +39,7 @@ const transforms = {
39
39
  const link = element.querySelector("a");
40
40
  const url = link?.getAttribute("href");
41
41
  return createBlock("core/button", {
42
+ ...attributes,
42
43
  ...getTransformedAttributes(
43
44
  attributes,
44
45
  "core/button",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/buttons/transforms.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { __unstableCreateElement as createElement } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { getTransformedAttributes } from '../utils/get-transformed-attributes';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/button' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) =>\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\tcreateBlock( 'core/button', attributes )\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) => {\n\t\t\t\t\t\tconst { content } = attributes;\n\t\t\t\t\t\tconst element = createElement( document, content );\n\t\t\t\t\t\t// Remove any HTML tags.\n\t\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\t\t// Get first url.\n\t\t\t\t\t\tconst link = element.querySelector( 'a' );\n\t\t\t\t\t\tconst url = link?.getAttribute( 'href' );\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\treturn createBlock( 'core/button', {\n\t\t\t\t\t\t\t...getTransformedAttributes(\n\t\t\t\t\t\t\t\tattributes,\n\t\t\t\t\t\t\t\t'core/button',\n\t\t\t\t\t\t\t\t( { content: contentBinding } ) => ( {\n\t\t\t\t\t\t\t\t\ttext: contentBinding,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} )\n\t\t\t\t),\n\t\t\tisMatch: ( paragraphs ) => {\n\t\t\t\treturn paragraphs.every( ( attributes ) => {\n\t\t\t\t\tconst element = createElement(\n\t\t\t\t\t\tdocument,\n\t\t\t\t\t\tattributes.content\n\t\t\t\t\t);\n\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\tconst links = element.querySelectorAll( 'a' );\n\t\t\t\t\treturn text.length <= 30 && links.length <= 1;\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],
5
- "mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B,qBAAqB;AAKzD,SAAS,gCAAgC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,cAAc;AAAA,MACd,QAAQ,CAAE,aAAc;AAAA,MACxB,WAAW,CAAE;AAAA;AAAA,QAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ;AAAA,YAAK,CAAE;AAAA;AAAA,cAEd,YAAa,eAAe,UAAW;AAAA;AAAA,UACxC;AAAA,QACD;AAAA;AAAA,IACF;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,cAAc;AAAA,MACd,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE;AAAA;AAAA,QAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ,IAAK,CAAE,eAAgB;AAC9B,kBAAM,EAAE,QAAQ,IAAI;AACpB,kBAAM,UAAU,cAAe,UAAU,OAAQ;AAEjD,kBAAM,OAAO,QAAQ,aAAa;AAElC,kBAAM,OAAO,QAAQ,cAAe,GAAI;AACxC,kBAAM,MAAM,MAAM,aAAc,MAAO;AAEvC,mBAAO,YAAa,eAAe;AAAA,cAClC,GAAG;AAAA,gBACF;AAAA,gBACA;AAAA,gBACA,CAAE,EAAE,SAAS,eAAe,OAAS;AAAA,kBACpC,MAAM;AAAA,gBACP;AAAA,cACD;AAAA,cACA;AAAA,cACA;AAAA,YACD,CAAE;AAAA,UACH,CAAE;AAAA,QACH;AAAA;AAAA,MACD,SAAS,CAAE,eAAgB;AAC1B,eAAO,WAAW,MAAO,CAAE,eAAgB;AAC1C,gBAAM,UAAU;AAAA,YACf;AAAA,YACA,WAAW;AAAA,UACZ;AACA,gBAAM,OAAO,QAAQ,aAAa;AAClC,gBAAM,QAAQ,QAAQ,iBAAkB,GAAI;AAC5C,iBAAO,KAAK,UAAU,MAAM,MAAM,UAAU;AAAA,QAC7C,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { __unstableCreateElement as createElement } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { getTransformedAttributes } from '../utils/get-transformed-attributes';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/button' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) =>\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\tcreateBlock( 'core/button', attributes )\n\t\t\t\t\t)\n\t\t\t\t),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tisMultiBlock: true,\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( buttons ) =>\n\t\t\t\t// Creates the buttons block.\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/buttons',\n\t\t\t\t\t{},\n\t\t\t\t\t// Loop the selected buttons.\n\t\t\t\t\tbuttons.map( ( attributes ) => {\n\t\t\t\t\t\tconst { content } = attributes;\n\t\t\t\t\t\tconst element = createElement( document, content );\n\t\t\t\t\t\t// Remove any HTML tags.\n\t\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\t\t// Get first url.\n\t\t\t\t\t\tconst link = element.querySelector( 'a' );\n\t\t\t\t\t\tconst url = link?.getAttribute( 'href' );\n\t\t\t\t\t\t// Create singular button in the buttons block.\n\t\t\t\t\t\treturn createBlock( 'core/button', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\t...getTransformedAttributes(\n\t\t\t\t\t\t\t\tattributes,\n\t\t\t\t\t\t\t\t'core/button',\n\t\t\t\t\t\t\t\t( { content: contentBinding } ) => ( {\n\t\t\t\t\t\t\t\t\ttext: contentBinding,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} )\n\t\t\t\t),\n\t\t\tisMatch: ( paragraphs ) => {\n\t\t\t\treturn paragraphs.every( ( attributes ) => {\n\t\t\t\t\tconst element = createElement(\n\t\t\t\t\t\tdocument,\n\t\t\t\t\t\tattributes.content\n\t\t\t\t\t);\n\t\t\t\t\tconst text = element.innerText || '';\n\t\t\t\t\tconst links = element.querySelectorAll( 'a' );\n\t\t\t\t\treturn text.length <= 30 && links.length <= 1;\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],
5
+ "mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B,qBAAqB;AAKzD,SAAS,gCAAgC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,cAAc;AAAA,MACd,QAAQ,CAAE,aAAc;AAAA,MACxB,WAAW,CAAE;AAAA;AAAA,QAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ;AAAA,YAAK,CAAE;AAAA;AAAA,cAEd,YAAa,eAAe,UAAW;AAAA;AAAA,UACxC;AAAA,QACD;AAAA;AAAA,IACF;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,cAAc;AAAA,MACd,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE;AAAA;AAAA,QAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ,IAAK,CAAE,eAAgB;AAC9B,kBAAM,EAAE,QAAQ,IAAI;AACpB,kBAAM,UAAU,cAAe,UAAU,OAAQ;AAEjD,kBAAM,OAAO,QAAQ,aAAa;AAElC,kBAAM,OAAO,QAAQ,cAAe,GAAI;AACxC,kBAAM,MAAM,MAAM,aAAc,MAAO;AAEvC,mBAAO,YAAa,eAAe;AAAA,cAClC,GAAG;AAAA,cACH,GAAG;AAAA,gBACF;AAAA,gBACA;AAAA,gBACA,CAAE,EAAE,SAAS,eAAe,OAAS;AAAA,kBACpC,MAAM;AAAA,gBACP;AAAA,cACD;AAAA,cACA;AAAA,cACA;AAAA,YACD,CAAE;AAAA,UACH,CAAE;AAAA,QACH;AAAA;AAAA,MACD,SAAS,CAAE,eAAgB;AAC1B,eAAO,WAAW,MAAO,CAAE,eAAgB;AAC1C,gBAAM,UAAU;AAAA,YACf;AAAA,YACA,WAAW;AAAA,UACZ;AACA,gBAAM,OAAO,QAAQ,aAAa;AAClC,gBAAM,QAAQ,QAAQ,iBAAkB,GAAI;AAC5C,iBAAO,KAAK,UAAU,MAAM,MAAM,UAAU;AAAA,QAC7C,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
6
6
  "names": []
7
7
  }
@@ -14,6 +14,7 @@ const transforms = {
14
14
  transform: (attributes) => {
15
15
  const { content } = attributes;
16
16
  return createBlock("core/code", {
17
+ ...attributes,
17
18
  ...getTransformedAttributes(attributes, "core/code"),
18
19
  content
19
20
  });
@@ -25,6 +26,7 @@ const transforms = {
25
26
  transform: (attributes) => {
26
27
  const { content: text } = attributes;
27
28
  return createBlock("core/code", {
29
+ ...attributes,
28
30
  ...getTransformedAttributes(attributes, "core/code"),
29
31
  // The HTML is plain text (with plain line breaks), so
30
32
  // convert it to rich text.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/code/transforms.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { create, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { getTransformedAttributes } from '../utils/get-transformed-attributes';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'enter',\n\t\t\tregExp: /^```$/,\n\t\t\ttransform: () => createBlock( 'core/code' ),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content } = attributes;\n\t\t\t\treturn createBlock( 'core/code', {\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/code' ),\n\t\t\t\t\tcontent,\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/html' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content: text } = attributes;\n\t\t\t\treturn createBlock( 'core/code', {\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/code' ),\n\t\t\t\t\t// The HTML is plain text (with plain line breaks), so\n\t\t\t\t\t// convert it to rich text.\n\t\t\t\t\tcontent: toHTMLString( { value: create( { text } ) } ),\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'raw',\n\t\t\tisMatch: ( node ) =>\n\t\t\t\tnode.nodeName === 'PRE' &&\n\t\t\t\tnode.children.length === 1 &&\n\t\t\t\tnode.firstChild.nodeName === 'CODE',\n\t\t\tschema: {\n\t\t\t\tpre: {\n\t\t\t\t\tchildren: {\n\t\t\t\t\t\tcode: {\n\t\t\t\t\t\t\tchildren: {\n\t\t\t\t\t\t\t\t'#text': {},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t],\n\tto: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content } = attributes;\n\t\t\t\treturn createBlock( 'core/paragraph', {\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/paragraph' ),\n\t\t\t\t\tcontent,\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],
5
- "mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,oBAAoB;AAKrC,SAAS,gCAAgC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,WAAW,MAAM,YAAa,WAAY;AAAA,IAC3C;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,QAAQ,IAAI;AACpB,eAAO,YAAa,aAAa;AAAA,UAChC,GAAG,yBAA0B,YAAY,WAAY;AAAA,UACrD;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,WAAY;AAAA,MACtB,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,SAAS,KAAK,IAAI;AAC1B,eAAO,YAAa,aAAa;AAAA,UAChC,GAAG,yBAA0B,YAAY,WAAY;AAAA;AAAA;AAAA,UAGrD,SAAS,aAAc,EAAE,OAAO,OAAQ,EAAE,KAAK,CAAE,EAAE,CAAE;AAAA,QACtD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,SAAS,CAAE,SACV,KAAK,aAAa,SAClB,KAAK,SAAS,WAAW,KACzB,KAAK,WAAW,aAAa;AAAA,MAC9B,QAAQ;AAAA,QACP,KAAK;AAAA,UACJ,UAAU;AAAA,YACT,MAAM;AAAA,cACL,UAAU;AAAA,gBACT,SAAS,CAAC;AAAA,cACX;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA,IAAI;AAAA,IACH;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,QAAQ,IAAI;AACpB,eAAO,YAAa,kBAAkB;AAAA,UACrC,GAAG,yBAA0B,YAAY,gBAAiB;AAAA,UAC1D;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { create, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { getTransformedAttributes } from '../utils/get-transformed-attributes';\n\nconst transforms = {\n\tfrom: [\n\t\t{\n\t\t\ttype: 'enter',\n\t\t\tregExp: /^```$/,\n\t\t\ttransform: () => createBlock( 'core/code' ),\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content } = attributes;\n\t\t\t\treturn createBlock( 'core/code', {\n\t\t\t\t\t...attributes,\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/code' ),\n\t\t\t\t\tcontent,\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/html' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content: text } = attributes;\n\t\t\t\treturn createBlock( 'core/code', {\n\t\t\t\t\t...attributes,\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/code' ),\n\t\t\t\t\t// The HTML is plain text (with plain line breaks), so\n\t\t\t\t\t// convert it to rich text.\n\t\t\t\t\tcontent: toHTMLString( { value: create( { text } ) } ),\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\ttype: 'raw',\n\t\t\tisMatch: ( node ) =>\n\t\t\t\tnode.nodeName === 'PRE' &&\n\t\t\t\tnode.children.length === 1 &&\n\t\t\t\tnode.firstChild.nodeName === 'CODE',\n\t\t\tschema: {\n\t\t\t\tpre: {\n\t\t\t\t\tchildren: {\n\t\t\t\t\t\tcode: {\n\t\t\t\t\t\t\tchildren: {\n\t\t\t\t\t\t\t\t'#text': {},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t],\n\tto: [\n\t\t{\n\t\t\ttype: 'block',\n\t\t\tblocks: [ 'core/paragraph' ],\n\t\t\ttransform: ( attributes ) => {\n\t\t\t\tconst { content } = attributes;\n\t\t\t\treturn createBlock( 'core/paragraph', {\n\t\t\t\t\t...getTransformedAttributes( attributes, 'core/paragraph' ),\n\t\t\t\t\tcontent,\n\t\t\t\t} );\n\t\t\t},\n\t\t},\n\t],\n};\n\nexport default transforms;\n"],
5
+ "mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,oBAAoB;AAKrC,SAAS,gCAAgC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,WAAW,MAAM,YAAa,WAAY;AAAA,IAC3C;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,QAAQ,IAAI;AACpB,eAAO,YAAa,aAAa;AAAA,UAChC,GAAG;AAAA,UACH,GAAG,yBAA0B,YAAY,WAAY;AAAA,UACrD;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,WAAY;AAAA,MACtB,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,SAAS,KAAK,IAAI;AAC1B,eAAO,YAAa,aAAa;AAAA,UAChC,GAAG;AAAA,UACH,GAAG,yBAA0B,YAAY,WAAY;AAAA;AAAA;AAAA,UAGrD,SAAS,aAAc,EAAE,OAAO,OAAQ,EAAE,KAAK,CAAE,EAAE,CAAE;AAAA,QACtD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,SAAS,CAAE,SACV,KAAK,aAAa,SAClB,KAAK,SAAS,WAAW,KACzB,KAAK,WAAW,aAAa;AAAA,MAC9B,QAAQ;AAAA,QACP,KAAK;AAAA,UACJ,UAAU;AAAA,YACT,MAAM;AAAA,cACL,UAAU;AAAA,gBACT,SAAS,CAAC;AAAA,cACX;AAAA,YACD;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA,IAAI;AAAA,IACH;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,QAAQ,IAAI;AACpB,eAAO,YAAa,kBAAkB;AAAA,UACrC,GAAG,yBAA0B,YAAY,gBAAiB;AAAA,UAC1D;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
6
6
  "names": []
7
7
  }
@@ -9,7 +9,8 @@
9
9
  "textdomain": "default",
10
10
  "attributes": {
11
11
  "label": {
12
- "type": "string"
12
+ "type": "string",
13
+ "role": "content"
13
14
  }
14
15
  },
15
16
  "usesContext": [
@@ -221,8 +221,11 @@ const { state, actions, callbacks } = store(
221
221
  `;
222
222
  },
223
223
  setButtonStyles() {
224
- const { imageId } = getContext();
225
224
  const { ref } = getElement();
225
+ if (!ref) {
226
+ return;
227
+ }
228
+ const { imageId } = getContext();
226
229
  state.metadata[imageId].imageRef = ref;
227
230
  state.metadata[imageId].currentSrc = ref.currentSrc;
228
231
  const {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/image/view.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tstore,\n\tgetContext,\n\tgetElement,\n\twithSyncEvent,\n} from '@wordpress/interactivity';\n\n/**\n * Tracks whether user is touching screen; used to differentiate behavior for\n * touch and mouse input.\n *\n * @type {boolean}\n */\nlet isTouching = false;\n\n/**\n * Tracks the last time the screen was touched; used to differentiate behavior\n * for touch and mouse input.\n *\n * @type {number}\n */\nlet lastTouchTime = 0;\n\nconst { state, actions, callbacks } = store(\n\t'core/image',\n\t{\n\t\tstate: {\n\t\t\tcurrentImageId: null,\n\t\t\tget currentImage() {\n\t\t\t\treturn state.metadata[ state.currentImageId ];\n\t\t\t},\n\t\t\tget overlayOpened() {\n\t\t\t\treturn state.currentImageId !== null;\n\t\t\t},\n\t\t\tget roleAttribute() {\n\t\t\t\treturn state.overlayOpened ? 'dialog' : null;\n\t\t\t},\n\t\t\tget ariaModal() {\n\t\t\t\treturn state.overlayOpened ? 'true' : null;\n\t\t\t},\n\t\t\tget enlargedSrc() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.currentImage.uploadedSrc ||\n\t\t\t\t\t'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='\n\t\t\t\t);\n\t\t\t},\n\t\t\tget figureStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.currentImage.figureStyles?.replace(\n\t\t\t\t\t\t/margin[^;]*;?/g,\n\t\t\t\t\t\t''\n\t\t\t\t\t) };`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imgStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.currentImage.imgStyles?.replace(\n\t\t\t\t\t\t/;$/,\n\t\t\t\t\t\t''\n\t\t\t\t\t) }; object-fit:cover;`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imageButtonRight() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ].imageButtonRight;\n\t\t\t},\n\t\t\tget imageButtonTop() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ].imageButtonTop;\n\t\t\t},\n\t\t\tget isContentHidden() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayEnabled && state.currentImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentVisible() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\t! state.overlayEnabled &&\n\t\t\t\t\tstate.currentImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\tactions: {\n\t\t\tshowLightbox() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails out if the image has not loaded yet.\n\t\t\t\tif ( ! state.metadata[ imageId ].imageRef?.complete ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Stores the positions of the scroll to fix it until the overlay is\n\t\t\t\t// closed.\n\t\t\t\tstate.scrollTopReset = document.documentElement.scrollTop;\n\t\t\t\tstate.scrollLeftReset = document.documentElement.scrollLeft;\n\n\t\t\t\t// Sets the current expanded image in the state and enables the overlay.\n\t\t\t\tstate.overlayEnabled = true;\n\t\t\t\tstate.currentImageId = imageId;\n\n\t\t\t\t// Computes the styles of the overlay for the animation.\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t},\n\t\t\thideLightbox() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tstate.overlayEnabled = false;\n\n\t\t\t\t\t// Waits until the close animation has completed before allowing a\n\t\t\t\t\t// user to scroll again. The duration of this animation is defined in\n\t\t\t\t\t// the `styles.scss` file, but in any case we should wait a few\n\t\t\t\t\t// milliseconds longer than the duration, otherwise a user may scroll\n\t\t\t\t\t// too soon and cause the animation to look sloppy.\n\t\t\t\t\tsetTimeout( function () {\n\t\t\t\t\t\t// Delays before changing the focus. Otherwise the focus ring will\n\t\t\t\t\t\t// appear on Firefox before the image has finished animating, which\n\t\t\t\t\t\t// looks broken.\n\t\t\t\t\t\tstate.currentImage.buttonRef.focus( {\n\t\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Resets the current image id to mark the overlay as closed.\n\t\t\t\t\t\tstate.currentImageId = null;\n\t\t\t\t\t}, 450 );\n\t\t\t\t}\n\t\t\t},\n\t\t\thandleKeydown: withSyncEvent( ( event ) => {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Focuses the close button when the user presses the tab key.\n\t\t\t\t\tif ( event.key === 'Tab' ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\t\tref.querySelector( 'button' ).focus();\n\t\t\t\t\t}\n\t\t\t\t\t// Closes the lightbox when the user presses the escape key.\n\t\t\t\t\tif ( event.key === 'Escape' ) {\n\t\t\t\t\t\tactions.hideLightbox();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchMove: withSyncEvent( ( event ) => {\n\t\t\t\t// On mobile devices, prevents triggering the scroll event because\n\t\t\t\t// otherwise the page jumps around when it resets the scroll position.\n\t\t\t\t// This also means that closing the lightbox requires that a user\n\t\t\t\t// perform a simple tap. This may be changed in the future if there is a\n\t\t\t\t// better alternative to override or reset the scroll position during\n\t\t\t\t// swipe actions.\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchStart() {\n\t\t\t\tisTouching = true;\n\t\t\t},\n\t\t\thandleTouchEnd() {\n\t\t\t\t// Waits a few milliseconds before resetting to ensure that pinch to\n\t\t\t\t// zoom works consistently on mobile devices when the lightbox is open.\n\t\t\t\tlastTouchTime = Date.now();\n\t\t\t\tisTouching = false;\n\t\t\t},\n\t\t\thandleScroll() {\n\t\t\t\t// Prevents scrolling behaviors that trigger content shift while the\n\t\t\t\t// lightbox is open. It would be better to accomplish through CSS alone,\n\t\t\t\t// but using overflow: hidden is currently the only way to do so and\n\t\t\t\t// that causes a layout to shift and prevents the zoom animation from\n\t\t\t\t// working in some cases because it's not possible to account for the\n\t\t\t\t// layout shift when doing the animation calculations. Instead, it uses\n\t\t\t\t// JavaScript to prevent and reset the scrolling behavior.\n\t\t\t\tif ( state.overlayOpened ) {\n\t\t\t\t\t// Avoids overriding the scroll behavior on mobile devices because\n\t\t\t\t\t// doing so breaks the pinch to zoom functionality, and users should\n\t\t\t\t\t// be able to zoom in further on the high-res image.\n\t\t\t\t\tif ( ! isTouching && Date.now() - lastTouchTime > 450 ) {\n\t\t\t\t\t\t// It doesn't rely on `event.preventDefault()` to prevent scrolling\n\t\t\t\t\t\t// because the scroll event can't be canceled, so it resets the\n\t\t\t\t\t\t// position instead.\n\t\t\t\t\t\twindow.scrollTo(\n\t\t\t\t\t\t\tstate.scrollLeftReset,\n\t\t\t\t\t\t\tstate.scrollTopReset\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tcallbacks: {\n\t\t\tsetOverlayStyles() {\n\t\t\t\tif ( ! state.overlayEnabled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth: originalWidth,\n\t\t\t\t\toffsetHeight: originalHeight,\n\t\t\t\t} = state.currentImage.imageRef;\n\t\t\t\tlet { x: screenPosX, y: screenPosY } =\n\t\t\t\t\tstate.currentImage.imageRef.getBoundingClientRect();\n\n\t\t\t\t// Natural ratio of the image clicked to open the lightbox.\n\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t// Original ratio of the image clicked to open the lightbox.\n\t\t\t\tlet originalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// If it has object-fit: contain, recalculates the original sizes\n\t\t\t\t// and the screen position without the blank spaces.\n\t\t\t\tif ( state.currentImage.scaleAttr === 'contain' ) {\n\t\t\t\t\tif ( naturalRatio > originalRatio ) {\n\t\t\t\t\t\tconst heightWithoutSpace = originalWidth / naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the top space.\n\t\t\t\t\t\tscreenPosY +=\n\t\t\t\t\t\t\t( originalHeight - heightWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalHeight = heightWithoutSpace;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst widthWithoutSpace = originalHeight * naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the left space.\n\t\t\t\t\t\tscreenPosX += ( originalWidth - widthWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalWidth = widthWithoutSpace;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toriginalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// Typically, it uses the image's full-sized dimensions. If those\n\t\t\t\t// dimensions have not been set (i.e. an external image with only one\n\t\t\t\t// size), the image's dimensions in the lightbox are the same\n\t\t\t\t// as those of the image in the content.\n\t\t\t\tlet imgMaxWidth = parseFloat(\n\t\t\t\t\tstate.currentImage.targetWidth !== 'none'\n\t\t\t\t\t\t? state.currentImage.targetWidth\n\t\t\t\t\t\t: naturalWidth\n\t\t\t\t);\n\t\t\t\tlet imgMaxHeight = parseFloat(\n\t\t\t\t\tstate.currentImage.targetHeight !== 'none'\n\t\t\t\t\t\t? state.currentImage.targetHeight\n\t\t\t\t\t\t: naturalHeight\n\t\t\t\t);\n\n\t\t\t\t// Ratio of the biggest image stored in the database.\n\t\t\t\tlet imgRatio = imgMaxWidth / imgMaxHeight;\n\t\t\t\tlet containerMaxWidth = imgMaxWidth;\n\t\t\t\tlet containerMaxHeight = imgMaxHeight;\n\t\t\t\tlet containerWidth = imgMaxWidth;\n\t\t\t\tlet containerHeight = imgMaxHeight;\n\n\t\t\t\t// Checks if the target image has a different ratio than the original\n\t\t\t\t// one (thumbnail). Recalculates the width and height.\n\t\t\t\tif ( naturalRatio.toFixed( 2 ) !== imgRatio.toFixed( 2 ) ) {\n\t\t\t\t\tif ( naturalRatio > imgRatio ) {\n\t\t\t\t\t\t// If the width is reached before the height, it keeps the maxWidth\n\t\t\t\t\t\t// and recalculates the height unless the difference between the\n\t\t\t\t\t\t// maxHeight and the reducedHeight is higher than the maxWidth,\n\t\t\t\t\t\t// where it keeps the reducedHeight and recalculate the width.\n\t\t\t\t\t\tconst reducedHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\tif ( imgMaxHeight - reducedHeight > imgMaxWidth ) {\n\t\t\t\t\t\t\timgMaxHeight = reducedHeight;\n\t\t\t\t\t\t\timgMaxWidth = reducedHeight * naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the height is reached before the width, it keeps the maxHeight\n\t\t\t\t\t\t// and recalculate the width unlesss the difference between the\n\t\t\t\t\t\t// maxWidth and the reducedWidth is higher than the maxHeight, where\n\t\t\t\t\t\t// it keeps the reducedWidth and recalculate the height.\n\t\t\t\t\t\tconst reducedWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\tif ( imgMaxWidth - reducedWidth > imgMaxHeight ) {\n\t\t\t\t\t\t\timgMaxWidth = reducedWidth;\n\t\t\t\t\t\t\timgMaxHeight = reducedWidth / naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontainerWidth = imgMaxWidth;\n\t\t\t\t\tcontainerHeight = imgMaxHeight;\n\t\t\t\t\timgRatio = imgMaxWidth / imgMaxHeight;\n\n\t\t\t\t\t// Calculates the max size of the container.\n\t\t\t\t\tif ( originalRatio > imgRatio ) {\n\t\t\t\t\t\tcontainerMaxWidth = imgMaxWidth;\n\t\t\t\t\t\tcontainerMaxHeight = containerMaxWidth / originalRatio;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontainerMaxHeight = imgMaxHeight;\n\t\t\t\t\t\tcontainerMaxWidth = containerMaxHeight * originalRatio;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the image has been pixelated on purpose, it keeps that size.\n\t\t\t\tif (\n\t\t\t\t\toriginalWidth > containerWidth ||\n\t\t\t\t\toriginalHeight > containerHeight\n\t\t\t\t) {\n\t\t\t\t\tcontainerWidth = originalWidth;\n\t\t\t\t\tcontainerHeight = originalHeight;\n\t\t\t\t}\n\n\t\t\t\t// Calculates the final lightbox image size and the scale factor.\n\t\t\t\t// MaxWidth is either the window container (accounting for padding) or\n\t\t\t\t// the image resolution.\n\t\t\t\tlet horizontalPadding = 0;\n\t\t\t\tif ( window.innerWidth > 480 ) {\n\t\t\t\t\thorizontalPadding = 80;\n\t\t\t\t} else if ( window.innerWidth > 1920 ) {\n\t\t\t\t\thorizontalPadding = 160;\n\t\t\t\t}\n\t\t\t\tconst verticalPadding = 80;\n\n\t\t\t\tconst targetMaxWidth = Math.min(\n\t\t\t\t\twindow.innerWidth - horizontalPadding,\n\t\t\t\t\tcontainerWidth\n\t\t\t\t);\n\t\t\t\tconst targetMaxHeight = Math.min(\n\t\t\t\t\twindow.innerHeight - verticalPadding,\n\t\t\t\t\tcontainerHeight\n\t\t\t\t);\n\t\t\t\tconst targetContainerRatio = targetMaxWidth / targetMaxHeight;\n\n\t\t\t\tif ( originalRatio > targetContainerRatio ) {\n\t\t\t\t\t// If targetMaxWidth is reached before targetMaxHeight.\n\t\t\t\t\tcontainerWidth = targetMaxWidth;\n\t\t\t\t\tcontainerHeight = containerWidth / originalRatio;\n\t\t\t\t} else {\n\t\t\t\t\t// If targetMaxHeight is reached before targetMaxWidth.\n\t\t\t\t\tcontainerHeight = targetMaxHeight;\n\t\t\t\t\tcontainerWidth = containerHeight * originalRatio;\n\t\t\t\t}\n\n\t\t\t\tconst containerScale = originalWidth / containerWidth;\n\t\t\t\tconst lightboxImgWidth =\n\t\t\t\t\timgMaxWidth * ( containerWidth / containerMaxWidth );\n\t\t\t\tconst lightboxImgHeight =\n\t\t\t\t\timgMaxHeight * ( containerHeight / containerMaxHeight );\n\n\t\t\t\t// As of this writing, using the calculations above will render the\n\t\t\t\t// lightbox with a small, erroneous whitespace on the left side of the\n\t\t\t\t// image in iOS Safari, perhaps due to an inconsistency in how browsers\n\t\t\t\t// handle absolute positioning and CSS transformation. In any case,\n\t\t\t\t// adding 1 pixel to the container width and height solves the problem,\n\t\t\t\t// though this can be removed if the issue is fixed in the future.\n\t\t\t\tstate.overlayStyles = `\n\t\t\t\t\t--wp--lightbox-initial-top-position: ${ screenPosY }px;\n\t\t\t\t\t--wp--lightbox-initial-left-position: ${ screenPosX }px;\n\t\t\t\t\t--wp--lightbox-container-width: ${ containerWidth + 1 }px;\n\t\t\t\t\t--wp--lightbox-container-height: ${ containerHeight + 1 }px;\n\t\t\t\t\t--wp--lightbox-image-width: ${ lightboxImgWidth }px;\n\t\t\t\t\t--wp--lightbox-image-height: ${ lightboxImgHeight }px;\n\t\t\t\t\t--wp--lightbox-scale: ${ containerScale };\n\t\t\t\t\t--wp--lightbox-scrollbar-width: ${\n\t\t\t\t\t\twindow.innerWidth - document.documentElement.clientWidth\n\t\t\t\t\t}px;\n\t\t\t\t`;\n\t\t\t},\n\t\t\tsetButtonStyles() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tconst { ref } = getElement();\n\n\t\t\t\tstate.metadata[ imageId ].imageRef = ref;\n\t\t\t\tstate.metadata[ imageId ].currentSrc = ref.currentSrc;\n\n\t\t\t\tconst {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth,\n\t\t\t\t\toffsetHeight,\n\t\t\t\t} = ref;\n\n\t\t\t\t// If the image isn't loaded yet, it can't calculate where the button\n\t\t\t\t// should be.\n\t\t\t\tif ( naturalWidth === 0 || naturalHeight === 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst figure = ref.parentElement;\n\t\t\t\tconst figureWidth = ref.parentElement.clientWidth;\n\n\t\t\t\t// It needs special handling for the height because a caption will cause\n\t\t\t\t// the figure to be taller than the image, which means it needs to\n\t\t\t\t// account for that when calculating the placement of the button in the\n\t\t\t\t// top right corner of the image.\n\t\t\t\tlet figureHeight = ref.parentElement.clientHeight;\n\t\t\t\tconst caption = figure.querySelector( 'figcaption' );\n\t\t\t\tif ( caption ) {\n\t\t\t\t\tconst captionComputedStyle =\n\t\t\t\t\t\twindow.getComputedStyle( caption );\n\t\t\t\t\tif (\n\t\t\t\t\t\t! [ 'absolute', 'fixed' ].includes(\n\t\t\t\t\t\t\tcaptionComputedStyle.position\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfigureHeight =\n\t\t\t\t\t\t\tfigureHeight -\n\t\t\t\t\t\t\tcaption.offsetHeight -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginTop ) -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginBottom );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst buttonOffsetTop = figureHeight - offsetHeight;\n\t\t\t\tconst buttonOffsetRight = figureWidth - offsetWidth;\n\n\t\t\t\tlet imageButtonTop = buttonOffsetTop + 16;\n\t\t\t\tlet imageButtonRight = buttonOffsetRight + 16;\n\n\t\t\t\t// In the case of an image with object-fit: contain, the size of the\n\t\t\t\t// <img> element can be larger than the image itself, so it needs to\n\t\t\t\t// calculate where to place the button.\n\t\t\t\tif ( state.metadata[ imageId ].scaleAttr === 'contain' ) {\n\t\t\t\t\t// Natural ratio of the image.\n\t\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t\t// Offset ratio of the image.\n\t\t\t\t\tconst offsetRatio = offsetWidth / offsetHeight;\n\n\t\t\t\t\tif ( naturalRatio >= offsetRatio ) {\n\t\t\t\t\t\t// If it reaches the width first, it keeps the width and compute the\n\t\t\t\t\t\t// height.\n\t\t\t\t\t\tconst referenceHeight = offsetWidth / naturalRatio;\n\t\t\t\t\t\timageButtonTop =\n\t\t\t\t\t\t\t( offsetHeight - referenceHeight ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetTop +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t\timageButtonRight = buttonOffsetRight + 16;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If it reaches the height first, it keeps the height and compute\n\t\t\t\t\t\t// the width.\n\t\t\t\t\t\tconst referenceWidth = offsetHeight * naturalRatio;\n\t\t\t\t\t\timageButtonTop = buttonOffsetTop + 16;\n\t\t\t\t\t\timageButtonRight =\n\t\t\t\t\t\t\t( offsetWidth - referenceWidth ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetRight +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstate.metadata[ imageId ].imageButtonTop = imageButtonTop;\n\t\t\t\tstate.metadata[ imageId ].imageButtonRight = imageButtonRight;\n\t\t\t},\n\t\t\tsetOverlayFocus() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Moves the focus to the dialog when it opens.\n\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\tref.focus();\n\t\t\t\t}\n\t\t\t},\n\t\t\tinitTriggerButton() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tconst { ref } = getElement();\n\t\t\t\tstate.metadata[ imageId ].buttonRef = ref;\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n"],
5
- "mappings": "AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAQP,IAAI,aAAa;AAQjB,IAAI,gBAAgB;AAEpB,MAAM,EAAE,OAAO,SAAS,UAAU,IAAI;AAAA,EACrC;AAAA,EACA;AAAA,IACC,OAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,IAAI,eAAe;AAClB,eAAO,MAAM,SAAU,MAAM,cAAe;AAAA,MAC7C;AAAA,MACA,IAAI,gBAAgB;AACnB,eAAO,MAAM,mBAAmB;AAAA,MACjC;AAAA,MACA,IAAI,gBAAgB;AACnB,eAAO,MAAM,gBAAgB,WAAW;AAAA,MACzC;AAAA,MACA,IAAI,YAAY;AACf,eAAO,MAAM,gBAAgB,SAAS;AAAA,MACvC;AAAA,MACA,IAAI,cAAc;AACjB,eACC,MAAM,aAAa,eACnB;AAAA,MAEF;AAAA,MACA,IAAI,eAAe;AAClB,eACC,MAAM,iBACN,GAAI,MAAM,aAAa,cAA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,cAAc;AAExC,YAAI,iBAAiB,kBAAkB;AACvC,YAAI,mBAAmB,oBAAoB;AAK3C,YAAK,MAAM,SAAU,OAAQ,EAAE,cAAc,WAAY;AAExD,gBAAM,eAAe,eAAe;AAEpC,gBAAM,cAAc,cAAc;AAElC,cAAK,gBAAgB,aAAc;AAGlC,kBAAM,kBAAkB,cAAc;AACtC,8BACG,eAAe,mBAAoB,IACrC,kBACA;AACD,+BAAmB,oBAAoB;AAAA,UACxC,OAAO;AAGN,kBAAM,iBAAiB,eAAe;AACtC,6BAAiB,kBAAkB;AACnC,gCACG,cAAc,kBAAmB,IACnC,oBACA;AAAA,UACF;AAAA,QACD;AAEA,cAAM,SAAU,OAAQ,EAAE,iBAAiB;AAC3C,cAAM,SAAU,OAAQ,EAAE,mBAAmB;AAAA,MAC9C;AAAA,MACA,kBAAkB;AACjB,YAAK,MAAM,gBAAiB;AAE3B,gBAAM,EAAE,IAAI,IAAI,WAAW;AAC3B,cAAI,MAAM;AAAA,QACX;AAAA,MACD;AAAA,MACA,oBAAoB;AACnB,cAAM,EAAE,QAAQ,IAAI,WAAW;AAC/B,cAAM,EAAE,IAAI,IAAI,WAAW;AAC3B,cAAM,SAAU,OAAQ,EAAE,YAAY;AAAA,MACvC;AAAA,IACD;AAAA,EACD;AAAA,EACA,EAAE,MAAM,KAAK;AACd;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tstore,\n\tgetContext,\n\tgetElement,\n\twithSyncEvent,\n} from '@wordpress/interactivity';\n\n/**\n * Tracks whether user is touching screen; used to differentiate behavior for\n * touch and mouse input.\n *\n * @type {boolean}\n */\nlet isTouching = false;\n\n/**\n * Tracks the last time the screen was touched; used to differentiate behavior\n * for touch and mouse input.\n *\n * @type {number}\n */\nlet lastTouchTime = 0;\n\nconst { state, actions, callbacks } = store(\n\t'core/image',\n\t{\n\t\tstate: {\n\t\t\tcurrentImageId: null,\n\t\t\tget currentImage() {\n\t\t\t\treturn state.metadata[ state.currentImageId ];\n\t\t\t},\n\t\t\tget overlayOpened() {\n\t\t\t\treturn state.currentImageId !== null;\n\t\t\t},\n\t\t\tget roleAttribute() {\n\t\t\t\treturn state.overlayOpened ? 'dialog' : null;\n\t\t\t},\n\t\t\tget ariaModal() {\n\t\t\t\treturn state.overlayOpened ? 'true' : null;\n\t\t\t},\n\t\t\tget enlargedSrc() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.currentImage.uploadedSrc ||\n\t\t\t\t\t'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='\n\t\t\t\t);\n\t\t\t},\n\t\t\tget figureStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.currentImage.figureStyles?.replace(\n\t\t\t\t\t\t/margin[^;]*;?/g,\n\t\t\t\t\t\t''\n\t\t\t\t\t) };`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imgStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.currentImage.imgStyles?.replace(\n\t\t\t\t\t\t/;$/,\n\t\t\t\t\t\t''\n\t\t\t\t\t) }; object-fit:cover;`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imageButtonRight() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ].imageButtonRight;\n\t\t\t},\n\t\t\tget imageButtonTop() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ].imageButtonTop;\n\t\t\t},\n\t\t\tget isContentHidden() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayEnabled && state.currentImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentVisible() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\t! state.overlayEnabled &&\n\t\t\t\t\tstate.currentImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\tactions: {\n\t\t\tshowLightbox() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails out if the image has not loaded yet.\n\t\t\t\tif ( ! state.metadata[ imageId ].imageRef?.complete ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Stores the positions of the scroll to fix it until the overlay is\n\t\t\t\t// closed.\n\t\t\t\tstate.scrollTopReset = document.documentElement.scrollTop;\n\t\t\t\tstate.scrollLeftReset = document.documentElement.scrollLeft;\n\n\t\t\t\t// Sets the current expanded image in the state and enables the overlay.\n\t\t\t\tstate.overlayEnabled = true;\n\t\t\t\tstate.currentImageId = imageId;\n\n\t\t\t\t// Computes the styles of the overlay for the animation.\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t},\n\t\t\thideLightbox() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tstate.overlayEnabled = false;\n\n\t\t\t\t\t// Waits until the close animation has completed before allowing a\n\t\t\t\t\t// user to scroll again. The duration of this animation is defined in\n\t\t\t\t\t// the `styles.scss` file, but in any case we should wait a few\n\t\t\t\t\t// milliseconds longer than the duration, otherwise a user may scroll\n\t\t\t\t\t// too soon and cause the animation to look sloppy.\n\t\t\t\t\tsetTimeout( function () {\n\t\t\t\t\t\t// Delays before changing the focus. Otherwise the focus ring will\n\t\t\t\t\t\t// appear on Firefox before the image has finished animating, which\n\t\t\t\t\t\t// looks broken.\n\t\t\t\t\t\tstate.currentImage.buttonRef.focus( {\n\t\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Resets the current image id to mark the overlay as closed.\n\t\t\t\t\t\tstate.currentImageId = null;\n\t\t\t\t\t}, 450 );\n\t\t\t\t}\n\t\t\t},\n\t\t\thandleKeydown: withSyncEvent( ( event ) => {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Focuses the close button when the user presses the tab key.\n\t\t\t\t\tif ( event.key === 'Tab' ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\t\tref.querySelector( 'button' ).focus();\n\t\t\t\t\t}\n\t\t\t\t\t// Closes the lightbox when the user presses the escape key.\n\t\t\t\t\tif ( event.key === 'Escape' ) {\n\t\t\t\t\t\tactions.hideLightbox();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchMove: withSyncEvent( ( event ) => {\n\t\t\t\t// On mobile devices, prevents triggering the scroll event because\n\t\t\t\t// otherwise the page jumps around when it resets the scroll position.\n\t\t\t\t// This also means that closing the lightbox requires that a user\n\t\t\t\t// perform a simple tap. This may be changed in the future if there is a\n\t\t\t\t// better alternative to override or reset the scroll position during\n\t\t\t\t// swipe actions.\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchStart() {\n\t\t\t\tisTouching = true;\n\t\t\t},\n\t\t\thandleTouchEnd() {\n\t\t\t\t// Waits a few milliseconds before resetting to ensure that pinch to\n\t\t\t\t// zoom works consistently on mobile devices when the lightbox is open.\n\t\t\t\tlastTouchTime = Date.now();\n\t\t\t\tisTouching = false;\n\t\t\t},\n\t\t\thandleScroll() {\n\t\t\t\t// Prevents scrolling behaviors that trigger content shift while the\n\t\t\t\t// lightbox is open. It would be better to accomplish through CSS alone,\n\t\t\t\t// but using overflow: hidden is currently the only way to do so and\n\t\t\t\t// that causes a layout to shift and prevents the zoom animation from\n\t\t\t\t// working in some cases because it's not possible to account for the\n\t\t\t\t// layout shift when doing the animation calculations. Instead, it uses\n\t\t\t\t// JavaScript to prevent and reset the scrolling behavior.\n\t\t\t\tif ( state.overlayOpened ) {\n\t\t\t\t\t// Avoids overriding the scroll behavior on mobile devices because\n\t\t\t\t\t// doing so breaks the pinch to zoom functionality, and users should\n\t\t\t\t\t// be able to zoom in further on the high-res image.\n\t\t\t\t\tif ( ! isTouching && Date.now() - lastTouchTime > 450 ) {\n\t\t\t\t\t\t// It doesn't rely on `event.preventDefault()` to prevent scrolling\n\t\t\t\t\t\t// because the scroll event can't be canceled, so it resets the\n\t\t\t\t\t\t// position instead.\n\t\t\t\t\t\twindow.scrollTo(\n\t\t\t\t\t\t\tstate.scrollLeftReset,\n\t\t\t\t\t\t\tstate.scrollTopReset\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tcallbacks: {\n\t\t\tsetOverlayStyles() {\n\t\t\t\tif ( ! state.overlayEnabled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth: originalWidth,\n\t\t\t\t\toffsetHeight: originalHeight,\n\t\t\t\t} = state.currentImage.imageRef;\n\t\t\t\tlet { x: screenPosX, y: screenPosY } =\n\t\t\t\t\tstate.currentImage.imageRef.getBoundingClientRect();\n\n\t\t\t\t// Natural ratio of the image clicked to open the lightbox.\n\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t// Original ratio of the image clicked to open the lightbox.\n\t\t\t\tlet originalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// If it has object-fit: contain, recalculates the original sizes\n\t\t\t\t// and the screen position without the blank spaces.\n\t\t\t\tif ( state.currentImage.scaleAttr === 'contain' ) {\n\t\t\t\t\tif ( naturalRatio > originalRatio ) {\n\t\t\t\t\t\tconst heightWithoutSpace = originalWidth / naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the top space.\n\t\t\t\t\t\tscreenPosY +=\n\t\t\t\t\t\t\t( originalHeight - heightWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalHeight = heightWithoutSpace;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst widthWithoutSpace = originalHeight * naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the left space.\n\t\t\t\t\t\tscreenPosX += ( originalWidth - widthWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalWidth = widthWithoutSpace;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toriginalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// Typically, it uses the image's full-sized dimensions. If those\n\t\t\t\t// dimensions have not been set (i.e. an external image with only one\n\t\t\t\t// size), the image's dimensions in the lightbox are the same\n\t\t\t\t// as those of the image in the content.\n\t\t\t\tlet imgMaxWidth = parseFloat(\n\t\t\t\t\tstate.currentImage.targetWidth !== 'none'\n\t\t\t\t\t\t? state.currentImage.targetWidth\n\t\t\t\t\t\t: naturalWidth\n\t\t\t\t);\n\t\t\t\tlet imgMaxHeight = parseFloat(\n\t\t\t\t\tstate.currentImage.targetHeight !== 'none'\n\t\t\t\t\t\t? state.currentImage.targetHeight\n\t\t\t\t\t\t: naturalHeight\n\t\t\t\t);\n\n\t\t\t\t// Ratio of the biggest image stored in the database.\n\t\t\t\tlet imgRatio = imgMaxWidth / imgMaxHeight;\n\t\t\t\tlet containerMaxWidth = imgMaxWidth;\n\t\t\t\tlet containerMaxHeight = imgMaxHeight;\n\t\t\t\tlet containerWidth = imgMaxWidth;\n\t\t\t\tlet containerHeight = imgMaxHeight;\n\n\t\t\t\t// Checks if the target image has a different ratio than the original\n\t\t\t\t// one (thumbnail). Recalculates the width and height.\n\t\t\t\tif ( naturalRatio.toFixed( 2 ) !== imgRatio.toFixed( 2 ) ) {\n\t\t\t\t\tif ( naturalRatio > imgRatio ) {\n\t\t\t\t\t\t// If the width is reached before the height, it keeps the maxWidth\n\t\t\t\t\t\t// and recalculates the height unless the difference between the\n\t\t\t\t\t\t// maxHeight and the reducedHeight is higher than the maxWidth,\n\t\t\t\t\t\t// where it keeps the reducedHeight and recalculate the width.\n\t\t\t\t\t\tconst reducedHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\tif ( imgMaxHeight - reducedHeight > imgMaxWidth ) {\n\t\t\t\t\t\t\timgMaxHeight = reducedHeight;\n\t\t\t\t\t\t\timgMaxWidth = reducedHeight * naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the height is reached before the width, it keeps the maxHeight\n\t\t\t\t\t\t// and recalculate the width unlesss the difference between the\n\t\t\t\t\t\t// maxWidth and the reducedWidth is higher than the maxHeight, where\n\t\t\t\t\t\t// it keeps the reducedWidth and recalculate the height.\n\t\t\t\t\t\tconst reducedWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\tif ( imgMaxWidth - reducedWidth > imgMaxHeight ) {\n\t\t\t\t\t\t\timgMaxWidth = reducedWidth;\n\t\t\t\t\t\t\timgMaxHeight = reducedWidth / naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontainerWidth = imgMaxWidth;\n\t\t\t\t\tcontainerHeight = imgMaxHeight;\n\t\t\t\t\timgRatio = imgMaxWidth / imgMaxHeight;\n\n\t\t\t\t\t// Calculates the max size of the container.\n\t\t\t\t\tif ( originalRatio > imgRatio ) {\n\t\t\t\t\t\tcontainerMaxWidth = imgMaxWidth;\n\t\t\t\t\t\tcontainerMaxHeight = containerMaxWidth / originalRatio;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontainerMaxHeight = imgMaxHeight;\n\t\t\t\t\t\tcontainerMaxWidth = containerMaxHeight * originalRatio;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the image has been pixelated on purpose, it keeps that size.\n\t\t\t\tif (\n\t\t\t\t\toriginalWidth > containerWidth ||\n\t\t\t\t\toriginalHeight > containerHeight\n\t\t\t\t) {\n\t\t\t\t\tcontainerWidth = originalWidth;\n\t\t\t\t\tcontainerHeight = originalHeight;\n\t\t\t\t}\n\n\t\t\t\t// Calculates the final lightbox image size and the scale factor.\n\t\t\t\t// MaxWidth is either the window container (accounting for padding) or\n\t\t\t\t// the image resolution.\n\t\t\t\tlet horizontalPadding = 0;\n\t\t\t\tif ( window.innerWidth > 480 ) {\n\t\t\t\t\thorizontalPadding = 80;\n\t\t\t\t} else if ( window.innerWidth > 1920 ) {\n\t\t\t\t\thorizontalPadding = 160;\n\t\t\t\t}\n\t\t\t\tconst verticalPadding = 80;\n\n\t\t\t\tconst targetMaxWidth = Math.min(\n\t\t\t\t\twindow.innerWidth - horizontalPadding,\n\t\t\t\t\tcontainerWidth\n\t\t\t\t);\n\t\t\t\tconst targetMaxHeight = Math.min(\n\t\t\t\t\twindow.innerHeight - verticalPadding,\n\t\t\t\t\tcontainerHeight\n\t\t\t\t);\n\t\t\t\tconst targetContainerRatio = targetMaxWidth / targetMaxHeight;\n\n\t\t\t\tif ( originalRatio > targetContainerRatio ) {\n\t\t\t\t\t// If targetMaxWidth is reached before targetMaxHeight.\n\t\t\t\t\tcontainerWidth = targetMaxWidth;\n\t\t\t\t\tcontainerHeight = containerWidth / originalRatio;\n\t\t\t\t} else {\n\t\t\t\t\t// If targetMaxHeight is reached before targetMaxWidth.\n\t\t\t\t\tcontainerHeight = targetMaxHeight;\n\t\t\t\t\tcontainerWidth = containerHeight * originalRatio;\n\t\t\t\t}\n\n\t\t\t\tconst containerScale = originalWidth / containerWidth;\n\t\t\t\tconst lightboxImgWidth =\n\t\t\t\t\timgMaxWidth * ( containerWidth / containerMaxWidth );\n\t\t\t\tconst lightboxImgHeight =\n\t\t\t\t\timgMaxHeight * ( containerHeight / containerMaxHeight );\n\n\t\t\t\t// As of this writing, using the calculations above will render the\n\t\t\t\t// lightbox with a small, erroneous whitespace on the left side of the\n\t\t\t\t// image in iOS Safari, perhaps due to an inconsistency in how browsers\n\t\t\t\t// handle absolute positioning and CSS transformation. In any case,\n\t\t\t\t// adding 1 pixel to the container width and height solves the problem,\n\t\t\t\t// though this can be removed if the issue is fixed in the future.\n\t\t\t\tstate.overlayStyles = `\n\t\t\t\t\t--wp--lightbox-initial-top-position: ${ screenPosY }px;\n\t\t\t\t\t--wp--lightbox-initial-left-position: ${ screenPosX }px;\n\t\t\t\t\t--wp--lightbox-container-width: ${ containerWidth + 1 }px;\n\t\t\t\t\t--wp--lightbox-container-height: ${ containerHeight + 1 }px;\n\t\t\t\t\t--wp--lightbox-image-width: ${ lightboxImgWidth }px;\n\t\t\t\t\t--wp--lightbox-image-height: ${ lightboxImgHeight }px;\n\t\t\t\t\t--wp--lightbox-scale: ${ containerScale };\n\t\t\t\t\t--wp--lightbox-scrollbar-width: ${\n\t\t\t\t\t\twindow.innerWidth - document.documentElement.clientWidth\n\t\t\t\t\t}px;\n\t\t\t\t`;\n\t\t\t},\n\t\t\tsetButtonStyles() {\n\t\t\t\tconst { ref } = getElement();\n\n\t\t\t\t// This guard prevents errors in images with the `srcset`\n\t\t\t\t// attribute, which can dispatch `load` events even after DOM\n\t\t\t\t// removal. Preact doesn't automatically clean up `load` event\n\t\t\t\t// listeners on unmounted `img` elements (see\n\t\t\t\t// https://github.com/preactjs/preact/issues/3141).\n\t\t\t\tif ( ! ref ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\tstate.metadata[ imageId ].imageRef = ref;\n\t\t\t\tstate.metadata[ imageId ].currentSrc = ref.currentSrc;\n\n\t\t\t\tconst {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth,\n\t\t\t\t\toffsetHeight,\n\t\t\t\t} = ref;\n\n\t\t\t\t// If the image isn't loaded yet, it can't calculate where the button\n\t\t\t\t// should be.\n\t\t\t\tif ( naturalWidth === 0 || naturalHeight === 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst figure = ref.parentElement;\n\t\t\t\tconst figureWidth = ref.parentElement.clientWidth;\n\n\t\t\t\t// It needs special handling for the height because a caption will cause\n\t\t\t\t// the figure to be taller than the image, which means it needs to\n\t\t\t\t// account for that when calculating the placement of the button in the\n\t\t\t\t// top right corner of the image.\n\t\t\t\tlet figureHeight = ref.parentElement.clientHeight;\n\t\t\t\tconst caption = figure.querySelector( 'figcaption' );\n\t\t\t\tif ( caption ) {\n\t\t\t\t\tconst captionComputedStyle =\n\t\t\t\t\t\twindow.getComputedStyle( caption );\n\t\t\t\t\tif (\n\t\t\t\t\t\t! [ 'absolute', 'fixed' ].includes(\n\t\t\t\t\t\t\tcaptionComputedStyle.position\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfigureHeight =\n\t\t\t\t\t\t\tfigureHeight -\n\t\t\t\t\t\t\tcaption.offsetHeight -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginTop ) -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginBottom );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst buttonOffsetTop = figureHeight - offsetHeight;\n\t\t\t\tconst buttonOffsetRight = figureWidth - offsetWidth;\n\n\t\t\t\tlet imageButtonTop = buttonOffsetTop + 16;\n\t\t\t\tlet imageButtonRight = buttonOffsetRight + 16;\n\n\t\t\t\t// In the case of an image with object-fit: contain, the size of the\n\t\t\t\t// <img> element can be larger than the image itself, so it needs to\n\t\t\t\t// calculate where to place the button.\n\t\t\t\tif ( state.metadata[ imageId ].scaleAttr === 'contain' ) {\n\t\t\t\t\t// Natural ratio of the image.\n\t\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t\t// Offset ratio of the image.\n\t\t\t\t\tconst offsetRatio = offsetWidth / offsetHeight;\n\n\t\t\t\t\tif ( naturalRatio >= offsetRatio ) {\n\t\t\t\t\t\t// If it reaches the width first, it keeps the width and compute the\n\t\t\t\t\t\t// height.\n\t\t\t\t\t\tconst referenceHeight = offsetWidth / naturalRatio;\n\t\t\t\t\t\timageButtonTop =\n\t\t\t\t\t\t\t( offsetHeight - referenceHeight ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetTop +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t\timageButtonRight = buttonOffsetRight + 16;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If it reaches the height first, it keeps the height and compute\n\t\t\t\t\t\t// the width.\n\t\t\t\t\t\tconst referenceWidth = offsetHeight * naturalRatio;\n\t\t\t\t\t\timageButtonTop = buttonOffsetTop + 16;\n\t\t\t\t\t\timageButtonRight =\n\t\t\t\t\t\t\t( offsetWidth - referenceWidth ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetRight +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstate.metadata[ imageId ].imageButtonTop = imageButtonTop;\n\t\t\t\tstate.metadata[ imageId ].imageButtonRight = imageButtonRight;\n\t\t\t},\n\t\t\tsetOverlayFocus() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Moves the focus to the dialog when it opens.\n\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\tref.focus();\n\t\t\t\t}\n\t\t\t},\n\t\t\tinitTriggerButton() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tconst { ref } = getElement();\n\t\t\t\tstate.metadata[ imageId ].buttonRef = ref;\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n"],
5
+ "mappings": "AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAQP,IAAI,aAAa;AAQjB,IAAI,gBAAgB;AAEpB,MAAM,EAAE,OAAO,SAAS,UAAU,IAAI;AAAA,EACrC;AAAA,EACA;AAAA,IACC,OAAO;AAAA,MACN,gBAAgB;AAAA,MAChB,IAAI,eAAe;AAClB,eAAO,MAAM,SAAU,MAAM,cAAe;AAAA,MAC7C;AAAA,MACA,IAAI,gBAAgB;AACnB,eAAO,MAAM,mBAAmB;AAAA,MACjC;AAAA,MACA,IAAI,gBAA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AAa;AACnD,YAAK,SAAU;AACd,gBAAM,uBACL,OAAO,iBAAkB,OAAQ;AAClC,cACC,CAAE,CAAE,YAAY,OAAQ,EAAE;AAAA,YACzB,qBAAqB;AAAA,UACtB,GACC;AACD,2BACC,eACA,QAAQ,eACR,WAAY,qBAAqB,SAAU,IAC3C,WAAY,qBAAqB,YAAa;AAAA,UAChD;AAAA,QACD;AAEA,cAAM,kBAAkB,eAAe;AACvC,cAAM,oBAAoB,cAAc;AAExC,YAAI,iBAAiB,kBAAkB;AACvC,YAAI,mBAAmB,oBAAoB;AAK3C,YAAK,MAAM,SAAU,OAAQ,EAAE,cAAc,WAAY;AAExD,gBAAM,eAAe,eAAe;AAEpC,gBAAM,cAAc,cAAc;AAElC,cAAK,gBAAgB,aAAc;AAGlC,kBAAM,kBAAkB,cAAc;AACtC,8BACG,eAAe,mBAAoB,IACrC,kBACA;AACD,+BAAmB,oBAAoB;AAAA,UACxC,OAAO;AAGN,kBAAM,iBAAiB,eAAe;AACtC,6BAAiB,kBAAkB;AACnC,gCACG,cAAc,kBAAmB,IACnC,oBACA;AAAA,UACF;AAAA,QACD;AAEA,cAAM,SAAU,OAAQ,EAAE,iBAAiB;AAC3C,cAAM,SAAU,OAAQ,EAAE,mBAAmB;AAAA,MAC9C;AAAA,MACA,kBAAkB;AACjB,YAAK,MAAM,gBAAiB;AAE3B,gBAAM,EAAE,IAAI,IAAI,WAAW;AAC3B,cAAI,MAAM;AAAA,QACX;AAAA,MACD;AAAA,MACA,oBAAoB;AACnB,cAAM,EAAE,QAAQ,IAAI,WAAW;AAC/B,cAAM,EAAE,IAAI,IAAI,WAAW;AAC3B,cAAM,SAAU,OAAQ,EAAE,YAAY;AAAA,MACvC;AAAA,IACD;AAAA,EACD;AAAA,EACA,EAAE,MAAM,KAAK;AACd;",
6
6
  "names": []
7
7
  }
@@ -66,6 +66,7 @@ function MathEdit({ attributes, setAttributes, isSelected }) {
66
66
  label: __("LaTeX math syntax"),
67
67
  hideLabelFromVision: true,
68
68
  value: latex,
69
+ className: "wp-block-math__textarea-control",
69
70
  onChange: (newLatex) => {
70
71
  if (!latexToMathML) {
71
72
  setAttributes({ latex: newLatex });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/math/edit.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tTextareaControl,\n\tPopover,\n\t__experimentalVStack as VStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { Badge } = unlock( componentsPrivateApis );\n\nexport default function MathEdit( { attributes, setAttributes, isSelected } ) {\n\tconst { latex } = attributes;\n\tconst [ blockRef, setBlockRef ] = useState();\n\tconst [ error, setError ] = useState( null );\n\tconst [ latexToMathML, setLatexToMathML ] = useState();\n\tconst initialLatex = useRef( attributes.latex );\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\timport( '@wordpress/latex-to-mathml' ).then( ( module ) => {\n\t\t\tsetLatexToMathML( () => module.default );\n\t\t\tif ( initialLatex.current ) {\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tmathML: module.default( initialLatex.current, {\n\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}, [\n\t\tinitialLatex,\n\t\tsetAttributes,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t] );\n\n\tconst blockProps = useBlockProps( {\n\t\tref: setBlockRef,\n\t\tposition: 'relative',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ attributes.mathML ? (\n\t\t\t\t<math\n\t\t\t\t\t// We can't spread block props on the math element because\n\t\t\t\t\t// it only supports a limited amount of global attributes.\n\t\t\t\t\t// For example, draggable will have no effect.\n\t\t\t\t\tdisplay=\"block\"\n\t\t\t\t\tdangerouslySetInnerHTML={ { __html: attributes.mathML } }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t'\\u200B'\n\t\t\t) }\n\t\t\t{ isSelected && (\n\t\t\t\t<Popover\n\t\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\t\toffset={ 8 }\n\t\t\t\t\tanchor={ blockRef }\n\t\t\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\t\t>\n\t\t\t\t\t<div style={ { padding: '4px', minWidth: '300px' } }>\n\t\t\t\t\t\t<VStack spacing={ 1 }>\n\t\t\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tlabel={ __( 'LaTeX math syntax' ) }\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tvalue={ latex }\n\t\t\t\t\t\t\t\tonChange={ ( newLatex ) => {\n\t\t\t\t\t\t\t\t\tif ( ! latexToMathML ) {\n\t\t\t\t\t\t\t\t\t\tsetAttributes( { latex: newLatex } );\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tlet mathML = '';\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tmathML = latexToMathML( newLatex, {\n\t\t\t\t\t\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\tsetError( null );\n\t\t\t\t\t\t\t\t\t} catch ( err ) {\n\t\t\t\t\t\t\t\t\t\tsetError( err.message );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tmathML,\n\t\t\t\t\t\t\t\t\t\tlatex: newLatex,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'e.g., x^2, \\\\frac{a}{b}' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{ error && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<Badge\n\t\t\t\t\t\t\t\t\t\tintent=\"error\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-math__error\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ error }\n\t\t\t\t\t\t\t\t\t</Badge>\n\t\t\t\t\t\t\t\t\t<style children=\".wp-block-math__error .components-badge__content{white-space:normal}\" />\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</div>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": "AA2DI,SA+CI,UA/CJ,KA+CI,YA/CJ;AAxDJ,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,SAAS;AAAA,OACH;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,eAAe;AAAA,OACT;AACP,SAAS,UAAU,WAAW,cAAc;AAC5C,SAAS,mBAAmB;AAK5B,SAAS,cAAc;AAEvB,MAAM,EAAE,MAAM,IAAI,OAAQ,qBAAsB;AAEjC,SAAR,SAA2B,EAAE,YAAY,eAAe,WAAW,GAAI;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,CAAE,UAAU,WAAY,IAAI,SAAS;AAC3C,QAAM,CAAE,OAAO,QAAS,IAAI,SAAU,IAAK;AAC3C,QAAM,CAAE,eAAe,gBAAiB,IAAI,SAAS;AACrD,QAAM,eAAe,OAAQ,WAAW,KAAM;AAC9C,Q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ACvB;AACA,8BAAe;AAAA,kBACd;AAAA,kBACA,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,cACA,aAAc,GAAI,yBAA0B;AAAA;AAAA,UAC7C;AAAA,UACE,SACD,iCACC;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,QAAO;AAAA,gBACP,WAAU;AAAA,gBAER;AAAA;AAAA,YACH;AAAA,YACA,oBAAC,WAAM,UAAS,wEAAuE;AAAA,aACxF;AAAA,WAEF,GACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tTextareaControl,\n\tPopover,\n\t__experimentalVStack as VStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { Badge } = unlock( componentsPrivateApis );\n\nexport default function MathEdit( { attributes, setAttributes, isSelected } ) {\n\tconst { latex } = attributes;\n\tconst [ blockRef, setBlockRef ] = useState();\n\tconst [ error, setError ] = useState( null );\n\tconst [ latexToMathML, setLatexToMathML ] = useState();\n\tconst initialLatex = useRef( attributes.latex );\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\timport( '@wordpress/latex-to-mathml' ).then( ( module ) => {\n\t\t\tsetLatexToMathML( () => module.default );\n\t\t\tif ( initialLatex.current ) {\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tmathML: module.default( initialLatex.current, {\n\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}, [\n\t\tinitialLatex,\n\t\tsetAttributes,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t] );\n\n\tconst blockProps = useBlockProps( {\n\t\tref: setBlockRef,\n\t\tposition: 'relative',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ attributes.mathML ? (\n\t\t\t\t<math\n\t\t\t\t\t// We can't spread block props on the math element because\n\t\t\t\t\t// it only supports a limited amount of global attributes.\n\t\t\t\t\t// For example, draggable will have no effect.\n\t\t\t\t\tdisplay=\"block\"\n\t\t\t\t\tdangerouslySetInnerHTML={ { __html: attributes.mathML } }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t'\\u200B'\n\t\t\t) }\n\t\t\t{ isSelected && (\n\t\t\t\t<Popover\n\t\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\t\toffset={ 8 }\n\t\t\t\t\tanchor={ blockRef }\n\t\t\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\t\t>\n\t\t\t\t\t<div style={ { padding: '4px', minWidth: '300px' } }>\n\t\t\t\t\t\t<VStack spacing={ 1 }>\n\t\t\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tlabel={ __( 'LaTeX math syntax' ) }\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tvalue={ latex }\n\t\t\t\t\t\t\t\tclassName=\"wp-block-math__textarea-control\"\n\t\t\t\t\t\t\t\tonChange={ ( newLatex ) => {\n\t\t\t\t\t\t\t\t\tif ( ! latexToMathML ) {\n\t\t\t\t\t\t\t\t\t\tsetAttributes( { latex: newLatex } );\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tlet mathML = '';\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tmathML = latexToMathML( newLatex, {\n\t\t\t\t\t\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t\tsetError( null );\n\t\t\t\t\t\t\t\t\t} catch ( err ) {\n\t\t\t\t\t\t\t\t\t\tsetError( err.message );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tmathML,\n\t\t\t\t\t\t\t\t\t\tlatex: newLatex,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tplaceholder={ __( 'e.g., x^2, \\\\frac{a}{b}' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{ error && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<Badge\n\t\t\t\t\t\t\t\t\t\tintent=\"error\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-math__error\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ error }\n\t\t\t\t\t\t\t\t\t</Badge>\n\t\t\t\t\t\t\t\t\t<style children=\".wp-block-math__error .components-badge__content{white-space:normal}\" />\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</div>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": "AA2DI,SAgDI,UAhDJ,KAgDI,YAhDJ;AAxDJ,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA,SAAS;AAAA,OACH;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,EACxB,eAAe;AAAA,OACT;AACP,SAAS,UAAU,WAAW,cAAc;AAC5C,SAAS,mBAAmB;AAK5B,SAAS,cAAc;AAEvB,MAAM,EAAE,MAAM,IAAI,OAAQ,qBAAsB;AAEjC,SAAR,SAA2B,EAAE,YAAY,eAAe,WAAW,GAAI;AAC7E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;AACtB,gCAAe,EAAE,OAAO,SAAS,CAAE;AACnC;AAAA,gBACD;AACA,oBAAI,SAAS;AACb,oBAAI;AACH,2BAAS,cAAe,UAAU;AAAA,oBACjC,aAAa;AAAA,kBACd,CAAE;AACF,2BAAU,IAAK;AAAA,gBAChB,SAAU,KAAM;AACf,2BAAU,IAAI,OAAQ;AAAA,gBACvB;AACA,8BAAe;AAAA,kBACd;AAAA,kBACA,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,cACA,aAAc,GAAI,yBAA0B;AAAA;AAAA,UAC7C;AAAA,UACE,SACD,iCACC;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,QAAO;AAAA,gBACP,WAAU;AAAA,gBAER;AAAA;AAAA,YACH;AAAA,YACA,oBAAC,WAAM,UAAS,wEAAuE;AAAA,aACxF;AAAA,WAEF,GACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,6 @@
1
1
  import { createBlock, parse } from "@wordpress/blocks";
2
2
  import { applyFilters } from "@wordpress/hooks";
3
+ import { buildNavigationLinkEntityBinding } from "../navigation-link/shared/use-entity-binding";
3
4
  function menuItemsToBlocks(menuItems) {
4
5
  if (!menuItems) {
5
6
  return null;
@@ -69,12 +70,13 @@ function menuItemToBlockAttributes({
69
70
  if (object && object === "post_tag") {
70
71
  object = "tag";
71
72
  }
73
+ const inferredKind = menuItemTypeField?.replace("_", "-") || "custom";
72
74
  return {
73
75
  label: menuItemTitleField?.rendered || "",
74
76
  ...object?.length && {
75
77
  type: object
76
78
  },
77
- kind: menuItemTypeField?.replace("_", "-") || "custom",
79
+ kind: inferredKind,
78
80
  url: url || "",
79
81
  ...xfn?.length && xfn.join(" ").trim() && {
80
82
  rel: xfn.join(" ").trim()
@@ -86,8 +88,11 @@ function menuItemToBlockAttributes({
86
88
  ...attr_title?.length && {
87
89
  title: attr_title
88
90
  },
89
- ...object_id && "custom" !== object && {
90
- id: object_id
91
+ ...object_id && (inferredKind === "post-type" || inferredKind === "taxonomy") && {
92
+ id: object_id,
93
+ metadata: {
94
+ bindings: buildNavigationLinkEntityBinding(inferredKind)
95
+ }
91
96
  },
92
97
  /* eslint-enable camelcase */
93
98
  ...description?.length && {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/navigation/menu-items-to-blocks.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock, parse } from '@wordpress/blocks';\nimport { applyFilters } from '@wordpress/hooks';\n\n/**\n * Convert a flat menu item structure to a nested blocks structure.\n *\n * @param {Object[]} menuItems An array of menu items.\n *\n * @return {WPBlock[]} An array of blocks.\n */\nexport default function menuItemsToBlocks( menuItems ) {\n\tif ( ! menuItems ) {\n\t\treturn null;\n\t}\n\n\tconst menuTree = createDataTree( menuItems );\n\tconst blocks = mapMenuItemsToBlocks( menuTree );\n\treturn applyFilters(\n\t\t'blocks.navigation.__unstableMenuItemsToBlocks',\n\t\tblocks,\n\t\tmenuItems\n\t);\n}\n\n/**\n * A recursive function that maps menu item nodes to blocks.\n *\n * @param {WPNavMenuItem[]} menuItems An array of WPNavMenuItem items.\n * @param {number} level An integer representing the nesting level.\n * @return {Object} Object containing innerBlocks and mapping.\n */\nfunction mapMenuItemsToBlocks( menuItems, level = 0 ) {\n\tlet mapping = {};\n\n\t// The menuItem should be in menu_order sort order.\n\tconst sortedItems = [ ...menuItems ].sort(\n\t\t( a, b ) => a.menu_order - b.menu_order\n\t);\n\n\tconst innerBlocks = sortedItems.map( ( menuItem ) => {\n\t\tif ( menuItem.type === 'block' ) {\n\t\t\tconst [ block ] = parse( menuItem.content.raw );\n\n\t\t\tif ( ! block ) {\n\t\t\t\treturn createBlock( 'core/freeform', {\n\t\t\t\t\tcontent: menuItem.content,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn block;\n\t\t}\n\n\t\tconst blockType = menuItem.children?.length\n\t\t\t? 'core/navigation-submenu'\n\t\t\t: 'core/navigation-link';\n\n\t\tconst attributes = menuItemToBlockAttributes(\n\t\t\tmenuItem,\n\t\t\tblockType,\n\t\t\tlevel\n\t\t);\n\n\t\t// If there are children recurse to build those nested blocks.\n\t\tconst {\n\t\t\tinnerBlocks: nestedBlocks = [], // alias to avoid shadowing\n\t\t\tmapping: nestedMapping = {}, // alias to avoid shadowing\n\t\t} = menuItem.children?.length\n\t\t\t? mapMenuItemsToBlocks( menuItem.children, level + 1 )\n\t\t\t: {};\n\n\t\t// Update parent mapping with nested mapping.\n\t\tmapping = {\n\t\t\t...mapping,\n\t\t\t...nestedMapping,\n\t\t};\n\n\t\t// Create block with nested \"innerBlocks\".\n\t\tconst block = createBlock( blockType, attributes, nestedBlocks );\n\n\t\t// Create mapping for menuItem -> block.\n\t\tmapping[ menuItem.id ] = block.clientId;\n\n\t\treturn block;\n\t} );\n\n\treturn {\n\t\tinnerBlocks,\n\t\tmapping,\n\t};\n}\n\n/**\n * A WP nav_menu_item object.\n * For more documentation on the individual fields present on a menu item please see:\n * https://core.trac.wordpress.org/browser/tags/5.7.1/src/wp-includes/nav-menu.php#L789\n *\n * @typedef WPNavMenuItem\n *\n * @property {Object} title stores the raw and rendered versions of the title/label for this menu item.\n * @property {Array} xfn the XFN relationships expressed in the link of this menu item.\n * @property {Array} classes the HTML class attributes for this menu item.\n * @property {string} attr_title the HTML title attribute for this menu item.\n * @property {string} object The type of object originally represented, such as 'category', 'post', or 'attachment'.\n * @property {string} object_id The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.\n * @property {string} description The description of this menu item.\n * @property {string} url The URL to which this menu item points.\n * @property {string} type The family of objects originally represented, such as 'post_type' or 'taxonomy'.\n * @property {string} target The target attribute of the link element for this menu item.\n */\n\n/**\n * Convert block attributes to menu item.\n *\n * @param {WPNavMenuItem} menuItem the menu item to be converted to block attributes.\n * @param {string} blockType The block type.\n * @param {number} level An integer representing the nesting level.\n * @return {Object} the block attributes converted from the WPNavMenuItem item.\n */\nfunction menuItemToBlockAttributes(\n\t{\n\t\ttitle: menuItemTitleField,\n\t\txfn,\n\t\tclasses,\n\t\t// eslint-disable-next-line camelcase\n\t\tattr_title,\n\t\tobject,\n\t\t// eslint-disable-next-line camelcase\n\t\tobject_id,\n\t\tdescription,\n\t\turl,\n\t\ttype: menuItemTypeField,\n\t\ttarget,\n\t},\n\tblockType,\n\tlevel\n) {\n\t// For historical reasons, the `core/navigation-link` variation type is `tag`\n\t// whereas WP Core expects `post_tag` as the `object` type.\n\t// To avoid writing a block migration we perform a conversion here.\n\t// See also inverse equivalent in `blockAttributesToMenuItem`.\n\tif ( object && object === 'post_tag' ) {\n\t\tobject = 'tag';\n\t}\n\n\treturn {\n\t\tlabel: menuItemTitleField?.rendered || '',\n\t\t...( object?.length && {\n\t\t\ttype: object,\n\t\t} ),\n\t\tkind: menuItemTypeField?.replace( '_', '-' ) || 'custom',\n\t\turl: url || '',\n\t\t...( xfn?.length &&\n\t\t\txfn.join( ' ' ).trim() && {\n\t\t\t\trel: xfn.join( ' ' ).trim(),\n\t\t\t} ),\n\t\t...( classes?.length &&\n\t\t\tclasses.join( ' ' ).trim() && {\n\t\t\t\tclassName: classes.join( ' ' ).trim(),\n\t\t\t} ),\n\t\t/* eslint-disable camelcase */\n\t\t...( attr_title?.length && {\n\t\t\ttitle: attr_title,\n\t\t} ),\n\t\t...( object_id &&\n\t\t\t'custom' !== object && {\n\t\t\t\tid: object_id,\n\t\t\t} ),\n\t\t/* eslint-enable camelcase */\n\t\t...( description?.length && {\n\t\t\tdescription,\n\t\t} ),\n\t\t...( target === '_blank' && {\n\t\t\topensInNewTab: true,\n\t\t} ),\n\t\t...( blockType === 'core/navigation-submenu' && {\n\t\t\tisTopLevelItem: level === 0,\n\t\t} ),\n\t\t...( blockType === 'core/navigation-link' && {\n\t\t\tisTopLevelLink: level === 0,\n\t\t} ),\n\t};\n}\n\n/**\n * Creates a nested, hierarchical tree representation from unstructured data that\n * has an inherent relationship defined between individual items.\n *\n * For example, by default, each element in the dataset should have an `id` and\n * `parent` property where the `parent` property indicates a relationship between\n * the current item and another item with a matching `id` properties.\n *\n * This is useful for building linked lists of data from flat data structures.\n *\n * @param {Array} dataset linked data to be rearranged into a hierarchical tree based on relational fields.\n * @param {string} id the property which uniquely identifies each entry within the array.\n * @param {*} relation the property which identifies how the current item is related to other items in the data (if at all).\n * @return {Array} a nested array of parent/child relationships\n */\nfunction createDataTree( dataset, id = 'id', relation = 'parent' ) {\n\tconst hashTable = Object.create( null );\n\tconst dataTree = [];\n\n\tfor ( const data of dataset ) {\n\t\thashTable[ data[ id ] ] = {\n\t\t\t...data,\n\t\t\tchildren: [],\n\t\t};\n\t\tif ( data[ relation ] ) {\n\t\t\thashTable[ data[ relation ] ] = hashTable[ data[ relation ] ] || {};\n\t\t\thashTable[ data[ relation ] ].children =\n\t\t\t\thashTable[ data[ relation ] ].children || [];\n\t\t\thashTable[ data[ relation ] ].children.push(\n\t\t\t\thashTable[ data[ id ] ]\n\t\t\t);\n\t\t} else {\n\t\t\tdataTree.push( hashTable[ data[ id ] ] );\n\t\t}\n\t}\n\n\treturn dataTree;\n}\n"],
5
- "mappings": "AAGA,SAAS,aAAa,aAAa;AACnC,SAAS,oBAAoB;AASd,SAAR,kBAAoC,WAAY;AACtD,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,eAAgB,SAAU;AAC3C,QAAM,SAAS,qBAAsB,QAAS;AAC9C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASA,SAAS,qBAAsB,WAAW,QAAQ,GAAI;AACrD,MAAI,UAAU,CAAC;AAGf,QAAM,cAAc,CAAE,GAAG,SAAU,EAAE;AAAA,IACpC,CAAE,GAAG,MAAO,EAAE,aAAa,EAAE;AAAA,EAC9B;AAEA,QAAM,cAAc,YAAY,IAAK,CAAE,aAAc;AACpD,QAAK,SAAS,SAAS,SAAU;AAChC,YAAM,CAAEA,MAAM,IAAI,MAAO,SAAS,Q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AA,MAC7B,WAAW,QAAQ,KAAM,GAAI,EAAE,KAAK;AAAA,IACrC;AAAA;AAAA,IAED,GAAK,YAAY,UAAU;AAAA,MAC1B,OAAO;AAAA,IACR;AAAA,IACA,GAAK,aACJ,aAAa,UAAU;AAAA,MACtB,IAAI;AAAA,IACL;AAAA;AAAA,IAED,GAAK,aAAa,UAAU;AAAA,MAC3B;AAAA,IACD;AAAA,IACA,GAAK,WAAW,YAAY;AAAA,MAC3B,eAAe;AAAA,IAChB;AAAA,IACA,GAAK,cAAc,6BAA6B;AAAA,MAC/C,gBAAgB,UAAU;AAAA,IAC3B;AAAA,IACA,GAAK,cAAc,0BAA0B;AAAA,MAC5C,gBAAgB,UAAU;AAAA,IAC3B;AAAA,EACD;AACD;AAiBA,SAAS,eAAgB,SAAS,KAAK,MAAM,WAAW,UAAW;AAClE,QAAM,YAAY,uBAAO,OAAQ,IAAK;AACtC,QAAM,WAAW,CAAC;AAElB,aAAY,QAAQ,SAAU;AAC7B,cAAW,KAAM,EAAG,CAAE,IAAI;AAAA,MACzB,GAAG;AAAA,MACH,UAAU,CAAC;AAAA,IACZ;AACA,QAAK,KAAM,QAAS,GAAI;AACvB,gBAAW,KAAM,QAAS,CAAE,IAAI,UAAW,KAAM,QAAS,CAAE,KAAK,CAAC;AAClE,gBAAW,KAAM,QAAS,CAAE,EAAE,WAC7B,UAAW,KAAM,QAAS,CAAE,EAAE,YAAY,CAAC;AAC5C,gBAAW,KAAM,QAAS,CAAE,EAAE,SAAS;AAAA,QACtC,UAAW,KAAM,EAAG,CAAE;AAAA,MACvB;AAAA,IACD,OAAO;AACN,eAAS,KAAM,UAAW,KAAM,EAAG,CAAE,CAAE;AAAA,IACxC;AAAA,EACD;AAEA,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createBlock, parse } from '@wordpress/blocks';\nimport { applyFilters } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { buildNavigationLinkEntityBinding } from '../navigation-link/shared/use-entity-binding';\n\n/**\n * Convert a flat menu item structure to a nested blocks structure.\n *\n * @param {Object[]} menuItems An array of menu items.\n *\n * @return {WPBlock[]} An array of blocks.\n */\nexport default function menuItemsToBlocks( menuItems ) {\n\tif ( ! menuItems ) {\n\t\treturn null;\n\t}\n\n\tconst menuTree = createDataTree( menuItems );\n\tconst blocks = mapMenuItemsToBlocks( menuTree );\n\treturn applyFilters(\n\t\t'blocks.navigation.__unstableMenuItemsToBlocks',\n\t\tblocks,\n\t\tmenuItems\n\t);\n}\n\n/**\n * A recursive function that maps menu item nodes to blocks.\n *\n * @param {WPNavMenuItem[]} menuItems An array of WPNavMenuItem items.\n * @param {number} level An integer representing the nesting level.\n * @return {Object} Object containing innerBlocks and mapping.\n */\nfunction mapMenuItemsToBlocks( menuItems, level = 0 ) {\n\tlet mapping = {};\n\n\t// The menuItem should be in menu_order sort order.\n\tconst sortedItems = [ ...menuItems ].sort(\n\t\t( a, b ) => a.menu_order - b.menu_order\n\t);\n\n\tconst innerBlocks = sortedItems.map( ( menuItem ) => {\n\t\tif ( menuItem.type === 'block' ) {\n\t\t\tconst [ block ] = parse( menuItem.content.raw );\n\n\t\t\tif ( ! block ) {\n\t\t\t\treturn createBlock( 'core/freeform', {\n\t\t\t\t\tcontent: menuItem.content,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn block;\n\t\t}\n\n\t\tconst blockType = menuItem.children?.length\n\t\t\t? 'core/navigation-submenu'\n\t\t\t: 'core/navigation-link';\n\n\t\tconst attributes = menuItemToBlockAttributes(\n\t\t\tmenuItem,\n\t\t\tblockType,\n\t\t\tlevel\n\t\t);\n\n\t\t// If there are children recurse to build those nested blocks.\n\t\tconst {\n\t\t\tinnerBlocks: nestedBlocks = [], // alias to avoid shadowing\n\t\t\tmapping: nestedMapping = {}, // alias to avoid shadowing\n\t\t} = menuItem.children?.length\n\t\t\t? mapMenuItemsToBlocks( menuItem.children, level + 1 )\n\t\t\t: {};\n\n\t\t// Update parent mapping with nested mapping.\n\t\tmapping = {\n\t\t\t...mapping,\n\t\t\t...nestedMapping,\n\t\t};\n\n\t\t// Create block with nested \"innerBlocks\".\n\t\tconst block = createBlock( blockType, attributes, nestedBlocks );\n\n\t\t// Create mapping for menuItem -> block.\n\t\tmapping[ menuItem.id ] = block.clientId;\n\n\t\treturn block;\n\t} );\n\n\treturn {\n\t\tinnerBlocks,\n\t\tmapping,\n\t};\n}\n\n/**\n * A WP nav_menu_item object.\n * For more documentation on the individual fields present on a menu item please see:\n * https://core.trac.wordpress.org/browser/tags/5.7.1/src/wp-includes/nav-menu.php#L789\n *\n * @typedef WPNavMenuItem\n *\n * @property {Object} title stores the raw and rendered versions of the title/label for this menu item.\n * @property {Array} xfn the XFN relationships expressed in the link of this menu item.\n * @property {Array} classes the HTML class attributes for this menu item.\n * @property {string} attr_title the HTML title attribute for this menu item.\n * @property {string} object The type of object originally represented, such as 'category', 'post', or 'attachment'.\n * @property {string} object_id The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.\n * @property {string} description The description of this menu item.\n * @property {string} url The URL to which this menu item points.\n * @property {string} type The family of objects originally represented, such as 'post_type' or 'taxonomy'.\n * @property {string} target The target attribute of the link element for this menu item.\n */\n\n/**\n * Convert block attributes to menu item.\n *\n * @param {WPNavMenuItem} menuItem the menu item to be converted to block attributes.\n * @param {string} blockType The block type.\n * @param {number} level An integer representing the nesting level.\n * @return {Object} the block attributes converted from the WPNavMenuItem item.\n */\nfunction menuItemToBlockAttributes(\n\t{\n\t\ttitle: menuItemTitleField,\n\t\txfn,\n\t\tclasses,\n\t\t// eslint-disable-next-line camelcase\n\t\tattr_title,\n\t\tobject,\n\t\t// eslint-disable-next-line camelcase\n\t\tobject_id,\n\t\tdescription,\n\t\turl,\n\t\ttype: menuItemTypeField,\n\t\ttarget,\n\t},\n\tblockType,\n\tlevel\n) {\n\t// For historical reasons, the `core/navigation-link` variation type is `tag`\n\t// whereas WP Core expects `post_tag` as the `object` type.\n\t// To avoid writing a block migration we perform a conversion here.\n\t// See also inverse equivalent in `blockAttributesToMenuItem`.\n\tif ( object && object === 'post_tag' ) {\n\t\tobject = 'tag';\n\t}\n\n\tconst inferredKind = menuItemTypeField?.replace( '_', '-' ) || 'custom';\n\n\treturn {\n\t\tlabel: menuItemTitleField?.rendered || '',\n\t\t...( object?.length && {\n\t\t\ttype: object,\n\t\t} ),\n\t\tkind: inferredKind,\n\t\turl: url || '',\n\t\t...( xfn?.length &&\n\t\t\txfn.join( ' ' ).trim() && {\n\t\t\t\trel: xfn.join( ' ' ).trim(),\n\t\t\t} ),\n\t\t...( classes?.length &&\n\t\t\tclasses.join( ' ' ).trim() && {\n\t\t\t\tclassName: classes.join( ' ' ).trim(),\n\t\t\t} ),\n\t\t/* eslint-disable camelcase */\n\t\t...( attr_title?.length && {\n\t\t\ttitle: attr_title,\n\t\t} ),\n\t\t...( object_id &&\n\t\t\t( inferredKind === 'post-type' || inferredKind === 'taxonomy' ) && {\n\t\t\t\tid: object_id,\n\t\t\t\tmetadata: {\n\t\t\t\t\tbindings: buildNavigationLinkEntityBinding( inferredKind ),\n\t\t\t\t},\n\t\t\t} ),\n\t\t/* eslint-enable camelcase */\n\t\t...( description?.length && {\n\t\t\tdescription,\n\t\t} ),\n\t\t...( target === '_blank' && {\n\t\t\topensInNewTab: true,\n\t\t} ),\n\t\t...( blockType === 'core/navigation-submenu' && {\n\t\t\tisTopLevelItem: level === 0,\n\t\t} ),\n\t\t...( blockType === 'core/navigation-link' && {\n\t\t\tisTopLevelLink: level === 0,\n\t\t} ),\n\t};\n}\n\n/**\n * Creates a nested, hierarchical tree representation from unstructured data that\n * has an inherent relationship defined between individual items.\n *\n * For example, by default, each element in the dataset should have an `id` and\n * `parent` property where the `parent` property indicates a relationship between\n * the current item and another item with a matching `id` properties.\n *\n * This is useful for building linked lists of data from flat data structures.\n *\n * @param {Array} dataset linked data to be rearranged into a hierarchical tree based on relational fields.\n * @param {string} id the property which uniquely identifies each entry within the array.\n * @param {*} relation the property which identifies how the current item is related to other items in the data (if at all).\n * @return {Array} a nested array of parent/child relationships\n */\nfunction createDataTree( dataset, id = 'id', relation = 'parent' ) {\n\tconst hashTable = Object.create( null );\n\tconst dataTree = [];\n\n\tfor ( const data of dataset ) {\n\t\thashTable[ data[ id ] ] = {\n\t\t\t...data,\n\t\t\tchildren: [],\n\t\t};\n\t\tif ( data[ relation ] ) {\n\t\t\thashTable[ data[ relation ] ] = hashTable[ data[ relation ] ] || {};\n\t\t\thashTable[ data[ relation ] ].children =\n\t\t\t\thashTable[ data[ relation ] ].children || [];\n\t\t\thashTable[ data[ relation ] ].children.push(\n\t\t\t\thashTable[ data[ id ] ]\n\t\t\t);\n\t\t} else {\n\t\t\tdataTree.push( hashTable[ data[ id ] ] );\n\t\t}\n\t}\n\n\treturn dataTree;\n}\n"],
5
+ "mappings": "AAGA,SAAS,aAAa,aAAa;AACnC,SAAS,oBAAoB;AAK7B,SAAS,wCAAwC;AASlC,SAAR,kBAAoC,WAAY;AACtD,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,eAAgB,SAAU;AAC3C,QAAM,SAAS,qBAAsB,QAAS;AAC9C,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASA,SAAS,qBAAsB,WAAW,QAAQ,GAAI;AACrD,MAAI,UAAU,CAAC;AAGf,QAAM,cAAc,CAAE,GAAG,SAAU,EAAE;AAAA,IACpC,CAAE,GAAG,MAAO,EAAE,aAAa,EAAE;AAAA,EAC9B;AAEA,QAAM,cAAc,YAAY,IAAK,CAAE,aAAc;AACpD,QAAK,SAAS,SAAS,SAAU;AAChC,YAAM,CAAEA,MAAM,IAAI,MAAO,SAAS,QAAQ,GAAI;AAE9C,UAAK,CAAEA,QAAQ;AACd,eAAO,YAAa,iBAAiB;AAAA,UACpC,SAAS,SAAS;AAAA,QACnB,CAAE;AAAA,MACH;AAEA,aAAOA;AAAA,IACR;AAEA,UAAM,YAA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K,cACF,iBAAiB,eAAe,iBAAiB,eAAgB;AAAA,MAClE,IAAI;AAAA,MACJ,UAAU;AAAA,QACT,UAAU,iCAAkC,YAAa;AAAA,MAC1D;AAAA,IACD;AAAA;AAAA,IAED,GAAK,aAAa,UAAU;AAAA,MAC3B;AAAA,IACD;AAAA,IACA,GAAK,WAAW,YAAY;AAAA,MAC3B,eAAe;AAAA,IAChB;AAAA,IACA,GAAK,cAAc,6BAA6B;AAAA,MAC/C,gBAAgB,UAAU;AAAA,IAC3B;AAAA,IACA,GAAK,cAAc,0BAA0B;AAAA,MAC5C,gBAAgB,UAAU;AAAA,IAC3B;AAAA,EACD;AACD;AAiBA,SAAS,eAAgB,SAAS,KAAK,MAAM,WAAW,UAAW;AAClE,QAAM,YAAY,uBAAO,OAAQ,IAAK;AACtC,QAAM,WAAW,CAAC;AAElB,aAAY,QAAQ,SAAU;AAC7B,cAAW,KAAM,EAAG,CAAE,IAAI;AAAA,MACzB,GAAG;AAAA,MACH,UAAU,CAAC;AAAA,IACZ;AACA,QAAK,KAAM,QAAS,GAAI;AACvB,gBAAW,KAAM,QAAS,CAAE,IAAI,UAAW,KAAM,QAAS,CAAE,KAAK,CAAC;AAClE,gBAAW,KAAM,QAAS,CAAE,EAAE,WAC7B,UAAW,KAAM,QAAS,CAAE,EAAE,YAAY,CAAC;AAC5C,gBAAW,KAAM,QAAS,CAAE,EAAE,SAAS;AAAA,QACtC,UAAW,KAAM,EAAG,CAAE;AAAA,MACvB;AAAA,IACD,OAAO;AACN,eAAS,KAAM,UAAW,KAAM,EAAG,CAAE,CAAE;AAAA,IACxC;AAAA,EACD;AAEA,SAAO;AACR;",
6
6
  "names": ["block"]
7
7
  }
@@ -102,13 +102,13 @@ const { state, actions } = store(
102
102
  }
103
103
  }
104
104
  }),
105
- handleMenuFocusout(event) {
105
+ handleMenuFocusout: withSyncEvent((event) => {
106
106
  const { modal, type } = getContext();
107
107
  if (event.relatedTarget === null || !modal?.contains(event.relatedTarget) && event.target !== window.document.activeElement && type === "submenu") {
108
108
  actions.closeMenu("click");
109
109
  actions.closeMenu("focus");
110
110
  }
111
- },
111
+ }),
112
112
  openMenu(menuOpenedOn = "click") {
113
113
  const { type } = getContext();
114
114
  state.menuOpenedBy[menuOpenedOn] = true;