{
  "version": 3,
  "sources": ["../../../src/components/widget-attributes/use-inline-fit.ts"],
  "sourcesContent": ["import type { Ref } from 'react';\nimport { useResizeObserver } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\nimport { useWidgetHeaderAvailableSize } from '../widget-header/widget-header-fit';\n\ninterface InlineFitOptions {\n\t/**\n\t * Holds the current presentation while the user interacts with it (an\n\t * open dropdown, focus inside the inline form). Measurements keep\n\t * flowing; the pending transition applies when the hold releases.\n\t */\n\tlocked?: boolean;\n}\n\ninterface InlineFit {\n\t/**\n\t * Ref for the element wrapping the inline controls at their natural\n\t * width. While mounted, the measurement tracks it live; when the caller\n\t * unmounts it (collapsed presentation), the last value is retained and\n\t * drives the expand-back decision, and remounting re-measures it.\n\t */\n\tmeasureRef: Ref< HTMLDivElement >;\n\n\t/**\n\t * Whether the inline controls exceed the header's budget and the\n\t * collapsed presentation should show instead.\n\t */\n\tcollapsed: boolean;\n}\n\n/**\n * Decides whether the inline attribute controls fit the space the header\n * row can grant its toolbar.\n *\n * @param {InlineFitOptions} [options] Fit options.\n */\nexport function useInlineFit( options: InlineFitOptions = {} ): InlineFit {\n\tconst { locked = false } = options;\n\n\tconst availableSize = useWidgetHeaderAvailableSize();\n\tconst [ naturalSize, setNaturalSize ] = useState( 0 );\n\n\tconst measureRef = useResizeObserver< HTMLDivElement >( ( [ entry ] ) =>\n\t\tsetNaturalSize( entry.contentRect.width )\n\t);\n\n\t// The zero guards keep environments without layout (JSDOM) on the\n\t// inline presentation.\n\tconst computed =\n\t\tavailableSize !== null &&\n\t\tnaturalSize > 0 &&\n\t\tnaturalSize > availableSize;\n\n\t// The latch: while locked, the surface the user is interacting with\n\t// must not be replaced under them, so the last unlocked decision holds.\n\t// Releasing the lock lets the pending transition apply.\n\tconst [ held, setHeld ] = useState( computed );\n\tif ( ! locked && held !== computed ) {\n\t\tsetHeld( computed );\n\t}\n\n\treturn { measureRef, collapsed: locked ? held : computed };\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAkC;AAClC,qBAAyB;AACzB,+BAA6C;AAiCtC,SAAS,aAAc,UAA4B,CAAC,GAAe;AACzE,QAAM,EAAE,SAAS,MAAM,IAAI;AAE3B,QAAM,oBAAgB,uDAA6B;AACnD,QAAM,CAAE,aAAa,cAAe,QAAI,yBAAU,CAAE;AAEpD,QAAM,iBAAa;AAAA,IAAqC,CAAE,CAAE,KAAM,MACjE,eAAgB,MAAM,YAAY,KAAM;AAAA,EACzC;AAIA,QAAM,WACL,kBAAkB,QAClB,cAAc,KACd,cAAc;AAKf,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAU,QAAS;AAC7C,MAAK,CAAE,UAAU,SAAS,UAAW;AACpC,YAAS,QAAS;AAAA,EACnB;AAEA,SAAO,EAAE,YAAY,WAAW,SAAS,OAAO,SAAS;AAC1D;",
  "names": []
}
