@wordpress/commands 1.32.0 → 1.32.1-next.b8c8708f3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +2 -2
  2. package/build/components/command-menu.js +261 -246
  3. package/build/components/command-menu.js.map +7 -1
  4. package/build/hooks/use-command-context.js +31 -35
  5. package/build/hooks/use-command-context.js.map +7 -1
  6. package/build/hooks/use-command-loader.js +35 -92
  7. package/build/hooks/use-command-loader.js.map +7 -1
  8. package/build/hooks/use-command.js +53 -90
  9. package/build/hooks/use-command.js.map +7 -1
  10. package/build/index.js +49 -45
  11. package/build/index.js.map +7 -1
  12. package/build/lock-unlock.js +31 -15
  13. package/build/lock-unlock.js.map +7 -1
  14. package/build/private-apis.js +41 -19
  15. package/build/private-apis.js.map +7 -1
  16. package/build/store/actions.js +42 -92
  17. package/build/store/actions.js.map +7 -1
  18. package/build/store/index.js +47 -44
  19. package/build/store/index.js.map +7 -1
  20. package/build/store/private-actions.js +27 -14
  21. package/build/store/private-actions.js.map +7 -1
  22. package/build/store/reducer.js +39 -70
  23. package/build/store/reducer.js.map +7 -1
  24. package/build/store/selectors.js +47 -54
  25. package/build/store/selectors.js.map +7 -1
  26. package/build-module/components/command-menu.js +232 -229
  27. package/build-module/components/command-menu.js.map +7 -1
  28. package/build-module/hooks/use-command-context.js +11 -28
  29. package/build-module/hooks/use-command-context.js.map +7 -1
  30. package/build-module/hooks/use-command-loader.js +17 -87
  31. package/build-module/hooks/use-command-loader.js.map +7 -1
  32. package/build-module/hooks/use-command.js +25 -79
  33. package/build-module/hooks/use-command.js.map +7 -1
  34. package/build-module/index.js +14 -6
  35. package/build-module/index.js.map +7 -1
  36. package/build-module/lock-unlock.js +8 -7
  37. package/build-module/lock-unlock.js.map +7 -1
  38. package/build-module/private-apis.js +7 -11
  39. package/build-module/private-apis.js.map +7 -1
  40. package/build-module/store/actions.js +21 -88
  41. package/build-module/store/actions.js.map +7 -1
  42. package/build-module/store/index.js +12 -32
  43. package/build-module/store/index.js.map +7 -1
  44. package/build-module/store/private-actions.js +6 -10
  45. package/build-module/store/private-actions.js.map +7 -1
  46. package/build-module/store/reducer.js +20 -64
  47. package/build-module/store/reducer.js.map +7 -1
  48. package/build-module/store/selectors.js +24 -49
  49. package/build-module/store/selectors.js.map +7 -1
  50. package/build-style/style-rtl.css +7 -138
  51. package/build-style/style.css +7 -138
  52. package/package.json +18 -10
  53. package/src/components/command-menu.js +4 -1
  54. package/src/components/style.scss +10 -0
  55. package/src/hooks/use-command.js +2 -2
  56. package/src/style.scss +2 -1
@@ -1 +1,7 @@
1
- {"version":3,"names":["_cmdk","require","_clsx","_interopRequireDefault","_data","_element","_i18n","_components","_keyboardShortcuts","_icons","_store","_jsxRuntime","inputLabel","__","CommandMenuLoader","name","search","hook","setLoader","close","_hook","isLoading","commands","useEffect","length","jsx","Fragment","children","map","command","_command$searchLabel","Command","Item","value","searchLabel","label","keywords","onSelect","callback","id","jsxs","__experimentalHStack","alignment","className","clsx","icon","Icon","TextHighlight","text","highlight","CommandMenuLoaderWrapper","currentLoaderRef","useRef","key","setKey","useState","current","prevKey","CommandMenuGroup","isContextual","loaders","useSelect","select","getCommands","getCommandLoaders","commandsStore","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","useCommandState","state","selectedItemId","useMemo","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","CommandMenu","registerShortcut","useDispatch","keyboardShortcutsStore","open","setLoaders","category","description","keyCombination","modifier","character","useShortcut","event","defaultPrevented","preventDefault","bindGlobal","useCallback","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","Modal","overlayClassName","onRequestClose","__experimentalHideHeader","contentLabel","inputIcon","List","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nconst inputLabel = __( 'Search commands and settings' );\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoaderRef = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoaderRef.current !== hook ) {\n\t\t\tcurrentLoaderRef.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoaderRef.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ inputLabel }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t\tcontentLabel={ __( 'Command palette' ) }\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command label={ inputLabel } onKeyDown={ onKeyDown }>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List label={ __( 'Command suggestions' ) }>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAOA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAKA,IAAAO,kBAAA,GAAAP,OAAA;AAIA,IAAAQ,MAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAA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js"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nconst inputLabel = __( 'Search commands and settings' );\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoaderRef = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoaderRef.current !== hook ) {\n\t\t\tcurrentLoaderRef.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoaderRef.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ inputLabel }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t\tcontentLabel={ __( 'Command palette' ) }\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command label={ inputLabel } onKeyDown={ onKeyDown }>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"commands-command-menu__header-search-icon\"\n\t\t\t\t\t\t\ticon={ inputIcon }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List label={ __( 'Command suggestions' ) }>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CE;AA5CF,kBAAyC;AACzC,kBAAiB;AAKjB,kBAAuC;A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A,QACA,6CAAC,oBAAQ,MAAR,EAAa,WAAQ,gBAAI,qBAAsB,GAC7C;AAAA,oBAAU,CAAE,aACb,4CAAC,oBAAQ,OAAR,EACE,8BAAI,mBAAoB,GAC3B;AAAA,UAED;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA,cACA,OAAQ;AAAA,cACR,cAAY;AAAA;AAAA,UACb;AAAA,UACE,UACD;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA,cACA,OAAQ;AAAA;AAAA,UACT;AAAA,WAEF;AAAA,SACD,GACD;AAAA;AAAA,EACD;AAEF;",
6
+ "names": ["HStack", "clsx", "commandsStore", "keyboardShortcutsStore", "inputIcon"]
7
+ }
@@ -1,43 +1,39 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var use_command_context_exports = {};
19
+ __export(use_command_context_exports, {
20
+ default: () => useCommandContext
5
21
  });
6
- exports.default = useCommandContext;
7
- var _element = require("@wordpress/element");
8
- var _data = require("@wordpress/data");
9
- var _store = require("../store");
10
- var _lockUnlock = require("../lock-unlock");
11
- /**
12
- * WordPress dependencies
13
- */
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
-
19
- /**
20
- * Sets the active context of the command palette
21
- *
22
- * @param {string} context Context to set.
23
- */
22
+ module.exports = __toCommonJS(use_command_context_exports);
23
+ var import_element = require("@wordpress/element");
24
+ var import_data = require("@wordpress/data");
25
+ var import_store = require("../store");
26
+ var import_lock_unlock = require("../lock-unlock");
24
27
  function useCommandContext(context) {
25
- const {
26
- getContext
27
- } = (0, _data.useSelect)(_store.store);
28
- const initialContext = (0, _element.useRef)(getContext());
29
- const {
30
- setContext
31
- } = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
32
- (0, _element.useEffect)(() => {
28
+ const { getContext } = (0, import_data.useSelect)(import_store.store);
29
+ const initialContext = (0, import_element.useRef)(getContext());
30
+ const { setContext } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store));
31
+ (0, import_element.useEffect)(() => {
33
32
  setContext(context);
34
33
  }, [context, setContext]);
35
-
36
- // This effects ensures that on unmount, we restore the context
37
- // that was set before the component actually mounts.
38
- (0, _element.useEffect)(() => {
34
+ (0, import_element.useEffect)(() => {
39
35
  const initialContextRef = initialContext.current;
40
36
  return () => setContext(initialContextRef);
41
37
  }, [setContext]);
42
38
  }
43
- //# sourceMappingURL=use-command-context.js.map
39
+ //# sourceMappingURL=use-command-context.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_data","_store","_lockUnlock","useCommandContext","context","getContext","useSelect","commandsStore","initialContext","useRef","setContext","unlock","useDispatch","useEffect","initialContextRef","current"],"sources":["@wordpress/commands/src/hooks/use-command-context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Sets the active context of the command palette\n *\n * @param {string} context Context to set.\n */\nexport default function useCommandContext( context ) {\n\tconst { getContext } = useSelect( commandsStore );\n\tconst initialContext = useRef( getContext() );\n\tconst { setContext } = unlock( useDispatch( commandsStore ) );\n\n\tuseEffect( () => {\n\t\tsetContext( context );\n\t}, [ context, setContext ] );\n\n\t// This effects ensures that on unmount, we restore the context\n\t// that was set before the component actually mounts.\n\tuseEffect( () => {\n\t\tconst initialContextRef = initialContext.current;\n\t\treturn () => setContext( initialContextRef );\n\t}, [ setContext ] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACe,SAASI,iBAAiBA,CAAEC,OAAO,EAAG;EACpD,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAAC,eAAS,EAAEC,YAAc,CAAC;EACjD,MAAMC,cAAc,GAAG,IAAAC,eAAM,EAAEJ,UAAU,CAAC,CAAE,CAAC;EAC7C,MAAM;IAAEK;EAAW,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAC,iBAAW,EAAEL,YAAc,CAAE,CAAC;EAE7D,IAAAM,kBAAS,EAAE,MAAM;IAChBH,UAAU,CAAEN,OAAQ,CAAC;EACtB,CAAC,EAAE,CAAEA,OAAO,EAAEM,UAAU,CAAG,CAAC;;EAE5B;EACA;EACA,IAAAG,kBAAS,EAAE,MAAM;IAChB,MAAMC,iBAAiB,GAAGN,cAAc,CAACO,OAAO;IAChD,OAAO,MAAML,UAAU,CAAEI,iBAAkB,CAAC;EAC7C,CAAC,EAAE,CAAEJ,UAAU,CAAG,CAAC;AACpB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-command-context.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Sets the active context of the command palette\n *\n * @param {string} context Context to set.\n */\nexport default function useCommandContext( context ) {\n\tconst { getContext } = useSelect( commandsStore );\n\tconst initialContext = useRef( getContext() );\n\tconst { setContext } = unlock( useDispatch( commandsStore ) );\n\n\tuseEffect( () => {\n\t\tsetContext( context );\n\t}, [ context, setContext ] );\n\n\t// This effects ensures that on unmount, we restore the context\n\t// that was set before the component actually mounts.\n\tuseEffect( () => {\n\t\tconst initialContextRef = initialContext.current;\n\t\treturn () => setContext( initialContextRef );\n\t}, [ setContext ] );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAkC;AAClC,kBAAuC;AAKvC,mBAAuC;AACvC,yBAAuB;AAOR,SAAR,kBAAoC,SAAU;AACpD,QAAM,EAAE,WAAW,QAAI,uBAAW,aAAAA,KAAc;AAChD,QAAM,qBAAiB,uBAAQ,WAAW,CAAE;AAC5C,QAAM,EAAE,WAAW,QAAI,+BAAQ,yBAAa,aAAAA,KAAc,CAAE;AAE5D,gCAAW,MAAM;AAChB,eAAY,OAAQ;AAAA,EACrB,GAAG,CAAE,SAAS,UAAW,CAAE;AAI3B,gCAAW,MAAM;AAChB,UAAM,oBAAoB,eAAe;AACzC,WAAO,MAAM,WAAY,iBAAkB;AAAA,EAC5C,GAAG,CAAE,UAAW,CAAE;AACnB;",
6
+ "names": ["commandsStore"]
7
+ }
@@ -1,95 +1,31 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var use_command_loader_exports = {};
19
+ __export(use_command_loader_exports, {
20
+ default: () => useCommandLoader
5
21
  });
6
- exports.default = useCommandLoader;
7
- var _element = require("@wordpress/element");
8
- var _data = require("@wordpress/data");
9
- var _store = require("../store");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /**
19
- * Attach a command loader to the command palette. Used for dynamic commands.
20
- *
21
- * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
22
- *
23
- * @example
24
- * ```js
25
- * import { useCommandLoader } from '@wordpress/commands';
26
- * import { post, page, layout, symbolFilled } from '@wordpress/icons';
27
- *
28
- * const icons = {
29
- * post,
30
- * page,
31
- * wp_template: layout,
32
- * wp_template_part: symbolFilled,
33
- * };
34
- *
35
- * function usePageSearchCommandLoader( { search } ) {
36
- * // Retrieve the pages for the "search" term.
37
- * const { records, isLoading } = useSelect( ( select ) => {
38
- * const { getEntityRecords } = select( coreStore );
39
- * const query = {
40
- * search: !! search ? search : undefined,
41
- * per_page: 10,
42
- * orderby: search ? 'relevance' : 'date',
43
- * };
44
- * return {
45
- * records: getEntityRecords( 'postType', 'page', query ),
46
- * isLoading: ! select( coreStore ).hasFinishedResolution(
47
- * 'getEntityRecords',
48
- * 'postType', 'page', query ]
49
- * ),
50
- * };
51
- * }, [ search ] );
52
- *
53
- * // Create the commands.
54
- * const commands = useMemo( () => {
55
- * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
56
- * return {
57
- * name: record.title?.rendered + ' ' + record.id,
58
- * label: record.title?.rendered
59
- * ? record.title?.rendered
60
- * : __( '(no title)' ),
61
- * icon: icons[ postType ],
62
- * callback: ( { close } ) => {
63
- * const args = {
64
- * postType,
65
- * postId: record.id,
66
- * ...extraArgs,
67
- * };
68
- * document.location = addQueryArgs( 'site-editor.php', args );
69
- * close();
70
- * },
71
- * };
72
- * } );
73
- * }, [ records, history ] );
74
- *
75
- * return {
76
- * commands,
77
- * isLoading,
78
- * };
79
- * }
80
- *
81
- * useCommandLoader( {
82
- * name: 'myplugin/page-search',
83
- * hook: usePageSearchCommandLoader,
84
- * } );
85
- * ```
86
- */
22
+ module.exports = __toCommonJS(use_command_loader_exports);
23
+ var import_element = require("@wordpress/element");
24
+ var import_data = require("@wordpress/data");
25
+ var import_store = require("../store");
87
26
  function useCommandLoader(loader) {
88
- const {
89
- registerCommandLoader,
90
- unregisterCommandLoader
91
- } = (0, _data.useDispatch)(_store.store);
92
- (0, _element.useEffect)(() => {
27
+ const { registerCommandLoader, unregisterCommandLoader } = (0, import_data.useDispatch)(import_store.store);
28
+ (0, import_element.useEffect)(() => {
93
29
  if (loader.disabled) {
94
30
  return;
95
31
  }
@@ -101,6 +37,13 @@ function useCommandLoader(loader) {
101
37
  return () => {
102
38
  unregisterCommandLoader(loader.name);
103
39
  };
104
- }, [loader.name, loader.hook, loader.context, loader.disabled, registerCommandLoader, unregisterCommandLoader]);
40
+ }, [
41
+ loader.name,
42
+ loader.hook,
43
+ loader.context,
44
+ loader.disabled,
45
+ registerCommandLoader,
46
+ unregisterCommandLoader
47
+ ]);
105
48
  }
106
- //# sourceMappingURL=use-command-loader.js.map
49
+ //# sourceMappingURL=use-command-loader.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_data","_store","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","useDispatch","commandsStore","useEffect","disabled","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette. Used for dynamic commands.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n *\n * @example\n * ```js\n * import { useCommandLoader } from '@wordpress/commands';\n * import { post, page, layout, symbolFilled } from '@wordpress/icons';\n *\n * const icons = {\n * post,\n * page,\n * wp_template: layout,\n * wp_template_part: symbolFilled,\n * };\n *\n * function usePageSearchCommandLoader( { search } ) {\n * // Retrieve the pages for the \"search\" term.\n * const { records, isLoading } = useSelect( ( select ) => {\n * const { getEntityRecords } = select( coreStore );\n * const query = {\n * search: !! search ? search : undefined,\n * per_page: 10,\n * orderby: search ? 'relevance' : 'date',\n * };\n * return {\n * records: getEntityRecords( 'postType', 'page', query ),\n * isLoading: ! select( coreStore ).hasFinishedResolution(\n * 'getEntityRecords',\n * 'postType', 'page', query ]\n * ),\n * };\n * }, [ search ] );\n *\n * // Create the commands.\n * const commands = useMemo( () => {\n * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n * return {\n * name: record.title?.rendered + ' ' + record.id,\n * label: record.title?.rendered\n * ? record.title?.rendered\n * : __( '(no title)' ),\n * icon: icons[ postType ],\n * callback: ( { close } ) => {\n * const args = {\n * postType,\n * postId: record.id,\n * ...extraArgs,\n * };\n * document.location = addQueryArgs( 'site-editor.php', args );\n * close();\n * },\n * };\n * } );\n * }, [ records, history ] );\n *\n * return {\n * commands,\n * isLoading,\n * };\n * }\n *\n * useCommandLoader( {\n * name: 'myplugin/page-search',\n * hook: usePageSearchCommandLoader,\n * } );\n * ```\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tif ( loader.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tloader.disabled,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvD,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC7B,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAKL,MAAM,CAACM,QAAQ,EAAG;MACtB;IACD;IACAL,qBAAqB,CAAE;MACtBM,IAAI,EAAEP,MAAM,CAACO,IAAI;MACjBC,IAAI,EAAER,MAAM,CAACQ,IAAI;MACjBC,OAAO,EAAET,MAAM,CAACS;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZP,uBAAuB,CAAEF,MAAM,CAACO,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFP,MAAM,CAACO,IAAI,EACXP,MAAM,CAACQ,IAAI,EACXR,MAAM,CAACS,OAAO,EACdT,MAAM,CAACM,QAAQ,EACfL,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-command-loader.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette. Used for dynamic commands.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n *\n * @example\n * ```js\n * import { useCommandLoader } from '@wordpress/commands';\n * import { post, page, layout, symbolFilled } from '@wordpress/icons';\n *\n * const icons = {\n * post,\n * page,\n * wp_template: layout,\n * wp_template_part: symbolFilled,\n * };\n *\n * function usePageSearchCommandLoader( { search } ) {\n * // Retrieve the pages for the \"search\" term.\n * const { records, isLoading } = useSelect( ( select ) => {\n * const { getEntityRecords } = select( coreStore );\n * const query = {\n * search: !! search ? search : undefined,\n * per_page: 10,\n * orderby: search ? 'relevance' : 'date',\n * };\n * return {\n * records: getEntityRecords( 'postType', 'page', query ),\n * isLoading: ! select( coreStore ).hasFinishedResolution(\n * 'getEntityRecords',\n * 'postType', 'page', query ]\n * ),\n * };\n * }, [ search ] );\n *\n * // Create the commands.\n * const commands = useMemo( () => {\n * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n * return {\n * name: record.title?.rendered + ' ' + record.id,\n * label: record.title?.rendered\n * ? record.title?.rendered\n * : __( '(no title)' ),\n * icon: icons[ postType ],\n * callback: ( { close } ) => {\n * const args = {\n * postType,\n * postId: record.id,\n * ...extraArgs,\n * };\n * document.location = addQueryArgs( 'site-editor.php', args );\n * close();\n * },\n * };\n * } );\n * }, [ records, history ] );\n *\n * return {\n * commands,\n * isLoading,\n * };\n * }\n *\n * useCommandLoader( {\n * name: 'myplugin/page-search',\n * hook: usePageSearchCommandLoader,\n * } );\n * ```\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tif ( loader.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tloader.disabled,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0B;AAC1B,kBAA4B;AAK5B,mBAAuC;AAuExB,SAAR,iBAAmC,QAAS;AAClD,QAAM,EAAE,uBAAuB,wBAAwB,QACtD,yBAAa,aAAAA,KAAc;AAC5B,gCAAW,MAAM;AAChB,QAAK,OAAO,UAAW;AACtB;AAAA,IACD;AACA,0BAAuB;AAAA,MACtB,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,MACb,SAAS,OAAO;AAAA,IACjB,CAAE;AACF,WAAO,MAAM;AACZ,8BAAyB,OAAO,IAAK;AAAA,IACtC;AAAA,EACD,GAAG;AAAA,IACF,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACD,CAAE;AACH;",
6
+ "names": ["commandsStore"]
7
+ }
@@ -1,52 +1,36 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var use_command_exports = {};
19
+ __export(use_command_exports, {
20
+ useCommand: () => useCommand,
21
+ useCommands: () => useCommands
5
22
  });
6
- exports.useCommand = useCommand;
7
- exports.useCommands = useCommands;
8
- var _element = require("@wordpress/element");
9
- var _data = require("@wordpress/data");
10
- var _store = require("../store");
11
- /**
12
- * WordPress dependencies
13
- */
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
-
19
- /**
20
- * Attach a command to the command palette. Used for static commands.
21
- *
22
- * @param {import('../store/actions').WPCommandConfig} command command config.
23
- *
24
- * @example
25
- * ```js
26
- * import { useCommand } from '@wordpress/commands';
27
- * import { plus } from '@wordpress/icons';
28
- *
29
- * useCommand( {
30
- * name: 'myplugin/my-command-name',
31
- * label: __( 'Add new post' ),
32
- * icon: plus,
33
- * callback: ({ close }) => {
34
- * document.location.href = 'post-new.php';
35
- * close();
36
- * },
37
- * } );
38
- * ```
39
- */
23
+ module.exports = __toCommonJS(use_command_exports);
24
+ var import_element = require("@wordpress/element");
25
+ var import_data = require("@wordpress/data");
26
+ var import_store = require("../store");
40
27
  function useCommand(command) {
41
- const {
42
- registerCommand,
43
- unregisterCommand
44
- } = (0, _data.useDispatch)(_store.store);
45
- const currentCallbackRef = (0, _element.useRef)(command.callback);
46
- (0, _element.useEffect)(() => {
28
+ const { registerCommand, unregisterCommand } = (0, import_data.useDispatch)(import_store.store);
29
+ const currentCallbackRef = (0, import_element.useRef)(command.callback);
30
+ (0, import_element.useEffect)(() => {
47
31
  currentCallbackRef.current = command.callback;
48
32
  }, [command.callback]);
49
- (0, _element.useEffect)(() => {
33
+ (0, import_element.useEffect)(() => {
50
34
  if (command.disabled) {
51
35
  return;
52
36
  }
@@ -62,62 +46,36 @@ function useCommand(command) {
62
46
  return () => {
63
47
  unregisterCommand(command.name);
64
48
  };
65
- }, [command.name, command.label, command.searchLabel, command.icon, command.context, command.keywords, command.disabled, registerCommand, unregisterCommand]);
66
- }
67
-
68
- /**
69
- * Attach multiple commands to the command palette. Used for static commands.
70
- *
71
- * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.
72
- *
73
- * @example
74
- * ```js
75
- * import { useCommands } from '@wordpress/commands';
76
- * import { plus, edit } from '@wordpress/icons';
77
- *
78
- * useCommands( [
79
- * {
80
- * name: 'myplugin/add-post',
81
- * label: __( 'Add new post' ),
82
- * icon: plus,
83
- * callback: ({ close }) => {
84
- * document.location.href = 'post-new.php';
85
- * close();
86
- * },
87
- * },
88
- * {
89
- * name: 'myplugin/edit-posts',
90
- * label: __( 'Edit posts' ),
91
- * icon: edit,
92
- * callback: ({ close }) => {
93
- * document.location.href = 'edit.php';
94
- * close();
95
- * },
96
- * },
97
- * ] );
98
- * ```
99
- */
100
- function useCommands(commands) {
101
- const {
49
+ }, [
50
+ command.name,
51
+ command.label,
52
+ command.searchLabel,
53
+ command.icon,
54
+ command.context,
55
+ command.keywords,
56
+ command.disabled,
102
57
  registerCommand,
103
58
  unregisterCommand
104
- } = (0, _data.useDispatch)(_store.store);
105
- const currentCallbacksRef = (0, _element.useRef)({});
106
- (0, _element.useEffect)(() => {
59
+ ]);
60
+ }
61
+ function useCommands(commands) {
62
+ const { registerCommand, unregisterCommand } = (0, import_data.useDispatch)(import_store.store);
63
+ const currentCallbacksRef = (0, import_element.useRef)({});
64
+ (0, import_element.useEffect)(() => {
107
65
  if (!commands) {
108
66
  return;
109
67
  }
110
- commands.forEach(command => {
68
+ commands.forEach((command) => {
111
69
  if (command.callback) {
112
70
  currentCallbacksRef.current[command.name] = command.callback;
113
71
  }
114
72
  });
115
73
  }, [commands]);
116
- (0, _element.useEffect)(() => {
74
+ (0, import_element.useEffect)(() => {
117
75
  if (!commands) {
118
76
  return;
119
77
  }
120
- commands.forEach(command => {
78
+ commands.forEach((command) => {
121
79
  if (command.disabled) {
122
80
  return;
123
81
  }
@@ -137,10 +95,15 @@ function useCommands(commands) {
137
95
  });
138
96
  });
139
97
  return () => {
140
- commands.forEach(command => {
98
+ commands.forEach((command) => {
141
99
  unregisterCommand(command.name);
142
100
  });
143
101
  };
144
102
  }, [commands, registerCommand, unregisterCommand]);
145
103
  }
146
- //# sourceMappingURL=use-command.js.map
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ useCommand,
107
+ useCommands
108
+ });
109
+ //# sourceMappingURL=use-command.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallbackRef","useRef","callback","useEffect","current","disabled","name","context","label","searchLabel","icon","keywords","args","useCommands","commands","currentCallbacksRef","forEach"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n *\n * @example\n * ```js\n * import { useCommand } from '@wordpress/commands';\n * import { plus } from '@wordpress/icons';\n *\n * useCommand( {\n * name: 'myplugin/my-command-name',\n * label: __( 'Add new post' ),\n *\t icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * } );\n * ```\n */\nexport function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tcommand.keywords,\n\t\tcommand.disabled,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n\n/**\n * Attach multiple commands to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.\n *\n * @example\n * ```js\n * import { useCommands } from '@wordpress/commands';\n * import { plus, edit } from '@wordpress/icons';\n *\n * useCommands( [\n * {\n * name: 'myplugin/add-post',\n * label: __( 'Add new post' ),\n * icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * },\n * {\n * name: 'myplugin/edit-posts',\n * label: __( 'Edit posts' ),\n * icon: edit,\n * callback: ({ close }) => {\n * document.location.href = 'edit.php';\n * close();\n * },\n * },\n * ] );\n * ```\n */\nexport function useCommands( commands ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbacksRef = useRef( {} );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.callback ) {\n\t\t\t\tcurrentCallbacksRef.current[ command.name ] = command.callback;\n\t\t\t}\n\t\t} );\n\t}, [ commands ] );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tregisterCommand( {\n\t\t\t\tname: command.name,\n\t\t\t\tcontext: command.context,\n\t\t\t\tlabel: command.label,\n\t\t\t\tsearchLabel: command.searchLabel,\n\t\t\t\ticon: command.icon,\n\t\t\t\tkeywords: command.keywords,\n\t\t\t\tcallback: ( ...args ) => {\n\t\t\t\t\tconst callback =\n\t\t\t\t\t\tcurrentCallbacksRef.current[ command.name ];\n\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\tcallback( ...args );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tcommands.forEach( ( command ) => {\n\t\t\t\tunregisterCommand( command.name );\n\t\t\t} );\n\t\t};\n\t}, [ commands, registerCommand, unregisterCommand ] );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,UAAUA,CAAEC,OAAO,EAAG;EACrC,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC3E,MAAMC,kBAAkB,GAAG,IAAAC,eAAM,EAAEN,OAAO,CAACO,QAAS,CAAC;EACrD,IAAAC,kBAAS,EAAE,MAAM;IAChBH,kBAAkB,CAACI,OAAO,GAAGT,OAAO,CAACO,QAAQ;EAC9C,CAAC,EAAE,CAAEP,OAAO,CAACO,QAAQ,CAAG,CAAC;EAEzB,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAKR,OAAO,CAACU,QAAQ,EAAG;MACvB;IACD;IACAT,eAAe,CAAE;MAChBU,IAAI,EAAEX,OAAO,CAACW,IAAI;MAClBC,OAAO,EAAEZ,OAAO,CAACY,OAAO;MACxBC,K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AAC;EAEjB,IAAAX,kBAAS,EAAE,MAAM;IAChB,IAAK,CAAEW,QAAQ,EAAG;MACjB;IACD;IACAA,QAAQ,CAACE,OAAO,CAAIrB,OAAO,IAAM;MAChC,IAAKA,OAAO,CAACU,QAAQ,EAAG;QACvB;MACD;MACAT,eAAe,CAAE;QAChBU,IAAI,EAAEX,OAAO,CAACW,IAAI;QAClBC,OAAO,EAAEZ,OAAO,CAACY,OAAO;QACxBC,KAAK,EAAEb,OAAO,CAACa,KAAK;QACpBC,WAAW,EAAEd,OAAO,CAACc,WAAW;QAChCC,IAAI,EAAEf,OAAO,CAACe,IAAI;QAClBC,QAAQ,EAAEhB,OAAO,CAACgB,QAAQ;QAC1BT,QAAQ,EAAEA,CAAE,GAAGU,IAAI,KAAM;UACxB,MAAMV,QAAQ,GACba,mBAAmB,CAACX,OAAO,CAAET,OAAO,CAACW,IAAI,CAAE;UAC5C,IAAKJ,QAAQ,EAAG;YACfA,QAAQ,CAAE,GAAGU,IAAK,CAAC;UACpB;QACD;MACD,CAAE,CAAC;IACJ,CAAE,CAAC;IAEH,OAAO,MAAM;MACZE,QAAQ,CAACE,OAAO,CAAIrB,OAAO,IAAM;QAChCE,iBAAiB,CAAEF,OAAO,CAACW,IAAK,CAAC;MAClC,CAAE,CAAC;IACJ,CAAC;EACF,CAAC,EAAE,CAAEQ,QAAQ,EAAElB,eAAe,EAAEC,iBAAiB,CAAG,CAAC;AACtD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-command.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n *\n * @example\n * ```js\n * import { useCommand } from '@wordpress/commands';\n * import { plus } from '@wordpress/icons';\n *\n * useCommand( {\n * name: 'myplugin/my-command-name',\n * label: __( 'Add new post' ),\n *\t icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * } );\n * ```\n */\nexport function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tcommand.keywords,\n\t\tcommand.disabled,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n\n/**\n * Attach multiple commands to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.\n *\n * @example\n * ```js\n * import { useCommands } from '@wordpress/commands';\n * import { plus, pencil } from '@wordpress/icons';\n *\n * useCommands( [\n * {\n * name: 'myplugin/add-post',\n * label: __( 'Add new post' ),\n * icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * },\n * {\n * name: 'myplugin/edit-posts',\n * label: __( 'Edit posts' ),\n * icon: pencil,\n * callback: ({ close }) => {\n * document.location.href = 'edit.php';\n * close();\n * },\n * },\n * ] );\n * ```\n */\nexport function useCommands( commands ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbacksRef = useRef( {} );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.callback ) {\n\t\t\t\tcurrentCallbacksRef.current[ command.name ] = command.callback;\n\t\t\t}\n\t\t} );\n\t}, [ commands ] );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tregisterCommand( {\n\t\t\t\tname: command.name,\n\t\t\t\tcontext: command.context,\n\t\t\t\tlabel: command.label,\n\t\t\t\tsearchLabel: command.searchLabel,\n\t\t\t\ticon: command.icon,\n\t\t\t\tkeywords: command.keywords,\n\t\t\t\tcallback: ( ...args ) => {\n\t\t\t\t\tconst callback =\n\t\t\t\t\t\tcurrentCallbacksRef.current[ command.name ];\n\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\tcallback( ...args );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tcommands.forEach( ( command ) => {\n\t\t\t\tunregisterCommand( command.name );\n\t\t\t} );\n\t\t};\n\t}, [ commands, registerCommand, unregisterCommand ] );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAkC;AAClC,kBAA4B;AAK5B,mBAAuC;AAuBhC,SAAS,WAAY,SAAU;AACrC,QAAM,EAAE,iBAAiB,kBAAkB,QAAI,yBAAa,aAAAA,KAAc;AAC1E,QAAM,yBAAqB,uBAAQ,QAAQ,QAAS;AACpD,gCAAW,MAAM;AAChB,uBAAmB,UAAU,QAAQ;AAAA,EACtC,GAAG,CAAE,QAAQ,QAAS,CAAE;AAExB,gCAAW,MAAM;AAChB,QAAK,QAAQ,UAAW;AACvB;AAAA,IACD;AACA,oBAAiB;AAAA,MAChB,MAAM,QAAQ;AAAA,MAC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