diff --git a/.changeset/long-cougars-juggle.md b/.changeset/long-cougars-juggle.md index fc6d313d9e..c7f2e4407c 100644 --- a/.changeset/long-cougars-juggle.md +++ b/.changeset/long-cougars-juggle.md @@ -2,4 +2,5 @@ "@zag-js/date-picker": patch --- -Fix issue in Vue.js where input value could not be changed by typing. +- Fix issue in Vue.js where input value could not be changed by typing. +- Fix issue where setting controlled `min` and `max` values throws an error. diff --git a/packages/core/src/deep-merge.ts b/packages/core/src/deep-merge.ts index 5c082bee04..146f8f3534 100644 --- a/packages/core/src/deep-merge.ts +++ b/packages/core/src/deep-merge.ts @@ -1,10 +1,10 @@ -import { compact, isObject } from "@zag-js/utils" +import { compact, isPlainObject } from "@zag-js/utils" export function deepMerge>(source: T, ...objects: T[]): T { for (const obj of objects) { const target = compact(obj) for (const key in target) { - if (isObject(obj[key])) { + if (isPlainObject(obj[key])) { if (!source[key]) { source[key] = {} as any } diff --git a/packages/utilities/core/src/guard.ts b/packages/utilities/core/src/guard.ts index ac3f88ecf7..038dd2f228 100644 --- a/packages/utilities/core/src/guard.ts +++ b/packages/utilities/core/src/guard.ts @@ -1,7 +1,8 @@ export const isDev = () => process.env.NODE_ENV !== "production" export const isArray = (v: any): v is any[] => Array.isArray(v) export const isBoolean = (v: any): v is boolean => v === true || v === false -export const isObject = (v: any): v is Record => !(v == null || typeof v !== "object" || isArray(v)) +export const isObjectLike = (v: any): v is Record => v != null && typeof v === "object" +export const isObject = (v: any): v is Record => isObjectLike(v) && !isArray(v) export const isNumber = (v: any): v is number => typeof v === "number" && !Number.isNaN(v) export const isString = (v: any): v is string => typeof v === "string" export const isFunction = (v: any): v is Function => typeof v === "function" @@ -9,3 +10,15 @@ export const isNull = (v: any): v is null | undefined => v == null export const hasProp = (obj: any, prop: T): obj is Record => Object.prototype.hasOwnProperty.call(obj, prop) + +const baseGetTag = (v: any) => Object.prototype.toString.call(v) +const fnToString = Function.prototype.toString +const objectCtorString = fnToString.call(Object) + +export const isPlainObject = (v: any) => { + if (!isObjectLike(v) || baseGetTag(v) != "[object Object]") return false + const proto = Object.getPrototypeOf(v) + if (proto === null) return true + const Ctor = hasProp(proto, "constructor") && proto.constructor + return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString +}