Private
Public Access
1
0

feat: Fluent UI Outlook Lite + connections mockup

This commit is contained in:
2026-04-14 18:52:25 +00:00
parent 1199eff6c3
commit dfa4010406
34820 changed files with 1003813 additions and 205 deletions

View File

@@ -0,0 +1,8 @@
/**
* @internal
* Clamps `value` to a number between the min and max.
*
* @param value - the value to be clamped
* @param min - the lowest valid value
* @param max - the highest valid value
*/ export const clamp = (value, min, max)=>Math.max(min, Math.min(max, value || 0));

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/clamp.ts"],"sourcesContent":["/**\n * @internal\n * Clamps `value` to a number between the min and max.\n *\n * @param value - the value to be clamped\n * @param min - the lowest valid value\n * @param max - the highest valid value\n */\nexport const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value || 0));\n"],"names":["clamp","value","min","max","Math"],"mappings":"AAAA;;;;;;;CAOC,GACD,OAAO,MAAMA,QAAQ,CAACC,OAAeC,KAAaC,MAAwBC,KAAKD,GAAG,CAACD,KAAKE,KAAKF,GAAG,CAACC,KAAKF,SAAS,IAAI"}

View File

@@ -0,0 +1,5 @@
/**
* Creates a set from a given iterable, in case the iterable is a set itself, returns the given set instead.
*/ export function createSetFromIterable(iterable) {
return iterable instanceof Set ? iterable : new Set(iterable);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/createSetFromIterable.ts"],"sourcesContent":["/**\n * Creates a set from a given iterable, in case the iterable is a set itself, returns the given set instead.\n */\nexport function createSetFromIterable<V>(iterable: Iterable<V>): Set<V> {\n return iterable instanceof Set ? iterable : new Set(iterable);\n}\n"],"names":["createSetFromIterable","iterable","Set"],"mappings":"AAAA;;CAEC,GACD,OAAO,SAASA,sBAAyBC,QAAqB;IAC5D,OAAOA,oBAAoBC,MAAMD,WAAW,IAAIC,IAAID;AACtD"}

View File

@@ -0,0 +1,62 @@
import * as React from 'react';
import { labelProperties, audioProperties, videoProperties, olProperties, liProperties, anchorProperties, buttonProperties, inputProperties, textAreaProperties, selectProperties, optionProperties, tableProperties, trProperties, thProperties, tdProperties, colGroupProperties, colProperties, fieldsetProperties, formProperties, iframeProperties, imgProperties, htmlElementProperties, getNativeProps, timeProperties, dialogProperties } from './properties';
const nativeElementMap = {
label: labelProperties,
audio: audioProperties,
video: videoProperties,
ol: olProperties,
li: liProperties,
a: anchorProperties,
button: buttonProperties,
input: inputProperties,
textarea: textAreaProperties,
select: selectProperties,
option: optionProperties,
table: tableProperties,
tr: trProperties,
th: thProperties,
td: tdProperties,
colGroup: colGroupProperties,
col: colProperties,
fieldset: fieldsetProperties,
form: formProperties,
iframe: iframeProperties,
img: imgProperties,
time: timeProperties,
dialog: dialogProperties
};
/**
* Given an element tagname and user props, filters the props to only allowed props for the given
* element type.
* @param tagName - Tag name (e.g. "div")
* @param props - Props object
* @param excludedPropNames - List of props to disallow
*
* @deprecated use getIntrinsicElementProps instead, it is a type-safe version of this method
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getNativeElementProps(tagName, props, excludedPropNames) {
const allowedPropNames = tagName && nativeElementMap[tagName] || htmlElementProperties;
allowedPropNames.as = 1;
return getNativeProps(props, allowedPropNames, excludedPropNames);
}
/**
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
*
* This function is only for use with components that have a primary slot other than `root`.
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
*
* @returns An object containing the native props for the `root` and primary slots.
*/ export const getPartitionedNativeProps = ({ primarySlotTagName, props, excludedPropNames })=>{
return {
root: {
style: props.style,
className: props.className
},
// eslint-disable-next-line @typescript-eslint/no-deprecated
primary: getNativeElementProps(primarySlotTagName, props, [
...excludedPropNames || [],
'style',
'className'
])
};
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
/**
* @internal
* Finds and swaps a provided key for it's right to left format.
*/ export const getRTLSafeKey = (key, dir)=>{
if (dir === 'rtl') {
switch(key){
case 'ArrowLeft':
{
return 'ArrowRight';
}
case 'ArrowRight':
{
return 'ArrowLeft';
}
}
}
return key;
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/getRTLSafeKey.ts"],"sourcesContent":["/**\n * @internal\n * Finds and swaps a provided key for it's right to left format.\n */\nexport const getRTLSafeKey = (key: string, dir: 'ltr' | 'rtl'): string => {\n if (dir === 'rtl') {\n switch (key) {\n case 'ArrowLeft': {\n return 'ArrowRight';\n }\n\n case 'ArrowRight': {\n return 'ArrowLeft';\n }\n }\n }\n\n return key;\n};\n"],"names":["getRTLSafeKey","key","dir"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,gBAAgB,CAACC,KAAaC;IACzC,IAAIA,QAAQ,OAAO;QACjB,OAAQD;YACN,KAAK;gBAAa;oBAChB,OAAO;gBACT;YAEA,KAAK;gBAAc;oBACjB,OAAO;gBACT;QACF;IACF;IAEA,OAAOA;AACT,EAAE"}

View File

@@ -0,0 +1,23 @@
import * as React from 'react';
/**
* React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
*
* Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
* ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
* are handled in bubble phase.
*/ export function getReactCallbackName(event) {
if (event._reactName) {
return event._reactName;
}
if (event.dispatchConfig) {
if (event.dispatchConfig.registrationName) {
return event.dispatchConfig.registrationName;
}
return event.dispatchConfig.phasedRegistrationNames.bubbled;
}
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.error(`@fluentui/react-utilities [${getReactCallbackName.name}]:
Passed React.SyntheticEvent does not contain ".dispatchConfig" or "._reactName". This should not happen, please report it to https://github.com/microsoft/fluentui.`);
}
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/getReactCallbackName.ts"],"sourcesContent":["import * as React from 'react';\n\ninterface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {\n // React 17/18\n // See https://github.com/facebook/react/pull/19236\n _reactName?: string;\n\n // React 16\n dispatchConfig?: {\n registrationName: string;\n phasedRegistrationNames: {\n bubbled: string;\n captured: string;\n };\n };\n}\n\ntype NonUndefined<A> = A extends undefined ? never : A;\ntype FunctionKeys<T extends object> = {\n [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;\n}[keyof T];\n\nexport type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;\n\n/**\n * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.\n *\n * Ideally, it should also distinguish regular and \"capture\" callbacks, but it's possible only with React 17 as\n * \".eventPhase\" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events\n * are handled in bubble phase.\n */\nexport function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined {\n if (event._reactName) {\n return event._reactName as ReactCallbackName;\n }\n\n if (event.dispatchConfig) {\n if (event.dispatchConfig.registrationName) {\n return event.dispatchConfig.registrationName as ReactCallbackName;\n }\n\n return event.dispatchConfig.phasedRegistrationNames.bubbled as ReactCallbackName;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [${getReactCallbackName.name}]:\n Passed React.SyntheticEvent does not contain \".dispatchConfig\" or \"._reactName\". This should not happen, please report it to https://github.com/microsoft/fluentui.\n `);\n }\n}\n"],"names":["React","getReactCallbackName","event","_reactName","dispatchConfig","registrationName","phasedRegistrationNames","bubbled","process","env","NODE_ENV","console","error","name"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAwB/B;;;;;;CAMC,GACD,OAAO,SAASC,qBAAqBC,KAA0B;IAC7D,IAAIA,MAAMC,UAAU,EAAE;QACpB,OAAOD,MAAMC,UAAU;IACzB;IAEA,IAAID,MAAME,cAAc,EAAE;QACxB,IAAIF,MAAME,cAAc,CAACC,gBAAgB,EAAE;YACzC,OAAOH,MAAME,cAAc,CAACC,gBAAgB;QAC9C;QAEA,OAAOH,MAAME,cAAc,CAACE,uBAAuB,CAACC,OAAO;IAC7D;IAEA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,sCAAsC;QACtCC,QAAQC,KAAK,CAAuB,CAAC,2BACR,EAAEX,qBAAqBY,IAAI,CAAC;mKAEzD,CAAC;IACH;AACF"}

View File

@@ -0,0 +1,16 @@
import * as React from 'react';
const IS_REACT_19_OR_HIGHER = parseInt(React.version, 10) >= 19;
/**
* Returns a ref for the React element in a backwards-compatible way.
*
* @param element - The element to get the ref for.
* @returns The ref for the element.
*/ export function getReactElementRef(element) {
if (!element) {
return undefined;
}
if (IS_REACT_19_OR_HIGHER) {
return element.props.ref;
}
return element.ref;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/getReactElementRef.ts"],"sourcesContent":["import * as React from 'react';\n\nconst IS_REACT_19_OR_HIGHER = parseInt(React.version, 10) >= 19;\n\n/**\n * Returns a ref for the React element in a backwards-compatible way.\n *\n * @param element - The element to get the ref for.\n * @returns The ref for the element.\n */\nexport function getReactElementRef<T>(element: React.ReactElement | null | undefined): React.Ref<T> | undefined {\n if (!element) {\n return undefined;\n }\n\n if (IS_REACT_19_OR_HIGHER) {\n return (element as React.ReactElement<{ ref?: React.Ref<T> }>).props.ref;\n }\n\n return (element as React.ReactElement & { ref: React.Ref<T> | undefined }).ref;\n}\n"],"names":["React","IS_REACT_19_OR_HIGHER","parseInt","version","getReactElementRef","element","undefined","props","ref"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,MAAMC,wBAAwBC,SAASF,MAAMG,OAAO,EAAE,OAAO;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,mBAAsBC,OAA8C;IAClF,IAAI,CAACA,SAAS;QACZ,OAAOC;IACT;IAEA,IAAIL,uBAAuB;QACzB,OAAO,AAACI,QAAuDE,KAAK,CAACC,GAAG;IAC1E;IAEA,OAAO,AAACH,QAAmEG,GAAG;AAChF"}

View File

@@ -0,0 +1,12 @@
export { clamp } from './clamp';
export { // eslint-disable-next-line @typescript-eslint/no-deprecated
getNativeElementProps, getPartitionedNativeProps } from './getNativeElementProps';
export { getReactElementRef } from './getReactElementRef';
export { getRTLSafeKey } from './getRTLSafeKey';
export { mergeCallbacks } from './mergeCallbacks';
export { omit } from './omit';
export { anchorProperties, audioProperties, baseElementEvents, baseElementProperties, buttonProperties, colGroupProperties, colProperties, dialogProperties, divProperties, fieldsetProperties, formProperties, getNativeProps, htmlElementProperties, iframeProperties, imgProperties, inputProperties, labelProperties, liProperties, microdataProperties, olProperties, optionProperties, selectProperties, tableProperties, tdProperties, textAreaProperties, thProperties, timeProperties, trProperties, videoProperties } from './properties';
export { isHTMLElement } from './isHTMLElement';
export { isInteractiveHTMLElement } from './isInteractiveHTMLElement';
export { createPriorityQueue } from './priorityQueue';
export { measureScrollbarWidth } from './measureScrollBarWidth';

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/index.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n getNativeElementProps,\n getPartitionedNativeProps,\n} from './getNativeElementProps';\nexport { getReactElementRef } from './getReactElementRef';\nexport { getRTLSafeKey } from './getRTLSafeKey';\nexport { mergeCallbacks } from './mergeCallbacks';\nexport { omit } from './omit';\nexport {\n anchorProperties,\n audioProperties,\n baseElementEvents,\n baseElementProperties,\n buttonProperties,\n colGroupProperties,\n colProperties,\n dialogProperties,\n divProperties,\n fieldsetProperties,\n formProperties,\n getNativeProps,\n htmlElementProperties,\n iframeProperties,\n imgProperties,\n inputProperties,\n labelProperties,\n liProperties,\n microdataProperties,\n olProperties,\n optionProperties,\n selectProperties,\n tableProperties,\n tdProperties,\n textAreaProperties,\n thProperties,\n timeProperties,\n trProperties,\n videoProperties,\n} from './properties';\nexport { isHTMLElement } from './isHTMLElement';\nexport { isInteractiveHTMLElement } from './isInteractiveHTMLElement';\nexport type { PriorityQueue, PriorityQueueCompareFn } from './priorityQueue';\nexport { createPriorityQueue } from './priorityQueue';\nexport { measureScrollbarWidth } from './measureScrollBarWidth';\n"],"names":["clamp","getNativeElementProps","getPartitionedNativeProps","getReactElementRef","getRTLSafeKey","mergeCallbacks","omit","anchorProperties","audioProperties","baseElementEvents","baseElementProperties","buttonProperties","colGroupProperties","colProperties","dialogProperties","divProperties","fieldsetProperties","formProperties","getNativeProps","htmlElementProperties","iframeProperties","imgProperties","inputProperties","labelProperties","liProperties","microdataProperties","olProperties","optionProperties","selectProperties","tableProperties","tdProperties","textAreaProperties","thProperties","timeProperties","trProperties","videoProperties","isHTMLElement","isInteractiveHTMLElement","createPriorityQueue","measureScrollbarWidth"],"mappings":"AAAA,SAASA,KAAK,QAAQ,UAAU;AAChC,SACE,4DAA4D;AAC5DC,qBAAqB,EACrBC,yBAAyB,QACpB,0BAA0B;AACjC,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,IAAI,QAAQ,SAAS;AAC9B,SACEC,gBAAgB,EAChBC,eAAe,EACfC,iBAAiB,EACjBC,qBAAqB,EACrBC,gBAAgB,EAChBC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,kBAAkB,EAClBC,cAAc,EACdC,cAAc,EACdC,qBAAqB,EACrBC,gBAAgB,EAChBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,mBAAmB,EACnBC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,YAAY,EACZC,eAAe,QACV,eAAe;AACtB,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,wBAAwB,QAAQ,6BAA6B;AAEtE,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,qBAAqB,QAAQ,0BAA0B"}

View File

@@ -0,0 +1,19 @@
/**
* Verifies if a given node is an HTMLElement,
* this method works seamlessly with frames and elements from different documents
*
* This is preferred over simply using `instanceof`.
* Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)
*
* @example
* ```ts
* isHTMLElement(event.target) && event.target.focus()
* isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value
* ```
*
*/ export function isHTMLElement(element, options) {
var _typedElement_ownerDocument;
const typedElement = element;
var _options_constructorName;
return Boolean((typedElement === null || typedElement === void 0 ? void 0 : (_typedElement_ownerDocument = typedElement.ownerDocument) === null || _typedElement_ownerDocument === void 0 ? void 0 : _typedElement_ownerDocument.defaultView) && typedElement instanceof typedElement.ownerDocument.defaultView[(_options_constructorName = options === null || options === void 0 ? void 0 : options.constructorName) !== null && _options_constructorName !== void 0 ? _options_constructorName : 'HTMLElement']);
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/isHTMLElement.ts"],"sourcesContent":["/**\n * Verifies if a given node is an HTMLElement,\n * this method works seamlessly with frames and elements from different documents\n *\n * This is preferred over simply using `instanceof`.\n * Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)\n *\n * @example\n * ```ts\n * isHTMLElement(event.target) && event.target.focus()\n * isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value\n * ```\n *\n */\nexport function isHTMLElement<ConstructorName extends HTMLElementConstructorName = 'HTMLElement'>(\n element?: unknown,\n options?: {\n /**\n * Can be used to provide a custom constructor instead of `HTMLElement`,\n * Like `HTMLInputElement` for example.\n */\n constructorName?: ConstructorName;\n },\n): element is InstanceType<(typeof globalThis)[ConstructorName]> {\n const typedElement = element as Node | null | undefined;\n return Boolean(\n typedElement?.ownerDocument?.defaultView &&\n typedElement instanceof typedElement.ownerDocument.defaultView[options?.constructorName ?? 'HTMLElement'],\n );\n}\n\ntype HTMLElementConstructorName =\n | 'HTMLElement'\n | 'HTMLAnchorElement'\n | 'HTMLAreaElement'\n | 'HTMLAudioElement'\n | 'HTMLBaseElement'\n | 'HTMLBodyElement'\n | 'HTMLBRElement'\n | 'HTMLButtonElement'\n | 'HTMLCanvasElement'\n | 'HTMLDataElement'\n | 'HTMLDataListElement'\n | 'HTMLDetailsElement'\n // NOTE: dialog is not supported in safari 14, also it was removed from lib-dom starting typescript 4.4\n // | 'HTMLDialogElement'\n | 'HTMLDivElement'\n | 'HTMLDListElement'\n | 'HTMLEmbedElement'\n | 'HTMLFieldSetElement'\n | 'HTMLFormElement'\n | 'HTMLHeadingElement'\n | 'HTMLHeadElement'\n | 'HTMLHRElement'\n | 'HTMLHtmlElement'\n | 'HTMLIFrameElement'\n | 'HTMLImageElement'\n | 'HTMLInputElement'\n | 'HTMLModElement'\n | 'HTMLLabelElement'\n | 'HTMLLegendElement'\n | 'HTMLLIElement'\n | 'HTMLLinkElement'\n | 'HTMLMapElement'\n | 'HTMLMetaElement'\n | 'HTMLMeterElement'\n | 'HTMLObjectElement'\n | 'HTMLOListElement'\n | 'HTMLOptGroupElement'\n | 'HTMLOptionElement'\n | 'HTMLOutputElement'\n | 'HTMLParagraphElement'\n | 'HTMLParamElement'\n | 'HTMLPreElement'\n | 'HTMLProgressElement'\n | 'HTMLQuoteElement'\n | 'HTMLSlotElement'\n | 'HTMLScriptElement'\n | 'HTMLSelectElement'\n | 'HTMLSourceElement'\n | 'HTMLSpanElement'\n | 'HTMLStyleElement'\n | 'HTMLTableElement'\n | 'HTMLTableColElement'\n | 'HTMLTableRowElement'\n | 'HTMLTableSectionElement'\n | 'HTMLTemplateElement'\n | 'HTMLTextAreaElement'\n | 'HTMLTimeElement'\n | 'HTMLTitleElement'\n | 'HTMLTrackElement'\n | 'HTMLUListElement'\n | 'HTMLVideoElement';\n"],"names":["isHTMLElement","element","options","typedElement","Boolean","ownerDocument","defaultView","constructorName"],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASA,cACdC,OAAiB,EACjBC,OAMC;QAICC;IAFF,MAAMA,eAAeF;QAG8CC;IAFnE,OAAOE,QACLD,CAAAA,yBAAAA,oCAAAA,8BAAAA,aAAcE,aAAa,cAA3BF,kDAAAA,4BAA6BG,WAAW,KACtCH,wBAAwBA,aAAaE,aAAa,CAACC,WAAW,CAACJ,CAAAA,2BAAAA,oBAAAA,8BAAAA,QAASK,eAAe,cAAxBL,sCAAAA,2BAA4B,cAAc;AAE/G"}

View File

@@ -0,0 +1,18 @@
import { isHTMLElement } from './isHTMLElement';
/**
* @internal
* Checks that the element has default behaviour from user input on click or 'Enter'/'Space' keys
*/ export function isInteractiveHTMLElement(element) {
if (!isHTMLElement(element)) {
return false;
}
const { tagName } = element;
switch(tagName){
case 'BUTTON':
case 'A':
case 'INPUT':
case 'TEXTAREA':
return true;
}
return element.isContentEditable;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/isInteractiveHTMLElement.ts"],"sourcesContent":["import { isHTMLElement } from './isHTMLElement';\n\n/**\n * @internal\n * Checks that the element has default behaviour from user input on click or 'Enter'/'Space' keys\n */\nexport function isInteractiveHTMLElement(element: unknown): boolean {\n if (!isHTMLElement(element)) {\n return false;\n }\n\n const { tagName } = element;\n switch (tagName) {\n case 'BUTTON':\n case 'A':\n case 'INPUT':\n case 'TEXTAREA':\n return true;\n }\n\n return element.isContentEditable;\n}\n"],"names":["isHTMLElement","isInteractiveHTMLElement","element","tagName","isContentEditable"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;AAEhD;;;CAGC,GACD,OAAO,SAASC,yBAAyBC,OAAgB;IACvD,IAAI,CAACF,cAAcE,UAAU;QAC3B,OAAO;IACT;IAEA,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,OAAQC;QACN,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAO;IACX;IAEA,OAAOD,QAAQE,iBAAiB;AAClC"}

View File

@@ -0,0 +1,16 @@
/**
* Measures the width of the scrollbar for the given document.
*
* @param targetDocument - Document to measure the scrollbar width
* @returns The width of the scrollbar in pixels
*/ export function measureScrollbarWidth(targetDocument) {
const outer = targetDocument.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll';
const inner = targetDocument.createElement('div');
outer.appendChild(inner);
targetDocument.body.appendChild(outer);
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
outer.remove();
return scrollbarWidth;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/measureScrollBarWidth.ts"],"sourcesContent":["/**\n * Measures the width of the scrollbar for the given document.\n *\n * @param targetDocument - Document to measure the scrollbar width\n * @returns The width of the scrollbar in pixels\n */\nexport function measureScrollbarWidth(targetDocument: Document): number {\n const outer = targetDocument.createElement('div');\n outer.style.visibility = 'hidden';\n outer.style.overflow = 'scroll';\n\n const inner = targetDocument.createElement('div');\n outer.appendChild(inner);\n\n targetDocument.body.appendChild(outer);\n const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;\n outer.remove();\n\n return scrollbarWidth;\n}\n"],"names":["measureScrollbarWidth","targetDocument","outer","createElement","style","visibility","overflow","inner","appendChild","body","scrollbarWidth","offsetWidth","remove"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,SAASA,sBAAsBC,cAAwB;IAC5D,MAAMC,QAAQD,eAAeE,aAAa,CAAC;IAC3CD,MAAME,KAAK,CAACC,UAAU,GAAG;IACzBH,MAAME,KAAK,CAACE,QAAQ,GAAG;IAEvB,MAAMC,QAAQN,eAAeE,aAAa,CAAC;IAC3CD,MAAMM,WAAW,CAACD;IAElBN,eAAeQ,IAAI,CAACD,WAAW,CAACN;IAChC,MAAMQ,iBAAiBR,MAAMS,WAAW,GAAGJ,MAAMI,WAAW;IAC5DT,MAAMU,MAAM;IAEZ,OAAOF;AACT"}

View File

@@ -0,0 +1,28 @@
/**
* @internal
* Combine two event callbacks into a single callback function that calls each one in order.
*
* Usage example:
* ```ts
* state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {
* // Handle onChange
* });
* ```
*
* The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a
* local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:
* * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.
* * Missing a call to the original onChange due to an early return or other conditional.
*
* If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.
*
* @param callback1 - The first callback to be called, or undefined
* @param callback2 - The second callback to be called, or undefined
*
* @returns A function that that calls the provided functions in order
*/ export function mergeCallbacks(callback1, callback2) {
return (...args)=>{
callback1 === null || callback1 === void 0 ? void 0 : callback1(...args);
callback2 === null || callback2 === void 0 ? void 0 : callback2(...args);
};
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/mergeCallbacks.ts"],"sourcesContent":["/**\n * @internal\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * Usage example:\n * ```ts\n * state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a\n * local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:\n * * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.\n * * Missing a call to the original onChange due to an early return or other conditional.\n *\n * If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.\n *\n * @param callback1 - The first callback to be called, or undefined\n * @param callback2 - The second callback to be called, or undefined\n *\n * @returns A function that that calls the provided functions in order\n */\nexport function mergeCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n): (...args: Args) => void {\n return (...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n };\n}\n"],"names":["mergeCallbacks","callback1","callback2","args"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASA,eACdC,SAAgD,EAChDC,SAAgD;IAEhD,OAAO,CAAC,GAAGC;QACTF,sBAAAA,gCAAAA,aAAeE;QACfD,sBAAAA,gCAAAA,aAAeC;IACjB;AACF"}

View File

@@ -0,0 +1,23 @@
/**
* Tiny helper to do the minimal amount of work in duplicating an object but omitting some
* props. This ends up faster than using object ...rest or reduce to filter.
*
* This behaves very much like filteredAssign, but does not merge many objects together,
* uses an exclusion object map, and avoids spreads all for optimal performance.
*
* See perf test for background:
* https://jsperf.com/omit-vs-rest-vs-reduce/1
*
* @param obj - The object to clone
* @param exclusions - The array of keys to exclude
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
export function omit(obj, exclusions) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = {};
for(const key in obj){
if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {
result[key] = obj[key];
}
}
return result;
}

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/omit.ts"],"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"],"names":["omit","obj","exclusions","result","key","indexOf","hasOwnProperty"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GACD,8DAA8D;AAC9D,OAAO,SAASA,KACdC,GAAS,EACTC,UAAsB;IAEtB,8DAA8D;IAC9D,MAAMC,SAA8B,CAAC;IAErC,IAAK,MAAMC,OAAOH,IAAK;QACrB,IAAIC,WAAWG,OAAO,CAACD,SAAS,CAAC,KAAKH,IAAIK,cAAc,CAACF,MAAM;YAC7DD,MAAM,CAACC,IAAI,GAAGH,GAAG,CAACG,IAAI;QACxB;IACF;IAEA,OAAOD;AACT"}

View File

@@ -0,0 +1,92 @@
/**
* @internal
*/ /**
* @internal
* @param compare - comparison function for items
* @returns Priority queue implemented with a min heap
*/ export function createPriorityQueue(compare) {
const arr = [];
let size = 0;
const swap = (a, b)=>{
const tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
};
const heapify = (i)=>{
let smallest = i;
const l = left(i);
const r = right(i);
if (l < size && compare(arr[l], arr[smallest]) < 0) {
smallest = l;
}
if (r < size && compare(arr[r], arr[smallest]) < 0) {
smallest = r;
}
if (smallest !== i) {
swap(smallest, i);
heapify(smallest);
}
};
const dequeue = ()=>{
if (size === 0) {
throw new Error('Priority queue empty');
}
const res = arr[0];
arr[0] = arr[--size];
heapify(0);
return res;
};
const peek = ()=>{
if (size === 0) {
return null;
}
return arr[0];
};
const enqueue = (item)=>{
arr[size++] = item;
let i = size - 1;
let p = parent(i);
while(i > 0 && compare(arr[p], arr[i]) > 0){
swap(p, i);
i = p;
p = parent(i);
}
};
const contains = (item)=>{
const index = arr.indexOf(item);
return index >= 0 && index < size;
};
const remove = (item)=>{
const i = arr.indexOf(item);
if (i === -1 || i >= size) {
return;
}
arr[i] = arr[--size];
heapify(i);
};
const clear = ()=>{
size = 0;
};
const all = ()=>{
return arr.slice(0, size);
};
return {
all,
clear,
contains,
dequeue,
enqueue,
peek,
remove,
size: ()=>size
};
}
const left = (i)=>{
return 2 * i + 1;
};
const right = (i)=>{
return 2 * i + 2;
};
const parent = (i)=>{
return Math.floor((i - 1) / 2);
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/utils/priorityQueue.ts"],"sourcesContent":["/**\n * @internal\n */\nexport type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\n/**\n * @internal\n */\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @internal\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n\nconst left = (i: number) => {\n return 2 * i + 1;\n};\n\nconst right = (i: number) => {\n return 2 * i + 2;\n};\n\nconst parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n};\n"],"names":["createPriorityQueue","compare","arr","size","swap","a","b","tmp","heapify","i","smallest","l","left","r","right","dequeue","Error","res","peek","enqueue","item","p","parent","contains","index","indexOf","remove","clear","all","slice","Math","floor"],"mappings":"AAAA;;CAEC,GAiBD;;;;CAIC,GACD,OAAO,SAASA,oBAAuBC,OAAkC;IACvE,MAAMC,MAAW,EAAE;IACnB,IAAIC,OAAO;IAEX,MAAMC,OAAO,CAACC,GAAWC;QACvB,MAAMC,MAAML,GAAG,CAACG,EAAE;QAClBH,GAAG,CAACG,EAAE,GAAGH,GAAG,CAACI,EAAE;QACfJ,GAAG,CAACI,EAAE,GAAGC;IACX;IAEA,MAAMC,UAAU,CAACC;QACf,IAAIC,WAAWD;QACf,MAAME,IAAIC,KAAKH;QACf,MAAMI,IAAIC,MAAML;QAEhB,IAAIE,IAAIR,QAAQF,QAAQC,GAAG,CAACS,EAAE,EAAET,GAAG,CAACQ,SAAS,IAAI,GAAG;YAClDA,WAAWC;QACb;QAEA,IAAIE,IAAIV,QAAQF,QAAQC,GAAG,CAACW,EAAE,EAAEX,GAAG,CAACQ,SAAS,IAAI,GAAG;YAClDA,WAAWG;QACb;QAEA,IAAIH,aAAaD,GAAG;YAClBL,KAAKM,UAAUD;YACfD,QAAQE;QACV;IACF;IAEA,MAAMK,UAAU;QACd,IAAIZ,SAAS,GAAG;YACd,MAAM,IAAIa,MAAM;QAClB;QAEA,MAAMC,MAAMf,GAAG,CAAC,EAAE;QAClBA,GAAG,CAAC,EAAE,GAAGA,GAAG,CAAC,EAAEC,KAAK;QACpBK,QAAQ;QAER,OAAOS;IACT;IAEA,MAAMC,OAAO;QACX,IAAIf,SAAS,GAAG;YACd,OAAO;QACT;QAEA,OAAOD,GAAG,CAAC,EAAE;IACf;IAEA,MAAMiB,UAAU,CAACC;QACflB,GAAG,CAACC,OAAO,GAAGiB;QACd,IAAIX,IAAIN,OAAO;QACf,IAAIkB,IAAIC,OAAOb;QACf,MAAOA,IAAI,KAAKR,QAAQC,GAAG,CAACmB,EAAE,EAAEnB,GAAG,CAACO,EAAE,IAAI,EAAG;YAC3CL,KAAKiB,GAAGZ;YACRA,IAAIY;YACJA,IAAIC,OAAOb;QACb;IACF;IAEA,MAAMc,WAAW,CAACH;QAChB,MAAMI,QAAQtB,IAAIuB,OAAO,CAACL;QAC1B,OAAOI,SAAS,KAAKA,QAAQrB;IAC/B;IAEA,MAAMuB,SAAS,CAACN;QACd,MAAMX,IAAIP,IAAIuB,OAAO,CAACL;QAEtB,IAAIX,MAAM,CAAC,KAAKA,KAAKN,MAAM;YACzB;QACF;QAEAD,GAAG,CAACO,EAAE,GAAGP,GAAG,CAAC,EAAEC,KAAK;QACpBK,QAAQC;IACV;IAEA,MAAMkB,QAAQ;QACZxB,OAAO;IACT;IAEA,MAAMyB,MAAM;QACV,OAAO1B,IAAI2B,KAAK,CAAC,GAAG1B;IACtB;IAEA,OAAO;QACLyB;QACAD;QACAJ;QACAR;QACAI;QACAD;QACAQ;QACAvB,MAAM,IAAMA;IACd;AACF;AAEA,MAAMS,OAAO,CAACH;IACZ,OAAO,IAAIA,IAAI;AACjB;AAEA,MAAMK,QAAQ,CAACL;IACb,OAAO,IAAIA,IAAI;AACjB;AAEA,MAAMa,SAAS,CAACb;IACd,OAAOqB,KAAKC,KAAK,CAAC,AAACtB,CAAAA,IAAI,CAAA,IAAK;AAC9B"}

View File

@@ -0,0 +1,419 @@
const toObjectMap = (...items)=>{
const result = {};
for (const item of items){
const keys = Array.isArray(item) ? item : Object.keys(item);
for (const key of keys){
result[key] = 1;
}
}
return result;
};
/**
* An array of events that are allowed on every html element type.
*
* @public
*/ export const baseElementEvents = toObjectMap([
'onAuxClick',
'onAnimationEnd',
'onAnimationStart',
'onCopy',
'onCut',
'onPaste',
'onCompositionEnd',
'onCompositionStart',
'onCompositionUpdate',
'onFocus',
'onFocusCapture',
'onBlur',
'onBlurCapture',
'onChange',
'onInput',
'onSubmit',
'onLoad',
'onError',
'onKeyDown',
'onKeyDownCapture',
'onKeyPress',
'onKeyUp',
'onAbort',
'onCanPlay',
'onCanPlayThrough',
'onDurationChange',
'onEmptied',
'onEncrypted',
'onEnded',
'onLoadedData',
'onLoadedMetadata',
'onLoadStart',
'onPause',
'onPlay',
'onPlaying',
'onProgress',
'onRateChange',
'onSeeked',
'onSeeking',
'onStalled',
'onSuspend',
'onTimeUpdate',
'onVolumeChange',
'onWaiting',
'onClick',
'onClickCapture',
'onContextMenu',
'onDoubleClick',
'onDrag',
'onDragEnd',
'onDragEnter',
'onDragExit',
'onDragLeave',
'onDragOver',
'onDragStart',
'onDrop',
'onMouseDown',
'onMouseDownCapture',
'onMouseEnter',
'onMouseLeave',
'onMouseMove',
'onMouseOut',
'onMouseOver',
'onMouseUp',
'onMouseUpCapture',
'onSelect',
'onTouchCancel',
'onTouchEnd',
'onTouchMove',
'onTouchStart',
'onScroll',
'onWheel',
'onPointerCancel',
'onPointerDown',
'onPointerEnter',
'onPointerLeave',
'onPointerMove',
'onPointerOut',
'onPointerOver',
'onPointerUp',
'onGotPointerCapture',
'onLostPointerCapture'
]);
/**
* An array of element attributes which are allowed on every html element type.
*
* @public
*/ export const baseElementProperties = toObjectMap([
'accessKey',
'children',
'className',
'contentEditable',
'dir',
'draggable',
'hidden',
'htmlFor',
'id',
'lang',
'popover',
'focusgroup',
'ref',
'role',
'style',
'tabIndex',
'title',
'translate',
'spellCheck',
'name'
]);
/**
* An array of microdata attributes that are allowed on every html element type.
*
* @public
*/ export const microdataProperties = toObjectMap([
'itemID',
'itemProp',
'itemRef',
'itemScope',
'itemType'
]);
/**
* An array of HTML element properties and events.
*
* @public
*/ export const htmlElementProperties = toObjectMap(baseElementProperties, baseElementEvents, microdataProperties);
/**
* An array of LABEL tag properties and events.
*
* @public
*/ export const labelProperties = toObjectMap(htmlElementProperties, [
'form'
]);
/**
* An array of AUDIO tag properties and events.
* @public
*/ export const audioProperties = toObjectMap(htmlElementProperties, [
'height',
'loop',
'muted',
'preload',
'src',
'width'
]);
/**
* An array of VIDEO tag properties and events.
*
* @public
*/ export const videoProperties = toObjectMap(audioProperties, [
'poster'
]);
/**
* An array of OL tag properties and events.
*
* @public
*/ export const olProperties = toObjectMap(htmlElementProperties, [
'start'
]);
/**
* An array of LI tag properties and events.
*
* @public
*/ export const liProperties = toObjectMap(htmlElementProperties, [
'value'
]);
/**
* An array of A tag properties and events.
*
* @public
*/ export const anchorProperties = toObjectMap(htmlElementProperties, [
'download',
'href',
'hrefLang',
'media',
'referrerPolicy',
'rel',
'target',
'type'
]);
/**
* An array of TIME tag properties and events.
*
* @public
*/ export const timeProperties = toObjectMap(htmlElementProperties, [
'dateTime'
]);
/**
* An array of BUTTON tag properties and events.
*
* @public
*/ export const buttonProperties = toObjectMap(htmlElementProperties, [
'autoFocus',
'disabled',
'form',
'formAction',
'formEncType',
'formMethod',
'formNoValidate',
'formTarget',
'popoverTarget',
'popoverTargetAction',
'type',
'value'
]);
/**
* An array of INPUT tag properties and events.
*
* @public
*/ export const inputProperties = toObjectMap(buttonProperties, [
'accept',
'alt',
'autoCorrect',
'autoCapitalize',
'autoComplete',
'checked',
'dirname',
'form',
'height',
'inputMode',
'list',
'max',
'maxLength',
'min',
'minLength',
'multiple',
'pattern',
'placeholder',
'readOnly',
'required',
'src',
'step',
'size',
'type',
'value',
'width'
]);
/**
* An array of TEXTAREA tag properties and events.
*
* @public
*/ export const textAreaProperties = toObjectMap(buttonProperties, [
'autoCapitalize',
'cols',
'dirname',
'form',
'maxLength',
'placeholder',
'readOnly',
'required',
'rows',
'wrap'
]);
/**
* An array of SELECT tag properties and events.
*
* @public
*/ export const selectProperties = toObjectMap(buttonProperties, [
'form',
'multiple',
'required'
]);
export const optionProperties = toObjectMap(htmlElementProperties, [
'selected',
'value'
]);
/**
* An array of TABLE tag properties and events.
*
* @public
*/ export const tableProperties = toObjectMap(htmlElementProperties, [
'cellPadding',
'cellSpacing'
]);
/**
* An array of TR tag properties and events.
*
* @public
*/ export const trProperties = htmlElementProperties;
/**
* An array of TH tag properties and events.
*
* @public
*/ export const thProperties = toObjectMap(htmlElementProperties, [
'colSpan',
'rowSpan',
'scope'
]);
/**
* An array of TD tag properties and events.
*
* @public
*/ export const tdProperties = toObjectMap(htmlElementProperties, [
'colSpan',
'headers',
'rowSpan',
'scope'
]);
export const colGroupProperties = toObjectMap(htmlElementProperties, [
'span'
]);
export const colProperties = toObjectMap(htmlElementProperties, [
'span'
]);
/**
* An array of FIELDSET tag properties and events.
*
* @public
*/ export const fieldsetProperties = toObjectMap(htmlElementProperties, [
'disabled',
'form'
]);
/**
* An array of FORM tag properties and events.
*
* @public
*/ export const formProperties = toObjectMap(htmlElementProperties, [
'acceptCharset',
'action',
'encType',
'encType',
'method',
'noValidate',
'target'
]);
/**
* An array of IFRAME tag properties and events.
*
* @public
*/ export const iframeProperties = toObjectMap(htmlElementProperties, [
'allow',
'allowFullScreen',
'allowPaymentRequest',
'allowTransparency',
'csp',
'height',
'importance',
'referrerPolicy',
'sandbox',
'src',
'srcDoc',
'width'
]);
/**
* An array of IMAGE tag properties and events.
*
* @public
*/ export const imgProperties = toObjectMap(htmlElementProperties, [
'alt',
'crossOrigin',
'height',
'src',
'srcSet',
'useMap',
'width'
]);
/**
* An array of DIALOG tag properties and events.
*
* @public
*/ export const dialogProperties = toObjectMap(htmlElementProperties, [
'open',
'onCancel',
'onClose'
]);
/**
* An array of DIV tag properties and events.
*
* @public
*/ export const divProperties = htmlElementProperties;
/**
* Gets native supported props for an html element provided the allowance set. Use one of the property
* sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
* props set. Note that all data- and aria- prefixed attributes will be allowed.
* NOTE: getNativeProps should always be applied first when adding props to a react component. The
* non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
* For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
* the component after an onClick function is added, then the getNativeProps onClick will override it.
*
* @public
* @param props - The unfiltered input props
* @param allowedPropNames - The array or record of allowed prop names.
* @param excludedPropNames
* @returns The filtered props
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getNativeProps(// eslint-disable-next-line @typescript-eslint/no-explicit-any
props, allowedPropNames, excludedPropNames) {
// It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for
// JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.
// Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then
// return native props.
// We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797
const isArray = Array.isArray(allowedPropNames);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result = {};
const keys = Object.keys(props);
for (const key of keys){
const isNativeProp = !isArray && allowedPropNames[key] || isArray && allowedPropNames.indexOf(key) >= 0 || key.indexOf('data-') === 0 || key.indexOf('aria-') === 0;
if (isNativeProp && (!excludedPropNames || (excludedPropNames === null || excludedPropNames === void 0 ? void 0 : excludedPropNames.indexOf(key)) === -1)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
result[key] = props[key];
}
}
return result;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
import * as React from 'react';

File diff suppressed because one or more lines are too long