UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 5.13 kB
{ "version": 3, "sources": ["../../../src/components/url-popover/index.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef, useState } from '@wordpress/element';\nimport {\n\tButton,\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { chevronDown } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport LinkViewer from './link-viewer';\nimport LinkEditor from './link-editor';\nimport { unlock } from '../../lock-unlock';\n\nconst { __experimentalPopoverLegacyPositionToPlacement } = unlock(\n\tcomponentsPrivateApis\n);\n\nconst DEFAULT_PLACEMENT = 'bottom';\n\nconst URLPopover = forwardRef(\n\t(\n\t\t{\n\t\t\tadditionalControls,\n\t\t\tchildren,\n\t\t\trenderSettings,\n\t\t\t// The DEFAULT_PLACEMENT value is assigned inside the function's body\n\t\t\tplacement,\n\t\t\tfocusOnMount = 'firstElement',\n\t\t\t// Deprecated\n\t\t\tposition,\n\t\t\t// Rest\n\t\t\t...popoverProps\n\t\t},\n\t\tref\n\t) => {\n\t\tif ( position !== undefined ) {\n\t\t\tdeprecated( '`position` prop in wp.blockEditor.URLPopover', {\n\t\t\t\tsince: '6.2',\n\t\t\t\talternative: '`placement` prop',\n\t\t\t} );\n\t\t}\n\n\t\t// Compute popover's placement:\n\t\t// - give priority to `placement` prop, if defined\n\t\t// - otherwise, compute it from the legacy `position` prop (if defined)\n\t\t// - finally, fallback to the DEFAULT_PLACEMENT.\n\t\tlet computedPlacement;\n\t\tif ( placement !== undefined ) {\n\t\t\tcomputedPlacement = placement;\n\t\t} else if ( position !== undefined ) {\n\t\t\tcomputedPlacement =\n\t\t\t\t__experimentalPopoverLegacyPositionToPlacement( position );\n\t\t}\n\t\tcomputedPlacement = computedPlacement || DEFAULT_PLACEMENT;\n\n\t\tconst [ isSettingsExpanded, setIsSettingsExpanded ] = useState( false );\n\n\t\tconst showSettings = !! renderSettings && isSettingsExpanded;\n\n\t\tconst toggleSettingsVisibility = () => {\n\t\t\tsetIsSettingsExpanded( ! isSettingsExpanded );\n\t\t};\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\tref={ ref }\n\t\t\t\trole=\"dialog\"\n\t\t\t\taria-modal=\"true\"\n\t\t\t\taria-label={ __( 'Edit URL' ) }\n\t\t\t\tclassName=\"block-editor-url-popover\"\n\t\t\t\tfocusOnMount={ focusOnMount }\n\t\t\t\tplacement={ computedPlacement }\n\t\t\t\tshift\n\t\t\t\tvariant=\"toolbar\"\n\t\t\t\t{ ...popoverProps }\n\t\t\t>\n\t\t\t\t<div className=\"block-editor-url-popover__input-container\">\n\t\t\t\t\t<div className=\"block-editor-url-popover__row\">\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t{ !! renderSettings && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"block-editor-url-popover__settings-toggle\"\n\t\t\t\t\t\t\t\ticon={ chevronDown }\n\t\t\t\t\t\t\t\tlabel={ __( 'Link settings' ) }\n\t\t\t\t\t\t\t\tonClick={ toggleSettingsVisibility }\n\t\t\t\t\t\t\t\taria-expanded={ isSettingsExpanded }\n\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t{ showSettings && (\n\t\t\t\t\t<div className=\"block-editor-url-popover__settings\">\n\t\t\t\t\t\t{ renderSettings() }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t\t{ additionalControls && ! showSettings && (\n\t\t\t\t\t<div className=\"block-editor-url-popover__additional-controls\">\n\t\t\t\t\t\t{ additionalControls }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</Popover>\n\t\t);\n\t}\n);\n\nURLPopover.LinkEditor = LinkEditor;\n\nURLPopover.LinkViewer = LinkViewer;\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-popover/README.md\n */\nexport default URLPopover;\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,qBAAqC;AACrC,wBAIO;AACP,mBAA4B;AAC5B,wBAAuB;AAKvB,yBAAuB;AACvB,yBAAuB;AACvB,yBAAuB;AAkElB;AAhEL,IAAM,EAAE,+CAA+C,QAAI;AAAA,EAC1D,kBAAAA;AACD;AAEA,IAAM,oBAAoB;AAE1B,IAAM,iBAAa;AAAA,EAClB,CACC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA;AAAA,IACA,eAAe;AAAA;AAAA,IAEf;AAAA;AAAA,IAEA,GAAG;AAAA,EACJ,GACA,QACI;AACJ,QAAK,aAAa,QAAY;AAC7B,4BAAAC,SAAY,gDAAgD;AAAA,QAC3D,OAAO;AAAA,QACP,aAAa;AAAA,MACd,CAAE;AAAA,IACH;AAMA,QAAI;AACJ,QAAK,cAAc,QAAY;AAC9B,0BAAoB;AAAA,IACrB,WAAY,aAAa,QAAY;AACpC,0BACC,+CAAgD,QAAS;AAAA,IAC3D;AACA,wBAAoB,qBAAqB;AAEzC,UAAM,CAAE,oBAAoB,qBAAsB,QAAI,yBAAU,KAAM;AAEtE,UAAM,eAAe,CAAC,CAAE,kBAAkB;AAE1C,UAAM,2BAA2B,MAAM;AACtC,4BAAuB,CAAE,kBAAmB;AAAA,IAC7C;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,MAAK;AAAA,QACL,cAAW;AAAA,QACX,kBAAa,gBAAI,UAAW;AAAA,QAC5B,WAAU;AAAA,QACV;AAAA,QACA,WAAY;AAAA,QACZ,OAAK;AAAA,QACL,SAAQ;AAAA,QACN,GAAG;AAAA,QAEL;AAAA,sDAAC,SAAI,WAAU,6CACd,uDAAC,SAAI,WAAU,iCACZ;AAAA;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