{
  "version": 3,
  "sources": ["../../../src/components/layout/hooks.js"],
  "sourcesContent": ["import { useEffect, useState } from '@wordpress/element';\nimport { select, subscribe } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\nconst MAX_LOADING_TIME = 10000; // 10 seconds\nconst MAX_PAUSE_TIME = 100;\n\n/**\n * Waits until the site editor has finished its initial loading.\n *\n * Resolves when there's a pause in resolving selectors (no active requests\n * for at least MAX_PAUSE_TIME ms), or after MAX_LOADING_TIME as a fallback\n * to prevent failed requests from blocking the editor indefinitely.\n *\n * @return {Promise<void>} Resolves when loading is considered complete.\n */\nfunction waitWhileSiteEditorLoading() {\n\tlet pauseTimeout;\n\n\tconst { promise, resolve } = Promise.withResolvers();\n\n\tfunction finish() {\n\t\tunsubscribe();\n\t\tclearTimeout( pauseTimeout );\n\t\tclearTimeout( maxTimeout );\n\t\tresolve();\n\t}\n\n\t/*\n\t * If the maximum expected loading time has passed, we consider the\n\t * editor loaded, in order to prevent any failed requests from blocking\n\t * the editor canvas from appearing.\n\t */\n\tconst maxTimeout = setTimeout( finish, MAX_LOADING_TIME );\n\n\tfunction checkResolving() {\n\t\tconst isResolving = select( coreStore ).hasResolvingSelectors();\n\n\t\tif ( isResolving ) {\n\t\t\tclearTimeout( pauseTimeout );\n\t\t\tpauseTimeout = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * We're using an arbitrary 100ms timeout here to catch brief\n\t\t * moments without any resolving selectors that would result in\n\t\t * displaying brief flickers of loading state and loaded state.\n\t\t *\n\t\t * It's worth experimenting with different values, since this also\n\t\t * adds 100ms of artificial delay after loading has finished.\n\t\t */\n\t\tif ( ! pauseTimeout ) {\n\t\t\tpauseTimeout = setTimeout( finish, MAX_PAUSE_TIME );\n\t\t}\n\t}\n\n\tconst unsubscribe = subscribe( checkResolving, coreStore );\n\tcheckResolving();\n\n\tfunction cancel() {\n\t\tunsubscribe();\n\t\tclearTimeout( pauseTimeout );\n\t\tclearTimeout( maxTimeout );\n\t}\n\n\treturn [ promise, cancel ];\n}\n\nexport function useIsSiteEditorLoading() {\n\tconst [ loaded, setLoaded ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst [ promise, cancel ] = waitWhileSiteEditorLoading();\n\t\tpromise.then( () => setLoaded( true ) );\n\t\treturn cancel;\n\t}, [] );\n\n\treturn ! loaded;\n}\n"],
  "mappings": ";AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,QAAQ,iBAAiB;AAClC,SAAS,SAAS,iBAAiB;AAEnC,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AAWvB,SAAS,6BAA6B;AACrC,MAAI;AAEJ,QAAM,EAAE,SAAS,QAAQ,IAAI,QAAQ,cAAc;AAEnD,WAAS,SAAS;AACjB,gBAAY;AACZ,iBAAc,YAAa;AAC3B,iBAAc,UAAW;AACzB,YAAQ;AAAA,EACT;AAOA,QAAM,aAAa,WAAY,QAAQ,gBAAiB;AAExD,WAAS,iBAAiB;AACzB,UAAM,cAAc,OAAQ,SAAU,EAAE,sBAAsB;AAE9D,QAAK,aAAc;AAClB,mBAAc,YAAa;AAC3B,qBAAe;AACf;AAAA,IACD;AAUA,QAAK,CAAE,cAAe;AACrB,qBAAe,WAAY,QAAQ,cAAe;AAAA,IACnD;AAAA,EACD;AAEA,QAAM,cAAc,UAAW,gBAAgB,SAAU;AACzD,iBAAe;AAEf,WAAS,SAAS;AACjB,gBAAY;AACZ,iBAAc,YAAa;AAC3B,iBAAc,UAAW;AAAA,EAC1B;AAEA,SAAO,CAAE,SAAS,MAAO;AAC1B;AAEO,SAAS,yBAAyB;AACxC,QAAM,CAAE,QAAQ,SAAU,IAAI,SAAU,KAAM;AAE9C,YAAW,MAAM;AAChB,UAAM,CAAE,SAAS,MAAO,IAAI,2BAA2B;AACvD,YAAQ,KAAM,MAAM,UAAW,IAAK,CAAE;AACtC,WAAO;AAAA,EACR,GAAG,CAAC,CAAE;AAEN,SAAO,CAAE;AACV;",
  "names": []
}
