UNPKG

@wordpress/global-styles-ui

Version:
8 lines (7 loc) • 1.35 kB
{ "version": 3, "sources": ["../../src/presets/use-presets.ts"], "sourcesContent": ["import type { BasePreset } from '@wordpress/global-styles-engine';\nimport { useSetting } from '../hooks';\n\nconst EMPTY_ARRAY: any[] = [];\n\n/**\n * Read + mutate the preset array stored at `${settingsPath}.${origin}`.\n *\n * `presets` reflects the merged (user-edited) value; `basePresets` is read\n * explicitly from the theme base, used to compare against or reset to the\n * theme-provided values.\n *\n * @param settingsPath Origin-keyed base path, e.g. 'shadow.presets'.\n * @param origin 'default' | 'theme' | 'custom'.\n */\nexport function usePresets< T extends BasePreset >(\n\tsettingsPath: string,\n\torigin: string\n) {\n\tconst path = `${ settingsPath }.${ origin }`;\n\tconst [ presets = EMPTY_ARRAY, setPresets ] = useSetting< T[] >( path );\n\tconst [ basePresets = EMPTY_ARRAY ] = useSetting< T[] >(\n\t\tpath,\n\t\tundefined,\n\t\t'base'\n\t);\n\n\treturn { presets, basePresets, setPresets };\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAE3B,IAAM,cAAqB,CAAC;AAYrB,SAAS,WACf,cACA,QACC;AACD,QAAM,OAAO,GAAI,YAAa,IAAK,MAAO;AAC1C,QAAM,CAAE,UAAU,aAAa,UAAW,QAAI,yBAAmB,IAAK;AACtE,QAAM,CAAE,cAAc,WAAY,QAAI;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,SAAO,EAAE,SAAS,aAAa,WAAW;AAC3C;", "names": [] }