UNPKG

@wordpress/block-editor

Version:
66 lines (62 loc) 2.07 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.useSetting = useSetting; exports.useSettings = useSettings; var _data = require("@wordpress/data"); var _deprecated = _interopRequireDefault(require("@wordpress/deprecated")); var _blockEdit = require("../block-edit"); var _store = require("../../store"); var _lockUnlock = require("../../lock-unlock"); /** * WordPress dependencies */ /** * Internal dependencies */ /** * Hook that retrieves the given settings for the block instance in use. * * It looks up the settings first in the block instance hierarchy. * If none are found, it'll look them up in the block editor settings. * * @param {string[]} paths The paths to the settings. * @return {any[]} Returns the values defined for the settings. * @example * ```js * const [ fixed, sticky ] = useSettings( 'position.fixed', 'position.sticky' ); * ``` */ function useSettings(...paths) { const { clientId = null } = (0, _blockEdit.useBlockEditContext)(); return (0, _data.useSelect)(select => (0, _lockUnlock.unlock)(select(_store.store)).getBlockSettings(clientId, ...paths), [clientId, ...paths]); } /** * Hook that retrieves the given setting for the block instance in use. * * It looks up the setting first in the block instance hierarchy. * If none is found, it'll look it up in the block editor settings. * * @deprecated 6.5.0 Use useSettings instead. * * @param {string} path The path to the setting. * @return {any} Returns the value defined for the setting. * @example * ```js * const isEnabled = useSetting( 'typography.dropCap' ); * ``` */ function useSetting(path) { (0, _deprecated.default)('wp.blockEditor.useSetting', { since: '6.5', alternative: 'wp.blockEditor.useSettings', note: 'The new useSettings function can retrieve multiple settings at once, with better performance.' }); const [value] = useSettings(path); return value; } //# sourceMappingURL=index.js.map