@wordpress/components 35.1.1-next.v.202606191442.0 → 36.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/CONTRIBUTING.md +33 -26
- package/build/box-control/{input-control.cjs → box-input-control.cjs} +9 -9
- package/build/box-control/box-input-control.cjs.map +7 -0
- package/build/box-control/index.cjs +9 -25
- package/build/box-control/index.cjs.map +3 -3
- package/build/disabled/index.cjs.map +2 -2
- package/build/divider/component.cjs +108 -3
- package/build/divider/component.cjs.map +4 -4
- package/build/higher-order/with-fallback-styles/index.cjs +18 -44
- package/build/higher-order/with-fallback-styles/index.cjs.map +2 -2
- package/build/text-control/index.cjs +3 -12
- package/build/text-control/index.cjs.map +3 -3
- package/build/validated-form-controls/components/text-control.cjs +0 -1
- package/build/validated-form-controls/components/text-control.cjs.map +2 -2
- package/build-module/box-control/{input-control.mjs → box-input-control.mjs} +6 -6
- package/build-module/box-control/box-input-control.mjs.map +7 -0
- package/build-module/box-control/index.mjs +9 -25
- package/build-module/box-control/index.mjs.map +2 -2
- package/build-module/disabled/index.mjs.map +2 -2
- package/build-module/divider/component.mjs +108 -3
- package/build-module/divider/component.mjs.map +3 -3
- package/build-module/higher-order/with-fallback-styles/index.mjs +20 -46
- package/build-module/higher-order/with-fallback-styles/index.mjs.map +2 -2
- package/build-module/text-control/index.mjs +3 -12
- package/build-module/text-control/index.mjs.map +2 -2
- package/build-module/validated-form-controls/components/text-control.mjs +0 -1
- package/build-module/validated-form-controls/components/text-control.mjs.map +2 -2
- package/build-style/style-rtl.css +3 -19
- package/build-style/style.css +3 -19
- package/build-types/box-control/box-input-control.d.ts +3 -0
- package/build-types/box-control/box-input-control.d.ts.map +1 -0
- package/build-types/box-control/index.d.ts +2 -6
- package/build-types/box-control/index.d.ts.map +1 -1
- package/build-types/box-control/stories/index.story.d.ts.map +1 -1
- package/build-types/box-control/types.d.ts +7 -6
- package/build-types/box-control/types.d.ts.map +1 -1
- package/build-types/disabled/index.d.ts +0 -1
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/disabled/stories/index.story.d.ts.map +1 -1
- package/build-types/divider/component.d.ts.map +1 -1
- package/build-types/higher-order/with-fallback-styles/index.d.ts +1 -35
- package/build-types/higher-order/with-fallback-styles/index.d.ts.map +1 -1
- package/build-types/higher-order/with-fallback-styles/test/index.d.ts +2 -0
- package/build-types/higher-order/with-fallback-styles/test/index.d.ts.map +1 -0
- package/build-types/icon/stories/index.story.d.ts +0 -1
- package/build-types/icon/stories/index.story.d.ts.map +1 -1
- package/build-types/placeholder/stories/index.story.d.ts.map +1 -1
- package/build-types/resizable-box/index.d.ts +0 -2
- package/build-types/resizable-box/index.d.ts.map +1 -1
- package/build-types/resizable-box/stories/index.story.d.ts +0 -2
- package/build-types/resizable-box/stories/index.story.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +0 -1
- package/build-types/text-control/index.d.ts.map +1 -1
- package/build-types/text-control/stories/index.story.d.ts.map +1 -1
- package/build-types/text-control/types.d.ts +2 -1
- package/build-types/text-control/types.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/combobox-control.d.ts +1 -1
- package/build-types/validated-form-controls/components/text-control.d.ts +2 -2
- package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/box-control/README.md +1 -13
- package/src/box-control/{input-control.tsx → box-input-control.tsx} +4 -4
- package/src/box-control/index.tsx +5 -23
- package/src/box-control/stories/index.story.tsx +1 -3
- package/src/box-control/test/index.tsx +15 -2
- package/src/box-control/types.ts +7 -6
- package/src/card/test/__snapshots__/index.tsx.snap +4 -6
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +4 -3
- package/src/custom-select-control/test/index.tsx +1 -1
- package/src/disabled/README.md +0 -1
- package/src/disabled/index.tsx +0 -1
- package/src/disabled/stories/index.story.tsx +0 -1
- package/src/divider/component.tsx +27 -3
- package/src/divider/style.module.scss +21 -0
- package/src/divider/test/index.tsx +21 -11
- package/src/higher-order/with-constrained-tabbing/README.md +0 -2
- package/src/higher-order/with-fallback-styles/index.tsx +31 -61
- package/src/higher-order/with-fallback-styles/test/index.tsx +47 -0
- package/src/higher-order/with-focus-return/README.md +0 -2
- package/src/icon/stories/index.story.tsx +0 -15
- package/src/menu/test/index.tsx +0 -16
- package/src/menu-item/test/__snapshots__/index.js.snap +2 -0
- package/src/modal/test/index.tsx +0 -24
- package/src/navigable-container/test/navigable-menu.tsx +0 -16
- package/src/navigable-container/test/tababble-container.tsx +0 -16
- package/src/navigator/test/index.tsx +0 -24
- package/src/notice/test/__snapshots__/index.tsx.snap +1 -0
- package/src/placeholder/stories/index.story.tsx +0 -1
- package/src/resizable-box/index.tsx +1 -2
- package/src/tab-panel/test/index.tsx +0 -17
- package/src/tabs/test/index.tsx +0 -17
- package/src/text-control/README.md +0 -9
- package/src/text-control/index.tsx +3 -14
- package/src/text-control/stories/index.story.tsx +0 -2
- package/src/text-control/style.scss +7 -11
- package/src/text-control/test/text-control.tsx +1 -5
- package/src/text-control/types.ts +2 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +4 -0
- package/src/tools-panel/tools-panel/README.md +0 -2
- package/src/tree-grid/test/index.tsx +0 -23
- package/src/validated-form-controls/components/text-control.tsx +2 -10
- package/build/box-control/input-control.cjs.map +0 -7
- package/build/divider/styles.cjs +0 -98
- package/build/divider/styles.cjs.map +0 -7
- package/build-module/box-control/input-control.mjs.map +0 -7
- package/build-module/divider/styles.mjs +0 -63
- package/build-module/divider/styles.mjs.map +0 -7
- package/build-types/box-control/input-control.d.ts +0 -3
- package/build-types/box-control/input-control.d.ts.map +0 -1
- package/build-types/divider/styles.d.ts +0 -10
- package/build-types/divider/styles.d.ts.map +0 -1
- package/src/divider/styles.ts +0 -81
- package/src/divider/test/__snapshots__/index.tsx.snap +0 -71
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/higher-order/with-fallback-styles/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { createHigherOrderComponent, useIsomorphicLayoutEffect } from '@wordpress/compose';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport default mapNodeToProps => createHigherOrderComponent(WrappedComponent => {\n return function WithFallbackStyles(props) {\n const [fallbackStyles, setFallbackStyles] = useState(undefined);\n const nodeRef = useRef(null);\n\n // Runs before paint, so the fallback styles apply without a flash.\n useIsomorphicLayoutEffect(() => {\n const node = props.node ?? nodeRef.current;\n // Derived from fallbackStyles: the grab is complete once every\n // mapped value has resolved to a truthy style.\n const grabStylesCompleted = !!fallbackStyles && Object.values(fallbackStyles).every(Boolean);\n if (node && !grabStylesCompleted) {\n const newFallbackStyles = mapNodeToProps(node, props);\n if (!fastDeepEqual(newFallbackStyles, fallbackStyles)) {\n setFallbackStyles(newFallbackStyles);\n }\n }\n });\n const wrappedComponent = /*#__PURE__*/_jsx(WrappedComponent, {\n ...props,\n ...fallbackStyles\n });\n return props.node ? wrappedComponent : /*#__PURE__*/_jsxs(\"div\", {\n ref: nodeRef,\n children: [\" \", wrappedComponent, \" \"]\n });\n };\n}, 'withFallbackStyles');"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,qBAAiC;AACjC,qBAAsE;AACtE,yBAA2C;AAC3C,IAAO,+BAAQ,wBAAkB,2CAA2B,sBAAoB;AAC9E,SAAO,SAAS,mBAAmB,OAAO;AACxC,UAAM,CAAC,gBAAgB,iBAAiB,QAAI,yBAAS,MAAS;AAC9D,UAAM,cAAU,uBAAO,IAAI;AAG3B,kDAA0B,MAAM;AAC9B,YAAM,OAAO,MAAM,QAAQ,QAAQ;AAGnC,YAAM,sBAAsB,CAAC,CAAC,kBAAkB,OAAO,OAAO,cAAc,EAAE,MAAM,OAAO;AAC3F,UAAI,QAAQ,CAAC,qBAAqB;AAChC,cAAM,oBAAoB,eAAe,MAAM,KAAK;AACpD,YAAI,KAAC,WAAAA,SAAc,mBAAmB,cAAc,GAAG;AACrD,4BAAkB,iBAAiB;AAAA,QACrC;AAAA,MACF;AAAA,IACF,CAAC;AACD,UAAM,mBAAgC,uCAAAC,KAAK,kBAAkB;AAAA,MAC3D,GAAG;AAAA,MACH,GAAG;AAAA,IACL,CAAC;AACD,WAAO,MAAM,OAAO,mBAAgC,uCAAAC,MAAM,OAAO;AAAA,MAC/D,KAAK;AAAA,MACL,UAAU,CAAC,KAAK,kBAAkB,GAAG;AAAA,IACvC,CAAC;AAAA,EACH;AACF,GAAG,oBAAoB;",
|
|
6
6
|
"names": ["fastDeepEqual", "_jsx", "_jsxs"]
|
|
7
7
|
}
|
|
@@ -34,17 +34,15 @@ __export(text_control_exports, {
|
|
|
34
34
|
default: () => text_control_default
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(text_control_exports);
|
|
37
|
-
var import_clsx = __toESM(require("clsx"));
|
|
38
37
|
var import_compose = require("@wordpress/compose");
|
|
39
38
|
var import_element = require("@wordpress/element");
|
|
40
39
|
var import_base_control = __toESM(require("../base-control/index.cjs"));
|
|
41
|
-
var import_deprecated_36px_size = require("../utils/deprecated-36px-size.cjs");
|
|
42
40
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
41
|
function UnforwardedTextControl(props, ref) {
|
|
44
42
|
const {
|
|
45
|
-
// Prevent passing
|
|
43
|
+
// Prevent passing legacy props to `input`.
|
|
46
44
|
__nextHasNoMarginBottom: _,
|
|
47
|
-
__next40pxDefaultSize
|
|
45
|
+
__next40pxDefaultSize: __,
|
|
48
46
|
label,
|
|
49
47
|
hideLabelFromVision,
|
|
50
48
|
value,
|
|
@@ -57,11 +55,6 @@ function UnforwardedTextControl(props, ref) {
|
|
|
57
55
|
} = props;
|
|
58
56
|
const id = (0, import_compose.useInstanceId)(TextControl, "inspector-text-control", idProp);
|
|
59
57
|
const onChangeValue = (event) => onChange(event.target.value);
|
|
60
|
-
(0, import_deprecated_36px_size.maybeWarnDeprecated36pxSize)({
|
|
61
|
-
componentName: "TextControl",
|
|
62
|
-
size: void 0,
|
|
63
|
-
__next40pxDefaultSize
|
|
64
|
-
});
|
|
65
58
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base_control.default, {
|
|
66
59
|
label,
|
|
67
60
|
hideLabelFromVision,
|
|
@@ -69,9 +62,7 @@ function UnforwardedTextControl(props, ref) {
|
|
|
69
62
|
help,
|
|
70
63
|
className,
|
|
71
64
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
72
|
-
className:
|
|
73
|
-
"is-next-40px-default-size": __next40pxDefaultSize
|
|
74
|
-
}),
|
|
65
|
+
className: "components-text-control__input",
|
|
75
66
|
type,
|
|
76
67
|
id,
|
|
77
68
|
value,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/text-control/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["_jsx", "BaseControl"
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../base-control';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nfunction UnforwardedTextControl(props, ref) {\n const {\n // Prevent passing legacy props to `input`.\n __nextHasNoMarginBottom: _,\n __next40pxDefaultSize: __,\n label,\n hideLabelFromVision,\n value,\n help,\n id: idProp,\n className,\n onChange,\n type = 'text',\n ...additionalProps\n } = props;\n const id = useInstanceId(TextControl, 'inspector-text-control', idProp);\n const onChangeValue = event => onChange(event.target.value);\n return /*#__PURE__*/_jsx(BaseControl, {\n label: label,\n hideLabelFromVision: hideLabelFromVision,\n id: id,\n help: help,\n className: className,\n children: /*#__PURE__*/_jsx(\"input\", {\n className: \"components-text-control__input\",\n type: type,\n id: id,\n value: value,\n onChange: onChangeValue,\n \"aria-describedby\": !!help ? id + '__help' : undefined,\n ref: ref,\n ...additionalProps\n })\n });\n}\n\n/**\n * TextControl components let users enter and edit text.\n *\n * ```jsx\n * import { TextControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTextControl = () => {\n * const [ className, setClassName ] = useState( '' );\n *\n * return (\n * <TextControl\n * label=\"Additional CSS Class\"\n * value={ className }\n * onChange={ ( value ) => setClassName( value ) }\n * />\n * );\n * };\n * ```\n */\nexport const TextControl = forwardRef(UnforwardedTextControl);\nTextControl.displayName = 'TextControl';\nexport default TextControl;"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qBAA8B;AAC9B,qBAA2B;AAK3B,0BAAwB;AACxB,yBAA4B;AAC5B,SAAS,uBAAuB,OAAO,KAAK;AAC1C,QAAM;AAAA;AAAA,IAEJ,yBAAyB;AAAA,IACzB,uBAAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,GAAG;AAAA,EACL,IAAI;AACJ,QAAM,SAAK,8BAAc,aAAa,0BAA0B,MAAM;AACtE,QAAM,gBAAgB,WAAS,SAAS,MAAM,OAAO,KAAK;AAC1D,SAAoB,uCAAAA,KAAK,oBAAAC,SAAa;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAuB,uCAAAD,KAAK,SAAS;AAAA,MACnC,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,oBAAoB,CAAC,CAAC,OAAO,KAAK,WAAW;AAAA,MAC7C;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AAAA,EACH,CAAC;AACH;AAsBO,IAAM,kBAAc,2BAAW,sBAAsB;AAC5D,YAAY,cAAc;AAC1B,IAAO,uBAAQ;",
|
|
6
|
+
"names": ["_jsx", "BaseControl"]
|
|
7
7
|
}
|
|
@@ -52,7 +52,6 @@ var UnforwardedValidatedTextControl = ({
|
|
|
52
52
|
customValidity,
|
|
53
53
|
getValidityTarget: () => validityTargetRef.current,
|
|
54
54
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_text_control.default, {
|
|
55
|
-
__next40pxDefaultSize: true,
|
|
56
55
|
ref: mergedRefs,
|
|
57
56
|
...restProps
|
|
58
57
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validated-form-controls/components/text-control.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { forwardRef, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport TextControl from '../../text-control';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst UnforwardedValidatedTextControl = ({\n required,\n customValidity,\n markWhenOptional,\n ...restProps\n}, forwardedRef) => {\n const validityTargetRef = useRef(null);\n const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]);\n return /*#__PURE__*/_jsx(ControlWithError, {\n required: required,\n markWhenOptional: markWhenOptional,\n customValidity: customValidity,\n getValidityTarget: () => validityTargetRef.current,\n children: /*#__PURE__*/_jsx(TextControl, {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA6B;AAC7B,qBAAmC;AAKnC,gCAAiC;AACjC,0BAAwB;AACxB,yBAA4B;AAC5B,IAAM,kCAAkC,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAG,iBAAiB;AAClB,QAAM,wBAAoB,uBAAO,IAAI;AACrC,QAAM,iBAAa,6BAAa,CAAC,cAAc,iBAAiB,CAAC;AACjE,SAAoB,uCAAAA,KAAK,4CAAkB;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,MAAM,kBAAkB;AAAA,IAC3C,UAAuB,uCAAAA,KAAK,oBAAAC,SAAa;AAAA,MACvC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMergeRefs } from '@wordpress/compose';\nimport { forwardRef, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { ControlWithError } from '../control-with-error';\nimport TextControl from '../../text-control';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst UnforwardedValidatedTextControl = ({\n required,\n customValidity,\n markWhenOptional,\n ...restProps\n}, forwardedRef) => {\n const validityTargetRef = useRef(null);\n const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]);\n return /*#__PURE__*/_jsx(ControlWithError, {\n required: required,\n markWhenOptional: markWhenOptional,\n customValidity: customValidity,\n getValidityTarget: () => validityTargetRef.current,\n children: /*#__PURE__*/_jsx(TextControl, {\n ref: mergedRefs,\n ...restProps\n })\n });\n};\nexport const ValidatedTextControl = forwardRef(UnforwardedValidatedTextControl);\nValidatedTextControl.displayName = 'ValidatedTextControl';"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA6B;AAC7B,qBAAmC;AAKnC,gCAAiC;AACjC,0BAAwB;AACxB,yBAA4B;AAC5B,IAAM,kCAAkC,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAG,iBAAiB;AAClB,QAAM,wBAAoB,uBAAO,IAAI;AACrC,QAAM,iBAAa,6BAAa,CAAC,cAAc,iBAAiB,CAAC;AACjE,SAAoB,uCAAAA,KAAK,4CAAkB;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,MAAM,kBAAkB;AAAA,IAC3C,UAAuB,uCAAAA,KAAK,oBAAAC,SAAa;AAAA,MACvC,KAAK;AAAA,MACL,GAAG;AAAA,IACL,CAAC;AAAA,EACH,CAAC;AACH;AACO,IAAM,2BAAuB,2BAAW,+BAA+B;AAC9E,qBAAqB,cAAc;",
|
|
6
6
|
"names": ["_jsx", "TextControl"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/components/src/box-control/input-control.tsx
|
|
1
|
+
// packages/components/src/box-control/box-input-control.tsx
|
|
2
2
|
import { useInstanceId } from "@wordpress/compose";
|
|
3
3
|
import { __ } from "@wordpress/i18n";
|
|
4
4
|
import { useState } from "@wordpress/element";
|
|
@@ -46,7 +46,6 @@ function getSidesToModify(side, sides, isAlt) {
|
|
|
46
46
|
return modifiedSides.filter((s) => allowedSides.has(s));
|
|
47
47
|
}
|
|
48
48
|
function BoxInputControl({
|
|
49
|
-
__next40pxDefaultSize,
|
|
50
49
|
onChange = noop,
|
|
51
50
|
onFocus = noop,
|
|
52
51
|
values,
|
|
@@ -57,6 +56,7 @@ function BoxInputControl({
|
|
|
57
56
|
min = 0,
|
|
58
57
|
presets,
|
|
59
58
|
presetKey,
|
|
59
|
+
placeholder: placeholderProp,
|
|
60
60
|
...props
|
|
61
61
|
}) {
|
|
62
62
|
const defaultValuesToModify = getSidesToModify(side, sides);
|
|
@@ -145,7 +145,7 @@ function BoxInputControl({
|
|
|
145
145
|
...props,
|
|
146
146
|
min,
|
|
147
147
|
__shouldNotWarnDeprecated36pxSize: true,
|
|
148
|
-
__next40pxDefaultSize,
|
|
148
|
+
__next40pxDefaultSize: true,
|
|
149
149
|
className: "component-box-control__unit-control",
|
|
150
150
|
id: inputId,
|
|
151
151
|
isPressEnterToChange: true,
|
|
@@ -155,11 +155,11 @@ function BoxInputControl({
|
|
|
155
155
|
onUnitChange: handleOnUnitChange,
|
|
156
156
|
onFocus: handleOnFocus,
|
|
157
157
|
label: LABELS[side],
|
|
158
|
-
placeholder: mixedPlaceholder,
|
|
158
|
+
placeholder: mixedPlaceholder ?? placeholderProp,
|
|
159
159
|
hideLabelFromVision: true
|
|
160
160
|
})
|
|
161
161
|
}), /* @__PURE__ */ _jsx(FlexedRangeControl, {
|
|
162
|
-
__next40pxDefaultSize,
|
|
162
|
+
__next40pxDefaultSize: true,
|
|
163
163
|
__shouldNotWarnDeprecated36pxSize: true,
|
|
164
164
|
"aria-controls": inputId,
|
|
165
165
|
label: LABELS[side],
|
|
@@ -205,4 +205,4 @@ function BoxInputControl({
|
|
|
205
205
|
export {
|
|
206
206
|
BoxInputControl as default
|
|
207
207
|
};
|
|
208
|
-
//# sourceMappingURL=input-control.mjs.map
|
|
208
|
+
//# sourceMappingURL=box-input-control.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/box-control/box-input-control.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { settings } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport Tooltip from '../tooltip';\nimport { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';\nimport { CUSTOM_VALUE_SETTINGS, getMergedValue, getAllowedSides, getPresetIndexFromValue, getPresetValueFromIndex, isValuePreset, isValuesDefined, isValueMixed, LABELS } from './utils';\nimport { FlexedBoxControlIcon, FlexedRangeControl, InputWrapper, StyledUnitControl } from './styles/box-control-styles';\nimport Button from '../button';\nimport { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst noop = () => {};\nfunction getSidesToModify(side, sides, isAlt) {\n const allowedSides = getAllowedSides(sides);\n let modifiedSides = [];\n switch (side) {\n case 'all':\n modifiedSides = ['top', 'bottom', 'left', 'right'];\n break;\n case 'horizontal':\n modifiedSides = ['left', 'right'];\n break;\n case 'vertical':\n modifiedSides = ['top', 'bottom'];\n break;\n default:\n modifiedSides = [side];\n }\n if (isAlt) {\n switch (side) {\n case 'top':\n modifiedSides.push('bottom');\n break;\n case 'bottom':\n modifiedSides.push('top');\n break;\n case 'left':\n modifiedSides.push('left');\n break;\n case 'right':\n modifiedSides.push('right');\n break;\n }\n }\n return modifiedSides.filter(s => allowedSides.has(s));\n}\nexport default function BoxInputControl({\n onChange = noop,\n onFocus = noop,\n values,\n selectedUnits,\n setSelectedUnits,\n sides,\n side,\n min = 0,\n presets,\n presetKey,\n placeholder: placeholderProp,\n ...props\n}) {\n const defaultValuesToModify = getSidesToModify(side, sides);\n const handleOnFocus = event => {\n onFocus(event, {\n side\n });\n };\n const handleOnChange = nextValues => {\n onChange(nextValues);\n };\n const handleRawOnValueChange = next => {\n const nextValues = {\n ...values\n };\n defaultValuesToModify.forEach(modifiedSide => {\n nextValues[modifiedSide] = next;\n });\n handleOnChange(nextValues);\n };\n const handleOnValueChange = (next, extra) => {\n const nextValues = {\n ...values\n };\n const isNumeric = next !== undefined && !isNaN(parseFloat(next));\n const nextValue = isNumeric ? next : undefined;\n const modifiedSides = getSidesToModify(side, sides,\n /**\n * Supports changing pair sides. For example, holding the ALT key\n * when changing the TOP will also update BOTTOM.\n */\n // @ts-expect-error - TODO: event.altKey is only present when the change event was\n // triggered by a keyboard event. Should this feature be implemented differently so\n // it also works with drag events?\n !!extra?.event.altKey);\n modifiedSides.forEach(modifiedSide => {\n nextValues[modifiedSide] = nextValue;\n });\n handleOnChange(nextValues);\n };\n const handleOnUnitChange = next => {\n const newUnits = {\n ...selectedUnits\n };\n defaultValuesToModify.forEach(modifiedSide => {\n newUnits[modifiedSide] = next;\n });\n setSelectedUnits(newUnits);\n };\n const mergedValue = getMergedValue(values, defaultValuesToModify);\n const hasValues = isValuesDefined(values);\n const isMixed = hasValues && defaultValuesToModify.length > 1 && isValueMixed(values, defaultValuesToModify);\n const [parsedQuantity, parsedUnit] = parseQuantityAndUnitFromRawValue(mergedValue);\n const computedUnit = hasValues ? parsedUnit : selectedUnits[defaultValuesToModify[0]];\n const generatedId = useInstanceId(BoxInputControl, 'box-control-input');\n const inputId = [generatedId, side].join('-');\n const isMixedUnit = defaultValuesToModify.length > 1 && mergedValue === undefined && defaultValuesToModify.some(s => selectedUnits[s] !== computedUnit);\n const usedValue = mergedValue === undefined && computedUnit ? computedUnit : mergedValue;\n const mixedPlaceholder = isMixed || isMixedUnit ? __('Mixed') : undefined;\n const hasPresets = presets && presets.length > 0 && presetKey;\n const hasPresetValue = hasPresets && mergedValue !== undefined && !isMixed && isValuePreset(mergedValue, presetKey);\n const [showCustomValueControl, setShowCustomValueControl] = useState(!hasPresets || !hasPresetValue && !isMixed && mergedValue !== undefined);\n const presetIndex = hasPresetValue ? getPresetIndexFromValue(mergedValue, presetKey, presets) : undefined;\n const marks = hasPresets ? [{\n value: 0,\n label: '',\n tooltip: __('None')\n }, ...presets.map((preset, index) => ({\n value: index + 1,\n label: '',\n tooltip: preset.name ?? preset.slug\n }))] : [];\n return /*#__PURE__*/_jsxs(InputWrapper, {\n expanded: true,\n children: [/*#__PURE__*/_jsx(FlexedBoxControlIcon, {\n side: side,\n sides: sides\n }), showCustomValueControl && /*#__PURE__*/_jsxs(_Fragment, {\n children: [/*#__PURE__*/_jsx(Tooltip, {\n placement: \"top-end\",\n text: LABELS[side],\n children: /*#__PURE__*/_jsx(StyledUnitControl, {\n ...props,\n min: min,\n __shouldNotWarnDeprecated36pxSize: true,\n __next40pxDefaultSize: true,\n className: \"component-box-control__unit-control\",\n id: inputId,\n isPressEnterToChange: true,\n disableUnits: isMixed || isMixedUnit,\n value: usedValue,\n onChange: handleOnValueChange,\n onUnitChange: handleOnUnitChange,\n onFocus: handleOnFocus,\n label: LABELS[side],\n placeholder: mixedPlaceholder ?? placeholderProp,\n hideLabelFromVision: true\n })\n }), /*#__PURE__*/_jsx(FlexedRangeControl, {\n __next40pxDefaultSize: true,\n __shouldNotWarnDeprecated36pxSize: true,\n \"aria-controls\": inputId,\n label: LABELS[side],\n hideLabelFromVision: true,\n onChange: newValue => {\n handleOnValueChange(newValue !== undefined ? [newValue, computedUnit].join('') : undefined);\n },\n min: isFinite(min) ? min : 0,\n max: CUSTOM_VALUE_SETTINGS[computedUnit ?? 'px']?.max ?? 10,\n step: CUSTOM_VALUE_SETTINGS[computedUnit ?? 'px']?.step ?? 0.1,\n value: parsedQuantity ?? 0,\n withInputField: false\n })]\n }), hasPresets && !showCustomValueControl && /*#__PURE__*/_jsx(FlexedRangeControl, {\n __next40pxDefaultSize: true,\n className: \"spacing-sizes-control__range-control\",\n value: presetIndex !== undefined ? presetIndex + 1 : 0,\n onChange: newIndex => {\n const newValue = newIndex === 0 || newIndex === undefined ? undefined : getPresetValueFromIndex(newIndex - 1, presetKey, presets);\n handleRawOnValueChange(newValue);\n },\n withInputField: false,\n \"aria-valuenow\": presetIndex !== undefined ? presetIndex + 1 : 0,\n \"aria-valuetext\": marks[presetIndex !== undefined ? presetIndex + 1 : 0].tooltip,\n renderTooltipContent: index => marks[!index ? 0 : index].tooltip,\n min: 0,\n max: marks.length - 1,\n marks: marks,\n label: LABELS[side],\n hideLabelFromVision: true\n }), hasPresets && /*#__PURE__*/_jsx(Button, {\n label: showCustomValueControl ? __('Use size preset') : __('Set custom size'),\n icon: settings,\n onClick: () => {\n setShowCustomValueControl(!showCustomValueControl);\n },\n isPressed: showCustomValueControl,\n size: \"small\",\n iconSize: 24\n })]\n }, `box-control-${side}`);\n}"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,qBAAqB;AAC9B,SAAS,UAAU;AACnB,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AAKzB,OAAO,aAAa;AACpB,SAAS,wCAAwC;AACjD,SAAS,uBAAuB,gBAAgB,iBAAiB,yBAAyB,yBAAyB,eAAe,iBAAiB,cAAc,cAAc;AAC/K,SAAS,sBAAsB,oBAAoB,cAAc,yBAAyB;AAC1F,OAAO,YAAY;AACnB,SAAS,OAAO,MAAM,YAAY,WAAW,QAAQ,aAAa;AAClE,IAAM,OAAO,MAAM;AAAC;AACpB,SAAS,iBAAiB,MAAM,OAAO,OAAO;AAC5C,QAAM,eAAe,gBAAgB,KAAK;AAC1C,MAAI,gBAAgB,CAAC;AACrB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,sBAAgB,CAAC,OAAO,UAAU,QAAQ,OAAO;AACjD;AAAA,IACF,KAAK;AACH,sBAAgB,CAAC,QAAQ,OAAO;AAChC;AAAA,IACF,KAAK;AACH,sBAAgB,CAAC,OAAO,QAAQ;AAChC;AAAA,IACF;AACE,sBAAgB,CAAC,IAAI;AAAA,EACzB;AACA,MAAI,OAAO;AACT,YAAQ,MAAM;AAAA,MACZ,KAAK;AACH,sBAAc,KAAK,QAAQ;AAC3B;AAAA,MACF,KAAK;AACH,sBAAc,KAAK,KAAK;AACxB;AAAA,MACF,KAAK;AACH,sBAAc,KAAK,MAAM;AACzB;AAAA,MACF,KAAK;AACH,sBAAc,KAAK,OAAO;AAC1B;AAAA,IACJ;AAAA,EACF;AACA,SAAO,cAAc,OAAO,OAAK,aAAa,IAAI,CAAC,CAAC;AACtD;AACe,SAAR,gBAAiC;AAAA,EAC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BAAsB,WAAS,MAAM,CAAC,QAAQ,IAAI,KAAK,EAAE;AAAA,MACzD,KAAK;AAAA,MACL,KAAK,MAAM,SAAS;AAAA,MACpB;AAAA,MACA,OAAO,OAAO,IAAI;AAAA,MAClB,qBAAqB;AAAA,IACvB,CAAC,GAAG,cAA2B,qBAAK,QAAQ;AAAA,MAC1C,OAAO,yBAAyB,GAAG,iBAAiB,IAAI,GAAG,iBAAiB;AAAA,MAC5E,MAAM;AAAA,MACN,SAAS,MAAM;AACb,kCAA0B,CAAC,sBAAsB;AAAA,MACnD;AAAA,MACA,WAAW;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,IACZ,CAAC,CAAC;AAAA,EACJ,GAAG,eAAe,IAAI,EAAE;AAC1B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -4,14 +4,13 @@ import { useState } from "@wordpress/element";
|
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
5
|
import warning from "@wordpress/warning";
|
|
6
6
|
import { BaseControl } from "../base-control/index.mjs";
|
|
7
|
-
import
|
|
7
|
+
import BoxInputControl from "./box-input-control.mjs";
|
|
8
8
|
import LinkedButton from "./linked-button.mjs";
|
|
9
9
|
import { Grid } from "../grid/index.mjs";
|
|
10
10
|
import { InputWrapper, ResetButton, LinkedButtonWrapper } from "./styles/box-control-styles.mjs";
|
|
11
11
|
import { parseQuantityAndUnitFromRawValue } from "../unit-control/utils.mjs";
|
|
12
12
|
import { DEFAULT_VALUES, isValueMixed, isValuesDefined, getAllowedSides } from "./utils.mjs";
|
|
13
13
|
import { useControlledState } from "../utils/hooks/index.mjs";
|
|
14
|
-
import { maybeWarnDeprecated36pxSize } from "../utils/deprecated-36px-size.mjs";
|
|
15
14
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
15
|
var defaultInputProps = {
|
|
17
16
|
min: 0
|
|
@@ -23,7 +22,6 @@ function useUniqueId(idProp) {
|
|
|
23
22
|
return idProp || instanceId;
|
|
24
23
|
}
|
|
25
24
|
function BoxControl({
|
|
26
|
-
__next40pxDefaultSize = false,
|
|
27
25
|
id: idProp,
|
|
28
26
|
inputProps = defaultInputProps,
|
|
29
27
|
onChange = noop,
|
|
@@ -80,15 +78,9 @@ function BoxControl({
|
|
|
80
78
|
setSelectedUnits,
|
|
81
79
|
sides,
|
|
82
80
|
values: inputValues,
|
|
83
|
-
__next40pxDefaultSize,
|
|
84
81
|
presets,
|
|
85
82
|
presetKey
|
|
86
83
|
};
|
|
87
|
-
maybeWarnDeprecated36pxSize({
|
|
88
|
-
componentName: "BoxControl",
|
|
89
|
-
__next40pxDefaultSize,
|
|
90
|
-
size: void 0
|
|
91
|
-
});
|
|
92
84
|
const sidesToRender = getAllowedSides(sides);
|
|
93
85
|
if (presets && !presetKey || !presets && presetKey) {
|
|
94
86
|
const definedProp = presets ? "presets" : "presetKey";
|
|
@@ -105,7 +97,7 @@ function BoxControl({
|
|
|
105
97
|
id: headingId,
|
|
106
98
|
children: label
|
|
107
99
|
}), isLinked && /* @__PURE__ */ _jsx(InputWrapper, {
|
|
108
|
-
children: /* @__PURE__ */ _jsx(
|
|
100
|
+
children: /* @__PURE__ */ _jsx(BoxInputControl, {
|
|
109
101
|
side: "all",
|
|
110
102
|
...inputControlProps
|
|
111
103
|
})
|
|
@@ -114,21 +106,13 @@ function BoxControl({
|
|
|
114
106
|
onClick: toggleLinked,
|
|
115
107
|
isLinked
|
|
116
108
|
})
|
|
117
|
-
}), !isLinked && splitOnAxis && ["vertical", "horizontal"].map((axis) => (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)), !isLinked && !splitOnAxis && Array.from(sidesToRender).map((axis) => (
|
|
125
|
-
// Disable reason: the parent component is handling the __next40pxDefaultSize prop
|
|
126
|
-
// eslint-disable-next-line @wordpress/components-no-missing-40px-size-prop
|
|
127
|
-
/* @__PURE__ */ _jsx(InputControl, {
|
|
128
|
-
side: axis,
|
|
129
|
-
...inputControlProps
|
|
130
|
-
}, axis)
|
|
131
|
-
)), allowReset && /* @__PURE__ */ _jsx(ResetButton, {
|
|
109
|
+
}), !isLinked && splitOnAxis && ["vertical", "horizontal"].map((axis) => /* @__PURE__ */ _jsx(BoxInputControl, {
|
|
110
|
+
side: axis,
|
|
111
|
+
...inputControlProps
|
|
112
|
+
}, axis)), !isLinked && !splitOnAxis && Array.from(sidesToRender).map((axis) => /* @__PURE__ */ _jsx(BoxInputControl, {
|
|
113
|
+
side: axis,
|
|
114
|
+
...inputControlProps
|
|
115
|
+
}, axis)), allowReset && /* @__PURE__ */ _jsx(ResetButton, {
|
|
132
116
|
className: "component-box-control__reset-button",
|
|
133
117
|
variant: "secondary",
|
|
134
118
|
size: "small",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/box-control/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { BaseControl } from '../base-control';\nimport
|
|
5
|
-
"mappings": ";AAGA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB,OAAO,aAAa;AAKpB,SAAS,mBAAmB;AAC5B,OAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { BaseControl } from '../base-control';\nimport BoxInputControl from './box-input-control';\nimport LinkedButton from './linked-button';\nimport { Grid } from '../grid';\nimport { InputWrapper, ResetButton, LinkedButtonWrapper } from './styles/box-control-styles';\nimport { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';\nimport { DEFAULT_VALUES, isValueMixed, isValuesDefined, getAllowedSides } from './utils';\nimport { useControlledState } from '../utils/hooks';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst defaultInputProps = {\n min: 0\n};\nconst noop = () => {};\nfunction useUniqueId(idProp) {\n const instanceId = useInstanceId(BoxControl, 'inspector-box-control');\n return idProp || instanceId;\n}\n\n/**\n * A control that lets users set values for top, right, bottom, and left. Can be\n * used as an input control for values like `padding` or `margin`.\n *\n * ```jsx\n * import { useState } from 'react';\n * import { BoxControl } from '@wordpress/components';\n *\n * function Example() {\n * const [ values, setValues ] = useState( {\n * top: '50px',\n * left: '10%',\n * right: '10%',\n * bottom: '50px',\n * } );\n *\n * return (\n * <BoxControl values={ values } onChange={ setValues } />\n * );\n * };\n * ```\n */\nfunction BoxControl({\n id: idProp,\n inputProps = defaultInputProps,\n onChange = noop,\n label = __('Box Control'),\n values: valuesProp,\n units,\n sides,\n splitOnAxis = false,\n allowReset = true,\n resetValues = DEFAULT_VALUES,\n presets,\n presetKey,\n onMouseOver,\n onMouseOut\n}) {\n const [values, setValues] = useControlledState(valuesProp, {\n fallback: DEFAULT_VALUES\n });\n const inputValues = values || DEFAULT_VALUES;\n const hasInitialValue = isValuesDefined(valuesProp);\n const hasOneSide = sides?.length === 1;\n const [isDirty, setIsDirty] = useState(hasInitialValue);\n const [isLinked, setIsLinked] = useState(!hasInitialValue || !isValueMixed(inputValues) || hasOneSide);\n\n // Tracking selected units via internal state allows filtering of CSS unit\n // only values from being saved while maintaining preexisting unit selection\n // behaviour. Filtering CSS only values prevents invalid style values.\n const [selectedUnits, setSelectedUnits] = useState({\n top: parseQuantityAndUnitFromRawValue(valuesProp?.top)[1],\n right: parseQuantityAndUnitFromRawValue(valuesProp?.right)[1],\n bottom: parseQuantityAndUnitFromRawValue(valuesProp?.bottom)[1],\n left: parseQuantityAndUnitFromRawValue(valuesProp?.left)[1]\n });\n const id = useUniqueId(idProp);\n const headingId = `${id}-heading`;\n const toggleLinked = () => {\n setIsLinked(!isLinked);\n };\n const handleOnChange = nextValues => {\n onChange(nextValues);\n setValues(nextValues);\n setIsDirty(true);\n };\n const handleOnReset = () => {\n onChange(resetValues);\n setValues(resetValues);\n setSelectedUnits(resetValues);\n setIsDirty(false);\n };\n const inputControlProps = {\n onMouseOver,\n onMouseOut,\n ...inputProps,\n onChange: handleOnChange,\n isLinked,\n units,\n selectedUnits,\n setSelectedUnits,\n sides,\n values: inputValues,\n presets,\n presetKey\n };\n const sidesToRender = getAllowedSides(sides);\n if (presets && !presetKey || !presets && presetKey) {\n const definedProp = presets ? 'presets' : 'presetKey';\n const missingProp = presets ? 'presetKey' : 'presets';\n globalThis.SCRIPT_DEBUG === true ? warning(`wp.components.BoxControl: the '${missingProp}' prop is required when the '${definedProp}' prop is defined.`) : void 0;\n }\n return /*#__PURE__*/_jsxs(Grid, {\n id: id,\n columns: 3,\n templateColumns: \"1fr min-content min-content\",\n role: \"group\",\n \"aria-labelledby\": headingId,\n children: [/*#__PURE__*/_jsx(BaseControl.VisualLabel, {\n id: headingId,\n children: label\n }), isLinked && /*#__PURE__*/_jsx(InputWrapper, {\n children: /*#__PURE__*/_jsx(BoxInputControl, {\n side: \"all\",\n ...inputControlProps\n })\n }), !hasOneSide && /*#__PURE__*/_jsx(LinkedButtonWrapper, {\n children: /*#__PURE__*/_jsx(LinkedButton, {\n onClick: toggleLinked,\n isLinked: isLinked\n })\n }), !isLinked && splitOnAxis && ['vertical', 'horizontal'].map(axis => /*#__PURE__*/_jsx(BoxInputControl, {\n side: axis,\n ...inputControlProps\n }, axis)), !isLinked && !splitOnAxis && Array.from(sidesToRender).map(axis => /*#__PURE__*/_jsx(BoxInputControl, {\n side: axis,\n ...inputControlProps\n }, axis)), allowReset && /*#__PURE__*/_jsx(ResetButton, {\n className: \"component-box-control__reset-button\",\n variant: \"secondary\",\n size: \"small\",\n onClick: handleOnReset,\n disabled: !isDirty,\n children: __('Reset')\n })]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AK,qBAAqB;AAAA,MACxD,UAAuB,qBAAK,cAAc;AAAA,QACxC,SAAS;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACH,CAAC,GAAG,CAAC,YAAY,eAAe,CAAC,YAAY,YAAY,EAAE,IAAI,UAAqB,qBAAK,iBAAiB;AAAA,MACxG,MAAM;AAAA,MACN,GAAG;AAAA,IACL,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,eAAe,MAAM,KAAK,aAAa,EAAE,IAAI,UAAqB,qBAAK,iBAAiB;AAAA,MAC/G,MAAM;AAAA,MACN,GAAG;AAAA,IACL,GAAG,IAAI,CAAC,GAAG,cAA2B,qBAAK,aAAa;AAAA,MACtD,WAAW;AAAA,MACX,SAAS;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,UAAU,CAAC;AAAA,MACX,UAAU,GAAG,OAAO;AAAA,IACtB,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AACA,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/disabled/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { disabledStyles } from './styles/disabled-styles';\nimport { useCx } from '../utils';\nimport Context from './context';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst {\n Consumer,\n Provider\n} = Context;\n\n/**\n * `Disabled` is a component which disables descendant tabbable elements and\n * prevents pointer interaction.\n *\n * _Note: this component may not behave as expected in browsers that don't\n * support the `inert` HTML attribute. We recommend adding the official WICG\n * polyfill when using this component in your project._\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n *\n * ```jsx\n * import { Button, Disabled, TextControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDisabled = () => {\n * \tconst [ isDisabled, setIsDisabled ] = useState( true );\n *\n *\tlet input = (\n *\t\t<TextControl\n *\t\t\
|
|
5
|
-
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB,OAAO,aAAa;AACpB,SAAS,OAAO,YAAY;AAC5B,IAAM;AAAA,EACJ;AAAA,EACA;AACF,IAAI;
|
|
4
|
+
"sourcesContent": ["import { disabledStyles } from './styles/disabled-styles';\nimport { useCx } from '../utils';\nimport Context from './context';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst {\n Consumer,\n Provider\n} = Context;\n\n/**\n * `Disabled` is a component which disables descendant tabbable elements and\n * prevents pointer interaction.\n *\n * _Note: this component may not behave as expected in browsers that don't\n * support the `inert` HTML attribute. We recommend adding the official WICG\n * polyfill when using this component in your project._\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert\n *\n * ```jsx\n * import { Button, Disabled, TextControl } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDisabled = () => {\n * \tconst [ isDisabled, setIsDisabled ] = useState( true );\n *\n *\tlet input = (\n *\t\t<TextControl\n *\t\t\tlabel=\"Input\"\n *\t\t\tonChange={ () => {} }\n *\t\t/>\n *\t);\n * \tif ( isDisabled ) {\n * \t\tinput = <Disabled>{ input }</Disabled>;\n * \t}\n *\n * \tconst toggleDisabled = () => {\n * \t\tsetIsDisabled( ( state ) => ! state );\n * \t};\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ input }\n * \t\t\t<Button variant=\"primary\" onClick={ toggleDisabled }>\n * \t\t\t\tToggle Disabled\n * \t\t\t</Button>\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nfunction Disabled({\n className,\n children,\n isDisabled = true,\n ...props\n}) {\n const cx = useCx();\n return /*#__PURE__*/_jsx(Provider, {\n value: isDisabled,\n children: /*#__PURE__*/_jsx(\"div\", {\n // @ts-ignore Reason: inert is a recent HTML attribute\n inert: isDisabled ? 'true' : undefined,\n className: isDisabled ? cx(disabledStyles, className, 'components-disabled') : undefined,\n ...props,\n children: children\n })\n });\n}\nDisabled.Context = Context;\nDisabled.Consumer = Consumer;\nexport default Disabled;"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB,OAAO,aAAa;AACpB,SAAS,OAAO,YAAY;AAC5B,IAAM;AAAA,EACJ;AAAA,EACA;AACF,IAAI;AA4CJ,SAAS,SAAS;AAAA,EAChB;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,GAAG;AACL,GAAG;AACD,QAAM,KAAK,MAAM;AACjB,SAAoB,qBAAK,UAAU;AAAA,IACjC,OAAO;AAAA,IACP,UAAuB,qBAAK,OAAO;AAAA;AAAA,MAEjC,OAAO,aAAa,SAAS;AAAA,MAC7B,WAAW,aAAa,GAAG,gBAAgB,WAAW,qBAAqB,IAAI;AAAA,MAC/E,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AACA,SAAS,UAAU;AACnB,SAAS,WAAW;AACpB,IAAO,mBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,117 @@
|
|
|
1
1
|
// packages/components/src/divider/component.tsx
|
|
2
2
|
import * as Ariakit from "@ariakit/react";
|
|
3
|
+
import clsx from "clsx";
|
|
3
4
|
import { contextConnect, useContextSystem } from "../context/index.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { space } from "../utils/space.mjs";
|
|
6
|
+
|
|
7
|
+
// packages/style-runtime/src/index.ts
|
|
8
|
+
var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
9
|
+
function getRuntime() {
|
|
10
|
+
const globalScope = globalThis;
|
|
11
|
+
if (globalScope.__wpStyleRuntime) {
|
|
12
|
+
return globalScope.__wpStyleRuntime;
|
|
13
|
+
}
|
|
14
|
+
globalScope.__wpStyleRuntime = {
|
|
15
|
+
documents: /* @__PURE__ */ new Map(),
|
|
16
|
+
styles: /* @__PURE__ */ new Map(),
|
|
17
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
18
|
+
};
|
|
19
|
+
if (typeof document !== "undefined") {
|
|
20
|
+
registerDocument(document);
|
|
21
|
+
}
|
|
22
|
+
return globalScope.__wpStyleRuntime;
|
|
23
|
+
}
|
|
24
|
+
function documentContainsStyleHash(targetDocument, hash) {
|
|
25
|
+
if (!targetDocument.head) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) {
|
|
29
|
+
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
function injectStyle(targetDocument, hash, css) {
|
|
36
|
+
if (!targetDocument.head) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const runtime = getRuntime();
|
|
40
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
41
|
+
if (!injectedStyles) {
|
|
42
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
43
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
44
|
+
}
|
|
45
|
+
if (injectedStyles.has(hash)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
49
|
+
injectedStyles.add(hash);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const style = targetDocument.createElement("style");
|
|
53
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
54
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
55
|
+
targetDocument.head.appendChild(style);
|
|
56
|
+
injectedStyles.add(hash);
|
|
57
|
+
}
|
|
58
|
+
function registerDocument(targetDocument) {
|
|
59
|
+
const runtime = getRuntime();
|
|
60
|
+
runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
|
|
61
|
+
for (const [hash, css] of runtime.styles) {
|
|
62
|
+
injectStyle(targetDocument, hash, css);
|
|
63
|
+
}
|
|
64
|
+
return () => {
|
|
65
|
+
const count = runtime.documents.get(targetDocument);
|
|
66
|
+
if (count === void 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (count <= 1) {
|
|
70
|
+
runtime.documents.delete(targetDocument);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function registerStyle(hash, css) {
|
|
77
|
+
const runtime = getRuntime();
|
|
78
|
+
runtime.styles.set(hash, css);
|
|
79
|
+
for (const targetDocument of runtime.documents.keys()) {
|
|
80
|
+
injectStyle(targetDocument, hash, css);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// packages/components/src/divider/style.module.scss
|
|
85
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
86
|
+
registerStyle("f2c8d759d8", ".e10c29fc10c181dc__divider{border:0;margin:0}.e10c29fc10c181dc__divider[aria-orientation=horizontal]{block-size:0;border-block-end:1px solid currentColor;inline-size:auto;margin-block-end:var(--wp-components-divider-margin-end,0);margin-block-start:var(--wp-components-divider-margin-start,0)}.e10c29fc10c181dc__divider[aria-orientation=vertical]{block-size:auto;border-inline-end:1px solid currentColor;display:inline;inline-size:0;margin-inline-end:var(--wp-components-divider-margin-end,0);margin-inline-start:var(--wp-components-divider-margin-start,0)}");
|
|
87
|
+
}
|
|
88
|
+
var style_module_default = { "divider": "e10c29fc10c181dc__divider" };
|
|
89
|
+
|
|
90
|
+
// packages/components/src/divider/component.tsx
|
|
5
91
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
92
|
function UnconnectedDivider(props, forwardedRef) {
|
|
7
|
-
const
|
|
93
|
+
const {
|
|
94
|
+
className,
|
|
95
|
+
margin,
|
|
96
|
+
marginEnd,
|
|
97
|
+
marginStart,
|
|
98
|
+
style,
|
|
99
|
+
...contextProps
|
|
100
|
+
} = useContextSystem(props, "Divider");
|
|
101
|
+
const dividerStyle = {
|
|
102
|
+
...style
|
|
103
|
+
};
|
|
104
|
+
const resolvedMarginStart = space(marginStart ?? margin);
|
|
105
|
+
const resolvedMarginEnd = space(marginEnd ?? margin);
|
|
106
|
+
if (resolvedMarginStart) {
|
|
107
|
+
dividerStyle["--wp-components-divider-margin-start"] = resolvedMarginStart;
|
|
108
|
+
}
|
|
109
|
+
if (resolvedMarginEnd) {
|
|
110
|
+
dividerStyle["--wp-components-divider-margin-end"] = resolvedMarginEnd;
|
|
111
|
+
}
|
|
8
112
|
return /* @__PURE__ */ _jsx(Ariakit.Separator, {
|
|
9
|
-
|
|
113
|
+
className: clsx(style_module_default.divider, className),
|
|
114
|
+
style: dividerStyle,
|
|
10
115
|
...contextProps,
|
|
11
116
|
ref: forwardedRef
|
|
12
117
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/divider/component.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as Ariakit from '@ariakit/react';\n\n/**\n * Internal dependencies\n */\n\nimport { contextConnect, useContextSystem } from '../context';\nimport {
|
|
5
|
-
"mappings": ";AAGA,YAAY,aAAa;
|
|
3
|
+
"sources": ["../../src/divider/component.tsx", "../../../style-runtime/src/index.ts", "../../src/divider/style.module.scss"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport * as Ariakit from '@ariakit/react';\nimport clsx from 'clsx';\n\n/**\n * Internal dependencies\n */\n\nimport { contextConnect, useContextSystem } from '../context';\nimport { space } from '../utils/space';\nimport styles from './style.module.scss';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nfunction UnconnectedDivider(props, forwardedRef) {\n const {\n className,\n margin,\n marginEnd,\n marginStart,\n style,\n ...contextProps\n } = useContextSystem(props, 'Divider');\n const dividerStyle = {\n ...style\n };\n const resolvedMarginStart = space(marginStart ?? margin);\n const resolvedMarginEnd = space(marginEnd ?? margin);\n if (resolvedMarginStart) {\n dividerStyle['--wp-components-divider-margin-start'] = resolvedMarginStart;\n }\n if (resolvedMarginEnd) {\n dividerStyle['--wp-components-divider-margin-end'] = resolvedMarginEnd;\n }\n return /*#__PURE__*/_jsx(Ariakit.Separator, {\n className: clsx(styles.divider, className),\n style: dividerStyle,\n ...contextProps,\n ref: forwardedRef\n });\n}\n\n/**\n * `Divider` is a layout component that separates groups of related content.\n *\n * ```js\n * import {\n * \t\t__experimentalDivider as Divider,\n * \t\t__experimentalText as Text,\n * \t\t__experimentalVStack as VStack,\n * } from `@wordpress/components`;\n *\n * function Example() {\n * \treturn (\n * \t\t<VStack spacing={4}>\n * \t\t\t<Text>Some text here</Text>\n * \t\t\t<Divider />\n * \t\t\t<Text>Some more text here</Text>\n * \t\t</VStack>\n * \t);\n * }\n * ```\n */\nexport const Divider = contextConnect(UnconnectedDivider, 'Divider');\nexport default Divider;", "const STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n const globalScope = globalThis;\n if (globalScope.__wpStyleRuntime) {\n return globalScope.__wpStyleRuntime;\n }\n globalScope.__wpStyleRuntime = {\n documents: new Map(),\n styles: new Map(),\n injectedStyles: new WeakMap()\n };\n if (typeof document !== 'undefined') {\n registerDocument(document);\n }\n return globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(targetDocument, hash) {\n if (!targetDocument.head) {\n return false;\n }\n for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) {\n if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle(targetDocument, hash, css) {\n if (!targetDocument.head) {\n return;\n }\n const runtime = getRuntime();\n let injectedStyles = runtime.injectedStyles.get(targetDocument);\n if (!injectedStyles) {\n injectedStyles = new Set();\n runtime.injectedStyles.set(targetDocument, injectedStyles);\n }\n if (injectedStyles.has(hash)) {\n return;\n }\n\n // Older generated CSS module output can still inject matching style tags\n // after this document's cache is created, so keep the DOM as the fallback\n // source of truth on cache misses.\n if (documentContainsStyleHash(targetDocument, hash)) {\n injectedStyles.add(hash);\n return;\n }\n const style = targetDocument.createElement('style');\n style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);\n style.appendChild(targetDocument.createTextNode(css));\n targetDocument.head.appendChild(style);\n injectedStyles.add(hash);\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument(targetDocument) {\n const runtime = getRuntime();\n runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);\n for (const [hash, css] of runtime.styles) {\n injectStyle(targetDocument, hash, css);\n }\n return () => {\n const count = runtime.documents.get(targetDocument);\n if (count === undefined) {\n return;\n }\n if (count <= 1) {\n runtime.documents.delete(targetDocument);\n return;\n }\n runtime.documents.set(targetDocument, count - 1);\n };\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle(hash, css) {\n const runtime = getRuntime();\n runtime.styles.set(hash, css);\n for (const targetDocument of runtime.documents.keys()) {\n injectStyle(targetDocument, hash, css);\n }\n}", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"f2c8d759d8\", \".e10c29fc10c181dc__divider{border:0;margin:0}.e10c29fc10c181dc__divider[aria-orientation=horizontal]{block-size:0;border-block-end:1px solid currentColor;inline-size:auto;margin-block-end:var(--wp-components-divider-margin-end,0);margin-block-start:var(--wp-components-divider-margin-start,0)}.e10c29fc10c181dc__divider[aria-orientation=vertical]{block-size:auto;border-inline-end:1px solid currentColor;display:inline;inline-size:0;margin-inline-end:var(--wp-components-divider-margin-end,0);margin-inline-start:var(--wp-components-divider-margin-start,0)}\");\n}\nexport default {\"divider\":\"e10c29fc10c181dc__divider\"};\n"],
|
|
5
|
+
"mappings": ";AAGA,YAAY,aAAa;AACzB,OAAO,UAAU;AAMjB,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,aAAa;;;ACXtB,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACpB,QAAM,cAAc;AACpB,MAAI,YAAY,kBAAkB;AAChC,WAAO,YAAY;AAAA,EACrB;AACA,cAAY,mBAAmB;AAAA,IAC7B,WAAW,oBAAI,IAAI;AAAA,IACnB,QAAQ,oBAAI,IAAI;AAAA,IAChB,gBAAgB,oBAAI,QAAQ;AAAA,EAC9B;AACA,MAAI,OAAO,aAAa,aAAa;AACnC,qBAAiB,QAAQ;AAAA,EAC3B;AACA,SAAO,YAAY;AACrB;AAUA,SAAS,0BAA0B,gBAAgB,MAAM;AACvD,MAAI,CAAC,eAAe,MAAM;AACxB,WAAO;AAAA,EACT;AACA,aAAW,SAAS,eAAe,KAAK,iBAAiB,SAAS,oBAAoB,GAAG,GAAG;AAC1F,QAAI,MAAM,aAAa,oBAAoB,MAAM,MAAM;AACrD,aAAO;AAAA,IACT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GAAG;AAAA,EACvC;AACF;;;AChIA,IAAI,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa,QAAQ;AACtE,gBAAc,cAAc,+iBAA+iB;AAC5kB;AACA,IAAO,uBAAQ,EAAC,WAAU,4BAA2B;;;AFSrD,SAAS,OAAO,YAAY;AAC5B,SAAS,mBAAmB,OAAO,cAAc;AAC/C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI,iBAAiB,OAAO,SAAS;AACrC,QAAM,eAAe;AAAA,IACnB,GAAG;AAAA,EACL;AACA,QAAM,sBAAsB,MAAM,eAAe,MAAM;AACvD,QAAM,oBAAoB,MAAM,aAAa,MAAM;AACnD,MAAI,qBAAqB;AACvB,iBAAa,sCAAsC,IAAI;AAAA,EACzD;AACA,MAAI,mBAAmB;AACrB,iBAAa,oCAAoC,IAAI;AAAA,EACvD;AACA,SAAoB,qBAAa,mBAAW;AAAA,IAC1C,WAAW,KAAK,qBAAO,SAAS,SAAS;AAAA,IACzC,OAAO;AAAA,IACP,GAAG;AAAA,IACH,KAAK;AAAA,EACP,CAAC;AACH;AAuBO,IAAM,UAAU,eAAe,oBAAoB,SAAS;AACnE,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,56 +1,30 @@
|
|
|
1
1
|
// packages/components/src/higher-order/with-fallback-styles/index.tsx
|
|
2
2
|
import fastDeepEqual from "fast-deep-equal/es6/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
3
|
+
import { useState, useRef } from "@wordpress/element";
|
|
4
|
+
import { createHigherOrderComponent, useIsomorphicLayoutEffect } from "@wordpress/compose";
|
|
5
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
var with_fallback_styles_default = (mapNodeToProps) => createHigherOrderComponent((WrappedComponent) => {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.bindRef = this.bindRef.bind(this);
|
|
16
|
-
}
|
|
17
|
-
bindRef(node) {
|
|
18
|
-
if (!node) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this.nodeRef = node;
|
|
22
|
-
}
|
|
23
|
-
componentDidMount() {
|
|
24
|
-
this.grabFallbackStyles();
|
|
25
|
-
}
|
|
26
|
-
componentDidUpdate() {
|
|
27
|
-
this.grabFallbackStyles();
|
|
28
|
-
}
|
|
29
|
-
grabFallbackStyles() {
|
|
30
|
-
const {
|
|
31
|
-
grabStylesCompleted,
|
|
32
|
-
fallbackStyles
|
|
33
|
-
} = this.state;
|
|
34
|
-
if (this.nodeRef && !grabStylesCompleted) {
|
|
35
|
-
const newFallbackStyles = mapNodeToProps(this.nodeRef, this.props);
|
|
7
|
+
return function WithFallbackStyles(props) {
|
|
8
|
+
const [fallbackStyles, setFallbackStyles] = useState(void 0);
|
|
9
|
+
const nodeRef = useRef(null);
|
|
10
|
+
useIsomorphicLayoutEffect(() => {
|
|
11
|
+
const node = props.node ?? nodeRef.current;
|
|
12
|
+
const grabStylesCompleted = !!fallbackStyles && Object.values(fallbackStyles).every(Boolean);
|
|
13
|
+
if (node && !grabStylesCompleted) {
|
|
14
|
+
const newFallbackStyles = mapNodeToProps(node, props);
|
|
36
15
|
if (!fastDeepEqual(newFallbackStyles, fallbackStyles)) {
|
|
37
|
-
|
|
38
|
-
fallbackStyles: newFallbackStyles,
|
|
39
|
-
grabStylesCompleted: Object.values(newFallbackStyles).every(Boolean)
|
|
40
|
-
});
|
|
16
|
+
setFallbackStyles(newFallbackStyles);
|
|
41
17
|
}
|
|
42
18
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
}
|
|
19
|
+
});
|
|
20
|
+
const wrappedComponent = /* @__PURE__ */ _jsx(WrappedComponent, {
|
|
21
|
+
...props,
|
|
22
|
+
...fallbackStyles
|
|
23
|
+
});
|
|
24
|
+
return props.node ? wrappedComponent : /* @__PURE__ */ _jsxs("div", {
|
|
25
|
+
ref: nodeRef,
|
|
26
|
+
children: [" ", wrappedComponent, " "]
|
|
27
|
+
});
|
|
54
28
|
};
|
|
55
29
|
}, "withFallbackStyles");
|
|
56
30
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/higher-order/with-fallback-styles/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,OAAO,mBAAmB;AAK1B,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { createHigherOrderComponent, useIsomorphicLayoutEffect } from '@wordpress/compose';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nexport default mapNodeToProps => createHigherOrderComponent(WrappedComponent => {\n return function WithFallbackStyles(props) {\n const [fallbackStyles, setFallbackStyles] = useState(undefined);\n const nodeRef = useRef(null);\n\n // Runs before paint, so the fallback styles apply without a flash.\n useIsomorphicLayoutEffect(() => {\n const node = props.node ?? nodeRef.current;\n // Derived from fallbackStyles: the grab is complete once every\n // mapped value has resolved to a truthy style.\n const grabStylesCompleted = !!fallbackStyles && Object.values(fallbackStyles).every(Boolean);\n if (node && !grabStylesCompleted) {\n const newFallbackStyles = mapNodeToProps(node, props);\n if (!fastDeepEqual(newFallbackStyles, fallbackStyles)) {\n setFallbackStyles(newFallbackStyles);\n }\n }\n });\n const wrappedComponent = /*#__PURE__*/_jsx(WrappedComponent, {\n ...props,\n ...fallbackStyles\n });\n return props.node ? wrappedComponent : /*#__PURE__*/_jsxs(\"div\", {\n ref: nodeRef,\n children: [\" \", wrappedComponent, \" \"]\n });\n };\n}, 'withFallbackStyles');"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,mBAAmB;AAK1B,SAAS,UAAU,cAAc;AACjC,SAAS,4BAA4B,iCAAiC;AACtE,SAAS,OAAO,MAAM,QAAQ,aAAa;AAC3C,IAAO,+BAAQ,oBAAkB,2BAA2B,sBAAoB;AAC9E,SAAO,SAAS,mBAAmB,OAAO;AACxC,UAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,MAAS;AAC9D,UAAM,UAAU,OAAO,IAAI;AAG3B,8BAA0B,MAAM;AAC9B,YAAM,OAAO,MAAM,QAAQ,QAAQ;AAGnC,YAAM,sBAAsB,CAAC,CAAC,kBAAkB,OAAO,OAAO,cAAc,EAAE,MAAM,OAAO;AAC3F,UAAI,QAAQ,CAAC,qBAAqB;AAChC,cAAM,oBAAoB,eAAe,MAAM,KAAK;AACpD,YAAI,CAAC,cAAc,mBAAmB,cAAc,GAAG;AACrD,4BAAkB,iBAAiB;AAAA,QACrC;AAAA,MACF;AAAA,IACF,CAAC;AACD,UAAM,mBAAgC,qBAAK,kBAAkB;AAAA,MAC3D,GAAG;AAAA,MACH,GAAG;AAAA,IACL,CAAC;AACD,WAAO,MAAM,OAAO,mBAAgC,sBAAM,OAAO;AAAA,MAC/D,KAAK;AAAA,MACL,UAAU,CAAC,KAAK,kBAAkB,GAAG;AAAA,IACvC,CAAC;AAAA,EACH;AACF,GAAG,oBAAoB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|