@homebound/beam 2.417.6 → 2.417.8
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/dist/{chunk-XH44AYND.js → chunk-ZPT2ZR5B.js} +28 -1
- package/dist/chunk-ZPT2ZR5B.js.map +1 -0
- package/dist/index.cjs +286 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +6 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +42 -7
- package/dist/index.d.ts +42 -7
- package/dist/index.js +294 -183
- package/dist/index.js.map +1 -1
- package/dist/utils/rtlUtils.cjs.map +1 -1
- package/dist/utils/rtlUtils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-XH44AYND.js.map +0 -1
|
@@ -28,6 +28,31 @@ function newMethodMissingProxy(object, methodMissing) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// src/utils/inlineStyles.ts
|
|
32
|
+
function isInlineStyleValue(value) {
|
|
33
|
+
return typeof value === "string" || typeof value === "number";
|
|
34
|
+
}
|
|
35
|
+
function setInlineStyles(el, styles) {
|
|
36
|
+
Object.entries(styles).forEach(([prop, value]) => {
|
|
37
|
+
if (!isInlineStyleValue(value)) return;
|
|
38
|
+
if (prop.startsWith("--")) {
|
|
39
|
+
el.style.setProperty(prop, String(value));
|
|
40
|
+
} else {
|
|
41
|
+
el.style[prop] = String(value);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function clearInlineStyles(el, styles) {
|
|
46
|
+
Object.entries(styles).forEach(([prop, value]) => {
|
|
47
|
+
if (!isInlineStyleValue(value)) return;
|
|
48
|
+
if (prop.startsWith("--")) {
|
|
49
|
+
el.style.removeProperty(prop);
|
|
50
|
+
} else {
|
|
51
|
+
el.style[prop] = "";
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
31
56
|
// src/utils/index.ts
|
|
32
57
|
function fail(message) {
|
|
33
58
|
throw new Error(message || "Failed");
|
|
@@ -76,6 +101,8 @@ function pluralize(count, noun, pluralNoun) {
|
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
export {
|
|
104
|
+
setInlineStyles,
|
|
105
|
+
clearInlineStyles,
|
|
79
106
|
defaultTestId,
|
|
80
107
|
useTestIds,
|
|
81
108
|
newMethodMissingProxy,
|
|
@@ -93,4 +120,4 @@ export {
|
|
|
93
120
|
isDefined,
|
|
94
121
|
pluralize
|
|
95
122
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-ZPT2ZR5B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/defaultTestId.ts","../src/utils/useTestIds.tsx","../src/utils/inlineStyles.ts","../src/utils/index.ts"],"sourcesContent":["import { camelCase } from \"change-case\";\n\n/**\n * Guesses an id based on a label string, i.e. given `Homeowner Contract`,\n * returns `homeownerContract`.\n *\n * This is useful for our (non-bound) form fields that will probably have a label,\n * but may not have a `data-testid` set by the encompassing page.\n *\n * (Bound form fields typically set their test id from their form-state field's key.)\n */\nexport function defaultTestId(label: string): string {\n // Strip `m:4` to `m4` to prevent it from becoming `m_4` which our rtl-utils assumes\n // means \"the 4th element with a data-testid value of 'm'\".\n return camelCase(label.replace(\":\", \"\"));\n}\n","import { defaultTestId } from \"src/utils/defaultTestId\";\n\nexport type TestIds = Record<string, object>;\n\n/**\n * Provides a way to easily generate `data-testid`s.\n *\n * The test ids are made of a `${prefix}_${key}`, where:\n *\n * - The prefix is the component name, like \"profile\", and\n * - The key is the specific DOM element that's being tagged, like \"firstName\"\n *\n * To determine the prefix, the component passes us their props, which we'll use\n * to look for an incoming `data-testid` to become the prefix the `data-testid`s\n * that we create. I.e.:\n *\n * ```tsx\n * const { a, b } = props;\n * const tid = useTestIds(props);\n *\n * return <Foo {...tid.foo} />;\n * ```\n *\n * This allows components that embed the component to customize the prefix, i.e.\n * `<TextField data-testid=\"firstName\" />` and `<TextField data-testid=\"lastName\" />`\n * would produce, within `TextField` itself, ids like:\n *\n * - `firstName_input`\n * - `firstName_errors`\n * - `lastName_input`\n * - `lastName_errors`\n *\n * @param props the component's `props` object, which we'll scan for `data-testid` to use as the prefix\n * @param defaultPrefix the default prefix to use if no `data-testid` is found on `props`\n */\nexport function useTestIds(props: object, defaultPrefix?: string): Record<string, object> {\n const prefix: string | undefined =\n (props as any)[\"data-testid\"] ||\n // Pass defaultPrefix through defaultTestId to allow `useTestIds(..., label)` usage\n (defaultPrefix ? defaultTestId(defaultPrefix) : undefined);\n const rootId = { \"data-testid\": prefix };\n return newMethodMissingProxy(rootId, (key) => {\n // If we get tagged ids, remove the colon so that we can do `r.foo_m2` for `m:2`\n key = key.replace(\":\", \"\");\n return { \"data-testid\": prefix ? `${prefix}_${key}` : key };\n }) as any;\n}\n\n/** Uses `object` for any keys that exist on it, otherwise calls `methodMissing` fn. */\nexport function newMethodMissingProxy<T extends object, Y>(\n object: T,\n methodMissing: (key: string) => Y,\n): T & Record<string, Y> {\n return new Proxy(object, {\n get(object, property) {\n if (Reflect.has(object, property)) {\n return Reflect.get(object, property);\n } else if (property === \"then\") {\n return undefined;\n } else {\n return methodMissing(String(property));\n }\n },\n }) as any;\n}\n","function isInlineStyleValue(value: unknown): value is string | number {\n return typeof value === \"string\" || typeof value === \"number\";\n}\n\nexport function setInlineStyles(el: HTMLElement, styles: object): void {\n Object.entries(styles as Record<string, unknown>).forEach(([prop, value]) => {\n if (!isInlineStyleValue(value)) return;\n if (prop.startsWith(\"--\")) {\n el.style.setProperty(prop, String(value));\n } else {\n (el.style as any)[prop] = String(value);\n }\n });\n}\n\nexport function clearInlineStyles(el: HTMLElement, styles: object): void {\n Object.entries(styles as Record<string, unknown>).forEach(([prop, value]) => {\n if (!isInlineStyleValue(value)) return;\n if (prop.startsWith(\"--\")) {\n el.style.removeProperty(prop);\n } else {\n (el.style as any)[prop] = \"\";\n }\n });\n}\n","import { MutableRefObject } from \"react\";\nimport type { CheckboxGroupState, ToggleState } from \"react-stately\";\n\nexport function fail(message?: string): never {\n throw new Error(message || \"Failed\");\n}\n\n/** Adapts our state to what useToggleState returns in a stateless manner. */\nexport function toToggleState(isSelected: boolean, onChange: (value: boolean) => void): ToggleState {\n return {\n isSelected,\n defaultSelected: false,\n setSelected: onChange,\n toggle: () => onChange(!isSelected),\n };\n}\n\n/** Adapts our state to what use*Group returns in a stateless manner. */\nexport function toGroupState<T extends string>(values: T[], onChange: (value: T[]) => void): CheckboxGroupState {\n const addValue = (value: T) => onChange([...values, value]);\n const removeValue = (value: T) => onChange(values.filter((_value) => _value !== value));\n\n return {\n value: values,\n defaultValue: [],\n setValue: onChange,\n isSelected: (value: T) => values.includes(value),\n addValue,\n removeValue,\n toggleValue: (value: T) => (values.includes(value) ? addValue(value) : removeValue(value)),\n isDisabled: false,\n isReadOnly: false,\n // We do not use the validation state, as our Switch groups do not support error states. However, this field is required by the `CheckboxGroupState` so we need to include it.\n // If we ever update our SwitchGroup component to support error states, we'll need to update this.\n validationState: \"valid\",\n isInvalid: false,\n isRequired: false,\n setInvalid: () => {},\n realtimeValidation: { isInvalid: false, validationErrors: [], validationDetails: {} as ValidityState },\n displayValidation: { isInvalid: false, validationErrors: [], validationDetails: {} as ValidityState },\n updateValidation: () => {},\n resetValidation: () => {},\n commitValidation: () => {},\n };\n}\n\n/**\n * Utility to maybe call a function if undefined with arguments\n *\n * @example\n * maybeCall(onChange, true)\n * maybeCall(onBlur)\n * maybeCall(onSelect, { id: 1, value: \"book 1\"}, true)\n */\nexport function maybeCall(callback: Function | undefined, ...args: any[]) {\n return callback && callback(...args);\n}\n\nexport * from \"./inlineStyles\";\nexport * from \"./useTestIds\";\n\n/** Casts `Object.keys` to \"what it should be\", as long as your instance doesn't have keys it shouldn't. */\nexport function safeKeys<T>(instance: T): (keyof T)[] {\n return Object.getOwnPropertyNames(instance) as any;\n}\n\n// Returns object with specified key removed\nexport const omitKey = <T, K extends keyof T>(key: K, { [key]: _, ...obj }: T) => obj as T;\n\nexport const noop = (..._: any) => {};\n\ntype Entries<T> = {\n [K in keyof T]: [K, T[K]];\n}[keyof T][];\n\nexport function safeEntries<T extends object>(obj: T): Entries<T> {\n return Object.entries(obj) as any;\n}\n\nexport class EmptyRef<T> implements MutableRefObject<T> {\n get current(): T {\n throw new Error(\"BeamProvider is missing\");\n }\n\n set current(_) {\n throw new Error(\"BeamProvider is missing\");\n }\n}\n\nexport const isAbsoluteUrl = (url: string) => /^(http(s?)):\\/\\//i.test(url);\n\nexport function areArraysEqual(a: any[], b: any[]): boolean {\n return a.length === b.length && a.every((val, idx) => val === b[idx]);\n}\n\nexport function isPromise(obj: any | Promise<any>): obj is Promise<any> {\n return typeof obj === \"object\" && \"then\" in obj && typeof obj.then === \"function\";\n}\n\nexport function isFunction(f: any): f is Function {\n return typeof f === \"function\";\n}\n\nexport function isDefined<T extends any>(param: T | undefined | null): param is T {\n return param !== null && param !== undefined;\n}\n\nexport function pluralize(count: number | unknown[], noun: string, pluralNoun?: string): string {\n if ((Array.isArray(count) ? count.length : count) === 1) return noun;\n return pluralNoun || `${noun}s`;\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAWnB,SAAS,cAAc,OAAuB;AAGnD,SAAO,UAAU,MAAM,QAAQ,KAAK,EAAE,CAAC;AACzC;;;ACoBO,SAAS,WAAW,OAAe,eAAgD;AACxF,QAAM,SACH,MAAc,aAAa;AAAA,GAE3B,gBAAgB,cAAc,aAAa,IAAI;AAClD,QAAM,SAAS,EAAE,eAAe,OAAO;AACvC,SAAO,sBAAsB,QAAQ,CAAC,QAAQ;AAE5C,UAAM,IAAI,QAAQ,KAAK,EAAE;AACzB,WAAO,EAAE,eAAe,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK,IAAI;AAAA,EAC5D,CAAC;AACH;AAGO,SAAS,sBACd,QACA,eACuB;AACvB,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAIA,SAAQ,UA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