@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
1 lines • 3.57 kB
Source Map (JSON)
{"version":3,"file":"dimensions-panel.cjs","names":["unlock","blockEditorPrivateApis","useStyle","useSetting","useMemo"],"sources":["../src/dimensions-panel.tsx"],"sourcesContent":["import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useMemo } from '@wordpress/element';\nimport { useStyle, useSetting } from './hooks';\nimport { unlock } from './lock-unlock';\n\nconst { useSettingsForBlockElement, DimensionsPanel: StylesDimensionsPanel } =\n\tunlock( blockEditorPrivateApis );\n\nconst DEFAULT_CONTROLS = {\n\tcontentSize: true,\n\twideSize: true,\n\tpadding: true,\n\tmargin: true,\n\tblockGap: true,\n\theight: true,\n\tminHeight: true,\n\tminWidth: true,\n\twidth: true,\n\tchildLayout: false,\n};\n\nexport default function DimensionsPanel() {\n\tconst [ style ] = useStyle( '', undefined, 'user', false );\n\tconst [ inheritedStyle, setStyle ] = useStyle(\n\t\t'',\n\t\tundefined,\n\t\t'merged',\n\t\tfalse\n\t);\n\tconst [ userSettings ] = useSetting( '', undefined, 'user' );\n\tconst [ rawSettings, setSettings ] = useSetting( '' );\n\tconst settings = useSettingsForBlockElement( rawSettings );\n\n\t// These intermediary objects are needed because the \"layout\" property is stored\n\t// in settings rather than styles.\n\tconst inheritedStyleWithLayout = useMemo( () => {\n\t\treturn {\n\t\t\t...inheritedStyle,\n\t\t\tlayout: settings.layout,\n\t\t};\n\t}, [ inheritedStyle, settings.layout ] );\n\n\tconst styleWithLayout = useMemo( () => {\n\t\treturn {\n\t\t\t...style,\n\t\t\tlayout: userSettings.layout,\n\t\t};\n\t}, [ style, userSettings.layout ] );\n\n\tconst onChange = ( newStyle: any ) => {\n\t\tconst updatedStyle = { ...newStyle };\n\t\tdelete updatedStyle.layout;\n\t\tsetStyle( updatedStyle );\n\n\t\tif ( newStyle.layout !== userSettings.layout ) {\n\t\t\tconst updatedSettings = {\n\t\t\t\t...userSettings,\n\t\t\t\tlayout: newStyle.layout,\n\t\t\t};\n\n\t\t\t// Ensure any changes to layout definitions are not persisted.\n\t\t\tif ( updatedSettings.layout?.definitions ) {\n\t\t\t\tdelete updatedSettings.layout.definitions;\n\t\t\t}\n\n\t\t\tsetSettings( updatedSettings );\n\t\t}\n\t};\n\n\treturn (\n\t\t<StylesDimensionsPanel\n\t\t\tinheritedValue={ inheritedStyleWithLayout }\n\t\t\tvalue={ styleWithLayout }\n\t\t\tonChange={ onChange }\n\t\t\tsettings={ settings }\n\t\t\tincludeLayoutControls\n\t\t\tdefaultControls={ DEFAULT_CONTROLS }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;;;AAKA,MAAM,EAAE,4BAA4B,iBAAiB,2BAAA,GACpDA,iBAAAA,OAAAA,CAAQC,wBAAAA,WAAuB;AAEhC,MAAM,mBAAmB;CACxB,aAAa;CACb,UAAU;CACV,SAAS;CACT,QAAQ;CACR,UAAU;CACV,QAAQ;CACR,WAAW;CACX,UAAU;CACV,OAAO;CACP,aAAa;AACd;AAEA,SAAwB,kBAAkB;CACzC,MAAM,CAAE,UAAA,GAAUC,WAAAA,SAAAA,CAAU,IAAI,KAAA,GAAW,QAAQ,KAAM;CACzD,MAAM,CAAE,gBAAgB,aAAA,GAAaA,WAAAA,SAAAA,CACpC,IACA,KAAA,GACA,UACA,KACD;CACA,MAAM,CAAE,iBAAA,GAAiBC,WAAAA,WAAAA,CAAY,IAAI,KAAA,GAAW,MAAO;CAC3D,MAAM,CAAE,aAAa,gBAAA,GAAgBA,WAAAA,WAAAA,CAAY,EAAG;CACpD,MAAM,WAAW,2BAA4B,WAAY;CAIzD,MAAM,4BAAA,GAA2BC,mBAAAA,QAAAA,OAAe;EAC/C,OAAO;GACN,GAAG;GACH,QAAQ,SAAS;EAClB;CACD,GAAG,CAAE,gBAAgB,SAAS,MAAO,CAAE;CAEvC,MAAM,mBAAA,GAAkBA,mBAAAA,QAAAA,OAAe;EACtC,OAAO;GACN,GAAG;GACH,QAAQ,a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