@wordpress/boot 0.25.0 → 0.26.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 (71) hide show
  1. package/build-module/components/app/index.mjs +29 -53
  2. package/build-module/components/app/index.mjs.map +1 -7
  3. package/build-module/components/app/router.mjs +238 -214
  4. package/build-module/components/app/router.mjs.map +1 -7
  5. package/build-module/components/app/use-route-title.mjs +35 -42
  6. package/build-module/components/app/use-route-title.mjs.map +1 -7
  7. package/build-module/components/canvas/back-button.mjs +21 -20
  8. package/build-module/components/canvas/back-button.mjs.map +1 -7
  9. package/build-module/components/canvas/index.mjs +104 -130
  10. package/build-module/components/canvas/index.mjs.map +1 -7
  11. package/build-module/components/canvas/site-preview.mjs +36 -43
  12. package/build-module/components/canvas/site-preview.mjs.map +1 -7
  13. package/build-module/components/canvas/use-navigate-to-entity-record.mjs +109 -113
  14. package/build-module/components/canvas/use-navigate-to-entity-record.mjs.map +1 -7
  15. package/build-module/components/canvas/viewport.mjs +25 -13
  16. package/build-module/components/canvas/viewport.mjs.map +1 -7
  17. package/build-module/components/canvas-renderer/index.mjs +40 -32
  18. package/build-module/components/canvas-renderer/index.mjs.map +1 -7
  19. package/build-module/components/error-boundary/index.mjs +160 -108
  20. package/build-module/components/error-boundary/index.mjs.map +1 -7
  21. package/build-module/components/navigation/drilldown-item/index.mjs +124 -127
  22. package/build-module/components/navigation/drilldown-item/index.mjs.map +1 -7
  23. package/build-module/components/navigation/dropdown-item/index.mjs +156 -173
  24. package/build-module/components/navigation/dropdown-item/index.mjs.map +1 -7
  25. package/build-module/components/navigation/index.mjs +55 -90
  26. package/build-module/components/navigation/index.mjs.map +1 -7
  27. package/build-module/components/navigation/items.mjs +51 -53
  28. package/build-module/components/navigation/items.mjs.map +1 -7
  29. package/build-module/components/navigation/navigation-item/index.mjs +120 -114
  30. package/build-module/components/navigation/navigation-item/index.mjs.map +1 -7
  31. package/build-module/components/navigation/navigation-screen/index.mjs +192 -185
  32. package/build-module/components/navigation/navigation-screen/index.mjs.map +1 -7
  33. package/build-module/components/navigation/path-matching.mjs +74 -73
  34. package/build-module/components/navigation/path-matching.mjs.map +1 -7
  35. package/build-module/components/navigation/router-link-item.mjs +13 -11
  36. package/build-module/components/navigation/router-link-item.mjs.map +1 -7
  37. package/build-module/components/navigation/use-sidebar-parent.mjs +37 -48
  38. package/build-module/components/navigation/use-sidebar-parent.mjs.map +1 -7
  39. package/build-module/components/plugin-area/index.mjs +20 -24
  40. package/build-module/components/plugin-area/index.mjs.map +1 -7
  41. package/build-module/components/root/index.mjs +227 -242
  42. package/build-module/components/root/index.mjs.map +1 -7
  43. package/build-module/components/root/single-page.mjs +174 -148
  44. package/build-module/components/root/single-page.mjs.map +1 -7
  45. package/build-module/components/root/use-sync-body-background.mjs +28 -22
  46. package/build-module/components/root/use-sync-body-background.mjs.map +1 -7
  47. package/build-module/components/save-button/index.mjs +170 -214
  48. package/build-module/components/save-button/index.mjs.map +1 -7
  49. package/build-module/components/save-panel/index.mjs +110 -106
  50. package/build-module/components/save-panel/index.mjs.map +1 -7
  51. package/build-module/components/save-panel/use-save-shortcut.mjs +42 -51
  52. package/build-module/components/save-panel/use-save-shortcut.mjs.map +1 -7
  53. package/build-module/components/sidebar/index.mjs +126 -104
  54. package/build-module/components/sidebar/index.mjs.map +1 -7
  55. package/build-module/index.mjs +1 -7
  56. package/build-module/lock-unlock.mjs +5 -10
  57. package/build-module/lock-unlock.mjs.map +1 -7
  58. package/build-module/store/actions.mjs +34 -31
  59. package/build-module/store/actions.mjs.map +1 -7
  60. package/build-module/store/index.mjs +9 -11
  61. package/build-module/store/index.mjs.map +1 -7
  62. package/build-module/store/reducer.mjs +48 -55
  63. package/build-module/store/reducer.mjs.map +1 -7
  64. package/build-module/store/selectors.mjs +21 -16
  65. package/build-module/store/selectors.mjs.map +1 -7
  66. package/build-module/store/types.mjs +0 -1
  67. package/build-types/components/error-boundary/index.d.ts.map +1 -1
  68. package/package.json +28 -28
  69. package/src/components/error-boundary/index.tsx +50 -4
  70. package/build-module/index.mjs.map +0 -7
  71. package/build-module/store/types.mjs.map +0 -7
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/save-button/index.tsx", "../../../../style-runtime/src/index.ts", "../../../src/components/save-button/style.module.scss"],
4
- "sourcesContent": ["import { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { _n, __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tariaKeyShortcut,\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n} from '@wordpress/keycodes';\nimport { check } from '@wordpress/icons';\nimport { EntitiesSavedStates } from '@wordpress/editor';\nimport { Button, Modal } from '@wordpress/components';\nimport {\n\tKeyboardShortcutDescription,\n\tKeyboardShortcutDisplay,\n\tTooltip,\n\tuseKeyboardShortcutProps,\n} from '@wordpress/ui';\nimport styles from './style.module.scss';\nimport useSaveShortcut from '../save-panel/use-save-shortcut';\n\nexport default function SaveButton() {\n\tconst [ isSaveViewOpen, setIsSaveViewOpened ] = useState( false );\n\tconst { isSaving, dirtyEntityRecordsCount } = useSelect( ( select ) => {\n\t\tconst { isSavingEntityRecord, __experimentalGetDirtyEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\treturn {\n\t\t\tisSaving: dirtyEntityRecords.some( ( record ) =>\n\t\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount: dirtyEntityRecords.length,\n\t\t};\n\t}, [] );\n\tconst [ showSavedState, setShowSavedState ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isSaving ) {\n\t\t\t// Proactively expect to show saved state. This is done once save\n\t\t\t// starts to avoid race condition where setting it after would cause\n\t\t\t// the button to be unmounted before state is updated.\n\t\t\tsetShowSavedState( true );\n\t\t}\n\t}, [ isSaving ] );\n\n\tconst hasChanges = dirtyEntityRecordsCount > 0;\n\n\t// Handle save failure case: If we were showing saved state but saving\n\t// failed, reset to show changes again.\n\tuseEffect( () => {\n\t\tif ( ! isSaving && hasChanges ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}, [ isSaving, hasChanges ] );\n\n\tfunction hideSavedState() {\n\t\tif ( showSavedState ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}\n\n\tconst shouldShowButton = hasChanges || showSavedState;\n\n\tuseSaveShortcut( { openSavePanel: () => setIsSaveViewOpened( true ) } );\n\tconst shortcut = {\n\t\tdisplayShortcut: displayShortcut.primary( 's' ),\n\t\tariaKeyShortcut: ariaKeyShortcut.primary( 's' ),\n\t\tlabel: shortcutAriaLabel.primary( 's' ),\n\t};\n\tconst { descriptionId, targetProps } = useKeyboardShortcutProps( {\n\t\tshortcut,\n\t} );\n\n\tif ( ! shouldShowButton ) {\n\t\treturn null;\n\t}\n\n\tconst isInSavedState = showSavedState && ! hasChanges;\n\tconst disabled = isSaving || isInSavedState;\n\n\tconst getLabel = () => {\n\t\tif ( isInSavedState ) {\n\t\t\treturn __( 'Saved' );\n\t\t}\n\t\treturn sprintf(\n\t\t\t// translators: %d: number of unsaved changes (number).\n\t\t\t_n(\n\t\t\t\t'Review %d change…',\n\t\t\t\t'Review %d changes…',\n\t\t\t\tdirtyEntityRecordsCount\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount\n\t\t);\n\t};\n\tconst label = getLabel();\n\n\treturn (\n\t\t<>\n\t\t\t<Tooltip.Root>\n\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t{ ...targetProps }\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tonClick={ () => setIsSaveViewOpened( true ) }\n\t\t\t\t\t\t\tonBlur={ hideSavedState }\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\tclassName={ styles[ 'save-button' ] }\n\t\t\t\t\t\t\ticon={ isInSavedState ? check : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t\t{ descriptionId && (\n\t\t\t\t\t\t<KeyboardShortcutDescription\n\t\t\t\t\t\t\tdescriptionId={ descriptionId }\n\t\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Tooltip.Trigger>\n\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t{ hasChanges && <span>{ label }</span> }\n\t\t\t\t\t<KeyboardShortcutDisplay\n\t\t\t\t\t\tclassName={ styles.shortcut }\n\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t/>\n\t\t\t\t</Tooltip.Popup>\n\t\t\t</Tooltip.Root>\n\t\t\t{ isSaveViewOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\t\t\tonRequestClose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<EntitiesSavedStates\n\t\t\t\t\t\tclose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\t\tvariant=\"inline\"\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"1c6bdcf0b8\", \"._9c7a13851fe5f446__save-button{width:100%}._266ea24d4569bd10__shortcut:not(:first-child){margin-inline-start:8px}\");\n}\nexport default {\"save-button\":\"_9c7a13851fe5f446__save-button\",\"shortcut\":\"_266ea24d4569bd10__shortcut\"};\n"],
5
- "mappings": ";AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,iBAAiB;AAC1B,SAAS,IAAI,IAAI,eAAe;AAChC,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa;AACtB,SAAS,2BAA2B;AACpC,SAAS,QAAQ,aAAa;AAC9B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;;;ACPP,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACrB,QAAM,cAAc;AAEpB,MAAK,YAAY,kBAAmB;AACnC,WAAO,YAAY;AAAA,EACpB;AAEA,cAAY,mBAAmB;AAAA,IAC9B,WAAW,oBAAI,IAAI;AAAA,IACnB,QAAQ,oBAAI,IAAI;AAAA,IAChB,gBAAgB,oBAAI,QAAQ;AAAA,EAC7B;AAEA,MAAK,OAAO,aAAa,aAAc;AACtC,qBAAkB,QAAS;AAAA,EAC5B;AAEA,SAAO,YAAY;AACpB;AAUA,SAAS,0BACR,gBACA,MACU;AACV,MAAK,CAAE,eAAe,MAAO;AAC5B,WAAO;AAAA,EACR;AAEA,aAAY,SAAS,eAAe,KAAK;AAAA,IACxC,SAAU,oBAAqB;AAAA,EAChC,GAAI;AACH,QAAK,MAAM,aAAc,oBAAqB,MAAM,MAAO;AAC1D,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AAUA,SAAS,YAAa,gBAA0B,MAAc,KAAc;AAC3E,MAAK,CAAE,eAAe,MAAO;AAC5B;AAAA,EACD;AAEA,QAAM,UAAU,WAAW;AAC3B,MAAI,iBAAiB,QAAQ,eAAe,IAAK,cAAe;AAEhE,MAAK,CAAE,gBAAiB;AACvB,qBAAiB,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AM,WAAW,YAAY;AAE7B,QAAM,WAAW,MAAM;AACtB,QAAK,gBAAiB;AACrB,aAAO,GAAI,OAAQ;AAAA,IACpB;AACA,WAAO;AAAA;AAAA,MAEN;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,QAAM,QAAQ,SAAS;AAEvB,SACC,iCACC;AAAA,yBAAC,QAAQ,MAAR,EACA;AAAA;AAAA,QAAC,QAAQ;AAAA,QAAR;AAAA,UACE,GAAG;AAAA,UACL,QACC;AAAA,YAAC;AAAA;AAAA,cACA,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,SAAU,MAAM,oBAAqB,IAAK;AAAA,cAC1C,QAAS;AAAA,cACT;AAAA,cACA,wBAAsB;AAAA,cACtB,QAAS;AAAA,cACT,WAAY,qBAAQ,aAAc;AAAA,cAClC,MAAO,iBAAiB,QAAQ;AAAA;AAAA,UACjC;AAAA,UAGC;AAAA;AAAA,YACA,iBACD;AAAA,cAAC;AAAA;AAAA,gBACA;AAAA,gBACA;AAAA;AAAA,YACD;AAAA;AAAA;AAAA,MAEF;AAAA,MACA,qBAAC,QAAQ,OAAR,EACE;AAAA,sBAAc,oBAAC,UAAO,iBAAO;AAAA,QAC/B;AAAA,UAAC;AAAA;AAAA,YACA,WAAY,qBAAO;AAAA,YACnB;AAAA;AAAA,QACD;AAAA,SACD;AAAA,OACD;AAAA,IACE,kBACD;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,GAAI,gBAAiB;AAAA,QAC7B,gBAAiB,MAAM,oBAAqB,KAAM;AAAA,QAClD,MAAK;AAAA,QAEL;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ,MAAM,oBAAqB,KAAM;AAAA,YACzC,SAAQ;AAAA;AAAA,QACT;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":["coreStore","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/save-button/style.module.scss","../../../src/components/save-button/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"da0f7c3ff6\", \"._4e8b2ecc322dfc1f__save-button{width:100%}._0e6f3a8336688e3f__shortcut:not(:first-child){margin-inline-start:8px}\");\n}\nexport default {\"save-button\":\"_4e8b2ecc322dfc1f__save-button\",\"shortcut\":\"_0e6f3a8336688e3f__shortcut\"};\n","import { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { _n, __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tariaKeyShortcut,\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n} from '@wordpress/keycodes';\nimport { check } from '@wordpress/icons';\nimport { EntitiesSavedStates } from '@wordpress/editor';\nimport { Button, Modal } from '@wordpress/components';\nimport {\n\tKeyboardShortcutDescription,\n\tKeyboardShortcutDisplay,\n\tTooltip,\n\tuseKeyboardShortcutProps,\n} from '@wordpress/ui';\nimport styles from './style.module.scss';\nimport useSaveShortcut from '../save-panel/use-save-shortcut';\n\nexport default function SaveButton() {\n\tconst [ isSaveViewOpen, setIsSaveViewOpened ] = useState( false );\n\tconst { isSaving, dirtyEntityRecordsCount } = useSelect( ( select ) => {\n\t\tconst { isSavingEntityRecord, __experimentalGetDirtyEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\treturn {\n\t\t\tisSaving: dirtyEntityRecords.some( ( record ) =>\n\t\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount: dirtyEntityRecords.length,\n\t\t};\n\t}, [] );\n\tconst [ showSavedState, setShowSavedState ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isSaving ) {\n\t\t\t// Proactively expect to show saved state. This is done once save\n\t\t\t// starts to avoid race condition where setting it after would cause\n\t\t\t// the button to be unmounted before state is updated.\n\t\t\tsetShowSavedState( true );\n\t\t}\n\t}, [ isSaving ] );\n\n\tconst hasChanges = dirtyEntityRecordsCount > 0;\n\n\t// Handle save failure case: If we were showing saved state but saving\n\t// failed, reset to show changes again.\n\tuseEffect( () => {\n\t\tif ( ! isSaving && hasChanges ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}, [ isSaving, hasChanges ] );\n\n\tfunction hideSavedState() {\n\t\tif ( showSavedState ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}\n\n\tconst shouldShowButton = hasChanges || showSavedState;\n\n\tuseSaveShortcut( { openSavePanel: () => setIsSaveViewOpened( true ) } );\n\tconst shortcut = {\n\t\tdisplayShortcut: displayShortcut.primary( 's' ),\n\t\tariaKeyShortcut: ariaKeyShortcut.primary( 's' ),\n\t\tlabel: shortcutAriaLabel.primary( 's' ),\n\t};\n\tconst { descriptionId, targetProps } = useKeyboardShortcutProps( {\n\t\tshortcut,\n\t} );\n\n\tif ( ! shouldShowButton ) {\n\t\treturn null;\n\t}\n\n\tconst isInSavedState = showSavedState && ! hasChanges;\n\tconst disabled = isSaving || isInSavedState;\n\n\tconst getLabel = () => {\n\t\tif ( isInSavedState ) {\n\t\t\treturn __( 'Saved' );\n\t\t}\n\t\treturn sprintf(\n\t\t\t// translators: %d: number of unsaved changes (number).\n\t\t\t_n(\n\t\t\t\t'Review %d change…',\n\t\t\t\t'Review %d changes…',\n\t\t\t\tdirtyEntityRecordsCount\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount\n\t\t);\n\t};\n\tconst label = getLabel();\n\n\treturn (\n\t\t<>\n\t\t\t<Tooltip.Root>\n\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t{ ...targetProps }\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tonClick={ () => setIsSaveViewOpened( true ) }\n\t\t\t\t\t\t\tonBlur={ hideSavedState }\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\tclassName={ styles[ 'save-button' ] }\n\t\t\t\t\t\t\ticon={ isInSavedState ? check : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t\t{ descriptionId && (\n\t\t\t\t\t\t<KeyboardShortcutDescription\n\t\t\t\t\t\t\tdescriptionId={ descriptionId }\n\t\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Tooltip.Trigger>\n\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t{ hasChanges && <span>{ label }</span> }\n\t\t\t\t\t<KeyboardShortcutDisplay\n\t\t\t\t\t\tclassName={ styles.shortcut }\n\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t/>\n\t\t\t\t</Tooltip.Popup>\n\t\t\t</Tooltip.Root>\n\t\t\t{ isSaveViewOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\t\t\tonRequestClose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<EntitiesSavedStates\n\t\t\t\t\t\tclose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\t\tvariant=\"inline\"\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;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AAA,CAAA;AAEJ"}
@@ -1,126 +1,130 @@
1
- // packages/boot/src/components/save-panel/index.tsx
2
1
  import { useState } from "@wordpress/element";
3
2
  import { Modal } from "@wordpress/components";
4
3
  import { EntitiesSavedStates } from "@wordpress/editor";
5
4
  import { __ } from "@wordpress/i18n";
6
5
  import useSaveShortcut from "./use-save-shortcut.mjs";
7
-
6
+ import { jsx } from "react/jsx-runtime";
8
7
  // packages/style-runtime/src/index.ts
9
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
8
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
9
+ /**
10
+ * Returns the shared style runtime registry.
11
+ *
12
+ * The registry is stored on `globalThis` so separately bundled copies of this
13
+ * package can coordinate through the same document and style maps.
14
+ *
15
+ * @return The shared runtime registry.
16
+ */
10
17
  function getRuntime() {
11
- const globalScope = globalThis;
12
- if (globalScope.__wpStyleRuntime) {
13
- return globalScope.__wpStyleRuntime;
14
- }
15
- globalScope.__wpStyleRuntime = {
16
- documents: /* @__PURE__ */ new Map(),
17
- styles: /* @__PURE__ */ new Map(),
18
- injectedStyles: /* @__PURE__ */ new WeakMap()
19
- };
20
- if (typeof document !== "undefined") {
21
- registerDocument(document);
22
- }
23
- return globalScope.__wpStyleRuntime;
18
+ const globalScope = globalThis;
19
+ if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
20
+ globalScope.__wpStyleRuntime = {
21
+ documents: /* @__PURE__ */ new Map(),
22
+ styles: /* @__PURE__ */ new Map(),
23
+ injectedStyles: /* @__PURE__ */ new WeakMap()
24
+ };
25
+ if (typeof document !== "undefined") registerDocument(document);
26
+ return globalScope.__wpStyleRuntime;
24
27
  }
28
+ /**
29
+ * Checks whether a document already contains a style tag for a hash.
30
+ *
31
+ * @param targetDocument Document to inspect.
32
+ * @param hash Stable hash for the transformed CSS.
33
+ *
34
+ * @return Whether the style hash already exists in the document.
35
+ */
25
36
  function documentContainsStyleHash(targetDocument, hash) {
26
- if (!targetDocument.head) {
27
- return false;
28
- }
29
- for (const style of targetDocument.head.querySelectorAll(
30
- `style[${STYLE_HASH_ATTRIBUTE}]`
31
- )) {
32
- if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
33
- return true;
34
- }
35
- }
36
- return false;
37
+ if (!targetDocument.head) return false;
38
+ for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
39
+ return false;
37
40
  }
41
+ /**
42
+ * Injects a registered style into a document, unless that document already
43
+ * contains a style tag for the same hash.
44
+ *
45
+ * @param targetDocument Document to inject the style into.
46
+ * @param hash Stable hash for the transformed CSS.
47
+ * @param css CSS text to inject.
48
+ */
38
49
  function injectStyle(targetDocument, hash, css) {
39
- if (!targetDocument.head) {
40
- return;
41
- }
42
- const runtime = getRuntime();
43
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
44
- if (!injectedStyles) {
45
- injectedStyles = /* @__PURE__ */ new Set();
46
- runtime.injectedStyles.set(targetDocument, injectedStyles);
47
- }
48
- if (injectedStyles.has(hash)) {
49
- return;
50
- }
51
- if (documentContainsStyleHash(targetDocument, hash)) {
52
- injectedStyles.add(hash);
53
- return;
54
- }
55
- const style = targetDocument.createElement("style");
56
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
57
- style.appendChild(targetDocument.createTextNode(css));
58
- targetDocument.head.appendChild(style);
59
- injectedStyles.add(hash);
50
+ if (!targetDocument.head) return;
51
+ const runtime = getRuntime();
52
+ let injectedStyles = runtime.injectedStyles.get(targetDocument);
53
+ if (!injectedStyles) {
54
+ injectedStyles = /* @__PURE__ */ new Set();
55
+ runtime.injectedStyles.set(targetDocument, injectedStyles);
56
+ }
57
+ if (injectedStyles.has(hash)) return;
58
+ if (documentContainsStyleHash(targetDocument, hash)) {
59
+ injectedStyles.add(hash);
60
+ return;
61
+ }
62
+ const style = targetDocument.createElement("style");
63
+ style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
64
+ style.appendChild(targetDocument.createTextNode(css));
65
+ targetDocument.head.appendChild(style);
66
+ injectedStyles.add(hash);
60
67
  }
68
+ /**
69
+ * Registers a document as a style injection target.
70
+ *
71
+ * Existing registered styles are replayed into the document immediately.
72
+ * Documents are reference-counted so multiple providers can safely register the
73
+ * same document without one cleanup removing it while another registration is
74
+ * still active.
75
+ *
76
+ * @param targetDocument Document to receive registered styles.
77
+ * @return Cleanup function that unregisters this document registration.
78
+ */
61
79
  function registerDocument(targetDocument) {
62
- const runtime = getRuntime();
63
- runtime.documents.set(
64
- targetDocument,
65
- (runtime.documents.get(targetDocument) ?? 0) + 1
66
- );
67
- for (const [hash, css] of runtime.styles) {
68
- injectStyle(targetDocument, hash, css);
69
- }
70
- return () => {
71
- const count = runtime.documents.get(targetDocument);
72
- if (count === void 0) {
73
- return;
74
- }
75
- if (count <= 1) {
76
- runtime.documents.delete(targetDocument);
77
- return;
78
- }
79
- runtime.documents.set(targetDocument, count - 1);
80
- };
80
+ const runtime = getRuntime();
81
+ runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
82
+ for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
83
+ return () => {
84
+ const count = runtime.documents.get(targetDocument);
85
+ if (count === void 0) return;
86
+ if (count <= 1) {
87
+ runtime.documents.delete(targetDocument);
88
+ return;
89
+ }
90
+ runtime.documents.set(targetDocument, count - 1);
91
+ };
81
92
  }
93
+ /**
94
+ * Registers a style and injects it into all registered documents.
95
+ *
96
+ * The hash is used as the deduplication key, so calling this repeatedly with
97
+ * the same hash will not add duplicate style tags to a document.
98
+ * Registered styles are retained for the lifetime of the page so they can be
99
+ * replayed into documents that are registered later.
100
+ *
101
+ * @param hash Stable hash for the transformed CSS.
102
+ * @param css CSS text to inject.
103
+ */
82
104
  function registerStyle(hash, css) {
83
- const runtime = getRuntime();
84
- runtime.styles.set(hash, css);
85
- for (const targetDocument of runtime.documents.keys()) {
86
- injectStyle(targetDocument, hash, css);
87
- }
105
+ const runtime = getRuntime();
106
+ runtime.styles.set(hash, css);
107
+ for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
88
108
  }
89
-
90
109
  // packages/boot/src/components/save-panel/style.module.scss
91
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
92
- registerStyle("df1a59bc40", "@media (min-width:600px){._77efcb9ca06f5774__modal{width:600px}}");
93
- }
94
- var style_module_default = { "modal": "_77efcb9ca06f5774__modal" };
95
-
110
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("e8f942db13", "@media (min-width:600px){._1bb5b45e7ea3b538__modal{width:600px}}");
111
+ var style_module_default = { "modal": "_1bb5b45e7ea3b538__modal" };
96
112
  // packages/boot/src/components/save-panel/index.tsx
97
- import { jsx } from "react/jsx-runtime";
98
113
  function SavePanel() {
99
- const [isOpen, setIsOpen] = useState(false);
100
- useSaveShortcut({
101
- openSavePanel: () => setIsOpen(true)
102
- });
103
- if (!isOpen) {
104
- return false;
105
- }
106
- return /* @__PURE__ */ jsx(
107
- Modal,
108
- {
109
- className: style_module_default.modal,
110
- onRequestClose: () => setIsOpen(false),
111
- title: __("Review changes"),
112
- size: "small",
113
- children: /* @__PURE__ */ jsx(
114
- EntitiesSavedStates,
115
- {
116
- close: () => setIsOpen(false),
117
- variant: "inline"
118
- }
119
- )
120
- }
121
- );
114
+ const [isOpen, setIsOpen] = useState(false);
115
+ useSaveShortcut({ openSavePanel: () => setIsOpen(true) });
116
+ if (!isOpen) return false;
117
+ return /* @__PURE__ */ jsx(Modal, {
118
+ className: style_module_default.modal,
119
+ onRequestClose: () => setIsOpen(false),
120
+ title: __("Review changes"),
121
+ size: "small",
122
+ children: /* @__PURE__ */ jsx(EntitiesSavedStates, {
123
+ close: () => setIsOpen(false),
124
+ variant: "inline"
125
+ })
126
+ });
122
127
  }
123
- export {
124
- SavePanel as default
125
- };
126
- //# sourceMappingURL=index.mjs.map
128
+ export { SavePanel as default };
129
+
130
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/save-panel/index.tsx", "../../../../style-runtime/src/index.ts", "../../../src/components/save-panel/style.module.scss"],
4
- "sourcesContent": ["import { useState } from '@wordpress/element';\nimport { Modal } from '@wordpress/components';\nimport { EntitiesSavedStates } from '@wordpress/editor';\nimport { __ } from '@wordpress/i18n';\nimport useSaveShortcut from './use-save-shortcut';\nimport styles from './style.module.scss';\n\nexport default function SavePanel() {\n\tconst [ isOpen, setIsOpen ] = useState< boolean >( false );\n\tuseSaveShortcut( {\n\t\topenSavePanel: () => setIsOpen( true ),\n\t} );\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\treturn (\n\t\t<Modal\n\t\t\tclassName={ styles.modal }\n\t\t\tonRequestClose={ () => setIsOpen( false ) }\n\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\tsize=\"small\"\n\t\t>\n\t\t\t<EntitiesSavedStates\n\t\t\t\tclose={ () => setIsOpen( false ) }\n\t\t\t\tvariant=\"inline\"\n\t\t\t/>\n\t\t</Modal>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"df1a59bc40\", \"@media (min-width:600px){._77efcb9ca06f5774__modal{width:600px}}\");\n}\nexport default {\"modal\":\"_77efcb9ca06f5774__modal\"};\n"],
5
- "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAS,2BAA2B;AACpC,SAAS,UAAU;AACnB,OAAO,qBAAqB;;;ACM5B,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACr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../style-runtime/src/index.ts","../../../src/components/save-panel/style.module.scss","../../../src/components/save-panel/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"e8f942db13\", \"@media (min-width:600px){._1bb5b45e7ea3b538__modal{width:600px}}\");\n}\nexport default {\"modal\":\"_1bb5b45e7ea3b538__modal\"};\n","import { useState } from '@wordpress/element';\nimport { Modal } from '@wordpress/components';\nimport { EntitiesSavedStates } from '@wordpress/editor';\nimport { __ } from '@wordpress/i18n';\nimport useSaveShortcut from './use-save-shortcut';\nimport styles from './style.module.scss';\n\nexport default function SavePanel() {\n\tconst [ isOpen, setIsOpen ] = useState< boolean >( false );\n\tuseSaveShortcut( {\n\t\topenSavePanel: () => setIsOpen( true ),\n\t} );\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\treturn (\n\t\t<Modal\n\t\t\tclassName={ styles.modal }\n\t\t\tonRequestClose={ () => setIsOpen( false ) }\n\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\tsize=\"small\"\n\t\t>\n\t\t\t<EntitiesSavedStates\n\t\t\t\tclose={ () => setIsOpen( false ) }\n\t\t\t\tvariant=\"inline\"\n\t\t\t/>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO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;;;;;;;;;;AAaA,SAAgB,cAAe,MAAc,KAAc;CAC1D,MAAM,UAAU,WAAW;CAE3B,QAAQ,OAAO,IAAK,MAAM,GAAI;CAE9B,KAAM,MAAM,kBAAkB,QAAQ,UAAU,KAAK,GACpD,YAAa,gBAAgB,MAAM,GAAI;AAEzC;;ACpKA,IAAI,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa,QAC9D,cAAc,cAAc,kEAAkE;AAE/F,IAAA,uBAAe,EAAC,SAAQ,2BAA0B;;ACGlD,SAAwB,YAAY;CACnC,MAAM,CAAE,QAAQ,aAAc,SAAqB,KAAM;CACzD,gBAAiB,EAChB,qBAAqB,UAAW,IAAK,EACtC,CAAE;CACF,IAAK,CAAE,QACN,OAAO;CAER,OACC,oBAAC,OAAD;EACC,WAAYA,qBAAO;EACnB,sBAAuB,UAAW,KAAM;EACxC,OAAQ,GAAI,gBAAiB;EAC7B,MAAK;EAEL,UAAA,oBAAC,qBAAD;GACC,aAAc,UAAW,KAAM;GAC/B,SAAQ;EACR,CAAA;CACK,CAAA;AAET"}
@@ -1,55 +1,46 @@
1
- // packages/boot/src/components/save-panel/use-save-shortcut.ts
2
1
  import { useEffect } from "@wordpress/element";
3
- import {
4
- useShortcut,
5
- store as keyboardShortcutsStore
6
- } from "@wordpress/keyboard-shortcuts";
2
+ import { store, useShortcut } from "@wordpress/keyboard-shortcuts";
7
3
  import { __ } from "@wordpress/i18n";
8
4
  import { useDispatch, useSelect } from "@wordpress/data";
9
- import { store as coreStore } from "@wordpress/core-data";
10
- import { store as editorStore } from "@wordpress/editor";
11
- var shortcutName = "core/boot/save";
12
- function useSaveShortcut({
13
- openSavePanel
14
- }) {
15
- const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } = useSelect(coreStore);
16
- const { hasNonPostEntityChanges, isPostSavingLocked } = useSelect(editorStore);
17
- const { savePost } = useDispatch(editorStore);
18
- const { registerShortcut, unregisterShortcut } = useDispatch(
19
- keyboardShortcutsStore
20
- );
21
- useEffect(() => {
22
- registerShortcut({
23
- name: shortcutName,
24
- category: "global",
25
- description: __("Save your changes."),
26
- keyCombination: {
27
- modifier: "primary",
28
- character: "s"
29
- }
30
- });
31
- return () => {
32
- unregisterShortcut(shortcutName);
33
- };
34
- }, [registerShortcut, unregisterShortcut]);
35
- useShortcut(shortcutName, (event) => {
36
- event.preventDefault();
37
- const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
38
- const hasDirtyEntities = !!dirtyEntityRecords.length;
39
- const isSaving = dirtyEntityRecords.some(
40
- (record) => isSavingEntityRecord(record.kind, record.name, record.key)
41
- );
42
- if (!hasDirtyEntities || isSaving) {
43
- return;
44
- }
45
- if (hasNonPostEntityChanges()) {
46
- openSavePanel();
47
- } else if (!isPostSavingLocked()) {
48
- savePost();
49
- }
50
- });
5
+ import { store as store$1 } from "@wordpress/core-data";
6
+ import { store as store$2 } from "@wordpress/editor";
7
+ // packages/boot/src/components/save-panel/use-save-shortcut.ts
8
+ const shortcutName = "core/boot/save";
9
+ /**
10
+ * Register the save keyboard shortcut in view mode.
11
+ *
12
+ * @param param0 Object containing the function to open the save panel.
13
+ * @param param0.openSavePanel Function to open the save panel.
14
+ */
15
+ function useSaveShortcut({ openSavePanel }) {
16
+ const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } = useSelect(store$1);
17
+ const { hasNonPostEntityChanges, isPostSavingLocked } = useSelect(store$2);
18
+ const { savePost } = useDispatch(store$2);
19
+ const { registerShortcut, unregisterShortcut } = useDispatch(store);
20
+ useEffect(() => {
21
+ registerShortcut({
22
+ name: shortcutName,
23
+ category: "global",
24
+ description: __("Save your changes."),
25
+ keyCombination: {
26
+ modifier: "primary",
27
+ character: "s"
28
+ }
29
+ });
30
+ return () => {
31
+ unregisterShortcut(shortcutName);
32
+ };
33
+ }, [registerShortcut, unregisterShortcut]);
34
+ useShortcut(shortcutName, (event) => {
35
+ event.preventDefault();
36
+ const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
37
+ const hasDirtyEntities = !!dirtyEntityRecords.length;
38
+ const isSaving = dirtyEntityRecords.some((record) => isSavingEntityRecord(record.kind, record.name, record.key));
39
+ if (!hasDirtyEntities || isSaving) return;
40
+ if (hasNonPostEntityChanges()) openSavePanel();
41
+ else if (!isPostSavingLocked()) savePost();
42
+ });
51
43
  }
52
- export {
53
- useSaveShortcut as default
54
- };
55
- //# sourceMappingURL=use-save-shortcut.mjs.map
44
+ export { useSaveShortcut as default };
45
+
46
+ //# sourceMappingURL=use-save-shortcut.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/save-panel/use-save-shortcut.ts"],
4
- "sourcesContent": ["import { useEffect } from '@wordpress/element';\nimport {\n\tuseShortcut,\n\tstore as keyboardShortcutsStore,\n} from '@wordpress/keyboard-shortcuts';\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\n\nconst shortcutName = 'core/boot/save';\n\n/**\n * Register the save keyboard shortcut in view mode.\n *\n * @param param0 Object containing the function to open the save panel.\n * @param param0.openSavePanel Function to open the save panel.\n */\nexport default function useSaveShortcut( {\n\topenSavePanel,\n}: {\n\topenSavePanel: () => void;\n} ) {\n\tconst { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } =\n\t\tuseSelect( coreStore );\n\tconst { hasNonPostEntityChanges, isPostSavingLocked } =\n\t\tuseSelect( editorStore );\n\tconst { savePost } = useDispatch( editorStore );\n\tconst { registerShortcut, unregisterShortcut } = useDispatch(\n\t\tkeyboardShortcutsStore\n\t);\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: shortcutName,\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Save your changes.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 's',\n\t\t\t},\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterShortcut( shortcutName );\n\t\t};\n\t}, [ registerShortcut, unregisterShortcut ] );\n\n\tuseShortcut( shortcutName, ( event: Event ) => {\n\t\tevent.preventDefault();\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\tconst hasDirtyEntities = !! dirtyEntityRecords.length;\n\t\tconst isSaving = dirtyEntityRecords.some( ( record ) =>\n\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t);\n\t\tif ( ! hasDirtyEntities || isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasNonPostEntityChanges() ) {\n\t\t\topenSavePanel();\n\t\t} else if ( ! isPostSavingLocked() ) {\n\t\t\tsavePost();\n\t\t}\n\t} );\n}\n"],
5
- "mappings": ";AAAA,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA,SAAS;AAAA,OACH;AACP,SAAS,UAAU;AACnB,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,mBAAmB;AAErC,IAAM,eAAe;AAQN,SAAR,gBAAkC;AAAA,EACxC;AACD,GAEI;AACH,QAAM,EAAE,qCAAqC,qBAAqB,IACjE,UAAW,SAAU;AACtB,QAAM,EAAE,yBAAyB,mBAAmB,IACnD,UAAW,WAAY;AACxB,QAAM,EAAE,SAAS,IAAI,YAAa,WAAY;AAC9C,QAAM,EAAE,kBAAkB,mBAAmB,IAAI;AAAA,IAChD;AAAA,EACD;AACA,YAAW,MAAM;AAChB,qBAAkB;AAAA,MACjB,MAAM;AAAA,MACN,UAAU;AAAA,MACV,aAAa,GAAI,oBAAqB;AAAA,MACtC,gBAAgB;AAAA,QACf,UAAU;AAAA,QACV,WAAW;AAAA,MACZ;AAAA,IACD,CAAE;AACF,WAAO,MAAM;AACZ,yBAAoB,YAAa;AAAA,IAClC;AAAA,EACD,GAAG,CAAE,kBAAkB,kBAAmB,CAAE;AAE5C,cAAa,cAAc,CAAE,UAAkB;AAC9C,UAAM,eAAe;AACrB,UAAM,qBAAqB,oCAAoC;AAC/D,UAAM,mBAAmB,CAAC,CAAE,mBAAmB;AAC/C,UAAM,WAAW,mBAAmB;AAAA,MAAM,CAAE,WAC3C,qBAAsB,OAAO,MAAM,OAAO,MAAM,OAAO,GAAI;AAAA,IAC5D;AACA,QAAK,CAAE,oBAAoB,UAAW;AACrC;AAAA,IACD;AACA,QAAK,wBAAwB,GAAI;AAChC,oBAAc;AAAA,IACf,WAAY,CAAE,mBAAmB,GAAI;AACpC,eAAS;AAAA,IACV;AAAA,EACD,CAAE;AACH;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-save-shortcut.mjs","names":["coreStore","editorStore","keyboardShortcutsStore"],"sources":["../../../src/components/save-panel/use-save-shortcut.ts"],"sourcesContent":["import { useEffect } from '@wordpress/element';\nimport {\n\tuseShortcut,\n\tstore as keyboardShortcutsStore,\n} from '@wordpress/keyboard-shortcuts';\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\n\nconst shortcutName = 'core/boot/save';\n\n/**\n * Register the save keyboard shortcut in view mode.\n *\n * @param param0 Object containing the function to open the save panel.\n * @param param0.openSavePanel Function to open the save panel.\n */\nexport default function useSaveShortcut( {\n\topenSavePanel,\n}: {\n\topenSavePanel: () => void;\n} ) {\n\tconst { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } =\n\t\tuseSelect( coreStore );\n\tconst { hasNonPostEntityChanges, isPostSavingLocked } =\n\t\tuseSelect( editorStore );\n\tconst { savePost } = useDispatch( editorStore );\n\tconst { registerShortcut, unregisterShortcut } = useDispatch(\n\t\tkeyboardShortcutsStore\n\t);\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: shortcutName,\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Save your changes.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 's',\n\t\t\t},\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterShortcut( shortcutName );\n\t\t};\n\t}, [ registerShortcut, unregisterShortcut ] );\n\n\tuseShortcut( shortcutName, ( event: Event ) => {\n\t\tevent.preventDefault();\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\tconst hasDirtyEntities = !! dirtyEntityRecords.length;\n\t\tconst isSaving = dirtyEntityRecords.some( ( record ) =>\n\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t);\n\t\tif ( ! hasDirtyEntities || isSaving ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( hasNonPostEntityChanges() ) {\n\t\t\topenSavePanel();\n\t\t} else if ( ! isPostSavingLocked() ) {\n\t\t\tsavePost();\n\t\t}\n\t} );\n}\n"],"mappings":";;;;;;;AAUA,MAAM,eAAe;;;;;;;AAQrB,SAAwB,gBAAiB,EACxC,iBAGG;CACH,MAAM,EAAE,qCAAqC,yBAC5C,UAAWA,OAAU;CACtB,MAAM,EAAE,yBAAyB,uBAChC,UAAWC,OAAY;CACxB,MAAM,EAAE,aAAa,YAAaA,OAAY;CAC9C,MAAM,EAAE,kBAAkB,uBAAuB,YAChDC,KACD;CACA,gBAAiB;EAChB,iBAAkB;GACjB,MAAM;GACN,UAAU;GACV,aAAa,GAAI,oBAAqB;GACtC,gBAAgB;IACf,UAAU;IACV,WAAW;GACZ;EACD,CAAE;EACF,aAAa;GACZ,mBAAoB,YAAa;EAClC;CACD,GAAG,CAAE,kBAAkB,kBAAmB,CAAE;CAE5C,YAAa,eAAgB,UAAkB;EAC9C,MAAM,eAAe;EACrB,MAAM,qBAAqB,oCAAoC;EAC/D,MAAM,mBAAmB,CAAC,CAAE,mBAAmB;EAC/C,MAAM,WAAW,mBAAmB,MAAQ,WAC3C,qBAAsB,OAAO,MAAM,OAAO,MAAM,OAAO,GAAI,CAC5D;EACA,IAAK,CAAE,oBAAoB,UAC1B;EAED,IAAK,wBAAwB,GAC5B,cAAc;OACR,IAAK,CAAE,mBAAmB,GAChC,SAAS;CAEX,CAAE;AACH"}