@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
package/lib/utils/omit.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["utils/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;AAYG;AACH;AACA,OAAM,SAAU,IAAV,CACJ,GADI,EAEJ,UAFI,EAEkB;EAEtB;EACA,MAAM,MAAM,GAAwB,EAApC;;EAEA,KAAK,MAAM,GAAX,IAAkB,GAAlB,EAAuB;IACrB,IAAI,UAAU,CAAC,OAAX,CAAmB,GAAnB,MAA4B,CAAC,CAA7B,IAAkC,GAAG,CAAC,cAAJ,CAAmB,GAAnB,CAAtC,EAA+D;MAC7D,MAAM,CAAC,GAAD,CAAN,GAAc,GAAG,CAAC,GAAD,CAAjB;IACD;EACF;;EAED,OAAO,MAAP;AACD","sourcesContent":["/**\n * Tiny helper to do the minimal amount of work in duplicating an object but omitting some\n * props. This ends up faster than using object ...rest or reduce to filter.\n *\n * This behaves very much like filteredAssign, but does not merge many objects together,\n * uses an exclusion object map, and avoids spreads all for optimal performance.\n *\n * See perf test for background:\n * https://jsperf.com/omit-vs-rest-vs-reduce/1\n *\n * @param obj - The object to clone\n * @param exclusions - The array of keys to exclude\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(\n obj: TObj,\n exclusions: Exclusions,\n): Omit<TObj, Exclusions[number]> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const key in obj) {\n if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {\n result[key] = obj[key];\n }\n }\n\n return result as TObj;\n}\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/utils/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;AAYG;AACH;AACA,OAAM,SAAU,IAAV,CACJ,GADI,EAEJ,UAFI,EAEkB;EAEtB;EACA,MAAM,MAAM,GAAwB,EAApC;;EAEA,KAAK,MAAM,GAAX,IAAkB,GAAlB,EAAuB;IACrB,IAAI,UAAU,CAAC,OAAX,CAAmB,GAAnB,MAA4B,CAAC,CAA7B,IAAkC,GAAG,CAAC,cAAJ,CAAmB,GAAnB,CAAtC,EAA+D;MAC7D,MAAM,CAAC,GAAD,CAAN,GAAc,GAAG,CAAC,GAAD,CAAjB;IACD;EACF;;EAED,OAAO,MAAP;AACD","sourcesContent":["/**\n * Tiny helper to do the minimal amount of work in duplicating an object but omitting some\n * props. This ends up faster than using object ...rest or reduce to filter.\n *\n * This behaves very much like filteredAssign, but does not merge many objects together,\n * uses an exclusion object map, and avoids spreads all for optimal performance.\n *\n * See perf test for background:\n * https://jsperf.com/omit-vs-rest-vs-reduce/1\n *\n * @param obj - The object to clone\n * @param exclusions - The array of keys to exclude\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(\n obj: TObj,\n exclusions: Exclusions,\n): Omit<TObj, Exclusions[number]> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const key in obj) {\n if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {\n result[key] = obj[key];\n }\n }\n\n return result as TObj;\n}\n"],"sourceRoot":"../src/"}
|
package/lib/utils/properties.js
CHANGED
@@ -153,7 +153,7 @@ export const trProperties = htmlElementProperties;
|
|
153
153
|
* @public
|
154
154
|
*/
|
155
155
|
|
156
|
-
export const thProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['rowSpan', 'scope' // th
|
156
|
+
export const thProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['colSpan', 'rowSpan', 'scope' // th
|
157
157
|
]);
|
158
158
|
/**
|
159
159
|
* An array of TD tag properties and events.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["utils/properties.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,CAAC,GAAG,KAAJ,KAAoD;EACtE,MAAM,MAAM,GAA2B,EAAvC;;EAEA,KAAK,MAAM,IAAX,IAAmB,KAAnB,EAA0B;IACxB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAN,CAAc,IAAd,IAAsB,IAAtB,GAA6B,MAAM,CAAC,IAAP,CAAY,IAAZ,CAA1C;;IAEA,KAAK,MAAM,GAAX,IAAkB,IA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d,CAAhB,CAR4B,CAS5B;;EACA,MAAM,MAAM,GAAwB,EAApC;EACA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAP,CAAY,KAAZ,CAAb;;EAEA,KAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;IACtB,MAAM,YAAY,GACf,CAAC,OAAD,IAAa,gBAA2C,CAAC,GAAD,CAAzD,IACC,OAAO,IAAK,gBAA6B,CAAC,OAA9B,CAAsC,GAAtC,KAA8C,CAD3D,IAEA,GAAG,CAAC,OAAJ,CAAY,OAAZ,MAAyB,CAFzB,IAGA,GAAG,CAAC,OAAJ,CAAY,OAAZ,MAAyB,CAJ3B;;IAMA,IAAI,YAAY,KAAK,CAAC,iBAAD,IAAsB,CAAA,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAE,OAAnB,CAA2B,GAA3B,CAAA,MAAoC,CAAC,CAAhE,CAAhB,EAAoF;MAClF;MACA,MAAM,CAAC,GAAD,CAAN,GAAc,KAAM,CAAC,GAAD,CAApB;IACD;EACF;;EAED,OAAO,MAAP;AACD","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 '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"],"sourceRoot":"../src/"}
|
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IG;;AACH,OAAO,MAAM,gBAAgB,gBAAG,WAAW,CAAC,qBAAD,EAAwB,CAAC,MAAD,EAAS,UAAT,EAAqB,SAArB,CAAxB,CAApC;AAEP;;;;AAIG;;AACH,OAAO,MAAM,aAAa,GAAG,qBAAtB;AAEP;;;;;;;;;;;;;;AAcG;AACH;;AACA,OAAM,SAAU,cAAV,EACJ;AACA,KAFI,EAGJ,gBAHI,EAIJ,iBAJI,EAIwB;EAE5B;EACA;EACA;EACA;EACA;EAEA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAN,CAAc,gBAAd,CAAhB,CAR4B,CAS5B;;EACA,MAAM,MAAM,GAAwB,EAApC;EACA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAP,CAAY,KAAZ,CAAb;;EAEA,KAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;IACtB,MAAM,YAAY,GACf,CAAC,OAAD,IAAa,gBAA2C,CAAC,GAAD,CAAzD,IACC,OAAO,IAAK,gBAA6B,CAAC,OAA9B,CAAsC,GAAtC,KAA8C,CAD3D,IAEA,GAAG,CAAC,OAAJ,CAAY,OAAZ,MAAyB,CAFzB,IAGA,GAAG,CAAC,OAAJ,CAAY,OAAZ,MAAyB,CAJ3B;;IAMA,IAAI,YAAY,KAAK,CAAC,iBAAD,IAAsB,CAAA,iBAAiB,KAAA,IAAjB,IAAA,iBAAiB,KAAA,KAAA,CAAjB,GAAiB,KAAA,CAAjB,GAAA,iBAAiB,CAAE,OAAnB,CAA2B,GAA3B,CAAA,MAAoC,CAAC,CAAhE,CAAhB,EAAoF;MAClF;MACA,MAAM,CAAC,GAAD,CAAN,GAAc,KAAM,CAAC,GAAD,CAApB;IACD;EACF;;EAED,OAAO,MAAP;AACD","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"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["utils/shouldPreventDefaultOnKeyDown.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AAGA;;;;;AAKG;;AACH,OAAM,SAAU,6BAAV,CAAwC,CAAxC,EAA8E;EAClF,IAAI,CAAC,CAAC,gBAAN,EAAwB;IACtB,OAAO,KAAP;EACD;;EAED,MAAM,GAAG,GAAG,CAAC,CAAC,GAAd;EACA,MAAM,MAAM,GAA4B,CAAC,CAAC,MAA1C;EAEA,MAAM,YAAY,GAAG,GAAG,KAAK,KAAR,IAAiB,GAAG,KAAK,KAA9C;;EAEA,IAAI,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,GAAxB,EAA6B;IAC3B,OAAO,GAAG,KAAK,KAAf;EACD;;EAED,MAAM,YAAY,GAChB,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,OAApB,IAA+B,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,UAAnD,IAAiE,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,iBAAR,MAA8B,IADjG;EAGA,OAAO,YAAY,IAAI,CAAC,YAAxB;AACD","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-utilities/src/utils/shouldPreventDefaultOnKeyDown.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AAGA;;;;;AAKG;;AACH,OAAM,SAAU,6BAAV,CAAwC,CAAxC,EAA8E;EAClF,IAAI,CAAC,CAAC,gBAAN,EAAwB;IACtB,OAAO,KAAP;EACD;;EAED,MAAM,GAAG,GAAG,CAAC,CAAC,GAAd;EACA,MAAM,MAAM,GAA4B,CAAC,CAAC,MAA1C;EAEA,MAAM,YAAY,GAAG,GAAG,KAAK,KAAR,IAAiB,GAAG,KAAK,KAA9C;;EAEA,IAAI,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,GAAxB,EAA6B;IAC3B,OAAO,GAAG,KAAK,KAAf;EACD;;EAED,MAAM,YAAY,GAChB,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,OAApB,IAA+B,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,UAAnD,IAAiE,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,iBAAR,MAA8B,IADjG;EAGA,OAAO,YAAY,IAAI,CAAC,YAAxB;AACD","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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
define(["require", "exports", "tslib", "react", "../utils/omit"], function (require, exports, tslib_1, React, omit_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getSlots = void 0;
|
5
|
+
/**
|
6
|
+
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
7
|
+
* collections.
|
8
|
+
*
|
9
|
+
* The root is derived from a mix of `components` props and `as` prop.
|
10
|
+
*
|
11
|
+
* Slots will render as null if they are rendered as primitives with undefined children.
|
12
|
+
*
|
13
|
+
* The slotProps will always omit the `as` prop within them, and for slots that are string
|
14
|
+
* primitives, the props will be filtered according to the slot type by the type system.
|
15
|
+
* For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
|
16
|
+
* anchor props. Note that this is only enforced at build time by Typescript -- there is no
|
17
|
+
* runtime code filtering props in this function.
|
18
|
+
*
|
19
|
+
* @param state - State including slot definitions
|
20
|
+
* @returns An object containing the `slots` map and `slotProps` map.
|
21
|
+
*/
|
22
|
+
function getSlots(state) {
|
23
|
+
var slots = {};
|
24
|
+
var slotProps = {};
|
25
|
+
var slotNames = Object.keys(state.components);
|
26
|
+
for (var _i = 0, slotNames_1 = slotNames; _i < slotNames_1.length; _i++) {
|
27
|
+
var slotName = slotNames_1[_i];
|
28
|
+
var _a = getSlot(state, slotName), slot = _a[0], props = _a[1];
|
29
|
+
slots[slotName] = slot;
|
30
|
+
slotProps[slotName] = props;
|
31
|
+
}
|
32
|
+
return { slots: slots, slotProps: slotProps };
|
33
|
+
}
|
34
|
+
exports.getSlots = getSlots;
|
35
|
+
function getSlot(state, slotName) {
|
36
|
+
var _a, _b, _c;
|
37
|
+
if (state[slotName] === undefined) {
|
38
|
+
return [null, undefined];
|
39
|
+
}
|
40
|
+
var _d = state[slotName], children = _d.children, asProp = _d.as, rest = tslib_1.__rest(_d, ["children", "as"]);
|
41
|
+
var slot = (((_a = state.components) === null || _a === void 0 ? void 0 : _a[slotName]) === undefined || typeof state.components[slotName] === 'string'
|
42
|
+
? asProp || ((_b = state.components) === null || _b === void 0 ? void 0 : _b[slotName]) || 'div'
|
43
|
+
: state.components[slotName]);
|
44
|
+
if (typeof children === 'function') {
|
45
|
+
var render = children;
|
46
|
+
return [
|
47
|
+
React.Fragment,
|
48
|
+
{
|
49
|
+
children: render(slot, rest),
|
50
|
+
},
|
51
|
+
];
|
52
|
+
}
|
53
|
+
var shouldOmitAsProp = typeof slot === 'string' && ((_c = state[slotName]) === null || _c === void 0 ? void 0 : _c.as);
|
54
|
+
var slotProps = (shouldOmitAsProp ? omit_1.omit(state[slotName], ['as']) : state[slotName]);
|
55
|
+
return [slot, slotProps];
|
56
|
+
}
|
57
|
+
});
|
58
|
+
//# sourceMappingURL=getSlots.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getSlots.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/compose/getSlots.ts"],"names":[],"mappings":";;;;IA+BA;;;;;;;;;;;;;;;;OAgBG;IACH,SAAgB,QAAQ,CACtB,KAAwB;QAKxB,IAAM,KAAK,GAAG,EAAc,CAAC;QAC7B,IAAM,SAAS,GAAG,EAAO,CAAC;QAE1B,IAAM,SAAS,GAAgB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7D,KAAuB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;YAA7B,IAAM,QAAQ,kBAAA;YACX,IAAA,KAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAvC,IAAI,QAAA,EAAE,KAAK,QAA4B,CAAC;YAC/C,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAiC,CAAC;YACpD,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;SAC7B;QACD,OAAO,EAAE,KAAK,OAAA,EAAE,SAAS,EAAG,SAA2C,EAAE,CAAC;IAC5E,CAAC;IAhBD,4BAgBC;IAED,SAAS,OAAO,CACd,KAAwB,EACxB,QAAW;;QAEX,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE;YACjC,OAAO,CAAC,IAAI,EAAE,SAAiB,CAAC,CAAC;SAClC;QACD,IAAM,KAAoC,KAAK,CAAC,QAAQ,CAAE,EAAlD,QAAQ,cAAA,EAAM,MAAM,QAAA,EAAK,IAAI,sBAA/B,kBAAiC,CAAmB,CAAC;QAE3D,IAAM,IAAI,GAAG,CAAC,CAAA,MAAA,KAAK,CAAC,UAAU,0CAAG,QAAQ,CAAC,MAAK,SAAS,IAAI,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,QAAQ;YACxG,CAAC,CAAC,MAAM,KAAI,MAAA,KAAK,CAAC,UAAU,0CAAG,QAAQ,CAAC,CAAA,IAAI,KAAK;YACjD,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAA4B,CAAC;QAE3D,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAClC,IAAM,MAAM,GAAG,QAAoC,CAAC;YACpD,OAAO;gBACL,KAAK,CAAC,QAAQ;gBACb;oBACC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,IAAqC,CAAC;iBAC1C;aACtB,CAAC;SACH;QAED,IAAM,gBAAgB,GAAG,OAAO,IAAI,KAAK,QAAQ,KAAI,MAAA,KAAK,CAAC,QAAQ,CAAC,0CAAE,EAAE,CAAA,CAAC;QACzE,IAAM,SAAS,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAI,CAAC,KAAK,CAAC,QAAQ,CAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAS,CAAC;QAEhG,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3B,CAAC","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"]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./getSlots", "./resolveShorthand", "./types", "./isResolvedShorthand"], function (require, exports, tslib_1, getSlots_1, resolveShorthand_1, types_1, isResolvedShorthand_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(getSlots_1, exports);
|
5
|
+
tslib_1.__exportStar(resolveShorthand_1, exports);
|
6
|
+
tslib_1.__exportStar(types_1, exports);
|
7
|
+
tslib_1.__exportStar(isResolvedShorthand_1, exports);
|
8
|
+
});
|
9
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/compose/index.ts"],"names":[],"mappings":";;;IAAA,0CAA2B;IAC3B,kDAAmC;IACnC,uCAAwB;IACxB,qDAAsC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, react_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.isResolvedShorthand = void 0;
|
5
|
+
/**
|
6
|
+
* Guard method that validates if a shorthand is a slot
|
7
|
+
* can be used to extends properties provided by a slot
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```
|
11
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
12
|
+
* defaultProps: {
|
13
|
+
* onClick: useEventCallback(event => {
|
14
|
+
* if (isResolvedShorthand(backdrop)) {
|
15
|
+
* backdrop.onClick?.(event)
|
16
|
+
* }
|
17
|
+
* // do something after passing click down the line
|
18
|
+
* }),
|
19
|
+
* },
|
20
|
+
* })
|
21
|
+
* ```
|
22
|
+
* @example
|
23
|
+
* ```
|
24
|
+
* const handleBackDropClick = (event) => {
|
25
|
+
* // do your thing
|
26
|
+
* }
|
27
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
28
|
+
* defaultProps: {
|
29
|
+
* onClick: useEventCallback(
|
30
|
+
* mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
|
31
|
+
* )
|
32
|
+
* })
|
33
|
+
* ```
|
34
|
+
*/
|
35
|
+
function isResolvedShorthand(shorthand) {
|
36
|
+
return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !react_1.isValidElement(shorthand);
|
37
|
+
}
|
38
|
+
exports.isResolvedShorthand = isResolvedShorthand;
|
39
|
+
});
|
40
|
+
//# sourceMappingURL=isResolvedShorthand.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isResolvedShorthand.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/compose/isResolvedShorthand.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,SAAgB,mBAAmB,CACjC,SAAqB;QAErB,OAAO,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,sBAAc,CAAC,SAAS,CAAC,CAAC;IACxH,CAAC;IAJD,kDAIC","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"]}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
define(["require", "exports", "tslib", "react"], function (require, exports, tslib_1, react_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.resolveShorthand = void 0;
|
5
|
+
/**
|
6
|
+
* Resolves shorthands into slot props, to ensure normalization of the signature
|
7
|
+
* being passed down to getSlots method
|
8
|
+
* @param value - the base shorthand props
|
9
|
+
* @param options - options to resolve shorthand props
|
10
|
+
*/
|
11
|
+
var resolveShorthand = function (value, options) {
|
12
|
+
var _a = options || {}, _b = _a.required, required = _b === void 0 ? false : _b, defaultProps = _a.defaultProps;
|
13
|
+
if (value === null || (value === undefined && !required)) {
|
14
|
+
return undefined;
|
15
|
+
}
|
16
|
+
var resolvedShorthand = {};
|
17
|
+
if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || react_1.isValidElement(value)) {
|
18
|
+
resolvedShorthand.children = value;
|
19
|
+
}
|
20
|
+
else if (typeof value === 'object') {
|
21
|
+
resolvedShorthand = value;
|
22
|
+
}
|
23
|
+
return defaultProps ? tslib_1.__assign(tslib_1.__assign({}, defaultProps), resolvedShorthand) : resolvedShorthand;
|
24
|
+
};
|
25
|
+
exports.resolveShorthand = resolveShorthand;
|
26
|
+
});
|
27
|
+
//# sourceMappingURL=resolveShorthand.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"resolveShorthand.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;IAkBA;;;;;OAKG;IACI,IAAM,gBAAgB,GAA6B,UAAC,KAAK,EAAE,OAAO;QACjE,IAAA,KAAqC,OAAO,IAAI,EAAE,EAAhD,gBAAgB,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAAE,YAAY,kBAAkB,CAAC;QACzD,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,QAAQ,CAAC,EAAE;YACxD,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,iBAAiB,GAAG,EAAsB,CAAC;QAE/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,sBAAc,CAAC,KAAK,CAAC,EAAE;YAC3G,iBAAiB,CAAC,QAAQ,GAAG,KAAK,CAAC;SACpC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACpC,iBAAiB,GAAG,KAAK,CAAC;SAC3B;QAED,OAAO,YAAY,CAAC,CAAC,uCAAM,YAAY,GAAK,iBAAiB,EAAG,CAAC,CAAC,iBAAiB,CAAC;IACtF,CAAC,CAAC;IAfW,QAAA,gBAAgB,oBAe3B","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"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/compose/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\nexport type SlotRenderFunction<Props> = (\n Component: React.ElementType<Props>,\n props: Omit<Props, 'children' | 'as'>,\n) => React.ReactNode;\n\n/**\n * Matches any component's Slots type (such as ButtonSlots).\n *\n * This should ONLY be used in type templates as in `extends SlotPropsRecord`;\n * it shouldn't be used as a component's Slots type.\n */\nexport type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;\n\n/**\n * The shorthand value of a slot allows specifying its child\n */\nexport type SlotShorthandValue = React.ReactChild | React.ReactNode[] | React.ReactPortal;\n\n/**\n * Matches any slot props type.\n *\n * This should ONLY be used in type templates as in `extends UnknownSlotProps`;\n * it shouldn't be used as the type of a slot.\n */\nexport type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {\n as?: keyof JSX.IntrinsicElements;\n};\n\n/**\n * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.\n */\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\n/**\n * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`\n * to be a render function that takes those props.\n */\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n\n/**\n * HTML element types that are not allowed to have children.\n *\n * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element\n */\ntype EmptyIntrisicElements =\n | 'area'\n | 'base'\n | 'br'\n | 'col'\n | 'embed'\n | 'hr'\n | 'img'\n | 'input'\n | 'link'\n | 'meta'\n | 'param'\n | 'source'\n | 'track'\n | 'wbr';\n\n/**\n * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:\n * * Removes legacy string ref.\n * * Disallows children for empty tags like 'img'.\n */\ntype IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> &\n (Type extends EmptyIntrisicElements ? { children?: never } : {});\n\n/**\n * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,\n * or a component like `typeof Button`.\n *\n * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).\n *\n * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,\n * wrap with `NonNullable` (see examples below).\n *\n * @example\n * ```\n * // Intrinsic element examples:\n * Slot<'div'> // Slot is always div\n * Slot<'button', 'a'> // Defaults to button, but allows as=\"a\" with anchor-specific props\n * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as=\"div\" or as=\"pre\"\n * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)\n *\n * // Component examples:\n * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props\n * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)\n * ```\n */\nexport type Slot<\n Type extends keyof JSX.IntrinsicElements | React.ComponentType | React.VoidFunctionComponent | UnknownSlotProps,\n AlternateAs extends keyof JSX.IntrinsicElements = never\n> = IsSingleton<Extract<Type, string>> extends true\n ?\n | WithSlotShorthandValue<\n Type extends keyof JSX.IntrinsicElements // Intrinsic elements like `div`\n ? { as?: Type } & WithSlotRenderFunction<IntrisicElementProps<Type>>\n : Type extends React.ComponentType<infer Props> // Component types like `typeof Button`\n ? WithSlotRenderFunction<Props>\n : Type // Props types like `ButtonProps`\n >\n | {\n [As in AlternateAs]: { as: As } & WithSlotRenderFunction<IntrisicElementProps<As>>;\n }[AlternateAs]\n | null\n : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';\n\n/**\n * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.\n *\n * ```\n * IsSingleton<'a'> // true\n * IsSingleton<'a' | 'b' | 'c'> // false\n * ```\n */\nexport type IsSingleton<T extends string> = { [K in T]: Exclude<T, K> extends never ? true : false }[T];\n\n/**\n * Helper type for inferring the type of the as prop from a Props type.\n *\n * For example:\n * ```\n * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;\n * ```\n */\nexport type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = { as?: As };\n\n/**\n * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)\n */\nexport type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;\n\n/**\n * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by\n * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.\n *\n * The conditional \"extends unknown\" (always true) exploits a quirk in the way TypeScript handles conditional\n * types, to prevent unions from being expanded.\n */\nexport type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;\n\n/**\n * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.\n */\nexport type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;\n\n/**\n * Defines the Props type for a component given its slots and the definition of which one is the primary slot,\n * defaulting to root if one is not provided.\n */\nexport type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> =\n // Include a prop for each slot (see note below about the Omit)\n Omit<Slots, Primary & 'root'> &\n // Include all of the props of the primary slot inline in the component's props\n PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;\n\n// Note: the `Omit<Slots, Primary & 'root'>` above is a little tricky. Here's what it's doing:\n// * If the Primary slot is 'root', then omit the `root` slot prop.\n// * Otherwise, don't omit any props: include *both* the Primary and `root` props.\n// We need both props to allow the user to specify native props for either slot because the `root` slot is\n// special and always gets className and style props, per RFC https://github.com/microsoft/fluentui/pull/18983\n\n/**\n * If type T includes `null`, remove it and add `undefined` instead.\n */\nexport type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;\n\n/**\n * Defines the State object of a component given its slots.\n */\nexport type ComponentState<Slots extends SlotPropsRecord> = {\n components: {\n [Key in keyof Slots]-?:\n | React.ComponentType<ExtractSlotProps<Slots[Key]>>\n | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n };\n} & {\n // Include a prop for each slot, with the shorthand resolved to a props object\n // The root slot can never be null, so also exclude null from it\n [Key in keyof Slots]: ReplaceNullWithUndefined<\n Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>\n >;\n};\n\n/**\n * This is part of a hack to infer the element type from a native element *props* type.\n * The only place the original element is found in a native props type (at least that's workable\n * for inference) is in the event handlers, so some of the helper types use this event handler\n * name to infer the original element type.\n *\n * Notes:\n * - Using an extremely obscure event handler reduces the likelihood that its signature will be\n * modified in any component's props.\n * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be\n * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.\n */\ntype ObscureEventName = 'onLostPointerCaptureCapture';\n\n/**\n * Return type for `React.forwardRef`, including inference of the proper typing for the ref.\n */\nexport type ForwardRefComponent<Props> = ObscureEventName extends keyof Props\n ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element>\n ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>>\n : never\n : never;\n// A definition like this would also work, but typescript is more likely to unnecessarily expand\n// the props type with this version (and it's likely much more expensive to evaluate)\n// export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>\n// ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>\n// : never;\n\n/**\n * Helper type to correctly define the slot class names object.\n */\nexport type SlotClassNames<Slots> = {\n [SlotName in keyof Slots]-?: string;\n};\n"]}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./useControllableState", "./useEventCallback", "./useFirstMount", "./useForceUpdate", "./useId", "./useIsomorphicLayoutEffect", "./useMergedRefs", "./useOnClickOutside", "./useOnScrollOutside", "./usePrevious", "./useTimeout"], function (require, exports, tslib_1, useControllableState_1, useEventCallback_1, useFirstMount_1, useForceUpdate_1, useId_1, useIsomorphicLayoutEffect_1, useMergedRefs_1, useOnClickOutside_1, useOnScrollOutside_1, usePrevious_1, useTimeout_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(useControllableState_1, exports);
|
5
|
+
tslib_1.__exportStar(useEventCallback_1, exports);
|
6
|
+
tslib_1.__exportStar(useFirstMount_1, exports);
|
7
|
+
tslib_1.__exportStar(useForceUpdate_1, exports);
|
8
|
+
tslib_1.__exportStar(useId_1, exports);
|
9
|
+
tslib_1.__exportStar(useIsomorphicLayoutEffect_1, exports);
|
10
|
+
tslib_1.__exportStar(useMergedRefs_1, exports);
|
11
|
+
tslib_1.__exportStar(useOnClickOutside_1, exports);
|
12
|
+
tslib_1.__exportStar(useOnScrollOutside_1, exports);
|
13
|
+
tslib_1.__exportStar(usePrevious_1, exports);
|
14
|
+
tslib_1.__exportStar(useTimeout_1, exports);
|
15
|
+
});
|
16
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/index.ts"],"names":[],"mappings":";;;IAAA,sDAAuC;IACvC,kDAAmC;IACnC,+CAAgC;IAChC,gDAAiC;IACjC,uCAAwB;IACxB,2DAA4C;IAC5C,+CAAgC;IAChC,mDAAoC;IACpC,oDAAqC;IACrC,6CAA8B;IAC9B,4CAA6B","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"]}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useControllableState = void 0;
|
5
|
+
function isFactoryDispatch(newState) {
|
6
|
+
return typeof newState === 'function';
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* @internal
|
10
|
+
*
|
11
|
+
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
12
|
+
* such as a checked state or text input string.
|
13
|
+
*
|
14
|
+
* Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
|
15
|
+
* controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
|
16
|
+
*
|
17
|
+
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
18
|
+
* of the current value and an updater (dispatch) function. The updater function is referentially
|
19
|
+
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
20
|
+
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
21
|
+
* to the updater function will only be respected if the component is uncontrolled.
|
22
|
+
* @see https://reactjs.org/docs/uncontrolled-components.html
|
23
|
+
*/
|
24
|
+
var useControllableState = function (options) {
|
25
|
+
var isControlled = useIsControlled(options.state);
|
26
|
+
var initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
|
27
|
+
var _a = React.useState(initialState), internalState = _a[0], setInternalState = _a[1];
|
28
|
+
var state = isControlled ? options.state : internalState;
|
29
|
+
var stateRef = React.useRef(state);
|
30
|
+
React.useEffect(function () {
|
31
|
+
stateRef.current = state;
|
32
|
+
}, [state]);
|
33
|
+
// To match the behavior of the setter returned by React.useState, this callback's identity
|
34
|
+
// should never change. This means it MUST NOT directly reference variables that can change.
|
35
|
+
var setState = React.useCallback(function (newState) {
|
36
|
+
// React dispatch can use a factory
|
37
|
+
// https://reactjs.org/docs/hooks-reference.html#functional-updates
|
38
|
+
if (isFactoryDispatch(newState)) {
|
39
|
+
stateRef.current = newState(stateRef.current);
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
stateRef.current = newState;
|
43
|
+
}
|
44
|
+
setInternalState(stateRef.current);
|
45
|
+
}, []);
|
46
|
+
return [state, setState];
|
47
|
+
};
|
48
|
+
exports.useControllableState = useControllableState;
|
49
|
+
/**
|
50
|
+
* Helper hook to handle previous comparison of controlled/uncontrolled
|
51
|
+
* Prints an error when isControlled value switches between subsequent renders
|
52
|
+
* @returns - whether the value is controlled
|
53
|
+
*/
|
54
|
+
var useIsControlled = function (controlledValue) {
|
55
|
+
var isControlled = React.useState(function () { return controlledValue !== undefined; })[0];
|
56
|
+
if (process.env.NODE_ENV !== 'production') {
|
57
|
+
// We don't want these warnings in production even though it is against native behaviour
|
58
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
59
|
+
React.useEffect(function () {
|
60
|
+
if (isControlled !== (controlledValue !== undefined)) {
|
61
|
+
var error = new Error();
|
62
|
+
var controlWarning = isControlled
|
63
|
+
? 'a controlled value to be uncontrolled'
|
64
|
+
: 'an uncontrolled value to be controlled';
|
65
|
+
var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';
|
66
|
+
// eslint-disable-next-line no-console
|
67
|
+
console.error([
|
68
|
+
// Default react error
|
69
|
+
'A component is changing ' + controlWarning + '. This is likely caused by the value',
|
70
|
+
'changing from ' + undefinedWarning + ' value, which should not happen.',
|
71
|
+
'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',
|
72
|
+
'More info: https://reactjs.org/link/controlled-components',
|
73
|
+
error.stack,
|
74
|
+
].join(' '));
|
75
|
+
}
|
76
|
+
}, [isControlled, controlledValue]);
|
77
|
+
}
|
78
|
+
return isControlled;
|
79
|
+
};
|
80
|
+
});
|
81
|
+
//# sourceMappingURL=useControllableState.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useControllableState.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;IAqBA,SAAS,iBAAiB,CAAQ,QAAqC;QACrE,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,IAAM,oBAAoB,GAAG,UAClC,OAA2C;QAE3C,IAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpD,IAAM,YAAY,GAAG,OAAO,OAAO,CAAC,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;QACzG,IAAA,KAAoC,KAAK,CAAC,QAAQ,CAAQ,YAAY,CAAC,EAAtE,aAAa,QAAA,EAAE,gBAAgB,QAAuC,CAAC;QAE9E,IAAM,KAAK,GAAG,YAAY,CAAC,CAAC,CAAE,OAAO,CAAC,KAAe,CAAC,CAAC,CAAC,aAAa,CAAC;QAEtE,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,KAAK,CAAC,SAAS,CAAC;YACd,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;QAC3B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAEZ,2FAA2F;QAC3F,4FAA4F;QAC5F,IAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,UAAC,QAAqC;YACvE,mCAAmC;YACnC,mEAAmE;YACnE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EA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,CAAC;SACrC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC","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"]}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
define(["require", "exports", "react", "./useIsomorphicLayoutEffect"], function (require, exports, React, useIsomorphicLayoutEffect_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useEventCallback = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
8
|
+
*
|
9
|
+
* Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
|
10
|
+
* e.g. user props are dependencies which could change on every render
|
11
|
+
* e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
|
12
|
+
*
|
13
|
+
* This should not be used often, but can be a useful re-render optimization since the callback is a ref and
|
14
|
+
* will not be invalidated between re-renders
|
15
|
+
*
|
16
|
+
* @param fn - The callback function that will be used
|
17
|
+
*/
|
18
|
+
var useEventCallback = function (fn) {
|
19
|
+
var callbackRef = React.useRef(function () {
|
20
|
+
throw new Error('Cannot call an event handler while rendering');
|
21
|
+
});
|
22
|
+
useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(function () {
|
23
|
+
callbackRef.current = fn;
|
24
|
+
}, [fn]);
|
25
|
+
return React.useCallback(function () {
|
26
|
+
var args = [];
|
27
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
28
|
+
args[_i] = arguments[_i];
|
29
|
+
}
|
30
|
+
var callback = callbackRef.current;
|
31
|
+
return callback.apply(void 0, args);
|
32
|
+
}, [callbackRef]);
|
33
|
+
};
|
34
|
+
exports.useEventCallback = useEventCallback;
|
35
|
+
});
|
36
|
+
//# sourceMappingURL=useEventCallback.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useEventCallback.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;;;;;;OAYG;IACI,IAAM,gBAAgB,GAAG,UAAiC,EAA6B;QAC5F,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAY;YAC1C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;QAEH,qDAAyB,CAAC;YACxB,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAC3B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAET,OAAO,KAAK,CAAC,WAAW,CACtB;YAAC,cAAa;iBAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;gBAAb,yBAAa;;YACZ,IAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;YACrC,OAAO,QAAQ,eAAI,IAAI,EAAE;QAC3B,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAC;IACJ,CAAC,CAAC;IAhBW,QAAA,gBAAgB,oBAgB3B","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"]}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useFirstMount = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Checks if components was mounted the first time.
|
8
|
+
* Since concurrent mode will be released in the future this needs to be verified
|
9
|
+
* Currently (React 17) will always render the initial mount once
|
10
|
+
* https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
|
11
|
+
* https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* const isFirstMount = useFirstMount();
|
15
|
+
*/
|
16
|
+
function useFirstMount() {
|
17
|
+
var isFirst = React.useRef(true);
|
18
|
+
if (isFirst.current) {
|
19
|
+
isFirst.current = false;
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
return isFirst.current;
|
23
|
+
}
|
24
|
+
exports.useFirstMount = useFirstMount;
|
25
|
+
});
|
26
|
+
//# sourceMappingURL=useFirstMount.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useFirstMount.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useFirstMount.ts"],"names":[],"mappings":";;;;IAEA;;;;;;;;;;OAUG;IACH,SAAgB,aAAa;QAC3B,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEnC,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;YACxB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IATD,sCASC","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, react_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useForceUpdate = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Forces a re-render, similar to `forceUpdate` in class components.
|
8
|
+
*/
|
9
|
+
function useForceUpdate() {
|
10
|
+
return react_1.useReducer(function (x) { return x + 1; }, 0)[1];
|
11
|
+
}
|
12
|
+
exports.useForceUpdate = useForceUpdate;
|
13
|
+
});
|
14
|
+
//# sourceMappingURL=useForceUpdate.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useForceUpdate.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;IAEA;;;OAGG;IACH,SAAgB,cAAc;QAC5B,OAAO,kBAAU,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAFD,wCAEC","sourcesContent":["import { useReducer } from 'react';\n\n/**\n * @internal\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return useReducer(x => x + 1, 0)[1];\n}\n"]}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
define(["require", "exports", "react", "../ssr/index"], function (require, exports, React, index_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useId = exports.resetIdsForTests = void 0;
|
5
|
+
/**
|
6
|
+
* Resets generated IDs, should be used only in tests.
|
7
|
+
*/
|
8
|
+
function resetIdsForTests() {
|
9
|
+
index_1.defaultSSRContextValue.current = 0;
|
10
|
+
}
|
11
|
+
exports.resetIdsForTests = resetIdsForTests;
|
12
|
+
/**
|
13
|
+
* Hook to generate a unique ID.
|
14
|
+
*
|
15
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
16
|
+
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
17
|
+
* without conditioning the hook call
|
18
|
+
* @returns The ID
|
19
|
+
*/
|
20
|
+
function useId(prefix, providedId) {
|
21
|
+
if (prefix === void 0) { prefix = 'fui-'; }
|
22
|
+
var contextValue = index_1.useSSRContext();
|
23
|
+
return React.useMemo(function () {
|
24
|
+
if (providedId) {
|
25
|
+
return providedId;
|
26
|
+
}
|
27
|
+
return "" + prefix + ++contextValue.current;
|
28
|
+
}, [prefix, providedId, contextValue]);
|
29
|
+
}
|
30
|
+
exports.useId = useId;
|
31
|
+
});
|
32
|
+
//# sourceMappingURL=useId.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useId.ts"],"names":[],"mappings":";;;;IAGA;;OAEG;IACH,SAAgB,gBAAgB;QAC9B,8BAAsB,CAAC,OAAO,GAAG,CAAC,CAAC;IACrC,CAAC;IAFD,4CAEC;IAED;;;;;;;OAOG;IACH,SAAgB,KAAK,CAAC,MAAuB,EAAE,UAAmB;QAA5C,uBAAA,EAAA,eAAuB;QAC3C,IAAM,YAAY,GAAG,qBAAa,EAAE,CAAC;QAErC,OAAO,KAAK,CAAC,OAAO,CAAC;YACnB,IAAI,UAAU,EAAE;gBACd,OAAO,UAAU,CAAC;aACnB;YAED,OAAO,KAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAS,CAAC;QAC9C,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,CAAC;IAVD,sBAUC","sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${prefix}${++contextValue.current}`;\n }, [prefix, providedId, contextValue]);\n}\n"]}
|