@fluentui/react-utilities 9.2.0 → 9.2.2
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.json +45 -1
- package/CHANGELOG.md +21 -2
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js.map +1 -1
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/ssr/index.js.map +1 -1
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/trigger/getTriggerChild.js.map +1 -1
- package/lib/trigger/index.js.map +1 -1
- package/lib/trigger/isFluentTrigger.js.map +1 -1
- package/lib/trigger/types.js.map +1 -1
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeCallbacks.js.map +1 -1
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +1 -1
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-amd/compose/getSlots.js +58 -0
- package/lib-amd/compose/getSlots.js.map +1 -0
- package/lib-amd/compose/index.js +9 -0
- package/lib-amd/compose/index.js.map +1 -0
- package/lib-amd/compose/isResolvedShorthand.js +40 -0
- package/lib-amd/compose/isResolvedShorthand.js.map +1 -0
- package/lib-amd/compose/resolveShorthand.js +27 -0
- package/lib-amd/compose/resolveShorthand.js.map +1 -0
- package/lib-amd/compose/types.js +5 -0
- package/lib-amd/compose/types.js.map +1 -0
- package/lib-amd/hooks/index.js +16 -0
- package/lib-amd/hooks/index.js.map +1 -0
- package/lib-amd/hooks/useControllableState.js +81 -0
- package/lib-amd/hooks/useControllableState.js.map +1 -0
- package/lib-amd/hooks/useEventCallback.js +36 -0
- package/lib-amd/hooks/useEventCallback.js.map +1 -0
- package/lib-amd/hooks/useFirstMount.js +26 -0
- package/lib-amd/hooks/useFirstMount.js.map +1 -0
- package/lib-amd/hooks/useForceUpdate.js +14 -0
- package/lib-amd/hooks/useForceUpdate.js.map +1 -0
- package/lib-amd/hooks/useId.js +32 -0
- package/lib-amd/hooks/useId.js.map +1 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js +17 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib-amd/hooks/useMergedRefs.js +34 -0
- package/lib-amd/hooks/useMergedRefs.js.map +1 -0
- package/lib-amd/hooks/useOnClickOutside.js +116 -0
- package/lib-amd/hooks/useOnClickOutside.js.map +1 -0
- package/lib-amd/hooks/useOnScrollOutside.js +31 -0
- package/lib-amd/hooks/useOnScrollOutside.js.map +1 -0
- package/lib-amd/hooks/usePrevious.js +17 -0
- package/lib-amd/hooks/usePrevious.js.map +1 -0
- package/lib-amd/hooks/useTimeout.js +33 -0
- package/lib-amd/hooks/useTimeout.js.map +1 -0
- package/lib-amd/index.js +33 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/ssr/SSRContext.js +69 -0
- package/lib-amd/ssr/SSRContext.js.map +1 -0
- package/lib-amd/ssr/canUseDOM.js +16 -0
- package/lib-amd/ssr/canUseDOM.js.map +1 -0
- package/lib-amd/ssr/index.js +7 -0
- package/lib-amd/ssr/index.js.map +1 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js +40 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib-amd/trigger/getTriggerChild.js +40 -0
- package/lib-amd/trigger/getTriggerChild.js.map +1 -0
- package/lib-amd/trigger/index.js +9 -0
- package/lib-amd/trigger/index.js.map +1 -0
- package/lib-amd/trigger/isFluentTrigger.js +15 -0
- package/lib-amd/trigger/isFluentTrigger.js.map +1 -0
- package/lib-amd/trigger/types.js +5 -0
- package/lib-amd/trigger/types.js.map +1 -0
- package/lib-amd/utils/clamp.js +16 -0
- package/lib-amd/utils/clamp.js.map +1 -0
- package/lib-amd/utils/getNativeElementProps.js +64 -0
- package/lib-amd/utils/getNativeElementProps.js.map +1 -0
- package/lib-amd/utils/getRTLSafeKey.js +24 -0
- package/lib-amd/utils/getRTLSafeKey.js.map +1 -0
- package/lib-amd/utils/index.js +12 -0
- package/lib-amd/utils/index.js.map +1 -0
- package/lib-amd/utils/mergeCallbacks.js +40 -0
- package/lib-amd/utils/mergeCallbacks.js.map +1 -0
- package/lib-amd/utils/omit.js +31 -0
- package/lib-amd/utils/omit.js.map +1 -0
- package/lib-amd/utils/properties.js +450 -0
- package/lib-amd/utils/properties.js.map +1 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js +26 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
- package/lib-commonjs/trigger/index.js.map +1 -1
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +1 -1
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +8 -8
@@ -0,0 +1,450 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getNativeProps = exports.divProperties = exports.dialogProperties = exports.imgProperties = exports.iframeProperties = exports.formProperties = exports.fieldsetProperties = exports.colProperties = exports.colGroupProperties = exports.tdProperties = exports.thProperties = exports.trProperties = exports.tableProperties = exports.optionProperties = exports.selectProperties = exports.textAreaProperties = exports.inputProperties = exports.buttonProperties = exports.timeProperties = exports.anchorProperties = exports.liProperties = exports.olProperties = exports.videoProperties = exports.audioProperties = exports.labelProperties = exports.htmlElementProperties = exports.microdataProperties = exports.baseElementProperties = exports.baseElementEvents = void 0;
|
5
|
+
var toObjectMap = function () {
|
6
|
+
var items = [];
|
7
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
8
|
+
items[_i] = arguments[_i];
|
9
|
+
}
|
10
|
+
var result = {};
|
11
|
+
for (var _a = 0, items_1 = items; _a < items_1.length; _a++) {
|
12
|
+
var item = items_1[_a];
|
13
|
+
var keys = Array.isArray(item) ? item : Object.keys(item);
|
14
|
+
for (var _b = 0, keys_1 = keys; _b < keys_1.length; _b++) {
|
15
|
+
var key = keys_1[_b];
|
16
|
+
result[key] = 1;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* An array of events that are allowed on every html element type.
|
23
|
+
*
|
24
|
+
* @public
|
25
|
+
*/
|
26
|
+
exports.baseElementEvents = toObjectMap([
|
27
|
+
'onAuxClick',
|
28
|
+
'onCopy',
|
29
|
+
'onCut',
|
30
|
+
'onPaste',
|
31
|
+
'onCompositionEnd',
|
32
|
+
'onCompositionStart',
|
33
|
+
'onCompositionUpdate',
|
34
|
+
'onFocus',
|
35
|
+
'onFocusCapture',
|
36
|
+
'onBlur',
|
37
|
+
'onBlurCapture',
|
38
|
+
'onChange',
|
39
|
+
'onInput',
|
40
|
+
'onSubmit',
|
41
|
+
'onLoad',
|
42
|
+
'onError',
|
43
|
+
'onKeyDown',
|
44
|
+
'onKeyDownCapture',
|
45
|
+
'onKeyPress',
|
46
|
+
'onKeyUp',
|
47
|
+
'onAbort',
|
48
|
+
'onCanPlay',
|
49
|
+
'onCanPlayThrough',
|
50
|
+
'onDurationChange',
|
51
|
+
'onEmptied',
|
52
|
+
'onEncrypted',
|
53
|
+
'onEnded',
|
54
|
+
'onLoadedData',
|
55
|
+
'onLoadedMetadata',
|
56
|
+
'onLoadStart',
|
57
|
+
'onPause',
|
58
|
+
'onPlay',
|
59
|
+
'onPlaying',
|
60
|
+
'onProgress',
|
61
|
+
'onRateChange',
|
62
|
+
'onSeeked',
|
63
|
+
'onSeeking',
|
64
|
+
'onStalled',
|
65
|
+
'onSuspend',
|
66
|
+
'onTimeUpdate',
|
67
|
+
'onVolumeChange',
|
68
|
+
'onWaiting',
|
69
|
+
'onClick',
|
70
|
+
'onClickCapture',
|
71
|
+
'onContextMenu',
|
72
|
+
'onDoubleClick',
|
73
|
+
'onDrag',
|
74
|
+
'onDragEnd',
|
75
|
+
'onDragEnter',
|
76
|
+
'onDragExit',
|
77
|
+
'onDragLeave',
|
78
|
+
'onDragOver',
|
79
|
+
'onDragStart',
|
80
|
+
'onDrop',
|
81
|
+
'onMouseDown',
|
82
|
+
'onMouseDownCapture',
|
83
|
+
'onMouseEnter',
|
84
|
+
'onMouseLeave',
|
85
|
+
'onMouseMove',
|
86
|
+
'onMouseOut',
|
87
|
+
'onMouseOver',
|
88
|
+
'onMouseUp',
|
89
|
+
'onMouseUpCapture',
|
90
|
+
'onSelect',
|
91
|
+
'onTouchCancel',
|
92
|
+
'onTouchEnd',
|
93
|
+
'onTouchMove',
|
94
|
+
'onTouchStart',
|
95
|
+
'onScroll',
|
96
|
+
'onWheel',
|
97
|
+
'onPointerCancel',
|
98
|
+
'onPointerDown',
|
99
|
+
'onPointerEnter',
|
100
|
+
'onPointerLeave',
|
101
|
+
'onPointerMove',
|
102
|
+
'onPointerOut',
|
103
|
+
'onPointerOver',
|
104
|
+
'onPointerUp',
|
105
|
+
'onGotPointerCapture',
|
106
|
+
'onLostPointerCapture',
|
107
|
+
]);
|
108
|
+
/**
|
109
|
+
* An array of element attributes which are allowed on every html element type.
|
110
|
+
*
|
111
|
+
* @public
|
112
|
+
*/
|
113
|
+
exports.baseElementProperties = toObjectMap([
|
114
|
+
'accessKey',
|
115
|
+
'children',
|
116
|
+
'className',
|
117
|
+
'contentEditable',
|
118
|
+
'dir',
|
119
|
+
'draggable',
|
120
|
+
'hidden',
|
121
|
+
'htmlFor',
|
122
|
+
'id',
|
123
|
+
'lang',
|
124
|
+
'ref',
|
125
|
+
'role',
|
126
|
+
'style',
|
127
|
+
'tabIndex',
|
128
|
+
'title',
|
129
|
+
'translate',
|
130
|
+
'spellCheck',
|
131
|
+
'name', // global
|
132
|
+
]);
|
133
|
+
/**
|
134
|
+
* An array of microdata attributes that are allowed on every html element type.
|
135
|
+
*
|
136
|
+
* @public
|
137
|
+
*/
|
138
|
+
exports.microdataProperties = toObjectMap([
|
139
|
+
'itemID',
|
140
|
+
'itemProp',
|
141
|
+
'itemRef',
|
142
|
+
'itemScope',
|
143
|
+
'itemType', // global
|
144
|
+
]);
|
145
|
+
/**
|
146
|
+
* An array of HTML element properties and events.
|
147
|
+
*
|
148
|
+
* @public
|
149
|
+
*/
|
150
|
+
exports.htmlElementProperties = toObjectMap(exports.baseElementProperties, exports.baseElementEvents, exports.microdataProperties);
|
151
|
+
/**
|
152
|
+
* An array of LABEL tag properties and events.
|
153
|
+
*
|
154
|
+
* @public
|
155
|
+
*/
|
156
|
+
exports.labelProperties = toObjectMap(exports.htmlElementProperties, [
|
157
|
+
'form', // button, fieldset, input, label, meter, object, output, select, textarea
|
158
|
+
]);
|
159
|
+
/**
|
160
|
+
* An array of AUDIO tag properties and events.
|
161
|
+
|
162
|
+
* @public
|
163
|
+
*/
|
164
|
+
exports.audioProperties = toObjectMap(exports.htmlElementProperties, [
|
165
|
+
'height',
|
166
|
+
'loop',
|
167
|
+
'muted',
|
168
|
+
'preload',
|
169
|
+
'src',
|
170
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
171
|
+
]);
|
172
|
+
/**
|
173
|
+
* An array of VIDEO tag properties and events.
|
174
|
+
*
|
175
|
+
* @public
|
176
|
+
*/
|
177
|
+
exports.videoProperties = toObjectMap(exports.audioProperties, [
|
178
|
+
'poster', // video
|
179
|
+
]);
|
180
|
+
/**
|
181
|
+
* An array of OL tag properties and events.
|
182
|
+
*
|
183
|
+
* @public
|
184
|
+
*/
|
185
|
+
exports.olProperties = toObjectMap(exports.htmlElementProperties, [
|
186
|
+
'start', // ol
|
187
|
+
]);
|
188
|
+
/**
|
189
|
+
* An array of LI tag properties and events.
|
190
|
+
*
|
191
|
+
* @public
|
192
|
+
*/
|
193
|
+
exports.liProperties = toObjectMap(exports.htmlElementProperties, [
|
194
|
+
'value', // button, input, li, option, meter, progress, param
|
195
|
+
]);
|
196
|
+
/**
|
197
|
+
* An array of A tag properties and events.
|
198
|
+
*
|
199
|
+
* @public
|
200
|
+
*/
|
201
|
+
exports.anchorProperties = toObjectMap(exports.htmlElementProperties, [
|
202
|
+
'download',
|
203
|
+
'href',
|
204
|
+
'hrefLang',
|
205
|
+
'media',
|
206
|
+
'rel',
|
207
|
+
'target',
|
208
|
+
'type', // a, button, input, link, menu, object, script, source, style
|
209
|
+
]);
|
210
|
+
/**
|
211
|
+
* An array of TIME tag properties and events.
|
212
|
+
*
|
213
|
+
* @public
|
214
|
+
*/
|
215
|
+
exports.timeProperties = toObjectMap(exports.htmlElementProperties, [
|
216
|
+
'dateTime', // time
|
217
|
+
]);
|
218
|
+
/**
|
219
|
+
* An array of BUTTON tag properties and events.
|
220
|
+
*
|
221
|
+
* @public
|
222
|
+
*/
|
223
|
+
exports.buttonProperties = toObjectMap(exports.htmlElementProperties, [
|
224
|
+
'autoFocus',
|
225
|
+
'disabled',
|
226
|
+
'form',
|
227
|
+
'formAction',
|
228
|
+
'formEncType',
|
229
|
+
'formMethod',
|
230
|
+
'formNoValidate',
|
231
|
+
'formTarget',
|
232
|
+
'type',
|
233
|
+
'value', // button, input, li, option, meter, progress, param,
|
234
|
+
]);
|
235
|
+
/**
|
236
|
+
* An array of INPUT tag properties and events.
|
237
|
+
*
|
238
|
+
* @public
|
239
|
+
*/
|
240
|
+
exports.inputProperties = toObjectMap(exports.buttonProperties, [
|
241
|
+
'accept',
|
242
|
+
'alt',
|
243
|
+
'autoCapitalize',
|
244
|
+
'autoComplete',
|
245
|
+
'checked',
|
246
|
+
'dirname',
|
247
|
+
'form',
|
248
|
+
'height',
|
249
|
+
'inputMode',
|
250
|
+
'list',
|
251
|
+
'max',
|
252
|
+
'maxLength',
|
253
|
+
'min',
|
254
|
+
'multiple',
|
255
|
+
'pattern',
|
256
|
+
'placeholder',
|
257
|
+
'readOnly',
|
258
|
+
'required',
|
259
|
+
'src',
|
260
|
+
'step',
|
261
|
+
'size',
|
262
|
+
'type',
|
263
|
+
'value',
|
264
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
265
|
+
]);
|
266
|
+
/**
|
267
|
+
* An array of TEXTAREA tag properties and events.
|
268
|
+
*
|
269
|
+
* @public
|
270
|
+
*/
|
271
|
+
exports.textAreaProperties = toObjectMap(exports.buttonProperties, [
|
272
|
+
'autoCapitalize',
|
273
|
+
'cols',
|
274
|
+
'dirname',
|
275
|
+
'form',
|
276
|
+
'maxLength',
|
277
|
+
'placeholder',
|
278
|
+
'readOnly',
|
279
|
+
'required',
|
280
|
+
'rows',
|
281
|
+
'wrap', // textarea
|
282
|
+
]);
|
283
|
+
/**
|
284
|
+
* An array of SELECT tag properties and events.
|
285
|
+
*
|
286
|
+
* @public
|
287
|
+
*/
|
288
|
+
exports.selectProperties = toObjectMap(exports.buttonProperties, [
|
289
|
+
'form',
|
290
|
+
'multiple',
|
291
|
+
'required', // input, select, textarea
|
292
|
+
]);
|
293
|
+
exports.optionProperties = toObjectMap(exports.htmlElementProperties, [
|
294
|
+
'selected',
|
295
|
+
'value', // button, input, li, option, meter, progress, param
|
296
|
+
]);
|
297
|
+
/**
|
298
|
+
* An array of TABLE tag properties and events.
|
299
|
+
*
|
300
|
+
* @public
|
301
|
+
*/
|
302
|
+
exports.tableProperties = toObjectMap(exports.htmlElementProperties, [
|
303
|
+
'cellPadding',
|
304
|
+
'cellSpacing', // table
|
305
|
+
]);
|
306
|
+
/**
|
307
|
+
* An array of TR tag properties and events.
|
308
|
+
*
|
309
|
+
* @public
|
310
|
+
*/
|
311
|
+
exports.trProperties = exports.htmlElementProperties;
|
312
|
+
/**
|
313
|
+
* An array of TH tag properties and events.
|
314
|
+
*
|
315
|
+
* @public
|
316
|
+
*/
|
317
|
+
exports.thProperties = toObjectMap(exports.htmlElementProperties, [
|
318
|
+
'colSpan',
|
319
|
+
'rowSpan',
|
320
|
+
'scope', // th
|
321
|
+
]);
|
322
|
+
/**
|
323
|
+
* An array of TD tag properties and events.
|
324
|
+
*
|
325
|
+
* @public
|
326
|
+
*/
|
327
|
+
exports.tdProperties = toObjectMap(exports.htmlElementProperties, [
|
328
|
+
'colSpan',
|
329
|
+
'headers',
|
330
|
+
'rowSpan',
|
331
|
+
'scope', // th
|
332
|
+
]);
|
333
|
+
exports.colGroupProperties = toObjectMap(exports.htmlElementProperties, [
|
334
|
+
'span', // col, colgroup
|
335
|
+
]);
|
336
|
+
exports.colProperties = toObjectMap(exports.htmlElementProperties, [
|
337
|
+
'span', // col, colgroup
|
338
|
+
]);
|
339
|
+
/**
|
340
|
+
* An array of FIELDSET tag properties and events.
|
341
|
+
*
|
342
|
+
* @public
|
343
|
+
*/
|
344
|
+
exports.fieldsetProperties = toObjectMap(exports.htmlElementProperties, [
|
345
|
+
'disabled',
|
346
|
+
'form', // button, fieldset, input, label, meter, object, output, select, textarea
|
347
|
+
]);
|
348
|
+
/**
|
349
|
+
* An array of FORM tag properties and events.
|
350
|
+
*
|
351
|
+
* @public
|
352
|
+
*/
|
353
|
+
exports.formProperties = toObjectMap(exports.htmlElementProperties, [
|
354
|
+
'acceptCharset',
|
355
|
+
'action',
|
356
|
+
'encType',
|
357
|
+
'encType',
|
358
|
+
'method',
|
359
|
+
'noValidate',
|
360
|
+
'target', // form
|
361
|
+
]);
|
362
|
+
/**
|
363
|
+
* An array of IFRAME tag properties and events.
|
364
|
+
*
|
365
|
+
* @public
|
366
|
+
*/
|
367
|
+
exports.iframeProperties = toObjectMap(exports.htmlElementProperties, [
|
368
|
+
'allow',
|
369
|
+
'allowFullScreen',
|
370
|
+
'allowPaymentRequest',
|
371
|
+
'allowTransparency',
|
372
|
+
'csp',
|
373
|
+
'height',
|
374
|
+
'importance',
|
375
|
+
'referrerPolicy',
|
376
|
+
'sandbox',
|
377
|
+
'src',
|
378
|
+
'srcDoc',
|
379
|
+
'width', // canvas, embed, iframe, img, input, object, video,
|
380
|
+
]);
|
381
|
+
/**
|
382
|
+
* An array of IMAGE tag properties and events.
|
383
|
+
*
|
384
|
+
* @public
|
385
|
+
*/
|
386
|
+
exports.imgProperties = toObjectMap(exports.htmlElementProperties, [
|
387
|
+
'alt',
|
388
|
+
'crossOrigin',
|
389
|
+
'height',
|
390
|
+
'src',
|
391
|
+
'srcSet',
|
392
|
+
'useMap',
|
393
|
+
'width', // canvas, embed, iframe, img, input, object, video
|
394
|
+
]);
|
395
|
+
/**
|
396
|
+
* An array of DIALOG tag properties and events.
|
397
|
+
*
|
398
|
+
* @public
|
399
|
+
*/
|
400
|
+
exports.dialogProperties = toObjectMap(exports.htmlElementProperties, ['open', 'onCancel', 'onClose']);
|
401
|
+
/**
|
402
|
+
* An array of DIV tag properties and events.
|
403
|
+
*
|
404
|
+
* @public
|
405
|
+
*/
|
406
|
+
exports.divProperties = exports.htmlElementProperties;
|
407
|
+
/**
|
408
|
+
* Gets native supported props for an html element provided the allowance set. Use one of the property
|
409
|
+
* sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
|
410
|
+
* props set. Note that all data- and aria- prefixed attributes will be allowed.
|
411
|
+
* NOTE: getNativeProps should always be applied first when adding props to a react component. The
|
412
|
+
* non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
|
413
|
+
* For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
|
414
|
+
* the component after an onClick function is added, then the getNativeProps onClick will override it.
|
415
|
+
*
|
416
|
+
* @public
|
417
|
+
* @param props - The unfiltered input props
|
418
|
+
* @param allowedPropNames - The array or record of allowed prop names.
|
419
|
+
* @param excludedPropNames
|
420
|
+
* @returns The filtered props
|
421
|
+
*/
|
422
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
423
|
+
function getNativeProps(
|
424
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
425
|
+
props, allowedPropNames, excludedPropNames) {
|
426
|
+
// It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for
|
427
|
+
// JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.
|
428
|
+
// Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then
|
429
|
+
// return native props.
|
430
|
+
// We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797
|
431
|
+
var isArray = Array.isArray(allowedPropNames);
|
432
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
433
|
+
var result = {};
|
434
|
+
var keys = Object.keys(props);
|
435
|
+
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
436
|
+
var key = keys_2[_i];
|
437
|
+
var isNativeProp = (!isArray && allowedPropNames[key]) ||
|
438
|
+
(isArray && allowedPropNames.indexOf(key) >= 0) ||
|
439
|
+
key.indexOf('data-') === 0 ||
|
440
|
+
key.indexOf('aria-') === 0;
|
441
|
+
if (isNativeProp && (!excludedPropNames || (excludedPropNames === null || excludedPropNames === void 0 ? void 0 : excludedPropNames.indexOf(key)) === -1)) {
|
442
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
443
|
+
result[key] = props[key];
|
444
|
+
}
|
445
|
+
}
|
446
|
+
return result;
|
447
|
+
}
|
448
|
+
exports.getNativeProps = getNativeProps;
|
449
|
+
});
|
450
|
+
//# sourceMappingURL=properties.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/properties.ts"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;gBAC/D,CAAC,OAAO,IAAK,gBAA6B,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC7D,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;gBAC1B,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAE7B,IAAI,YAAY,IAAI,CAAC,CAAC,iBAAiB,IAAI,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,CAAC,GAAG,CAAC,MAAK,CAAC,CAAC,CAAC,EAAE;gBAClF,8DAA8D;gBAC9D,MAAM,CAAC,GAAG,CAAC,GAAG,KAAM,CAAC,GAAG,CAAQ,CAAC;aAClC;SACF;QAED,OAAO,MAAW,CAAC;IACrB,CAAC;IA/BD,wCA+BC","sourcesContent":["const toObjectMap = (...items: (string[] | Record<string, number>)[]) => {\n const result: Record<string, number> = {};\n\n for (const item of items) {\n const keys = Array.isArray(item) ? item : Object.keys(item);\n\n for (const key of keys) {\n result[key] = 1;\n }\n }\n\n return result;\n};\n\n/**\n * An array of events that are allowed on every html element type.\n *\n * @public\n */\nexport const baseElementEvents = toObjectMap([\n 'onAuxClick',\n 'onCopy',\n 'onCut',\n 'onPaste',\n 'onCompositionEnd',\n 'onCompositionStart',\n 'onCompositionUpdate',\n 'onFocus',\n 'onFocusCapture',\n 'onBlur',\n 'onBlurCapture',\n 'onChange',\n 'onInput',\n 'onSubmit',\n 'onLoad',\n 'onError',\n 'onKeyDown',\n 'onKeyDownCapture',\n 'onKeyPress',\n 'onKeyUp',\n 'onAbort',\n 'onCanPlay',\n 'onCanPlayThrough',\n 'onDurationChange',\n 'onEmptied',\n 'onEncrypted',\n 'onEnded',\n 'onLoadedData',\n 'onLoadedMetadata',\n 'onLoadStart',\n 'onPause',\n 'onPlay',\n 'onPlaying',\n 'onProgress',\n 'onRateChange',\n 'onSeeked',\n 'onSeeking',\n 'onStalled',\n 'onSuspend',\n 'onTimeUpdate',\n 'onVolumeChange',\n 'onWaiting',\n 'onClick',\n 'onClickCapture',\n 'onContextMenu',\n 'onDoubleClick',\n 'onDrag',\n 'onDragEnd',\n 'onDragEnter',\n 'onDragExit',\n 'onDragLeave',\n 'onDragOver',\n 'onDragStart',\n 'onDrop',\n 'onMouseDown',\n 'onMouseDownCapture',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseMove',\n 'onMouseOut',\n 'onMouseOver',\n 'onMouseUp',\n 'onMouseUpCapture',\n 'onSelect',\n 'onTouchCancel',\n 'onTouchEnd',\n 'onTouchMove',\n 'onTouchStart',\n 'onScroll',\n 'onWheel',\n 'onPointerCancel',\n 'onPointerDown',\n 'onPointerEnter',\n 'onPointerLeave',\n 'onPointerMove',\n 'onPointerOut',\n 'onPointerOver',\n 'onPointerUp',\n 'onGotPointerCapture',\n 'onLostPointerCapture',\n]);\n\n/**\n * An array of element attributes which are allowed on every html element type.\n *\n * @public\n */\nexport const baseElementProperties = toObjectMap([\n 'accessKey', // global\n 'children', // global\n 'className', // global\n 'contentEditable', // global\n 'dir', // global\n 'draggable', // global\n 'hidden', // global\n 'htmlFor', // global\n 'id', // global\n 'lang', // global\n 'ref', // global\n 'role', // global\n 'style', // global\n 'tabIndex', // global\n 'title', // global\n 'translate', // global\n 'spellCheck', // global\n 'name', // global\n]);\n\n/**\n * An array of microdata attributes that are allowed on every html element type.\n *\n * @public\n */\nexport const microdataProperties = toObjectMap([\n 'itemID', // global\n 'itemProp', // global\n 'itemRef', // global\n 'itemScope', // global\n 'itemType', // global\n]);\n\n/**\n * An array of HTML element properties and events.\n *\n * @public\n */\nexport const htmlElementProperties = toObjectMap(baseElementProperties, baseElementEvents, microdataProperties);\n\n/**\n * An array of LABEL tag properties and events.\n *\n * @public\n */\nexport const labelProperties = toObjectMap(htmlElementProperties, [\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n]);\n\n/**\n * An array of AUDIO tag properties and events.\n\n * @public\n */\nexport const audioProperties = toObjectMap(htmlElementProperties, [\n 'height', // canvas, embed, iframe, img, input, object, video\n 'loop', // audio, video\n 'muted', // audio, video\n 'preload', // audio, video\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * An array of VIDEO tag properties and events.\n *\n * @public\n */\nexport const videoProperties = toObjectMap(audioProperties, [\n 'poster', // video\n]);\n\n/**\n * An array of OL tag properties and events.\n *\n * @public\n */\nexport const olProperties = toObjectMap(htmlElementProperties, [\n 'start', // ol\n]);\n\n/**\n * An array of LI tag properties and events.\n *\n * @public\n */\nexport const liProperties = toObjectMap(htmlElementProperties, [\n 'value', // button, input, li, option, meter, progress, param\n]);\n\n/**\n * An array of A tag properties and events.\n *\n * @public\n */\nexport const anchorProperties = toObjectMap(htmlElementProperties, [\n 'download', // a, area\n 'href', // a, area, base, link\n 'hrefLang', // a, area, link\n 'media', // a, area, link, source, style\n 'rel', // a, area, link\n 'target', // a, area, base, form\n 'type', // a, button, input, link, menu, object, script, source, style\n]);\n\n/**\n * An array of TIME tag properties and events.\n *\n * @public\n */\nexport const timeProperties = toObjectMap(htmlElementProperties, [\n 'dateTime', // time\n]);\n\n/**\n * An array of BUTTON tag properties and events.\n *\n * @public\n */\nexport const buttonProperties = toObjectMap(htmlElementProperties, [\n 'autoFocus', // button, input, select, textarea\n 'disabled', // button, fieldset, input, optgroup, option, select, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'formAction', // input, button\n 'formEncType', // input, button\n 'formMethod', // input, button\n 'formNoValidate', // input, button\n 'formTarget', // input, button\n 'type', // a, button, input, link, menu, object, script, source, style\n 'value', // button, input, li, option, meter, progress, param,\n]);\n\n/**\n * An array of INPUT tag properties and events.\n *\n * @public\n */\nexport const inputProperties = toObjectMap(buttonProperties, [\n 'accept', // input\n 'alt', // area, img, input\n 'autoCapitalize', // input, textarea\n 'autoComplete', // form, input\n 'checked', // input\n 'dirname', // input, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'height', // canvas, embed, iframe, img, input, object, video\n 'inputMode', // input\n 'list', // input\n 'max', // input, meter\n 'maxLength', // input, textarea\n 'min', // input, meter\n 'multiple', // input, select\n 'pattern', // input\n 'placeholder', // input, textarea\n 'readOnly', // input, textarea\n 'required', // input, select, textarea\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'step', // input\n 'size', // input\n 'type', // a, button, input, link, menu, object, script, source, style\n 'value', // button, input, li, option, meter, progress, param\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * An array of TEXTAREA tag properties and events.\n *\n * @public\n */\nexport const textAreaProperties = toObjectMap(buttonProperties, [\n 'autoCapitalize', // input, textarea\n 'cols', // textarea\n 'dirname', // input, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'maxLength', // input, textarea\n 'placeholder', // input, textarea\n 'readOnly', // input, textarea\n 'required', // input, select, textarea\n 'rows', // textarea\n 'wrap', // textarea\n]);\n\n/**\n * An array of SELECT tag properties and events.\n *\n * @public\n */\nexport const selectProperties = toObjectMap(buttonProperties, [\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'multiple', // input, select\n 'required', // input, select, textarea\n]);\n\nexport const optionProperties = toObjectMap(htmlElementProperties, [\n 'selected', // option\n 'value', // button, input, li, option, meter, progress, param\n]);\n\n/**\n * An array of TABLE tag properties and events.\n *\n * @public\n */\nexport const tableProperties = toObjectMap(htmlElementProperties, [\n 'cellPadding', // table\n 'cellSpacing', // table\n]);\n\n/**\n * An array of TR tag properties and events.\n *\n * @public\n */\nexport const trProperties = htmlElementProperties;\n\n/**\n * An array of TH tag properties and events.\n *\n * @public\n */\nexport const thProperties = toObjectMap(htmlElementProperties, [\n 'colSpan', // td, th\n 'rowSpan', // td, th\n 'scope', // th\n]);\n\n/**\n * An array of TD tag properties and events.\n *\n * @public\n */\nexport const tdProperties = toObjectMap(htmlElementProperties, [\n 'colSpan', // td\n 'headers', // td\n 'rowSpan', // td, th\n 'scope', // th\n]);\n\nexport const colGroupProperties = toObjectMap(htmlElementProperties, [\n 'span', // col, colgroup\n]);\n\nexport const colProperties = toObjectMap(htmlElementProperties, [\n 'span', // col, colgroup\n]);\n\n/**\n * An array of FIELDSET tag properties and events.\n *\n * @public\n */\nexport const fieldsetProperties = toObjectMap(htmlElementProperties, [\n 'disabled', // button, fieldset, input, optgroup, option, select, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n]);\n\n/**\n * An array of FORM tag properties and events.\n *\n * @public\n */\nexport const formProperties = toObjectMap(htmlElementProperties, [\n 'acceptCharset', // form\n 'action', // form\n 'encType', // form\n 'encType', // form\n 'method', // form\n 'noValidate', // form\n 'target', // form\n]);\n\n/**\n * An array of IFRAME tag properties and events.\n *\n * @public\n */\nexport const iframeProperties = toObjectMap(htmlElementProperties, [\n 'allow', // iframe\n 'allowFullScreen', // iframe\n 'allowPaymentRequest', // iframe\n 'allowTransparency', // iframe\n 'csp', // iframe\n 'height', // canvas, embed, iframe, img, input, object, video\n 'importance', // iframe\n 'referrerPolicy', // iframe\n 'sandbox', // iframe\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'srcDoc', // iframe\n 'width', // canvas, embed, iframe, img, input, object, video,\n]);\n\n/**\n * An array of IMAGE tag properties and events.\n *\n * @public\n */\nexport const imgProperties = toObjectMap(htmlElementProperties, [\n 'alt', // area, img, input\n 'crossOrigin', // img\n 'height', // canvas, embed, iframe, img, input, object, video\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'srcSet', // img, source\n 'useMap', // img, object,\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * An array of DIALOG tag properties and events.\n *\n * @public\n */\nexport const dialogProperties = toObjectMap(htmlElementProperties, ['open', 'onCancel', 'onClose']);\n\n/**\n * An array of DIV tag properties and events.\n *\n * @public\n */\nexport const divProperties = htmlElementProperties;\n\n/**\n * Gets native supported props for an html element provided the allowance set. Use one of the property\n * sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given\n * props set. Note that all data- and aria- prefixed attributes will be allowed.\n * NOTE: getNativeProps should always be applied first when adding props to a react component. The\n * non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.\n * For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to\n * the component after an onClick function is added, then the getNativeProps onClick will override it.\n *\n * @public\n * @param props - The unfiltered input props\n * @param allowedPropNames - The array or record of allowed prop names.\n * @param excludedPropNames\n * @returns The filtered props\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeProps<T extends Record<string, any>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n props: Record<string, any>,\n allowedPropNames: string[] | Record<string, number>,\n excludedPropNames?: string[],\n): T {\n // It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for\n // JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.\n // Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then\n // return native props.\n // We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797\n\n const isArray = Array.isArray(allowedPropNames);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n const keys = Object.keys(props);\n\n for (const key of keys) {\n const isNativeProp =\n (!isArray && (allowedPropNames as Record<string, number>)[key]) ||\n (isArray && (allowedPropNames as string[]).indexOf(key) >= 0) ||\n key.indexOf('data-') === 0 ||\n key.indexOf('aria-') === 0;\n\n if (isNativeProp && (!excludedPropNames || excludedPropNames?.indexOf(key) === -1)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result[key] = props![key] as any;\n }\n }\n\n return result as T;\n}\n"]}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
define(["require", "exports", "@fluentui/keyboard-keys"], function (require, exports, keyboard_keys_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.shouldPreventDefaultOnKeyDown = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
|
8
|
+
*
|
9
|
+
* Useful for situations where a keydown needs to be transformed to a click event
|
10
|
+
*/
|
11
|
+
function shouldPreventDefaultOnKeyDown(e) {
|
12
|
+
if (e.defaultPrevented) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
var key = e.key;
|
16
|
+
var target = e.target;
|
17
|
+
var matchesByKey = key === keyboard_keys_1.Space || key === keyboard_keys_1.Enter;
|
18
|
+
if ((target === null || target === void 0 ? void 0 : target.tagName) === 'A') {
|
19
|
+
return key === keyboard_keys_1.Space;
|
20
|
+
}
|
21
|
+
var ignoredByTag = (target === null || target === void 0 ? void 0 : target.tagName) === 'INPUT' || (target === null || target === void 0 ? void 0 : target.tagName) === 'TEXTAREA' || (target === null || target === void 0 ? void 0 : target.isContentEditable) === true;
|
22
|
+
return matchesByKey && !ignoredByTag;
|
23
|
+
}
|
24
|
+
exports.shouldPreventDefaultOnKeyDown = shouldPreventDefaultOnKeyDown;
|
25
|
+
});
|
26
|
+
//# sourceMappingURL=shouldPreventDefaultOnKeyDown.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shouldPreventDefaultOnKeyDown.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/shouldPreventDefaultOnKeyDown.ts"],"names":[],"mappings":";;;;IAGA;;;;;OAKG;IACH,SAAgB,6BAA6B,CAAC,CAAsC;QAClF,IAAI,CAAC,CAAC,gBAAgB,EAAE;YACtB,OAAO,KAAK,CAAC;SACd;QAED,IAAM,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;QAClB,IAAM,MAAM,GAA4B,CAAC,CAAC,MAAqB,CAAC;QAEhE,IAAM,YAAY,GAAG,GAAG,KAAK,qBAAK,IAAI,GAAG,KAAK,qBAAK,CAAC;QAEpD,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,MAAK,GAAG,EAAE;YAC3B,OAAO,GAAG,KAAK,qBAAK,CAAC;SACtB;QAED,IAAM,YAAY,GAChB,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,MAAK,OAAO,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,MAAK,UAAU,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,iBAAiB,MAAK,IAAI,CAAC;QAEtG,OAAO,YAAY,IAAI,CAAC,YAAY,CAAC;IACvC,CAAC;IAlBD,sEAkBC","sourcesContent":["import { Space, Enter } from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * @internal\n * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys\n *\n * Useful for situations where a keydown needs to be transformed to a click event\n */\nexport function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React.KeyboardEvent) {\n if (e.defaultPrevented) {\n return false;\n }\n\n const key = e.key;\n const target: HTMLElement | undefined = e.target as HTMLElement;\n\n const matchesByKey = key === Space || key === Enter;\n\n if (target?.tagName === 'A') {\n return key === Space;\n }\n\n const ignoredByTag =\n target?.tagName === 'INPUT' || target?.tagName === 'TEXTAREA' || target?.isContentEditable === true;\n\n return matchesByKey && !ignoredByTag;\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/getSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAEA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AA6BA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAC0B;EAKxB,MAAM,KAAK,GAAG,EAAd;EACA,MAAM,SAAS,GAAG,EAAlB;EAEA,MAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;EACA,KAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;IAChC,MAAM,CAAC,IA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AAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;EACA,MAAM,SAAS,GAAI,gBAAgB,GAAG,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;EAEA,OAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: (slotProps as unknown) as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/compose/getSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAEA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AA6BA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAC0B;EAKxB,MAAM,KAAK,GAAG,EAAd;EACA,MAAM,SAAS,GAAG,EAAlB;EAEA,MAAM,SAAS,GAAgB,MAAM,CAAC,IAAP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P;IADjB,CAFI,CAAP;EAMD;;EAED,MAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;EACA,MAAM,SAAS,GAAI,gBAAgB,GAAG,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;EAEA,OAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: (slotProps as unknown) as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,uBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/compose/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,uBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/isResolvedShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;;;AACH,SAAgB,mBAAhB,CACE,SADF,EACuB;EAErB,OAAO,SAAS,KAAK,IAAd,IAAsB,OAAO,SAAP,KAAqB,QAA3C,IAAuD,CAAC,KAAK,CAAC,OAAN,CAAc,SAAd,CAAxD,IAAoF,CAAC,OAAA,CAAA,cAAA,CAAe,SAAf,CAA5F;AACD;;AAJD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/compose/isResolvedShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;;;AACH,SAAgB,mBAAhB,CACE,SADF,EACuB;EAErB,OAAO,SAAS,KAAK,IAAd,IAAsB,OAAO,SAAP,KAAqB,QAA3C,IAAuD,CAAC,KAAK,CAAC,OAAN,CAAc,SAAd,CAAxD,IAAoF,CAAC,OAAA,CAAA,cAAA,CAAe,SAAf,CAA5F;AACD;;AAJD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAkBA;;;;;AAKG;;;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;EAC3E,MAAM;IAAE,QAAQ,GAAG,KAAb;IAAoB;EAApB,IAAqC,OAAO,IAAI,EAAtD;;EACA,IAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;IACxD,OAAO,SAAP;EACD;;EAED,IAAI,iBAAiB,GAAG,EAAxB;;EAEA,IAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;IAC3G,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;EACD,CAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;IACpC,iBAAiB,GAAG,KAApB;EACD;;EAED,OAAO,YAAY,GAAG,EAAE,GAAG,YAAL;IAAmB,GAAG;EAAtB,CAAH,GAA+C,iBAAlE;AACD,CAfM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAkBA;;;;;AAKG;;;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;EAC3E,MAAM;IAAE,QAAQ,GAAG,KAAb;IAAoB;EAApB,IAAqC,OAAO,IAAI,EAAtD;;EACA,IAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;IACxD,OAAO,SAAP;EACD;;EAED,IAAI,iBAAiB,GAAG,EAAxB;;EAEA,IAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;IAC3G,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;EACD,CAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;IACpC,iBAAiB,GAAG,KAApB;EACD;;EAED,OAAO,YAAY,GAAG,EAAE,GAAG,YAAL;IAAmB,GAAG;EAAtB,CAAH,GAA+C,iBAAlE;AACD,CAfM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAqBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;EACrE,OAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;;;AAeG;;;AACI,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;EACxD,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;EACA,MAAM,YAAY,GAAG,OAAO,OAAO,CAAC,YAAf,KAAgC,WAAhC,GAA8C,OAAO,CAAC,YAAtD,GAAqE,OAAO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AG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;QACA,OAAO,CAAC,KAAR,CACE,CACE;QACA,6BAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;MAUD;IACF,CAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;EAuBD;;EAED,OAAO,YAAP;AACD,CAhCD","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,\n * such as a checked state or text input string.\n *\n * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a\n * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.\n *\n * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array\n * of the current value and an updater (dispatch) function. The updater function is referentially\n * stable (won't change during the component's lifecycle). It can take either a new value, or a\n * function which is passed the previous value and returns the new value. Unlike `setState`, calls\n * to the updater function will only be respected if the component is uncontrolled.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const isControlled = useIsControlled(options.state);\n const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;\n const [internalState, setInternalState] = React.useState<State>(initialState);\n\n const state = isControlled ? (options.state as State) : internalState;\n\n const stateRef = React.useRef(state);\n React.useEffect(() => {\n stateRef.current = state;\n }, [state]);\n\n // To match the behavior of the setter returned by React.useState, this callback's identity\n // should never change. This means it MUST NOT directly reference variables that can change.\n const setState = React.useCallback((newState: React.SetStateAction<State>) => {\n // React dispatch can use a factory\n // https://reactjs.org/docs/hooks-reference.html#functional-updates\n if (isFactoryDispatch(newState)) {\n stateRef.current = newState(stateRef.current);\n } else {\n stateRef.current = newState;\n }\n\n setInternalState(stateRef.current);\n }, []);\n\n return [state, setState];\n};\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = (controlledValue: unknown) => {\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAqBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;EACrE,OAAO,OAAO,QAAP,KAAoB,UAA3B;AAC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IACzC;IACA;IACA,KAAK,CAAC,SAAN,CAAgB,MAAK;MACnB,IAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;QACpD,MAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;QAEA,MAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;QAIA,MAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;QACA,OAAO,CAAC,KAAR,CACE,CACE;QACA,6BAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;MAUD;IACF,CAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;EAuBD;;EAED,OAAO,YAAP;AACD,CAhCD","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,\n * such as a checked state or text input string.\n *\n * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a\n * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.\n *\n * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array\n * of the current value and an updater (dispatch) function. The updater function is referentially\n * stable (won't change during the component's lifecycle). It can take either a new value, or a\n * function which is passed the previous value and returns the new value. Unlike `setState`, calls\n * to the updater function will only be respected if the component is uncontrolled.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const isControlled = useIsControlled(options.state);\n const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;\n const [internalState, setInternalState] = React.useState<State>(initialState);\n\n const state = isControlled ? (options.state as State) : internalState;\n\n const stateRef = React.useRef(state);\n React.useEffect(() => {\n stateRef.current = state;\n }, [state]);\n\n // To match the behavior of the setter returned by React.useState, this callback's identity\n // should never change. This means it MUST NOT directly reference variables that can change.\n const setState = React.useCallback((newState: React.SetStateAction<State>) => {\n // React dispatch can use a factory\n // https://reactjs.org/docs/hooks-reference.html#functional-updates\n if (isFactoryDispatch(newState)) {\n stateRef.current = newState(stateRef.current);\n } else {\n stateRef.current = newState;\n }\n\n setInternalState(stateRef.current);\n }, []);\n\n return [state, setState];\n};\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = (controlledValue: unknown) => {\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;;AAYG;;;AACI,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;EAChG,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;IAC/C,MAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;EACD,CAFmB,CAApB;EAIA,2BAAA,CAAA,yBAAA,CAA0B,MAAK;IAC7B,WAAW,CAAC,OAAZ,GAAsB,EAAtB;EACD,CAFD,EAEG,CAAC,EAAD,CAFH;EAIA,OAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;IAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;IACA,OAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;EACD,CAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;;AAYG;;;AACI,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;EAChG,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;IAC/C,MAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;EACD,CAFmB,CAApB;EAIA,2BAAA,CAAA,yBAAA,CAA0B,MAAK;IAC7B,WAAW,CAAC,OAAZ,GAAsB,EAAtB;EACD,CAFD,EAEG,CAAC,EAAD,CAFH;EAIA,OAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;IAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;IACA,OAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;EACD,CAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"sourceRoot":"../src/"}
|