@wordpress/block-library 9.33.2-next.36001005c.0 → 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.
- package/build/accordion/block.json +1 -1
- package/build/accordion/edit.js +11 -9
- package/build/accordion/edit.js.map +2 -2
- package/build/accordion-heading/block.json +1 -1
- package/build/accordion-item/block.json +1 -1
- package/build/accordion-panel/block.json +1 -1
- package/build/buttons/transforms.js +1 -0
- package/build/buttons/transforms.js.map +2 -2
- package/build/code/transforms.js +2 -0
- package/build/code/transforms.js.map +2 -2
- package/build/home-link/block.json +2 -1
- package/build/image/view.js +4 -1
- package/build/image/view.js.map +2 -2
- package/build/math/edit.js +1 -0
- package/build/math/edit.js.map +2 -2
- package/build/navigation/edit/menu-inspector-controls.js +1 -1
- package/build/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build/navigation/menu-items-to-blocks.js +8 -3
- package/build/navigation/menu-items-to-blocks.js.map +2 -2
- package/build/navigation/view.js +2 -2
- package/build/navigation/view.js.map +2 -2
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +2 -2
- package/build/navigation-link/shared/controls.js +16 -36
- package/build/navigation-link/shared/controls.js.map +2 -2
- package/build/navigation-link/shared/use-entity-binding.js +1 -1
- package/build/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build/navigation-submenu/edit.js +1 -1
- package/build/navigation-submenu/edit.js.map +2 -2
- package/build/post-date/block.json +1 -1
- package/build/post-date/edit.js +11 -5
- package/build/post-date/edit.js.map +3 -3
- package/build/post-date/variations.js +4 -7
- package/build/post-date/variations.js.map +2 -2
- package/build/post-template/edit.js +13 -1
- package/build/post-template/edit.js.map +2 -2
- package/build/query/index.js +11 -1
- package/build/query/index.js.map +2 -2
- package/build/query/variations.js +16 -11
- package/build/query/variations.js.map +2 -2
- package/build/search/view.js +4 -4
- package/build/search/view.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/index.js +1 -1
- package/build/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build/utils/get-transformed-attributes.js +1 -10
- package/build/utils/get-transformed-attributes.js.map +2 -2
- package/build-module/accordion/block.json +1 -1
- package/build-module/accordion/edit.js +11 -9
- package/build-module/accordion/edit.js.map +2 -2
- package/build-module/accordion-heading/block.json +1 -1
- package/build-module/accordion-item/block.json +1 -1
- package/build-module/accordion-panel/block.json +1 -1
- package/build-module/buttons/transforms.js +1 -0
- package/build-module/buttons/transforms.js.map +2 -2
- package/build-module/code/transforms.js +2 -0
- package/build-module/code/transforms.js.map +2 -2
- package/build-module/home-link/block.json +2 -1
- package/build-module/image/view.js +4 -1
- package/build-module/image/view.js.map +2 -2
- package/build-module/math/edit.js +1 -0
- package/build-module/math/edit.js.map +2 -2
- package/build-module/navigation/edit/menu-inspector-controls.js +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build-module/navigation/menu-items-to-blocks.js +8 -3
- package/build-module/navigation/menu-items-to-blocks.js.map +2 -2
- package/build-module/navigation/view.js +2 -2
- package/build-module/navigation/view.js.map +2 -2
- package/build-module/navigation-link/edit.js +1 -1
- package/build-module/navigation-link/edit.js.map +2 -2
- package/build-module/navigation-link/shared/controls.js +17 -37
- package/build-module/navigation-link/shared/controls.js.map +2 -2
- package/build-module/navigation-link/shared/use-entity-binding.js +1 -1
- package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build-module/navigation-submenu/edit.js +1 -1
- package/build-module/navigation-submenu/edit.js.map +2 -2
- package/build-module/post-date/block.json +1 -1
- package/build-module/post-date/edit.js +11 -5
- package/build-module/post-date/edit.js.map +2 -2
- package/build-module/post-date/variations.js +4 -7
- package/build-module/post-date/variations.js.map +2 -2
- package/build-module/post-template/edit.js +13 -1
- package/build-module/post-template/edit.js.map +2 -2
- package/build-module/query/index.js +11 -1
- package/build-module/query/index.js.map +2 -2
- package/build-module/query/variations.js +16 -11
- package/build-module/query/variations.js.map +2 -2
- package/build-module/search/view.js +4 -4
- package/build-module/search/view.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/index.js +1 -1
- package/build-module/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build-module/utils/get-transformed-attributes.js +1 -10
- package/build-module/utils/get-transformed-attributes.js.map +2 -2
- package/build-style/editor-rtl.css +7 -2
- package/build-style/editor.css +8 -2
- package/build-style/math/editor-rtl.css +49 -0
- package/build-style/math/editor.css +50 -0
- package/build-style/navigation-link/editor-rtl.css +1 -1
- package/build-style/navigation-link/editor.css +1 -1
- package/build-style/video/editor-rtl.css +1 -1
- package/build-style/video/editor.css +1 -1
- package/package.json +37 -37
- package/src/accordion/block.json +1 -1
- package/src/accordion/edit.js +16 -16
- package/src/accordion-heading/block.json +1 -1
- package/src/accordion-item/block.json +1 -1
- package/src/accordion-panel/block.json +1 -1
- package/src/buttons/transforms.js +1 -0
- package/src/code/transforms.js +2 -0
- package/src/editor.scss +1 -0
- package/src/home-link/block.json +2 -1
- package/src/image/index.php +9 -9
- package/src/image/view.js +11 -1
- package/src/math/edit.js +1 -0
- package/src/math/editor.scss +7 -0
- package/src/navigation/edit/menu-inspector-controls.js +1 -1
- package/src/navigation/index.php +7 -7
- package/src/navigation/menu-items-to-blocks.js +12 -2
- package/src/navigation/test/menu-items-to-blocks.js +144 -0
- package/src/navigation/view.js +2 -2
- package/src/navigation-link/edit.js +1 -1
- package/src/navigation-link/editor.scss +1 -1
- package/src/navigation-link/shared/controls.js +18 -58
- package/src/navigation-link/shared/test/controls.js +9 -14
- package/src/navigation-link/shared/use-entity-binding.js +1 -1
- package/src/navigation-submenu/edit.js +1 -1
- package/src/post-date/block.json +1 -1
- package/src/post-date/edit.js +15 -10
- package/src/post-date/variations.js +2 -5
- package/src/post-template/edit.js +13 -1
- package/src/query/index.js +10 -0
- package/src/query/variations.js +17 -11
- package/src/query-pagination-next/index.php +1 -1
- package/src/query-pagination-previous/index.php +1 -1
- package/src/search/index.php +2 -2
- package/src/search/view.js +4 -4
- package/src/term-template/index.php +8 -2
- package/src/terms-query/edit/inspector-controls/index.js +2 -2
- package/src/terms-query/edit/inspector-controls/inherit-control.js +1 -3
- package/src/utils/get-transformed-attributes.js +5 -16
- package/src/video/editor.scss +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "core/accordion",
|
|
5
5
|
"title": "Accordion",
|
|
6
6
|
"category": "design",
|
|
7
|
-
"description": "Displays a
|
|
7
|
+
"description": "Displays a foldable layout that groups content in collapsible sections.",
|
|
8
8
|
"example": {},
|
|
9
9
|
"supports": {
|
|
10
10
|
"anchor": true,
|
package/build/accordion/edit.js
CHANGED
|
@@ -84,15 +84,17 @@ function Edit({
|
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
86
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
87
|
-
isSingleSelected && !isContentOnlyMode && /* @__PURE__ */ (0, import_jsx_runtime.
|
|
88
|
-
import_block_editor.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
isSingleSelected && !isContentOnlyMode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
88
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockControls, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ToolbarGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
|
+
import_block_editor.HeadingLevelDropdown,
|
|
90
|
+
{
|
|
91
|
+
value: headingLevel,
|
|
92
|
+
options: levelOptions,
|
|
93
|
+
onChange: updateHeadingLevel
|
|
94
|
+
}
|
|
95
|
+
) }) }),
|
|
96
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockControls, { group: "other", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ToolbarButton, { onClick: addAccordionItemBlock, children: (0, import_i18n.__)("Add") }) })
|
|
97
|
+
] }),
|
|
96
98
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
97
99
|
import_components.__experimentalToolsPanel,
|
|
98
100
|
{
|
|
@@ -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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwGI;AArGJ,0BAQO;AACP,kBAAmB;AACnB,wBAQO;AACP,kBAAoD;AACpD,oBAA4B;AAK5B,mBAA+C;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,EAC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AAU;AAAA,kBACV,UAAO;AAAA,oBACN;AAAA,kBACD;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA,UACE,YACD;AAAA,YAAC,kBAAAA;AAAA,YAAA;AAAA,cACA,WAAQ,gBAAI,eAAgB;AAAA,cAC5B,kBAAgB;AAAA,cAChB,UAAW,MAAM,iBAAiB;AAAA,cAClC,YAAa,MACZ,cAAe,EAAE,cAAc,QAAQ,CAAE;AAAA,cAG1C;AAAA,gBAAC,kBAAAC;AAAA,gBAAA;AAAA,kBACA,yBAAuB;AAAA,kBACvB,uBAAqB;AAAA,kBACrB,SAAO;AAAA,kBACP,WAAQ,gBAAI,eAAgB;AAAA,kBAC5B,OAAQ;AAAA,kBACR,UAAW,CAAE,UAAW;AACvB,kCAAe,EAAE,cAAc,MAAM,CAAE;AAAA,kBACxC;AAAA,kBAEA;AAAA;AAAA,sBAAC,kBAAAC;AAAA,sBAAA;AAAA,wBACA,WAAQ,gBAAI,MAAO;AAAA,wBACnB,OAAM;AAAA;AAAA,oBACP;AAAA,oBACA;AAAA,sBAAC,kBAAAA;AAAA,sBAAA;AAAA,wBACA,WAAQ,gBAAI,OAAQ;AAAA,wBACpB,OAAM;AAAA;AAAA,oBACP;AAAA;AAAA;AAAA,cACD;AAAA;AAAA,UACD;AAAA;AAAA;AAAA,IAEF,KAzFsB,SA0FvB;AAAA,IACA,4CAAC,SAAM,GAAG,kBAAmB;AAAA,KAC9B;AAEF;",
|
|
6
6
|
"names": ["blockEditorStore", "ToolsPanel", "ToolsPanelItem", "ToggleGroupControl", "ToggleGroupControlOption"]
|
|
7
7
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "core/accordion-heading",
|
|
5
5
|
"title": "Accordion Heading",
|
|
6
6
|
"category": "design",
|
|
7
|
-
"description": "
|
|
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": "
|
|
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": "
|
|
7
|
+
"description": "Contains the hidden or revealed content beneath the heading.",
|
|
8
8
|
"parent": [ "core/accordion-item" ],
|
|
9
9
|
"supports": {
|
|
10
10
|
"html": false,
|
|
@@ -62,6 +62,7 @@ const transforms = {
|
|
|
62
62
|
const link = element.querySelector("a");
|
|
63
63
|
const url = link?.getAttribute("href");
|
|
64
64
|
return (0, import_blocks.createBlock)("core/button", {
|
|
65
|
+
...attributes,
|
|
65
66
|
...(0, import_get_transformed_attributes.getTransformedAttributes)(
|
|
66
67
|
attributes,
|
|
67
68
|
"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;\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;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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAC5B,uBAAyD;AAKzD,wCAAyC;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,YAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ;AAAA,YAAK,CAAE;AAAA;AAAA,kBAEd,2BAAa,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,YAEZ;AAAA,UACC;AAAA,UACA,CAAC;AAAA;AAAA,UAED,QAAQ,IAAK,CAAE,eAAgB;AAC9B,kBAAM,EAAE,QAAQ,IAAI;AACpB,kBAAM,cAAU,iBAAAA,yBAAe,UAAU,OAAQ;AAEjD,kBAAM,OAAO,QAAQ,aAAa;AAElC,kBAAM,OAAO,QAAQ,cAAe,GAAI;AACxC,kBAAM,MAAM,MAAM,aAAc,MAAO;AAEvC,uBAAO,2BAAa,eAAe;AAAA,cAClC,GAAG;AAAA,cACH,OAAG;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,cAAU,iBAAAA;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": ["createElement"]
|
|
7
7
|
}
|
package/build/code/transforms.js
CHANGED
|
@@ -37,6 +37,7 @@ const transforms = {
|
|
|
37
37
|
transform: (attributes) => {
|
|
38
38
|
const { content } = attributes;
|
|
39
39
|
return (0, import_blocks.createBlock)("core/code", {
|
|
40
|
+
...attributes,
|
|
40
41
|
...(0, import_get_transformed_attributes.getTransformedAttributes)(attributes, "core/code"),
|
|
41
42
|
content
|
|
42
43
|
});
|
|
@@ -48,6 +49,7 @@ const transforms = {
|
|
|
48
49
|
transform: (attributes) => {
|
|
49
50
|
const { content: text } = attributes;
|
|
50
51
|
return (0, import_blocks.createBlock)("core/code", {
|
|
52
|
+
...attributes,
|
|
51
53
|
...(0, import_get_transformed_attributes.getTransformedAttributes)(attributes, "core/code"),
|
|
52
54
|
// The HTML is plain text (with plain line breaks), so
|
|
53
55
|
// 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAC5B,uBAAqC;AAKrC,wCAAyC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,WAAW,UAAM,2BAAa,WAAY;AAAA,IAC3C;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,QAAQ,CAAE,gBAAiB;AAAA,MAC3B,WAAW,CAAE,eAAgB;AAC5B,cAAM,EAAE,QAAQ,IAAI;AACpB,mBAAO,2BAAa,aAAa;AAAA,UAChC,OAAG,4DAA0B,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,mBAAO,2BAAa,aAAa;AAAA,UAChC,OAAG,4DAA0B,YAAY,WAAY;AAAA;AAAA;AAAA,UAGrD,aAAS,+BAAc,EAAE,WAAO,yBAAQ,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,mBAAO,2BAAa,kBAAkB;AAAA,UACrC,OAAG,4DAA0B,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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAC5B,uBAAqC;AAKrC,wCAAyC;AAEzC,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,IACL;AAAA,MACC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,WAAW,UAAM,2BAAa,WAAY;AAAA,IAC3C;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,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,11 @@ const { state, actions, callbacks } = (0, import_interactivity.store)(
|
|
|
217
217
|
`;
|
|
218
218
|
},
|
|
219
219
|
setButtonStyles() {
|
|
220
|
-
const { imageId } = (0, import_interactivity.getContext)();
|
|
221
220
|
const { ref } = (0, import_interactivity.getElement)();
|
|
221
|
+
if (!ref) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const { imageId } = (0, import_interactivity.getContext)();
|
|
222
225
|
state.metadata[imageId].imageRef = ref;
|
|
223
226
|
state.metadata[imageId].currentSrc = ref.currentSrc;
|
|
224
227
|
const {
|
package/build/image/view.js.map
CHANGED
|
@@ -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,2BAKO;AAQP,IAAI,aAAa;AAQjB,IAAI,gBAAgB;AAEpB,MAAM,EAAE,OAAO,SAAS,UAAU,QAAI;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,cAAc;AAAA,UACpC;AAAA,UACA;AAAA,QACD,CAAE;AAAA,MAEJ;AAAA,MACA,IAAI,YAAY;AACf,eACC,MAAM,iBACN,GAAI,MAAM,aAAa,WAAW;AAAA,UACjC;AAAA,UACA;AAAA,QACD,CAAE;AAAA,MAEJ;AAAA,MACA,IAAI,mBAAmB;AACtB,cAAM,EAAE,QAAQ,QAAI,iCAAW;AAC/B,eAAO,MAAM,SAAU,OAAQ,EAAE;AAAA,MAClC;AAAA,MACA,IAAI,iBAAiB;AACpB,cAAM,EAAE,QAAQ,QAAI,iCAAW;AAC/B,eAAO,MAAM,SAA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AA,wCAClB,kBAAkB,CAAE;AAAA,mCACzB,gBAAiB;AAAA,oCAChB,iBAAkB;AAAA,6BACzB,cAAe;AAAA,uCAEvC,OAAO,aAAa,SAAS,gBAAgB,WAC9C;AAAA;AAAA,MAEF;AAAA,MACA,kBAAkB;AACjB,cAAM,EAAE,
|
|
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,2BAKO;AAQP,IAAI,aAAa;AAQjB,IAAI,gBAAgB;AAEpB,MAAM,EAAE,OAAO,SAAS,UAAU,QAAI;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,cAAc;AAAA,UACpC;AAAA,UACA;AAAA,QACD,CAAE;AAAA,MAEJ;AAAA,MACA,IAAI,YAAY;AACf,eACC,MAAM,iBACN,GAAI,MAAM,aAAa,WAAW;AAAA,UACjC;AAAA,UACA;AAAA,QACD,CAAE;AAAA,MAEJ;AAAA,MACA,IAAI,mBAAmB;AACtB,cAAM,EAAE,QAAQ,QAAI,iCAAW;AAC/B,eAAO,MAAM,SAAU,OAAQ,EAAE;AAAA,MAClC;AAAA,MACA,IAAI,iBAAiB;AACpB,cAAM,EAAE,QAAQ,QAAI,iCAAW;AAC/B,eAAO,MAAM,SAAU,OAAQ,EAAE;AAAA,MAClC;AAAA,MACA,IAAI,kBA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AAmB,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,QAAI,iCAAW;AAC3B,cAAI,MAAM;AAAA,QACX;AAAA,MACD;AAAA,MACA,oBAAoB;AACnB,cAAM,EAAE,QAAQ,QAAI,iCAAW;AAC/B,cAAM,EAAE,IAAI,QAAI,iCAAW;AAC3B,cAAM,SAAU,OAAQ,EAAE,YAAY;AAAA,MACvC;AAAA,IACD;AAAA,EACD;AAAA,EACA,EAAE,MAAM,KAAK;AACd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/math/edit.js
CHANGED
|
@@ -91,6 +91,7 @@ function MathEdit({ attributes, setAttributes, isSelected }) {
|
|
|
91
91
|
label: (0, import_i18n.__)("LaTeX math syntax"),
|
|
92
92
|
hideLabelFromVision: true,
|
|
93
93
|
value: latex,
|
|
94
|
+
className: "wp-block-math__textarea-control",
|
|
94
95
|
onChange: (newLatex) => {
|
|
95
96
|
if (!latexToMathML) {
|
|
96
97
|
setAttributes({ latex: newLatex });
|
package/build/math/edit.js.map
CHANGED
|
@@ -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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ACR,yBAA0B,EAAE,QAAQ,WAAW,OAAO;AAAA;AAAA,IACvD,IAEA;AAAA,IAEC,cACD;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,QAAS;AAAA,QACT,QAAS;AAAA,QACT,cAAa;AAAA,QAEb,sDAAC,SAAI,OAAQ,EAAE,SAAS,OAAO,UAAU,QAAQ,GAChD,uDAAC,kBAAAC,sBAAA,EAAO,SAAU,GACjB;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,yBAAuB;AAAA,cACvB,uBAAqB;AAAA,cACrB,WAAQ,gBAAI,mBAAoB;AAAA,cAChC,qBAAmB;AAAA,cACnB,OAAQ;AAAA,cACR,UAAW,CAAE,aAAc;AAC1B,oBAAK,CAAE,eAAgB;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,iBAAc,gBAAI,yBAA0B;AAAA;AAAA,UAC7C;AAAA,UACE,SACD,4EACC;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,QAAO;AAAA,gBACP,WAAU;AAAA,gBAER;AAAA;AAAA,YACH;AAAA,YACA,4CAAC,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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DI;AAxDJ,kBAAmB;AACnB,0BAGO;AACP,wBAKO;AACP,qBAA4C;AAC5C,kBAA4B;AAK5B,yBAAuB;AAEvB,MAAM,EAAE,MAAM,QAAI,2BAAQ,kBAAAA,WAAsB;AAEjC,SAAR,SAA2B,EAAE,YAAY,eAAe,WAAW,GAAI;AAC7E,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,CAAE,UAAU,WAAY,QAAI,yBAAS;AAC3C,QAAM,CAAE,OAAO,QAAS,QAAI,yBAAU,IAAK;AAC3C,QAAM,CAAE,eAAe,gBAAiB,QAAI,yBAAS;AACrD,QAAM,mBAAe,uBAAQ,WAAW,KAAM;AAC9C,QAAM,EAAE,wCAAwC,QAC/C,yBAAa,oBAAAC,KAAiB;AAE/B,gCAAW,MAAM;AAChB,WAAQ,4BAA6B,EAAE,KAAM,CAAEC,YAAY;AAC1D,uBAAkB,MAAMA,QAAO,OAAQ;AACvC,UAAK,aAAa,SAAU;AAC3B,gDAAwC;AACxC,sBAAe;AAAA,UACd,QAAQA,QAAO,QAAS,aAAa,SAAS;AAAA,YAC7C,aAAa;AAAA,UACd,CAAE;AAAA,QACH,CAAE;AAAA,MACH;AAAA,IACD,CAAE;AAAA,EACH,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACD,C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",
|
|
6
6
|
"names": ["componentsPrivateApis", "blockEditorStore", "module", "VStack"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation/edit/menu-inspector-controls.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\t__experimentalHStack as HStack,\n\t__experimentalHeading as Heading,\n\tSpinner,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenuSelector from './navigation-menu-selector';\nimport { unlock } from '../../lock-unlock';\nimport DeletedNavigationWarning from './deleted-navigation-warning';\nimport useNavigationMenu from '../use-navigation-menu';\nimport LeafMoreMenu from './leaf-more-menu';\nimport {\n\tLinkUI,\n\tupdateAttributes,\n\tuseEntityBinding,\n} from '../../navigation-link/shared';\n\nconst actionLabel =\n\t/* translators: %s: The name of a menu. */ __( \"Switch to '%s'\" );\nconst BLOCKS_WITH_LINK_UI_SUPPORT = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\nconst { PrivateListView } = unlock( blockEditorPrivateApis );\n\nfunction AdditionalBlockContent( { block, insertedBlock, setInsertedBlock } ) {\n\tconst { updateBlockAttributes, removeBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(\n\t\tinsertedBlock?.name\n\t);\n\tconst blockWasJustInserted = insertedBlock?.clientId === block.clientId;\n\tconst showLinkControls = supportsLinkControls && blockWasJustInserted;\n\n\t// Get binding utilities for the inserted block\n\tconst { createBinding, clearBinding } = useEntityBinding( {\n\t\tclientId: insertedBlock?.clientId,\n\t\tattributes: insertedBlock?.attributes || {},\n\t} );\n\n\tif ( ! showLinkControls ) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Cleanup function for auto-inserted Navigation Link blocks.\n\t *\n\t * Removes the block if it has no URL and clears the inserted block state.\n\t * This ensures consistent cleanup behavior across different contexts.\n\t */\n\tconst cleanupInsertedBlock = () => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// Follows the exact same pattern as Navigation Link block's onClose handler\n\t\t// If there is no URL then remove the auto-inserted block to avoid empty blocks\n\t\tif ( ! insertedBlock?.attributes?.url && insertedBlock?.clientId ) {\n\t\t\t// Remove the block entirely to avoid poor UX\n\t\t\t// This matches the Navigation Link block's behavior\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( null );\n\t};\n\n\tconst setInsertedBlockAttributes =\n\t\t( _insertedBlockClientId ) => ( _updatedAttributes ) => {\n\t\t\tif ( ! _insertedBlockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupdateBlockAttributes( _insertedBlockClientId, _updatedAttributes );\n\t\t};\n\n\t// Wrapper function to clean up original block when a new block is selected\n\tconst handleSetInsertedBlock = ( newBlock ) => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// If we have an existing inserted block and a new block is being set,\n\t\t// remove the original block to avoid duplicates\n\t\tif ( insertedBlock?.clientId && newBlock ) {\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( newBlock );\n\t};\n\n\treturn (\n\t\t<LinkUI\n\t\t\tclientId={ insertedBlock?.clientId }\n\t\t\tlink={ insertedBlock?.attributes }\n\t\t\tonBlockInsert={ handleSetInsertedBlock }\n\t\t\tonClose={ () => {\n\t\t\t\t// Use cleanup function\n\t\t\t\tcleanupInsertedBlock();\n\t\t\t} }\n\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t// updateAttributes determines the final state and returns metadata\n\t\t\t\tconst { isEntityLink, attributes: updatedAttributes } =\n\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\tsetInsertedBlockAttributes( insertedBlock?.clientId ),\n\t\t\t\t\t\tinsertedBlock?.attributes\n\t\t\t\t\t);\n\n\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t} else {\n\t\t\t\t\tclearBinding();\n\t\t\t\t}\n\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst MainContent = ( {\n\tclientId,\n\tcurrentMenuId,\n\tisLoading,\n\tisNavigationMenuMissing,\n\tonCreateNew,\n} ) => {\n\tconst hasChildren = useSelect(\n\t\t( select ) => {\n\t\t\treturn !! select( blockEditorStore ).getBlockCount( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { navigationMenu } = useNavigationMenu( currentMenuId );\n\n\tif ( currentMenuId && isNavigationMenuMissing ) {\n\t\treturn (\n\t\t\t<DeletedNavigationWarning onCreateNew={ onCreateNew } isNotice />\n\t\t);\n\t}\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst description = navigationMenu\n\t\t? sprintf(\n\t\t\t\t/* translators: %s: The name of a menu. */\n\t\t\t\t__( 'Structure for Navigation Menu: %s' ),\n\t\t\t\tnavigationMenu?.title || __( 'Untitled menu' )\n\t\t )\n\t\t: __(\n\t\t\t\t'You have not yet created any menus. Displaying a list of your Pages'\n\t\t );\n\n\treturn (\n\t\t<div className=\"wp-block-navigation__menu-inspector-controls\">\n\t\t\t{ ! hasChildren && (\n\t\t\t\t<p className=\"wp-block-navigation__menu-inspector-controls__empty-message\">\n\t\t\t\t\t{ __( 'This Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<PrivateListView\n\t\t\t\trootClientId={ clientId }\n\t\t\t\tisExpanded\n\t\t\t\tdescription={ description }\n\t\t\t\tshowAppender\n\t\t\t\tblockSettingsMenu={ LeafMoreMenu }\n\t\t\t\tadditionalBlockContent={ AdditionalBlockContent }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nconst MenuInspectorControls = ( props ) => {\n\tconst {\n\t\tcreateNavigationMenuIsSuccess,\n\t\tcreateNavigationMenuIsError,\n\t\tcurrentMenuId = null,\n\t\tonCreateNew,\n\t\tonSelectClassicMenu,\n\t\tonSelectNavigationMenu,\n\t\tisManageMenusButtonDisabled,\n\t\tblockEditingMode,\n\t} = props;\n\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody title={ null }>\n\t\t\t\t<HStack className=\"wp-block-navigation-off-canvas-editor__header\">\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tclassName=\"wp-block-navigation-off-canvas-editor__title\"\n\t\t\t\t\t\tlevel={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Menu' ) }\n\t\t\t\t\t</Heading>\n\t\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t\t<NavigationMenuSelector\n\t\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcreateNavigationMenuIsError={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tactionLabel={ actionLabel }\n\t\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\t\tisManageMenusButtonDisabled\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</HStack>\n\t\t\t\t<MainContent { ...props } />\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default MenuInspectorControls;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGE;AApGF,0BAIO;AACP,wBAKO;AACP,kBAAuC;AACvC,kBAA4B;AAK5B,sCAAmC;AACnC,yBAAuB;AACvB,wCAAqC;AACrC,iCAA8B;AAC9B,4BAAyB;AACzB,oBAIO;AAEP,MAAM;AAAA;AAAA,MACsC,gBAAI,gBAAiB;AAAA;AACjE,MAAM,8BAA8B;AAAA,EACnC;AAAA,EACA;AACD;AACA,MAAM,EAAE,gBAAgB,QAAI,2BAAQ,oBAAAA,WAAuB;AAE3D,SAAS,uBAAwB,EAAE,OAAO,eAAe,iBAAiB,GAAI;AAC7E,QAAM,EAAE,uBAAuB,YAAY,QAC1C,yBAAa,oBAAAC,KAAiB;AAE/B,QAAM,uBAAuB,6BAA6B;AAAA,IACzD,eAAe;AAAA,EAChB;AACA,QAAM,uBAAuB,eAAe,aAAa,MAAM;AAC/D,QAAM,mBAAmB,wBAAwB;AAGjD,QAAM,EAAE,eAAe,aAAa,QAAI,gCAAkB;AAAA,IACzD,UAAU,eAAe;AAAA,IACzB,YAAY,eAAe,cAAc,CAAC;AAAA,EAC3C,CAAE;AAEF,MAAK,CAAE,kBAAmB;AACzB,WAAO;AAAA,EACR;AAQA,QAAM,uBAAuB,MAAM;AAGlC,UAAM,wBAAwB;AAI9B,QAAK,CAAE,eAAe,YAAY,OAAO,eAAe,UAAW;AAGlE,kBAAa,cAAc,UAAU,qBAAsB;AAAA,IAC5D;AACA,qBAAkB,IAAK;AAAA,EACxB;AAEA,QAAM,6BACL,CAAE,2BAA4B,CAAE,uBAAwB;AACvD,QAAK,CAAE,wBAAyB;AAC/B;AAAA,IACD;AACA,0BAAuB,wBAAwB,kBAAmB;AAAA,EACnE;AAGD,QAAM,yBAAyB,CAAE,aAAc;AAG9C,UAAM,wBAAwB;AAI9B,QAAK,eAAe,YAAY,UAAW;AAC1C,kBAAa,cAAc,UAAU,qBAAsB;AAAA,IAC5D;AACA,qBAAkB,QAAS;AAAA,EAC5B;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,UAAW,eAAe;AAAA,MAC1B,MAAO,eAAe;AAAA,MACtB,eAAgB;AAAA,MAChB,SAAU,MAAM;AAEf,6BAAqB;AAAA,MACtB;AAAA,MACA,UAAW,CAAE,iBAAkB;AAE9B,cAAM,EAAE,cAAc,YAAY,kBAAkB,QACnD;AAAA,UACC;AAAA,UACA,2BAA4B,eAAe,QAAS;AAAA,UACpD,eAAe;AAAA,QAChB;AAKD,YAAK,cAAe;AACnB,wBAAe,iBAAkB;AAAA,QAClC,OAAO;AACN,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\t__experimentalHStack as HStack,\n\t__experimentalHeading as Heading,\n\tSpinner,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenuSelector from './navigation-menu-selector';\nimport { unlock } from '../../lock-unlock';\nimport DeletedNavigationWarning from './deleted-navigation-warning';\nimport useNavigationMenu from '../use-navigation-menu';\nimport LeafMoreMenu from './leaf-more-menu';\nimport {\n\tLinkUI,\n\tupdateAttributes,\n\tuseEntityBinding,\n} from '../../navigation-link/shared';\n\nconst actionLabel =\n\t/* translators: %s: The name of a menu. */ __( \"Switch to '%s'\" );\nconst BLOCKS_WITH_LINK_UI_SUPPORT = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\nconst { PrivateListView } = unlock( blockEditorPrivateApis );\n\nfunction AdditionalBlockContent( { block, insertedBlock, setInsertedBlock } ) {\n\tconst { updateBlockAttributes, removeBlock } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(\n\t\tinsertedBlock?.name\n\t);\n\tconst blockWasJustInserted = insertedBlock?.clientId === block.clientId;\n\tconst showLinkControls = supportsLinkControls && blockWasJustInserted;\n\n\t// Get binding utilities for the inserted block\n\tconst { createBinding, clearBinding } = useEntityBinding( {\n\t\tclientId: insertedBlock?.clientId,\n\t\tattributes: insertedBlock?.attributes || {},\n\t} );\n\n\tif ( ! showLinkControls ) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Cleanup function for auto-inserted Navigation Link blocks.\n\t *\n\t * Removes the block if it has no URL and clears the inserted block state.\n\t * This ensures consistent cleanup behavior across different contexts.\n\t */\n\tconst cleanupInsertedBlock = () => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// Follows the exact same pattern as Navigation Link block's onClose handler\n\t\t// If there is no URL then remove the auto-inserted block to avoid empty blocks\n\t\tif ( ! insertedBlock?.attributes?.url && insertedBlock?.clientId ) {\n\t\t\t// Remove the block entirely to avoid poor UX\n\t\t\t// This matches the Navigation Link block's behavior\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( null );\n\t};\n\n\tconst setInsertedBlockAttributes =\n\t\t( _insertedBlockClientId ) => ( _updatedAttributes ) => {\n\t\t\tif ( ! _insertedBlockClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tupdateBlockAttributes( _insertedBlockClientId, _updatedAttributes );\n\t\t};\n\n\t// Wrapper function to clean up original block when a new block is selected\n\tconst handleSetInsertedBlock = ( newBlock ) => {\n\t\t// Prevent automatic block selection when removing blocks in list view context\n\t\t// This avoids focus stealing that would close the list view and switch to canvas\n\t\tconst shouldAutoSelectBlock = false;\n\n\t\t// If we have an existing inserted block and a new block is being set,\n\t\t// remove the original block to avoid duplicates\n\t\tif ( insertedBlock?.clientId && newBlock ) {\n\t\t\tremoveBlock( insertedBlock.clientId, shouldAutoSelectBlock );\n\t\t}\n\t\tsetInsertedBlock( newBlock );\n\t};\n\n\treturn (\n\t\t<LinkUI\n\t\t\tclientId={ insertedBlock?.clientId }\n\t\t\tlink={ insertedBlock?.attributes }\n\t\t\tonBlockInsert={ handleSetInsertedBlock }\n\t\t\tonClose={ () => {\n\t\t\t\t// Use cleanup function\n\t\t\t\tcleanupInsertedBlock();\n\t\t\t} }\n\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t// updateAttributes determines the final state and returns metadata\n\t\t\t\tconst { isEntityLink, attributes: updatedAttributes } =\n\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\tsetInsertedBlockAttributes( insertedBlock?.clientId ),\n\t\t\t\t\t\tinsertedBlock?.attributes\n\t\t\t\t\t);\n\n\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t} else {\n\t\t\t\t\tclearBinding( updatedAttributes );\n\t\t\t\t}\n\n\t\t\t\tsetInsertedBlock( null );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nconst MainContent = ( {\n\tclientId,\n\tcurrentMenuId,\n\tisLoading,\n\tisNavigationMenuMissing,\n\tonCreateNew,\n} ) => {\n\tconst hasChildren = useSelect(\n\t\t( select ) => {\n\t\t\treturn !! select( blockEditorStore ).getBlockCount( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { navigationMenu } = useNavigationMenu( currentMenuId );\n\n\tif ( currentMenuId && isNavigationMenuMissing ) {\n\t\treturn (\n\t\t\t<DeletedNavigationWarning onCreateNew={ onCreateNew } isNotice />\n\t\t);\n\t}\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\tconst description = navigationMenu\n\t\t? sprintf(\n\t\t\t\t/* translators: %s: The name of a menu. */\n\t\t\t\t__( 'Structure for Navigation Menu: %s' ),\n\t\t\t\tnavigationMenu?.title || __( 'Untitled menu' )\n\t\t )\n\t\t: __(\n\t\t\t\t'You have not yet created any menus. Displaying a list of your Pages'\n\t\t );\n\n\treturn (\n\t\t<div className=\"wp-block-navigation__menu-inspector-controls\">\n\t\t\t{ ! hasChildren && (\n\t\t\t\t<p className=\"wp-block-navigation__menu-inspector-controls__empty-message\">\n\t\t\t\t\t{ __( 'This Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<PrivateListView\n\t\t\t\trootClientId={ clientId }\n\t\t\t\tisExpanded\n\t\t\t\tdescription={ description }\n\t\t\t\tshowAppender\n\t\t\t\tblockSettingsMenu={ LeafMoreMenu }\n\t\t\t\tadditionalBlockContent={ AdditionalBlockContent }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nconst MenuInspectorControls = ( props ) => {\n\tconst {\n\t\tcreateNavigationMenuIsSuccess,\n\t\tcreateNavigationMenuIsError,\n\t\tcurrentMenuId = null,\n\t\tonCreateNew,\n\t\tonSelectClassicMenu,\n\t\tonSelectNavigationMenu,\n\t\tisManageMenusButtonDisabled,\n\t\tblockEditingMode,\n\t} = props;\n\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody title={ null }>\n\t\t\t\t<HStack className=\"wp-block-navigation-off-canvas-editor__header\">\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tclassName=\"wp-block-navigation-off-canvas-editor__title\"\n\t\t\t\t\t\tlevel={ 2 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Menu' ) }\n\t\t\t\t\t</Heading>\n\t\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t\t<NavigationMenuSelector\n\t\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsSuccess\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcreateNavigationMenuIsError={\n\t\t\t\t\t\t\t\tcreateNavigationMenuIsError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tactionLabel={ actionLabel }\n\t\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\t\tisManageMenusButtonDisabled\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</HStack>\n\t\t\t\t<MainContent { ...props } />\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default MenuInspectorControls;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGE;AApGF,0BAIO;AACP,wBAKO;AACP,kBAAuC;AACvC,kBAA4B;AAK5B,sCAAmC;AACnC,yBAAuB;AACvB,wCAAqC;AACrC,iCAA8B;AAC9B,4BAAyB;AACzB,oBAIO;AAEP,MAAM;AAAA;AAAA,MACsC,gBAAI,gBAAiB;AAAA;AACjE,MAAM,8BAA8B;AAAA,EACnC;AAAA,EACA;AACD;AACA,MAAM,EAAE,gBAAgB,QAAI,2BAAQ,oBAAAA,WAAuB;AAE3D,SAAS,uB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iDACjB;AAAA;AAAA,QAAC,kBAAAC;AAAA,QAAA;AAAA,UACA,WAAU;AAAA,UACV,OAAQ;AAAA,UAEN,8BAAI,MAAO;AAAA;AAAA,MACd;AAAA,MACE,qBAAqB,aACtB;AAAA,QAAC,gCAAAC;AAAA,QAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAGA;AAAA,UAGA;AAAA,UACA;AAAA;AAAA,MAGD;AAAA,OAEF;AAAA,IACA,4CAAC,eAAc,GAAG,OAAQ;AAAA,KAC3B,GACD;AAEF;AAEA,IAAO,kCAAQ;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "blockEditorStore", "useNavigationMenu", "DeletedNavigationWarning", "LeafMoreMenu", "HStack", "Heading", "NavigationMenuSelector"]
|
|
7
7
|
}
|
|
@@ -23,6 +23,7 @@ __export(menu_items_to_blocks_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(menu_items_to_blocks_exports);
|
|
24
24
|
var import_blocks = require("@wordpress/blocks");
|
|
25
25
|
var import_hooks = require("@wordpress/hooks");
|
|
26
|
+
var import_use_entity_binding = require("../navigation-link/shared/use-entity-binding");
|
|
26
27
|
function menuItemsToBlocks(menuItems) {
|
|
27
28
|
if (!menuItems) {
|
|
28
29
|
return null;
|
|
@@ -92,12 +93,13 @@ function menuItemToBlockAttributes({
|
|
|
92
93
|
if (object && object === "post_tag") {
|
|
93
94
|
object = "tag";
|
|
94
95
|
}
|
|
96
|
+
const inferredKind = menuItemTypeField?.replace("_", "-") || "custom";
|
|
95
97
|
return {
|
|
96
98
|
label: menuItemTitleField?.rendered || "",
|
|
97
99
|
...object?.length && {
|
|
98
100
|
type: object
|
|
99
101
|
},
|
|
100
|
-
kind:
|
|
102
|
+
kind: inferredKind,
|
|
101
103
|
url: url || "",
|
|
102
104
|
...xfn?.length && xfn.join(" ").trim() && {
|
|
103
105
|
rel: xfn.join(" ").trim()
|
|
@@ -109,8 +111,11 @@ function menuItemToBlockAttributes({
|
|
|
109
111
|
...attr_title?.length && {
|
|
110
112
|
title: attr_title
|
|
111
113
|
},
|
|
112
|
-
...object_id && "
|
|
113
|
-
id: object_id
|
|
114
|
+
...object_id && (inferredKind === "post-type" || inferredKind === "taxonomy") && {
|
|
115
|
+
id: object_id,
|
|
116
|
+
metadata: {
|
|
117
|
+
bindings: (0, import_use_entity_binding.buildNavigationLinkEntityBinding)(inferredKind)
|
|
118
|
+
}
|
|
114
119
|
},
|
|
115
120
|
/* eslint-enable camelcase */
|
|
116
121
|
...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:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmC;AACnC,mBAA6B;
|
|
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmC;AACnC,mBAA6B;AAK7B,gCAAiD;AASlC,SAAR,kBAAoC,WAAY;AACtD,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAEA,QAAM,WAAW,eAAgB,SAAU;AAC3C,QAAM,SAAS,qBAAsB,QAAS;AAC9C,aAAO;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,QAAI,qBAAO,SAAS,QAAQ,GAAI;AAE9C,UAAK,CAAEA,QAAQ;AACd,mBAAO,2BAAa,iBAAiB;AAAA,UACpC,SAAS,SAAS;AAAA,QACnB,CAAE;AAAA,MACH;AAEA,aAAOA;AAAA,IACR;AAEA,UAAM,YAAY,SAAS,UAAU,SAClC,4BACA;AAEH,UAAM,aAAa;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAGA,UAAM;AAAA,MACL,aAAa,eAAe,CAAC;AAAA;AAAA,MAC7B,SAAS,gBAAgB,CAAC;AAAA;AAAA,IAC3B,IAAI,SAAS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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
|
}
|
package/build/navigation/view.js
CHANGED
|
@@ -98,13 +98,13 @@ const { state, actions } = (0, import_interactivity.store)(
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}),
|
|
101
|
-
handleMenuFocusout(event) {
|
|
101
|
+
handleMenuFocusout: (0, import_interactivity.withSyncEvent)((event) => {
|
|
102
102
|
const { modal, type } = (0, import_interactivity.getContext)();
|
|
103
103
|
if (event.relatedTarget === null || !modal?.contains(event.relatedTarget) && event.target !== window.document.activeElement && type === "submenu") {
|
|
104
104
|
actions.closeMenu("click");
|
|
105
105
|
actions.closeMenu("focus");
|
|
106
106
|
}
|
|
107
|
-
},
|
|
107
|
+
}),
|
|
108
108
|
openMenu(menuOpenedOn = "click") {
|
|
109
109
|
const { type } = (0, import_interactivity.getContext)();
|
|
110
110
|
state.menuOpenedBy[menuOpenedOn] = true;
|