@wordpress/components 32.5.0 → 32.5.2-next.v.202604091042.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/AGENTS.md +2 -2
- package/CHANGELOG.md +20 -0
- package/README.md +18 -4
- package/build/autocomplete/autocompleter-ui.cjs +75 -79
- package/build/autocomplete/autocompleter-ui.cjs.map +2 -2
- package/build/autocomplete/get-autocomplete-match.cjs +91 -0
- package/build/autocomplete/get-autocomplete-match.cjs.map +7 -0
- package/build/autocomplete/index.cjs +104 -107
- package/build/autocomplete/index.cjs.map +3 -3
- package/build/box-control/index.cjs +0 -8
- package/build/box-control/index.cjs.map +2 -2
- package/build/box-control/utils.cjs +1 -10
- package/build/box-control/utils.cjs.map +2 -2
- package/build/calendar/utils/use-localization-props.cjs +3 -2
- package/build/calendar/utils/use-localization-props.cjs.map +2 -2
- package/build/custom-select-control/index.cjs.map +3 -3
- package/build/custom-select-control-v2/custom-select.cjs +2 -2
- package/build/custom-select-control-v2/custom-select.cjs.map +2 -2
- package/build/custom-select-control-v2/index.cjs.map +3 -3
- package/build/sandbox/index.cjs +2 -2
- package/build/sandbox/index.cjs.map +2 -2
- package/build/validated-form-controls/control-with-error.cjs +12 -8
- package/build/validated-form-controls/control-with-error.cjs.map +2 -2
- package/build-module/autocomplete/autocompleter-ui.mjs +74 -78
- package/build-module/autocomplete/autocompleter-ui.mjs.map +2 -2
- package/build-module/autocomplete/get-autocomplete-match.mjs +56 -0
- package/build-module/autocomplete/get-autocomplete-match.mjs.map +7 -0
- package/build-module/autocomplete/index.mjs +103 -107
- package/build-module/autocomplete/index.mjs.map +3 -3
- package/build-module/box-control/index.mjs +1 -9
- package/build-module/box-control/index.mjs.map +2 -2
- package/build-module/box-control/utils.mjs +1 -9
- package/build-module/box-control/utils.mjs.map +2 -2
- package/build-module/calendar/utils/use-localization-props.mjs +3 -2
- package/build-module/calendar/utils/use-localization-props.mjs.map +2 -2
- package/build-module/custom-select-control/index.mjs +2 -2
- package/build-module/custom-select-control/index.mjs.map +2 -2
- package/build-module/custom-select-control-v2/custom-select.mjs +2 -2
- package/build-module/custom-select-control-v2/custom-select.mjs.map +2 -2
- package/build-module/custom-select-control-v2/index.mjs +2 -2
- package/build-module/custom-select-control-v2/index.mjs.map +2 -2
- package/build-module/sandbox/index.mjs +2 -2
- package/build-module/sandbox/index.mjs.map +2 -2
- package/build-module/validated-form-controls/control-with-error.mjs +12 -8
- package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
- package/build-style/style-rtl.css +0 -3
- package/build-style/style.css +0 -3
- package/build-types/autocomplete/autocompleter-ui.d.ts +2 -2
- package/build-types/autocomplete/autocompleter-ui.d.ts.map +1 -1
- package/build-types/autocomplete/get-autocomplete-match.d.ts +11 -0
- package/build-types/autocomplete/get-autocomplete-match.d.ts.map +1 -0
- package/build-types/autocomplete/index.d.ts +8 -0
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/autocomplete/test/get-autocomplete-match.d.ts +2 -0
- package/build-types/autocomplete/test/get-autocomplete-match.d.ts.map +1 -0
- package/build-types/autocomplete/types.d.ts +23 -9
- package/build-types/autocomplete/types.d.ts.map +1 -1
- package/build-types/box-control/index.d.ts.map +1 -1
- package/build-types/box-control/utils.d.ts +7 -16
- package/build-types/box-control/utils.d.ts.map +1 -1
- package/build-types/button/stories/index.story.d.ts +0 -1
- package/build-types/button/stories/index.story.d.ts.map +1 -1
- package/build-types/calendar/utils/use-localization-props.d.ts +3 -3
- package/build-types/calendar/utils/use-localization-props.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/constants.d.ts +2 -2
- package/build-types/custom-select-control-v2/custom-select.d.ts +3 -3
- package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/types.d.ts +1 -1
- package/build-types/custom-select-control-v2/types.d.ts.map +1 -1
- package/build-types/font-size-picker/constants.d.ts +2 -2
- package/build-types/font-size-picker/constants.d.ts.map +1 -1
- package/build-types/palette-edit/index.d.ts +1 -1
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/alignment-matrix-control/README.md +1 -1
- package/src/angle-picker-control/style.module.scss +1 -0
- package/src/autocomplete/README.md +2 -2
- package/src/autocomplete/autocompleter-ui.native.js +166 -173
- package/src/autocomplete/autocompleter-ui.tsx +114 -116
- package/src/autocomplete/get-autocomplete-match.ts +115 -0
- package/src/autocomplete/index.tsx +129 -208
- package/src/autocomplete/test/get-autocomplete-match.ts +338 -0
- package/src/autocomplete/test/index.tsx +112 -4
- package/src/autocomplete/types.ts +17 -10
- package/src/box-control/index.tsx +1 -19
- package/src/box-control/utils.ts +1 -19
- package/src/button/README.md +1 -1
- package/src/button/stories/index.story.tsx +0 -1
- package/src/button/style.scss +0 -6
- package/src/calendar/utils/use-localization-props.ts +3 -4
- package/src/custom-select-control/index.tsx +3 -3
- package/src/custom-select-control-v2/custom-select.tsx +4 -4
- package/src/custom-select-control-v2/index.tsx +2 -2
- package/src/custom-select-control-v2/types.ts +1 -1
- package/src/divider/README.md +5 -6
- package/src/flex/stories/index.story.tsx +1 -1
- package/src/form-file-upload/README.md +3 -3
- package/src/gradient-picker/README.md +2 -2
- package/src/h-stack/README.md +10 -15
- package/src/h-stack/stories/index.story.tsx +2 -2
- package/src/heading/stories/index.story.tsx +1 -1
- package/src/higher-order/with-focus-outside/index.native.js +21 -20
- package/src/icon/README.md +1 -1
- package/src/menu/README.md +2 -2
- package/src/mobile/utils/get-px-from-css-unit.native.js +1 -1
- package/src/sandbox/index.native.js +2 -2
- package/src/sandbox/index.tsx +2 -2
- package/src/tabs/README.md +6 -6
- package/src/text/stories/index.story.tsx +1 -1
- package/src/toolbar/toolbar-button/toolbar-button-container.native.js +3 -1
- package/src/tree-select/README.md +1 -1
- package/src/v-stack/README.md +10 -15
- package/src/v-stack/stories/index.story.tsx +2 -2
- package/src/validated-form-controls/control-with-error.tsx +17 -12
- package/src/validated-form-controls/test/control-with-error.tsx +28 -1
- package/src/view/README.md +2 -5
- package/src/button/stories/style.css +0 -8
|
@@ -32,22 +32,60 @@ var autocomplete_exports = {};
|
|
|
32
32
|
__export(autocomplete_exports, {
|
|
33
33
|
default: () => Autocomplete,
|
|
34
34
|
useAutocomplete: () => useAutocomplete,
|
|
35
|
-
useAutocompleteProps: () => useAutocompleteProps
|
|
35
|
+
useAutocompleteProps: () => useAutocompleteProps,
|
|
36
|
+
useLastDifferentValue: () => useLastDifferentValue
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(autocomplete_exports);
|
|
38
|
-
var import_remove_accents = __toESM(require("remove-accents"));
|
|
39
39
|
var import_element = require("@wordpress/element");
|
|
40
40
|
var import_compose = require("@wordpress/compose");
|
|
41
41
|
var import_rich_text = require("@wordpress/rich-text");
|
|
42
42
|
var import_a11y = require("@wordpress/a11y");
|
|
43
43
|
var import_keycodes = require("@wordpress/keycodes");
|
|
44
44
|
var import_autocompleter_ui = require("./autocompleter-ui.cjs");
|
|
45
|
-
var
|
|
45
|
+
var import_get_autocomplete_match = require("./get-autocomplete-match.cjs");
|
|
46
46
|
var import_with_ignore_ime_events = require("../utils/with-ignore-ime-events.cjs");
|
|
47
47
|
var import_get_node_text = __toESM(require("../utils/get-node-text.cjs"));
|
|
48
48
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
49
|
var EMPTY_FILTERED_OPTIONS = [];
|
|
50
50
|
var AUTOCOMPLETE_HOOK_REFERENCE = {};
|
|
51
|
+
function getCompletionObject(completion) {
|
|
52
|
+
if (completion !== null && typeof completion === "object" && "action" in completion && completion.action !== void 0 && "value" in completion && completion.value !== void 0) {
|
|
53
|
+
return completion;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
action: "insert-at-caret",
|
|
57
|
+
value: completion
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var initialState = {
|
|
61
|
+
selectedIndex: 0,
|
|
62
|
+
filteredOptions: EMPTY_FILTERED_OPTIONS,
|
|
63
|
+
filterValue: "",
|
|
64
|
+
autocompleter: null
|
|
65
|
+
};
|
|
66
|
+
function autocompleteReducer(state, action) {
|
|
67
|
+
switch (action.type) {
|
|
68
|
+
case "RESET":
|
|
69
|
+
return initialState;
|
|
70
|
+
case "SELECT":
|
|
71
|
+
return {
|
|
72
|
+
...state,
|
|
73
|
+
selectedIndex: action.index
|
|
74
|
+
};
|
|
75
|
+
case "OPTIONS":
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
filteredOptions: action.options,
|
|
79
|
+
selectedIndex: action.options.length === state.filteredOptions.length ? state.selectedIndex : 0
|
|
80
|
+
};
|
|
81
|
+
case "MATCH":
|
|
82
|
+
return {
|
|
83
|
+
...state,
|
|
84
|
+
autocompleter: action.completer,
|
|
85
|
+
filterValue: action.query
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
51
89
|
function useAutocomplete({
|
|
52
90
|
record,
|
|
53
91
|
onChange,
|
|
@@ -56,11 +94,13 @@ function useAutocomplete({
|
|
|
56
94
|
contentRef
|
|
57
95
|
}) {
|
|
58
96
|
const instanceId = (0, import_compose.useInstanceId)(AUTOCOMPLETE_HOOK_REFERENCE);
|
|
59
|
-
const [
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
97
|
+
const [state, dispatch] = (0, import_element.useReducer)(autocompleteReducer, initialState);
|
|
98
|
+
const {
|
|
99
|
+
selectedIndex,
|
|
100
|
+
filteredOptions,
|
|
101
|
+
filterValue,
|
|
102
|
+
autocompleter
|
|
103
|
+
} = state;
|
|
64
104
|
const backspacingRef = (0, import_element.useRef)(false);
|
|
65
105
|
function insertCompletion(replacement) {
|
|
66
106
|
if (autocompleter === null) {
|
|
@@ -81,14 +121,7 @@ function useAutocomplete({
|
|
|
81
121
|
return;
|
|
82
122
|
}
|
|
83
123
|
if (getOptionCompletion) {
|
|
84
|
-
const
|
|
85
|
-
const isCompletionObject = (obj) => {
|
|
86
|
-
return obj !== null && typeof obj === "object" && "action" in obj && obj.action !== void 0 && "value" in obj && obj.value !== void 0;
|
|
87
|
-
};
|
|
88
|
-
const completionObject = isCompletionObject(completion) ? completion : {
|
|
89
|
-
action: "insert-at-caret",
|
|
90
|
-
value: completion
|
|
91
|
-
};
|
|
124
|
+
const completionObject = getCompletionObject(getOptionCompletion(option.value, filterValue));
|
|
92
125
|
if ("replace" === completionObject.action) {
|
|
93
126
|
onReplace([completionObject.value]);
|
|
94
127
|
return;
|
|
@@ -96,19 +129,16 @@ function useAutocomplete({
|
|
|
96
129
|
insertCompletion(completionObject.value);
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
|
-
|
|
132
|
+
dispatch({
|
|
133
|
+
type: "RESET"
|
|
134
|
+
});
|
|
100
135
|
contentRef.current?.focus();
|
|
101
136
|
}
|
|
102
|
-
function reset() {
|
|
103
|
-
setSelectedIndex(0);
|
|
104
|
-
setFilteredOptions(EMPTY_FILTERED_OPTIONS);
|
|
105
|
-
setFilterValue("");
|
|
106
|
-
setAutocompleter(null);
|
|
107
|
-
setAutocompleterUI(null);
|
|
108
|
-
}
|
|
109
137
|
function onChangeOptions(options) {
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
dispatch({
|
|
139
|
+
type: "OPTIONS",
|
|
140
|
+
options
|
|
141
|
+
});
|
|
112
142
|
}
|
|
113
143
|
function handleKeyDown(event) {
|
|
114
144
|
backspacingRef.current = event.key === "Backspace";
|
|
@@ -122,25 +152,23 @@ function useAutocomplete({
|
|
|
122
152
|
return;
|
|
123
153
|
}
|
|
124
154
|
switch (event.key) {
|
|
125
|
-
case "ArrowUp":
|
|
126
|
-
const newIndex = (selectedIndex === 0 ? filteredOptions.length : selectedIndex) - 1;
|
|
127
|
-
setSelectedIndex(newIndex);
|
|
128
|
-
if ((0, import_keycodes.isAppleOS)()) {
|
|
129
|
-
(0, import_a11y.speak)((0, import_get_node_text.default)(filteredOptions[newIndex].label), "assertive");
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
155
|
+
case "ArrowUp":
|
|
133
156
|
case "ArrowDown": {
|
|
134
|
-
const
|
|
135
|
-
|
|
157
|
+
const offset = event.key === "ArrowUp" ? -1 : 1;
|
|
158
|
+
const newIndex = (selectedIndex + offset + filteredOptions.length) % filteredOptions.length;
|
|
159
|
+
dispatch({
|
|
160
|
+
type: "SELECT",
|
|
161
|
+
index: newIndex
|
|
162
|
+
});
|
|
136
163
|
if ((0, import_keycodes.isAppleOS)()) {
|
|
137
164
|
(0, import_a11y.speak)((0, import_get_node_text.default)(filteredOptions[newIndex].label), "assertive");
|
|
138
165
|
}
|
|
139
166
|
break;
|
|
140
167
|
}
|
|
141
168
|
case "Escape":
|
|
142
|
-
|
|
143
|
-
|
|
169
|
+
dispatch({
|
|
170
|
+
type: "RESET"
|
|
171
|
+
});
|
|
144
172
|
event.preventDefault();
|
|
145
173
|
break;
|
|
146
174
|
case "Enter":
|
|
@@ -148,7 +176,9 @@ function useAutocomplete({
|
|
|
148
176
|
break;
|
|
149
177
|
case "ArrowLeft":
|
|
150
178
|
case "ArrowRight":
|
|
151
|
-
|
|
179
|
+
dispatch({
|
|
180
|
+
type: "RESET"
|
|
181
|
+
});
|
|
152
182
|
return;
|
|
153
183
|
default:
|
|
154
184
|
return;
|
|
@@ -162,69 +192,27 @@ function useAutocomplete({
|
|
|
162
192
|
return "";
|
|
163
193
|
}, [record]);
|
|
164
194
|
(0, import_element.useEffect)(() => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
reset();
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
195
|
+
function getTextAfterSelection() {
|
|
196
|
+
return textContent ? (0, import_rich_text.getTextContent)((0, import_rich_text.slice)(record, void 0, (0, import_rich_text.getTextContent)(record).length)) : "";
|
|
170
197
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const lastTriggerIndex = lastTrigger !== null ? textContent.lastIndexOf(lastTrigger.triggerPrefix) : -1;
|
|
174
|
-
return triggerIndex2 > lastTriggerIndex ? currentCompleter : lastTrigger;
|
|
175
|
-
}, null);
|
|
176
|
-
if (!completer) {
|
|
198
|
+
const match = (0, import_get_autocomplete_match.getAutocompleteMatch)(textContent, completers, filteredOptions.length, backspacingRef.current, getTextAfterSelection);
|
|
199
|
+
if (!match) {
|
|
177
200
|
if (autocompleter) {
|
|
178
|
-
|
|
201
|
+
dispatch({
|
|
202
|
+
type: "RESET"
|
|
203
|
+
});
|
|
179
204
|
}
|
|
180
205
|
return;
|
|
181
206
|
}
|
|
182
207
|
const {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
const mismatch = filteredOptions.length === 0;
|
|
193
|
-
const wordsFromTrigger = textWithoutTrigger.split(/\s/);
|
|
194
|
-
const hasOneTriggerWord = wordsFromTrigger.length === 1;
|
|
195
|
-
const matchingWhileBackspacing = backspacingRef.current && wordsFromTrigger.length <= 3;
|
|
196
|
-
if (mismatch && !(matchingWhileBackspacing || hasOneTriggerWord)) {
|
|
197
|
-
if (autocompleter) {
|
|
198
|
-
reset();
|
|
199
|
-
}
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const textAfterSelection = (0, import_rich_text.getTextContent)((0, import_rich_text.slice)(record, void 0, (0, import_rich_text.getTextContent)(record).length));
|
|
203
|
-
if (allowContext && !allowContext(textContent.slice(0, triggerIndex), textAfterSelection)) {
|
|
204
|
-
if (autocompleter) {
|
|
205
|
-
reset();
|
|
206
|
-
}
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (/^\s/.test(textWithoutTrigger) || /\s\s+$/.test(textWithoutTrigger)) {
|
|
210
|
-
if (autocompleter) {
|
|
211
|
-
reset();
|
|
212
|
-
}
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (!/[\u0000-\uFFFF]*$/.test(textWithoutTrigger)) {
|
|
216
|
-
if (autocompleter) {
|
|
217
|
-
reset();
|
|
218
|
-
}
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const safeTrigger = (0, import_strings.escapeRegExp)(completer.triggerPrefix);
|
|
222
|
-
const text = (0, import_remove_accents.default)(textContent);
|
|
223
|
-
const match = text.slice(text.lastIndexOf(completer.triggerPrefix)).match(new RegExp(`${safeTrigger}([\0-\uFFFF]*)$`));
|
|
224
|
-
const query = match && match[1];
|
|
225
|
-
setAutocompleter(completer);
|
|
226
|
-
setAutocompleterUI(() => completer !== autocompleter ? (0, import_autocompleter_ui.getAutoCompleterUI)(completer) : AutocompleterUI);
|
|
227
|
-
setFilterValue(query === null ? "" : query);
|
|
208
|
+
completer,
|
|
209
|
+
filterValue: query
|
|
210
|
+
} = match;
|
|
211
|
+
dispatch({
|
|
212
|
+
type: "MATCH",
|
|
213
|
+
completer,
|
|
214
|
+
query
|
|
215
|
+
});
|
|
228
216
|
}, [textContent]);
|
|
229
217
|
const {
|
|
230
218
|
key: selectedKey = ""
|
|
@@ -236,12 +224,13 @@ function useAutocomplete({
|
|
|
236
224
|
const listBoxId = isExpanded ? `components-autocomplete-listbox-${instanceId}` : void 0;
|
|
237
225
|
const activeId = isExpanded ? `components-autocomplete-item-${instanceId}-${selectedKey}` : null;
|
|
238
226
|
const hasSelection = record.start !== void 0;
|
|
239
|
-
const showPopover = !!textContent && hasSelection && !!
|
|
227
|
+
const showPopover = !!textContent && hasSelection && !!autocompleter;
|
|
240
228
|
return {
|
|
241
229
|
listBoxId,
|
|
242
230
|
activeId,
|
|
243
231
|
onKeyDown: (0, import_with_ignore_ime_events.withIgnoreIMEEvents)(handleKeyDown),
|
|
244
|
-
popover: showPopover && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleterUI, {
|
|
232
|
+
popover: showPopover && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_autocompleter_ui.AutocompleterUI, {
|
|
233
|
+
autocompleter,
|
|
245
234
|
className,
|
|
246
235
|
filterValue,
|
|
247
236
|
instanceId,
|
|
@@ -249,19 +238,26 @@ function useAutocomplete({
|
|
|
249
238
|
selectedIndex,
|
|
250
239
|
onChangeOptions,
|
|
251
240
|
onSelect: select,
|
|
252
|
-
value: record,
|
|
253
241
|
contentRef,
|
|
254
|
-
reset
|
|
255
|
-
|
|
242
|
+
reset: () => dispatch({
|
|
243
|
+
type: "RESET"
|
|
244
|
+
})
|
|
245
|
+
}, autocompleter.name + autocompleter.triggerPrefix)
|
|
256
246
|
};
|
|
257
247
|
}
|
|
248
|
+
function recordValuesMatch(a, b) {
|
|
249
|
+
return a.text === b.text && a.start === b.start && a.end === b.end;
|
|
250
|
+
}
|
|
258
251
|
function useLastDifferentValue(value) {
|
|
259
|
-
const history = (0, import_element.useRef)(
|
|
260
|
-
history.current.
|
|
261
|
-
if (
|
|
262
|
-
history.current.
|
|
252
|
+
const history = (0, import_element.useRef)([]);
|
|
253
|
+
const lastEntry = history.current[history.current.length - 1];
|
|
254
|
+
if (!lastEntry || !recordValuesMatch(value, lastEntry)) {
|
|
255
|
+
history.current.push(value);
|
|
256
|
+
}
|
|
257
|
+
if (history.current.length > 2) {
|
|
258
|
+
history.current.shift();
|
|
263
259
|
}
|
|
264
|
-
return
|
|
260
|
+
return history.current[0];
|
|
265
261
|
}
|
|
266
262
|
function useAutocompleteProps(options) {
|
|
267
263
|
const ref = (0, import_element.useRef)(null);
|
|
@@ -319,6 +315,7 @@ function Autocomplete({
|
|
|
319
315
|
// Annotate the CommonJS export names for ESM import in node:
|
|
320
316
|
0 && (module.exports = {
|
|
321
317
|
useAutocomplete,
|
|
322
|
-
useAutocompleteProps
|
|
318
|
+
useAutocompleteProps,
|
|
319
|
+
useLastDifferentValue
|
|
323
320
|
});
|
|
324
321
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/autocomplete/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport { renderToString, useEffect, useState, useRef, useMemo } from '@wordpress/element';\nimport { useInstanceId, useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { create, slice, insert, isCollapsed, getTextContent } from '@wordpress/rich-text';\nimport { speak } from '@wordpress/a11y';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { getAutoCompleterUI } from './autocompleter-ui';\nimport { escapeRegExp } from '../utils/strings';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport getNodeText from '../utils/get-node-text';\nimport { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst EMPTY_FILTERED_OPTIONS = [];\n\n// Used for generating the instance ID\nconst AUTOCOMPLETE_HOOK_REFERENCE = {};\nexport function useAutocomplete({\n record,\n onChange,\n onReplace,\n completers,\n contentRef\n}) {\n const instanceId = useInstanceId(AUTOCOMPLETE_HOOK_REFERENCE);\n const [selectedIndex, setSelectedIndex] = useState(0);\n const [filteredOptions, setFilteredOptions] = useState(EMPTY_FILTERED_OPTIONS);\n const [filterValue, setFilterValue] = useState('');\n const [autocompleter, setAutocompleter] = useState(null);\n const [AutocompleterUI, setAutocompleterUI] = useState(null);\n const backspacingRef = useRef(false);\n function insertCompletion(replacement) {\n if (autocompleter === null) {\n return;\n }\n const end = record.start;\n const start = end - autocompleter.triggerPrefix.length - filterValue.length;\n const toInsert = create({\n html: renderToString(replacement)\n });\n onChange(insert(record, toInsert, start, end));\n }\n function select(option) {\n const {\n getOptionCompletion\n } = autocompleter || {};\n if (option.isDisabled) {\n return;\n }\n if (getOptionCompletion) {\n const completion = getOptionCompletion(option.value, filterValue);\n const isCompletionObject = obj => {\n return obj !== null && typeof obj === 'object' && 'action' in obj && obj.action !== undefined && 'value' in obj && obj.value !== undefined;\n };\n const completionObject = isCompletionObject(completion) ? completion : {\n action: 'insert-at-caret',\n value: completion\n };\n if ('replace' === completionObject.action) {\n onReplace([completionObject.value]);\n // When replacing, the component will unmount, so don't reset\n // state (below) on an unmounted component.\n return;\n } else if ('insert-at-caret' === completionObject.action) {\n insertCompletion(completionObject.value);\n }\n }\n\n // Reset autocomplete state after insertion rather than before\n // so insertion events don't cause the completion menu to redisplay.\n reset();\n\n // Make sure that the content remains focused after making a selection\n // and that the text cursor position is not lost.\n contentRef.current?.focus();\n }\n function reset() {\n setSelectedIndex(0);\n setFilteredOptions(EMPTY_FILTERED_OPTIONS);\n setFilterValue('');\n setAutocompleter(null);\n setAutocompleterUI(null);\n }\n\n /**\n * Load options for an autocompleter.\n *\n * @param {Array} options\n */\n function onChangeOptions(options) {\n setSelectedIndex(options.length === filteredOptions.length ? selectedIndex : 0);\n setFilteredOptions(options);\n }\n function handleKeyDown(event) {\n backspacingRef.current = event.key === 'Backspace';\n if (!autocompleter) {\n return;\n }\n if (filteredOptions.length === 0) {\n return;\n }\n if (event.defaultPrevented) {\n return;\n }\n switch (event.key) {\n case 'ArrowUp':\n {\n const newIndex = (selectedIndex === 0 ? filteredOptions.length : selectedIndex) - 1;\n setSelectedIndex(newIndex);\n // See the related PR as to why this is necessary: https://github.com/WordPress/gutenberg/pull/54902.\n if (isAppleOS()) {\n speak(getNodeText(filteredOptions[newIndex].label), 'assertive');\n }\n break;\n }\n case 'ArrowDown':\n {\n const newIndex = (selectedIndex + 1) % filteredOptions.length;\n setSelectedIndex(newIndex);\n if (isAppleOS()) {\n speak(getNodeText(filteredOptions[newIndex].label), 'assertive');\n }\n break;\n }\n case 'Escape':\n setAutocompleter(null);\n setAutocompleterUI(null);\n event.preventDefault();\n break;\n case 'Enter':\n select(filteredOptions[selectedIndex]);\n break;\n case 'ArrowLeft':\n case 'ArrowRight':\n reset();\n return;\n default:\n return;\n }\n\n // Any handled key should prevent original behavior. This relies on\n // the early return in the default case.\n event.preventDefault();\n }\n\n // textContent is a primitive (string), memoizing is not strictly necessary\n // but this is a preemptive performance improvement, since the autocompleter\n // is a potential bottleneck for the editor type metric.\n const textContent = useMemo(() => {\n if (isCollapsed(record)) {\n return getTextContent(slice(record, 0));\n }\n return '';\n }, [record]);\n useEffect(() => {\n if (!textContent) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n\n // Find the completer with the highest triggerPrefix index in the\n // textContent.\n const completer = completers.reduce((lastTrigger, currentCompleter) => {\n const triggerIndex = textContent.lastIndexOf(currentCompleter.triggerPrefix);\n const lastTriggerIndex = lastTrigger !== null ? textContent.lastIndexOf(lastTrigger.triggerPrefix) : -1;\n return triggerIndex > lastTriggerIndex ? currentCompleter : lastTrigger;\n }, null);\n if (!completer) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n const {\n allowContext,\n triggerPrefix\n } = completer;\n const triggerIndex = textContent.lastIndexOf(triggerPrefix);\n const textWithoutTrigger = textContent.slice(triggerIndex + triggerPrefix.length);\n const tooDistantFromTrigger = textWithoutTrigger.length > 50; // 50 chars seems to be a good limit.\n // This is a final barrier to prevent the effect from completing with\n // an extremely long string, which causes the editor to slow-down\n // significantly. This could happen, for example, if `matchingWhileBackspacing`\n // is true and one of the \"words\" end up being too long. If that's the case,\n // it will be caught by this guard.\n if (tooDistantFromTrigger) {\n return;\n }\n const mismatch = filteredOptions.length === 0;\n const wordsFromTrigger = textWithoutTrigger.split(/\\s/);\n // We need to allow the effect to run when not backspacing and if there\n // was a mismatch. i.e when typing a trigger + the match string or when\n // clicking in an existing trigger word on the page. We do that if we\n // detect that we have one word from trigger in the current textual context.\n //\n // Ex.: \"Some text @a\" <-- \"@a\" will be detected as the trigger word and\n // allow the effect to run. It will run until there's a mismatch.\n const hasOneTriggerWord = wordsFromTrigger.length === 1;\n // This is used to allow the effect to run when backspacing and if\n // \"touching\" a word that \"belongs\" to a trigger. We consider a \"trigger\n // word\" any word up to the limit of 3 from the trigger character.\n // Anything beyond that is ignored if there's a mismatch. This allows\n // us to \"escape\" a mismatch when backspacing, but still imposing some\n // sane limits.\n //\n // Ex: \"Some text @marcelo sekkkk\" <--- \"kkkk\" caused a mismatch, but\n // if the user presses backspace here, it will show the completion popup again.\n const matchingWhileBackspacing = backspacingRef.current && wordsFromTrigger.length <= 3;\n if (mismatch && !(matchingWhileBackspacing || hasOneTriggerWord)) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n const textAfterSelection = getTextContent(slice(record, undefined, getTextContent(record).length));\n if (allowContext && !allowContext(textContent.slice(0, triggerIndex), textAfterSelection)) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n if (/^\\s/.test(textWithoutTrigger) || /\\s\\s+$/.test(textWithoutTrigger)) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n if (!/[\\u0000-\\uFFFF]*$/.test(textWithoutTrigger)) {\n if (autocompleter) {\n reset();\n }\n return;\n }\n const safeTrigger = escapeRegExp(completer.triggerPrefix);\n const text = removeAccents(textContent);\n const match = text.slice(text.lastIndexOf(completer.triggerPrefix)).match(new RegExp(`${safeTrigger}([\\u0000-\\uFFFF]*)$`));\n const query = match && match[1];\n setAutocompleter(completer);\n setAutocompleterUI(() => completer !== autocompleter ? getAutoCompleterUI(completer) : AutocompleterUI);\n setFilterValue(query === null ? '' : query);\n // We want to avoid introducing unexpected side effects.\n // See https://github.com/WordPress/gutenberg/pull/41820\n }, [textContent]);\n const {\n key: selectedKey = ''\n } = filteredOptions[selectedIndex] || {};\n const {\n className\n } = autocompleter || {};\n const isExpanded = !!autocompleter && filteredOptions.length > 0;\n const listBoxId = isExpanded ? `components-autocomplete-listbox-${instanceId}` : undefined;\n const activeId = isExpanded ? `components-autocomplete-item-${instanceId}-${selectedKey}` : null;\n const hasSelection = record.start !== undefined;\n const showPopover = !!textContent && hasSelection && !!AutocompleterUI;\n return {\n listBoxId,\n activeId,\n onKeyDown: withIgnoreIMEEvents(handleKeyDown),\n popover: showPopover && /*#__PURE__*/_jsx(AutocompleterUI, {\n className: className,\n filterValue: filterValue,\n instanceId: instanceId,\n listBoxId: listBoxId,\n selectedIndex: selectedIndex,\n onChangeOptions: onChangeOptions,\n onSelect: select,\n value: record,\n contentRef: contentRef,\n reset: reset\n })\n };\n}\nfunction useLastDifferentValue(value) {\n const history = useRef(new Set());\n history.current.add(value);\n\n // Keep the history size to 2.\n if (history.current.size > 2) {\n history.current.delete(Array.from(history.current)[0]);\n }\n return Array.from(history.current)[0];\n}\nexport function useAutocompleteProps(options) {\n const ref = useRef(null);\n const onKeyDownRef = useRef(undefined);\n const {\n record\n } = options;\n const previousRecord = useLastDifferentValue(record);\n const {\n popover,\n listBoxId,\n activeId,\n onKeyDown\n } = useAutocomplete({\n ...options,\n contentRef: ref\n });\n onKeyDownRef.current = onKeyDown;\n const mergedRefs = useMergeRefs([ref, useRefEffect(element => {\n function _onKeyDown(event) {\n onKeyDownRef.current?.(event);\n }\n element.addEventListener('keydown', _onKeyDown);\n return () => {\n element.removeEventListener('keydown', _onKeyDown);\n };\n }, [])]);\n\n // We only want to show the popover if the user has typed something.\n const didUserInput = record.text !== previousRecord?.text;\n if (!didUserInput) {\n return {\n ref: mergedRefs\n };\n }\n return {\n ref: mergedRefs,\n children: popover,\n 'aria-autocomplete': listBoxId ? 'list' : undefined,\n 'aria-owns': listBoxId,\n 'aria-activedescendant': activeId\n };\n}\nexport default function Autocomplete({\n children,\n isSelected,\n ...options\n}) {\n const {\n popover,\n ...props\n } = useAutocomplete(options);\n return /*#__PURE__*/_jsxs(_Fragment, {\n children: [children(props), isSelected && popover]\n });\n}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["getNodeText", "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { renderToString, useEffect, useMemo, useReducer, useRef } from '@wordpress/element';\nimport { useInstanceId, useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { create, slice, insert, isCollapsed, getTextContent } from '@wordpress/rich-text';\nimport { speak } from '@wordpress/a11y';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { AutocompleterUI } from './autocompleter-ui';\nimport { getAutocompleteMatch } from './get-autocomplete-match';\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport getNodeText from '../utils/get-node-text';\nimport { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst EMPTY_FILTERED_OPTIONS = [];\n\n// Used for generating the instance ID\nconst AUTOCOMPLETE_HOOK_REFERENCE = {};\nfunction getCompletionObject(completion) {\n if (completion !== null && typeof completion === 'object' && 'action' in completion && completion.action !== undefined && 'value' in completion && completion.value !== undefined) {\n return completion;\n }\n return {\n action: 'insert-at-caret',\n value: completion\n };\n}\nconst initialState = {\n selectedIndex: 0,\n filteredOptions: EMPTY_FILTERED_OPTIONS,\n filterValue: '',\n autocompleter: null\n};\nfunction autocompleteReducer(state, action) {\n switch (action.type) {\n case 'RESET':\n return initialState;\n case 'SELECT':\n return {\n ...state,\n selectedIndex: action.index\n };\n case 'OPTIONS':\n return {\n ...state,\n filteredOptions: action.options,\n selectedIndex: action.options.length === state.filteredOptions.length ? state.selectedIndex : 0\n };\n case 'MATCH':\n return {\n ...state,\n autocompleter: action.completer,\n filterValue: action.query\n };\n }\n}\nexport function useAutocomplete({\n record,\n onChange,\n onReplace,\n completers,\n contentRef\n}) {\n const instanceId = useInstanceId(AUTOCOMPLETE_HOOK_REFERENCE);\n const [state, dispatch] = useReducer(autocompleteReducer, initialState);\n const {\n selectedIndex,\n filteredOptions,\n filterValue,\n autocompleter\n } = state;\n const backspacingRef = useRef(false);\n function insertCompletion(replacement) {\n if (autocompleter === null) {\n return;\n }\n const end = record.start;\n const start = end - autocompleter.triggerPrefix.length - filterValue.length;\n const toInsert = create({\n html: renderToString(replacement)\n });\n onChange(insert(record, toInsert, start, end));\n }\n function select(option) {\n const {\n getOptionCompletion\n } = autocompleter || {};\n if (option.isDisabled) {\n return;\n }\n if (getOptionCompletion) {\n const completionObject = getCompletionObject(getOptionCompletion(option.value, filterValue));\n if ('replace' === completionObject.action) {\n onReplace([completionObject.value]);\n // When replacing, the component will unmount, so don't reset\n // state (below) on an unmounted component.\n return;\n } else if ('insert-at-caret' === completionObject.action) {\n insertCompletion(completionObject.value);\n }\n }\n\n // Reset autocomplete state after insertion rather than before\n // so insertion events don't cause the completion menu to redisplay.\n dispatch({\n type: 'RESET'\n });\n\n // Make sure that the content remains focused after making a selection\n // and that the text cursor position is not lost.\n contentRef.current?.focus();\n }\n function onChangeOptions(options) {\n dispatch({\n type: 'OPTIONS',\n options\n });\n }\n function handleKeyDown(event) {\n backspacingRef.current = event.key === 'Backspace';\n if (!autocompleter) {\n return;\n }\n if (filteredOptions.length === 0) {\n return;\n }\n if (event.defaultPrevented) {\n return;\n }\n switch (event.key) {\n case 'ArrowUp':\n case 'ArrowDown':\n {\n const offset = event.key === 'ArrowUp' ? -1 : 1;\n const newIndex = (selectedIndex + offset + filteredOptions.length) % filteredOptions.length;\n dispatch({\n type: 'SELECT',\n index: newIndex\n });\n // See the related PR as to why this is necessary: https://github.com/WordPress/gutenberg/pull/54902.\n if (isAppleOS()) {\n speak(getNodeText(filteredOptions[newIndex].label), 'assertive');\n }\n break;\n }\n case 'Escape':\n dispatch({\n type: 'RESET'\n });\n event.preventDefault();\n break;\n case 'Enter':\n select(filteredOptions[selectedIndex]);\n break;\n case 'ArrowLeft':\n case 'ArrowRight':\n dispatch({\n type: 'RESET'\n });\n return;\n default:\n return;\n }\n\n // Any handled key should prevent original behavior. This relies on\n // the early return in the default case.\n event.preventDefault();\n }\n\n // textContent is a primitive (string), memoizing is not strictly necessary\n // but this is a preemptive performance improvement, since the autocompleter\n // is a potential bottleneck for the editor type metric.\n const textContent = useMemo(() => {\n if (isCollapsed(record)) {\n return getTextContent(slice(record, 0));\n }\n return '';\n }, [record]);\n useEffect(() => {\n function getTextAfterSelection() {\n return textContent ? getTextContent(slice(record, undefined, getTextContent(record).length)) : '';\n }\n const match = getAutocompleteMatch(textContent, completers, filteredOptions.length, backspacingRef.current, getTextAfterSelection);\n if (!match) {\n if (autocompleter) {\n dispatch({\n type: 'RESET'\n });\n }\n return;\n }\n const {\n completer,\n filterValue: query\n } = match;\n dispatch({\n type: 'MATCH',\n completer,\n query\n });\n // We want to avoid introducing unexpected side effects.\n // See https://github.com/WordPress/gutenberg/pull/41820\n }, [textContent]);\n const {\n key: selectedKey = ''\n } = filteredOptions[selectedIndex] || {};\n const {\n className\n } = autocompleter || {};\n const isExpanded = !!autocompleter && filteredOptions.length > 0;\n const listBoxId = isExpanded ? `components-autocomplete-listbox-${instanceId}` : undefined;\n const activeId = isExpanded ? `components-autocomplete-item-${instanceId}-${selectedKey}` : null;\n const hasSelection = record.start !== undefined;\n const showPopover = !!textContent && hasSelection && !!autocompleter;\n return {\n listBoxId,\n activeId,\n onKeyDown: withIgnoreIMEEvents(handleKeyDown),\n popover: showPopover && /*#__PURE__*/_jsx(AutocompleterUI, {\n autocompleter: autocompleter,\n className: className,\n filterValue: filterValue,\n instanceId: instanceId,\n listBoxId: listBoxId,\n selectedIndex: selectedIndex,\n onChangeOptions: onChangeOptions,\n onSelect: select,\n contentRef: contentRef,\n reset: () => dispatch({\n type: 'RESET'\n })\n }, autocompleter.name + autocompleter.triggerPrefix)\n };\n}\n\n/**\n * Checks whether two records represent the same user-visible state\n * (same text content and cursor position).\n */\nfunction recordValuesMatch(a, b) {\n return a.text === b.text && a.start === b.start && a.end === b.end;\n}\n\n/**\n * Tracks the last record whose value differed from the current one.\n * Used to determine whether the user has actually typed something\n */\nexport function useLastDifferentValue(value) {\n const history = useRef([]);\n const lastEntry = history.current[history.current.length - 1];\n\n // Only add to history if the value is meaningfully different from\n // the most recent entry (analogous to Set.add being a no-op for\n // duplicate references in the original implementation).\n if (!lastEntry || !recordValuesMatch(value, lastEntry)) {\n history.current.push(value);\n }\n\n // Keep the history size to 2.\n if (history.current.length > 2) {\n history.current.shift();\n }\n return history.current[0];\n}\nexport function useAutocompleteProps(options) {\n const ref = useRef(null);\n const onKeyDownRef = useRef(undefined);\n const {\n record\n } = options;\n const previousRecord = useLastDifferentValue(record);\n const {\n popover,\n listBoxId,\n activeId,\n onKeyDown\n } = useAutocomplete({\n ...options,\n contentRef: ref\n });\n onKeyDownRef.current = onKeyDown;\n const mergedRefs = useMergeRefs([ref, useRefEffect(element => {\n function _onKeyDown(event) {\n onKeyDownRef.current?.(event);\n }\n element.addEventListener('keydown', _onKeyDown);\n return () => {\n element.removeEventListener('keydown', _onKeyDown);\n };\n }, [])]);\n\n // We only want to show the popover if the user has typed something.\n const didUserInput = record.text !== previousRecord?.text;\n if (!didUserInput) {\n return {\n ref: mergedRefs\n };\n }\n return {\n ref: mergedRefs,\n children: popover,\n 'aria-autocomplete': listBoxId ? 'list' : undefined,\n 'aria-owns': listBoxId,\n 'aria-activedescendant': activeId\n };\n}\nexport default function Autocomplete({\n children,\n isSelected,\n ...options\n}) {\n const {\n popover,\n ...props\n } = useAutocomplete(options);\n return /*#__PURE__*/_jsxs(_Fragment, {\n children: [children(props), isSelected && popover]\n });\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAuE;AACvE,qBAA0D;AAC1D,uBAAmE;AACnE,kBAAsB;AACtB,sBAA0B;AAK1B,8BAAgC;AAChC,oCAAqC;AACrC,oCAAoC;AACpC,2BAAwB;AACxB,yBAAkE;AAClE,IAAM,yBAAyB,CAAC;AAGhC,IAAM,8BAA8B,CAAC;AACrC,SAAS,oBAAoB,YAAY;AACvC,MAAI,eAAe,QAAQ,OAAO,eAAe,YAAY,YAAY,cAAc,WAAW,WAAW,UAAa,WAAW,cAAc,WAAW,UAAU,QAAW;AACjL,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,OA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BAAgB;AACrD,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF;AACA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,UAAU;AAAA,IACV,qBAAqB,YAAY,SAAS;AAAA,IAC1C,aAAa;AAAA,IACb,yBAAyB;AAAA,EAC3B;AACF;AACe,SAAR,aAA8B;AAAA,EACnC;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAG;AACD,QAAM;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACL,IAAI,gBAAgB,OAAO;AAC3B,SAAoB,uCAAAC,MAAM,mBAAAC,UAAW;AAAA,IACnC,UAAU,CAAC,SAAS,KAAK,GAAG,cAAc,OAAO;AAAA,EACnD,CAAC;AACH;",
|
|
6
|
+
"names": ["getNodeText", "_jsx", "_jsxs", "_Fragment"]
|
|
7
7
|
}
|
|
@@ -83,7 +83,6 @@ function BoxControl({
|
|
|
83
83
|
const hasOneSide = sides?.length === 1;
|
|
84
84
|
const [isDirty, setIsDirty] = (0, import_element.useState)(hasInitialValue);
|
|
85
85
|
const [isLinked, setIsLinked] = (0, import_element.useState)(!hasInitialValue || !(0, import_utils2.isValueMixed)(inputValues) || hasOneSide);
|
|
86
|
-
const [side, setSide] = (0, import_element.useState)((0, import_utils2.getInitialSide)(isLinked, splitOnAxis));
|
|
87
86
|
const [selectedUnits, setSelectedUnits] = (0, import_element.useState)({
|
|
88
87
|
top: (0, import_utils.parseQuantityAndUnitFromRawValue)(valuesProp?.top)[1],
|
|
89
88
|
right: (0, import_utils.parseQuantityAndUnitFromRawValue)(valuesProp?.right)[1],
|
|
@@ -94,12 +93,6 @@ function BoxControl({
|
|
|
94
93
|
const headingId = `${id}-heading`;
|
|
95
94
|
const toggleLinked = () => {
|
|
96
95
|
setIsLinked(!isLinked);
|
|
97
|
-
setSide((0, import_utils2.getInitialSide)(!isLinked, splitOnAxis));
|
|
98
|
-
};
|
|
99
|
-
const handleOnFocus = (_event, {
|
|
100
|
-
side: nextSide
|
|
101
|
-
}) => {
|
|
102
|
-
setSide(nextSide);
|
|
103
96
|
};
|
|
104
97
|
const handleOnChange = (nextValues) => {
|
|
105
98
|
onChange(nextValues);
|
|
@@ -117,7 +110,6 @@ function BoxControl({
|
|
|
117
110
|
onMouseOut,
|
|
118
111
|
...inputProps,
|
|
119
112
|
onChange: handleOnChange,
|
|
120
|
-
onFocus: handleOnFocus,
|
|
121
113
|
isLinked,
|
|
122
114
|
units,
|
|
123
115
|
selectedUnits,
|
|
@@ -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 InputControl from './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,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAC9B,qBAAyB;AACzB,kBAAmB;AACnB,qBAAoB;AAKpB,0BAA4B;AAC5B,2BAAyB;AACzB,2BAAyB;AACzB,kBAAqB;AACrB,gCAA+D;AAC/D,mBAAiD;AACjD,IAAAA,gBAA+
|
|
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 InputControl from './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 { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';\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\n * __next40pxDefaultSize\n * values={ values }\n * onChange={ setValues }\n * />\n * );\n * };\n * ```\n */\nfunction BoxControl({\n __next40pxDefaultSize = false,\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 __next40pxDefaultSize,\n presets,\n presetKey\n };\n maybeWarnDeprecated36pxSize({\n componentName: 'BoxControl',\n __next40pxDefaultSize,\n size: undefined\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(InputControl, {\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 =>\n /*#__PURE__*/\n // Disable reason: the parent component is handling the __next40pxDefaultSize prop\n // eslint-disable-next-line @wordpress/components-no-missing-40px-size-prop\n _jsx(InputControl, {\n side: axis,\n ...inputControlProps\n }, axis)), !isLinked && !splitOnAxis && Array.from(sidesToRender).map(axis =>\n /*#__PURE__*/\n // Disable reason: the parent component is handling the __next40pxDefaultSize prop\n // eslint-disable-next-line @wordpress/components-no-missing-40px-size-prop\n _jsx(InputControl, {\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 })]\n });\n}\nexport { applyValueToSides } from './utils';\nexport default BoxControl;"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAC9B,qBAAyB;AACzB,kBAAmB;AACnB,qBAAoB;AAKpB,0BAA4B;AAC5B,2BAAyB;AACzB,2BAAyB;AACzB,kBAAqB;AACrB,gCAA+D;AAC/D,mBAAiD;AACjD,IAAAA,gBAA+E;AAC/E,mBAAmC;AACnC,kCAA4C;AAC5C,yBAA2C;AA4J3C,IAAAA,gBAAkC;AA3JlC,IAAM,oBAAoB;AAAA,EACxB,KAAK;AACP;AACA,IAAM,OAAO,MAAM;AAAC;AACpB,SAAS,YAAY,QAAQ;AAC3B,QAAM,iBAAa,8BAAc,YAAY,uBAAuB;AACpE,SAAO,UAAU;AACnB;AA4BA,SAAS,WAAW;AAAA,EAClB,wBAAwB;AAAA,EACxB,IAAI;AAAA,EACJ,aAAa;AAAA,EACb,WAAW;AAAA,EACX,YAAQ,gBAAG,aAAa;AAAA,EACxB,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA,EACd;AAAA,EACA;AAAA,E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,CAAC;AAAA,MACX,cAAU,gBAAG,OAAO;AAAA,IACtB,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AAEA,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["import_utils", "warning", "_jsxs", "_jsx", "InputControl", "LinkedButton"]
|
|
7
7
|
}
|
|
@@ -37,7 +37,6 @@ __export(utils_exports, {
|
|
|
37
37
|
applyValueToSides: () => applyValueToSides,
|
|
38
38
|
getAllUnitFallback: () => getAllUnitFallback,
|
|
39
39
|
getAllowedSides: () => getAllowedSides,
|
|
40
|
-
getInitialSide: () => getInitialSide,
|
|
41
40
|
getMergedValue: () => getMergedValue,
|
|
42
41
|
getPresetIndexFromValue: () => getPresetIndexFromValue,
|
|
43
42
|
getPresetValueFromIndex: () => getPresetValueFromIndex,
|
|
@@ -47,8 +46,8 @@ __export(utils_exports, {
|
|
|
47
46
|
normalizeSides: () => normalizeSides
|
|
48
47
|
});
|
|
49
48
|
module.exports = __toCommonJS(utils_exports);
|
|
50
|
-
var import_i18n = require("@wordpress/i18n");
|
|
51
49
|
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
50
|
+
var import_i18n = require("@wordpress/i18n");
|
|
52
51
|
var CUSTOM_VALUE_SETTINGS = {
|
|
53
52
|
px: {
|
|
54
53
|
max: 300,
|
|
@@ -208,13 +207,6 @@ function isValuesDefined(values) {
|
|
|
208
207
|
(value) => !!value && /\d/.test(value)
|
|
209
208
|
).length > 0;
|
|
210
209
|
}
|
|
211
|
-
function getInitialSide(isLinked, splitOnAxis) {
|
|
212
|
-
let initialSide = "all";
|
|
213
|
-
if (!isLinked) {
|
|
214
|
-
initialSide = splitOnAxis ? "vertical" : "top";
|
|
215
|
-
}
|
|
216
|
-
return initialSide;
|
|
217
|
-
}
|
|
218
210
|
function normalizeSides(sides) {
|
|
219
211
|
const filteredSides = [];
|
|
220
212
|
if (!sides?.length) {
|
|
@@ -300,7 +292,6 @@ function getPresetValueFromIndex(index, presetKey, presets) {
|
|
|
300
292
|
applyValueToSides,
|
|
301
293
|
getAllUnitFallback,
|
|
302
294
|
getAllowedSides,
|
|
303
|
-
getInitialSide,
|
|
304
295
|
getMergedValue,
|
|
305
296
|
getPresetIndexFromValue,
|
|
306
297
|
getPresetValueFromIndex,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/box-control/utils.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\n\nexport const CUSTOM_VALUE_SETTINGS = {\n px: {\n max: 300,\n step: 1\n },\n '%': {\n max: 100,\n step: 1\n },\n vw: {\n max: 100,\n step: 1\n },\n vh: {\n max: 100,\n step: 1\n },\n em: {\n max: 10,\n step: 0.1\n },\n rm: {\n max: 10,\n step: 0.1\n },\n svw: {\n max: 100,\n step: 1\n },\n lvw: {\n max: 100,\n step: 1\n },\n dvw: {\n max: 100,\n step: 1\n },\n svh: {\n max: 100,\n step: 1\n },\n lvh: {\n max: 100,\n step: 1\n },\n dvh: {\n max: 100,\n step: 1\n },\n vi: {\n max: 100,\n step: 1\n },\n svi: {\n max: 100,\n step: 1\n },\n lvi: {\n max: 100,\n step: 1\n },\n dvi: {\n max: 100,\n step: 1\n },\n vb: {\n max: 100,\n step: 1\n },\n svb: {\n max: 100,\n step: 1\n },\n lvb: {\n max: 100,\n step: 1\n },\n dvb: {\n max: 100,\n step: 1\n },\n vmin: {\n max: 100,\n step: 1\n },\n svmin: {\n max: 100,\n step: 1\n },\n lvmin: {\n max: 100,\n step: 1\n },\n dvmin: {\n max: 100,\n step: 1\n },\n vmax: {\n max: 100,\n step: 1\n },\n svmax: {\n max: 100,\n step: 1\n },\n lvmax: {\n max: 100,\n step: 1\n },\n dvmax: {\n max: 100,\n step: 1\n }\n};\nexport const LABELS = {\n all: __('All sides'),\n top: __('Top side'),\n bottom: __('Bottom side'),\n left: __('Left side'),\n right: __('Right side'),\n vertical: __('Top and bottom sides'),\n horizontal: __('Left and right sides')\n};\nexport const DEFAULT_VALUES = {\n top: undefined,\n right: undefined,\n bottom: undefined,\n left: undefined\n};\nexport const ALL_SIDES = ['top', 'right', 'bottom', 'left'];\n\n/**\n * Gets an items with the most occurrence within an array\n * https://stackoverflow.com/a/20762713\n *\n * @param arr Array of items to check.\n * @return The item with the most occurrences.\n */\nfunction mode(arr) {\n return arr.sort((a, b) => arr.filter(v => v === a).length - arr.filter(v => v === b).length).pop();\n}\n\n/**\n * Gets the merged input value and unit from values data.\n *\n * @param values Box values.\n * @param availableSides Available box sides to evaluate.\n *\n * @return A value + unit for the 'all' input.\n */\nexport function getMergedValue(values = {}, availableSides = ALL_SIDES) {\n const sides = normalizeSides(availableSides);\n if (sides.every(side => values[side] === values[sides[0]])) {\n return values[sides[0]];\n }\n return undefined;\n}\n\n/**\n * Checks if the values are mixed.\n *\n * @param values Box values.\n * @param availableSides Available box sides to evaluate.\n * @return Whether the values are mixed.\n */\nexport function isValueMixed(values = {}, availableSides = ALL_SIDES) {\n const sides = normalizeSides(availableSides);\n return sides.some(side => values[side] !== values[sides[0]]);\n}\n\n/**\n * Determine the most common unit selection to use as a fallback option.\n *\n * @param selectedUnits Current unit selections for individual sides.\n * @return Most common unit selection.\n */\nexport function getAllUnitFallback(selectedUnits) {\n if (!selectedUnits || typeof selectedUnits !== 'object') {\n return undefined;\n }\n const filteredUnits = Object.values(selectedUnits).filter(Boolean);\n return mode(filteredUnits);\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param values Box values.\n *\n * @return Whether values are mixed.\n */\nexport function isValuesDefined(values) {\n return values && Object.values(values).filter(\n // Switching units when input is empty causes values only\n // containing units. This gives false positive on mixed values\n // unless filtered.\n value => !!value && /\\d/.test(value)).length > 0;\n}\n\n/**\n * Normalizes provided sides configuration to an array containing only top,\n * right, bottom and left. This essentially just maps `horizontal` or `vertical`\n * to their appropriate sides to facilitate correctly determining value for\n * all input control.\n *\n * @param sides Available sides for box control.\n * @return Normalized sides configuration.\n */\nexport function normalizeSides(sides) {\n const filteredSides = [];\n if (!sides?.length) {\n return ALL_SIDES;\n }\n if (sides.includes('vertical')) {\n filteredSides.push(...['top', 'bottom']);\n } else if (sides.includes('horizontal')) {\n filteredSides.push(...['left', 'right']);\n } else {\n const newSides = ALL_SIDES.filter(side => sides.includes(side));\n filteredSides.push(...newSides);\n }\n return filteredSides;\n}\n\n/**\n * Applies a value to an object representing top, right, bottom and left sides\n * while taking into account any custom side configuration.\n *\n * @deprecated\n *\n * @param currentValues The current values for each side.\n * @param newValue The value to apply to the sides object.\n * @param sides Array defining valid sides.\n *\n * @return Object containing the updated values for each side.\n */\nexport function applyValueToSides(currentValues, newValue, sides) {\n deprecated('applyValueToSides', {\n since: '6.8',\n version: '7.0'\n });\n const newValues = {\n ...currentValues\n };\n if (sides?.length) {\n sides.forEach(side => {\n if (side === 'vertical') {\n newValues.top = newValue;\n newValues.bottom = newValue;\n } else if (side === 'horizontal') {\n newValues.left = newValue;\n newValues.right = newValue;\n } else {\n newValues[side] = newValue;\n }\n });\n } else {\n ALL_SIDES.forEach(side => newValues[side] = newValue);\n }\n return newValues;\n}\n\n/**\n * Return the allowed sides based on the sides configuration.\n *\n * @param sides Sides configuration.\n * @return Allowed sides.\n */\nexport function getAllowedSides(sides) {\n const allowedSides = new Set(!sides ? ALL_SIDES : []);\n sides?.forEach(allowedSide => {\n if (allowedSide === 'vertical') {\n allowedSides.add('top');\n allowedSides.add('bottom');\n } else if (allowedSide === 'horizontal') {\n allowedSides.add('right');\n allowedSides.add('left');\n } else {\n allowedSides.add(allowedSide);\n }\n });\n return allowedSides;\n}\n\n/**\n * Checks if a value is a preset value.\n *\n * @param value The value to check.\n * @param presetKey The preset key to check against.\n * @return Whether the value is a preset value.\n */\nexport function isValuePreset(value, presetKey) {\n return value.startsWith(`var:preset|${presetKey}|`);\n}\n\n/**\n * Returns the index of the preset value in the presets array.\n *\n * @param value The value to check.\n * @param presetKey The preset key to check against.\n * @param presets The array of presets to search.\n * @return The index of the preset value in the presets array.\n */\nexport function getPresetIndexFromValue(value, presetKey, presets) {\n if (!isValuePreset(value, presetKey)) {\n return undefined;\n }\n const match = value.match(new RegExp(`^var:preset\\\\|${presetKey}\\\\|(.+)$`));\n if (!match) {\n return undefined;\n }\n const slug = match[1];\n const index = presets.findIndex(preset => {\n return preset.slug === slug;\n });\n return index !== -1 ? index : undefined;\n}\n\n/**\n * Returns the preset value from the index.\n *\n * @param index The index of the preset value in the presets array.\n * @param presetKey The preset key to check against.\n * @param presets The array of presets to search.\n * @return The preset value from the index.\n */\nexport function getPresetValueFromIndex(index, presetKey, presets) {\n const preset = presets[index];\n return `var:preset|${presetKey}|${preset.slug}`;\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,kBAAmB;AAMZ,IAAM,wBAAwB;AAAA,EACnC,IAAI;AAAA,IACF,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AAAA,EACA,KAAK;AAAA,IACH,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AAAA,EACA,IAAI;AAAA,IACF,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AAAA,EACA,IAAI;AAAA,IACF,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AAAA,EACA,IAAI;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,EACtD;AACA,SAAO;AACT;AAQO,SAAS,gBAAgB,OAAO;AACrC,QAAM,eAAe,IAAI,IAAI,CAAC,QAAQ,YAAY,CAAC,CAAC;AACpD,SAAO,QAAQ,iBAAe;AAC5B,QAAI,gBAAgB,YAAY;AAC9B,mBAAa,IAAI,KAAK;AACtB,mBAAa,IAAI,QAAQ;AAAA,IAC3B,WAAW,gBAAgB,cAAc;AACvC,mBAAa,IAAI,OAAO;AACxB,mBAAa,IAAI,MAAM;AAAA,IACzB,OAAO;AACL,mBAAa,IAAI,WAAW;AAAA,IAC9B;AAAA,EACF,CAAC;AACD,SAAO;AACT;AASO,SAAS,cAAc,OAAO,WAAW;AAC9C,SAAO,MAAM,WAAW,cAAc,SAAS,GAAG;AACpD;AAUO,SAAS,wBAAwB,OAAO,WAAW,SAAS;AACjE,MAAI,CAAC,cAAc,OAAO,SAAS,GAAG;AACpC,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,MAAM,MAAM,IAAI,OAAO,iBAAiB,SAAS,UAAU,CAAC;AAC1E,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,QAAM,OAAO,MAAM,CAAC;AACpB,QAAM,QAAQ,QAAQ,UAAU,YAAU;AACxC,WAAO,OAAO,SAAS;AAAA,EACzB,CAAC;AACD,SAAO,UAAU,KAAK,QAAQ;AAChC;AAUO,SAAS,wBAAwB,OAAO,WAAW,SAAS;AACjE,QAAM,SAAS,QAAQ,KAAK;AAC5B,SAAO,cAAc,SAAS,IAAI,OAAO,IAAI;AAC/C;",
|
|
6
6
|
"names": ["deprecated"]
|
|
7
7
|
}
|
|
@@ -27,8 +27,9 @@ var import_i18n = require("@wordpress/i18n");
|
|
|
27
27
|
var import_element = require("@wordpress/element");
|
|
28
28
|
function isLocaleRTL(localeCode) {
|
|
29
29
|
const localeObj = new Intl.Locale(localeCode);
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const direction = localeObj.getTextInfo?.().direction;
|
|
31
|
+
if (direction) {
|
|
32
|
+
return direction === "rtl";
|
|
32
33
|
}
|
|
33
34
|
return [
|
|
34
35
|
"ar",
|