@swan-io/lake 7.0.4 → 7.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "7.0.4",
3
+ "version": "7.0.6",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -14,6 +14,9 @@ export type LakeTagInputProps = Merge<TextInputProps, {
14
14
  onValuesChanged: (values: string[]) => void;
15
15
  placeholder?: string;
16
16
  }>;
17
+ export type TagInputRef = TextInput & {
18
+ pushPendingValue: () => void;
19
+ };
17
20
  export declare const LakeTagInput: import("react").ForwardRefExoticComponent<{
18
21
  allowFontScaling?: boolean | undefined;
19
22
  autoCapitalize?: "none" | "sentences" | "words" | "characters" | undefined;
@@ -216,4 +219,4 @@ export declare const LakeTagInput: import("react").ForwardRefExoticComponent<{
216
219
  values: string[];
217
220
  onValuesChanged: (values: string[]) => void;
218
221
  placeholder?: string | undefined;
219
- } & import("react").RefAttributes<TextInput | null>>;
222
+ } & import("react").RefAttributes<TagInputRef>>;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useCallback, useRef, useState } from "react";
2
+ import { forwardRef, useCallback, useImperativeHandle, useRef, useState } from "react";
3
3
  import { StyleSheet, TextInput, View, } from "react-native";
4
4
  import { P, match } from "ts-pattern";
5
5
  import { backgroundColor, colors, radii, shadows, spacings } from "../constants/design";
@@ -77,11 +77,12 @@ const styles = StyleSheet.create({
77
77
  },
78
78
  });
79
79
  const SEPARATORS_REGEX = /,| /;
80
- export const LakeTagInput = forwardRef(({ validator = () => true, onFocus: originalOnFocus, onBlur: originalOnBlur, validateOnBlur = true, values, onValuesChanged, readOnly = false, disabled = false, valid = false, hideErrors = false, placeholder, help, error, }, forwardRef) => {
80
+ export const LakeTagInput = forwardRef(({ validator = () => true, onFocus: originalOnFocus, onBlur: originalOnBlur, validateOnBlur = true, values, onValuesChanged, readOnly = false, disabled = false, valid = false, hideErrors = false, placeholder, help, error, }, forwardedRef) => {
81
81
  const inputRef = useRef(null);
82
82
  const containerRef = useRef(null);
83
83
  const [isFocused, setIsFocused] = useState(false);
84
84
  const [isHovered, setIsHovered] = useState(false);
85
+ const mergedRef = useMergeRefs(inputRef, forwardedRef);
85
86
  useHover(containerRef, {
86
87
  onHoverStart: () => setIsHovered(true),
87
88
  onHoverEnd: () => setIsHovered(false),
@@ -131,7 +132,16 @@ export const LakeTagInput = forwardRef(({ validator = () => true, onFocus: origi
131
132
  setIsFocused(false);
132
133
  originalOnBlur === null || originalOnBlur === void 0 ? void 0 : originalOnBlur(event);
133
134
  }, [pushNewValues, originalOnBlur, validateOnBlur]);
134
- const mergedRef = useMergeRefs(inputRef, forwardRef);
135
+ useImperativeHandle(forwardedRef, () => ({
136
+ pushPendingValue: () => {
137
+ const input = inputRef.current;
138
+ if (input instanceof HTMLInputElement &&
139
+ isNotNullishOrEmpty(input.value) &&
140
+ validateOnBlur) {
141
+ pushNewValues([input.value]);
142
+ }
143
+ },
144
+ }), [pushNewValues, validateOnBlur]);
135
145
  const hasError = isNotNullishOrEmpty(error);
136
146
  return (_jsxs(View, { children: [_jsxs(Pressable, { style: [
137
147
  styles.root,
@@ -1,2 +1,2 @@
1
1
  export declare const isPlainObject: (value: unknown) => boolean;
2
- export declare const pick: <T extends Record<K, unknown>, K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
2
+ export declare const pick: <T extends Record<K, unknown>, const K extends keyof T>(object: T, keys: K[]) => Pick<T, K>;
@@ -0,0 +1,2 @@
1
+ import { LegacyRef, MutableRefObject, RefCallback } from "react";
2
+ export declare const mergeRefs: <T>(refs: (MutableRefObject<T> | LegacyRef<T> | null | undefined)[]) => RefCallback<T>;
@@ -0,0 +1,11 @@
1
+ // From https://github.com/gregberge/react-merge-refs
2
+ export const mergeRefs = (refs) => value => {
3
+ refs.forEach(ref => {
4
+ if (typeof ref === "function") {
5
+ ref(value);
6
+ }
7
+ else if (ref != null) {
8
+ ref.current = value;
9
+ }
10
+ });
11
+ };