Skip to content

Releases: lawvs/fn-sphere

@fn-sphere/filter@1.3.0

17 Feb 18:13
4c298ae

Choose a tag to compare

Minor Changes

  • 3eee173 Thanks @lawvs! - Support lazy initializer function for defaultRule in useFilterSphere. Accepts () => FilterGroup in addition to FilterGroup.

Patch Changes

  • c7d1d08 Thanks @lawvs! - Fix React 18 compatibility by using Context.Provider instead of the React 19-only Context JSX pattern

  • Updated dependencies [be2bf20]:

    • @fn-sphere/core@1.3.0

@fn-sphere/core@1.3.0

17 Feb 18:13
4c298ae

Choose a tag to compare

Minor Changes

  • be2bf20 Thanks @lawvs! - Add sorting functionality with createSorterSphere and utilities. Provides schema-driven, multi-field sorting for Zod-typed data with customizable comparison functions and a built-in presetSort for strings, numbers, booleans, dates, and enums.

@fn-sphere/filter@1.2.0

28 Dec 11:54
7f80232

Choose a tag to compare

Minor Changes

  • 4f62a4b Thanks @lawvs! - Add ErrorBoundary component
    • Added ErrorBoundary component to the theme components for handling rendering errors in filter UI
    • ErrorBoundary wraps FilterGroupContainer and SingleFilterContainer to catch and handle errors gracefully
    • Provides delete functionality to remove error-causing filter rules or groups via onDelete callback
    • Displays user-friendly error fallback UI with error message and delete button

Patch Changes

  • 4c0eccc Thanks @lawvs! - Export defaultGetLocaleText function for accessing localized filter names

  • Updated dependencies [604b283]:

    • @fn-sphere/core@1.2.0

@fn-sphere/core@1.2.0

28 Dec 11:54
7f80232

Choose a tag to compare

Minor Changes

  • 604b283 Thanks @lawvs! - Add error handling support to filter predicates
    • Added fallbackValue parameter to control behavior when filter rules are not available or errors occur (defaults to true)
    • Added errorHandling option with catchError and logError properties for configurable error handling (defaults to { catchError: true, logError: true })
    • Renamed createFilterPredicate to createUnsafeFilterPredicate (internal use)
    • New createFilterPredicate now safely handles errors by default
    • When fallbackValue is true, items are included in filtered results on error; when false, items are excluded

@fn-sphere/filter@1.1.0

07 Nov 20:21
aa8924f

Choose a tag to compare

Minor Changes

  • #185 7a93fcd Thanks @lawvs! - Add support for Zod enum types in filter predicates and UI components.
    • Added enumEquals and enumNotEqual filter functions for enum types
    • Extended contains and notContains functions to work with z.enum() schemas
    • Added enum and enum array data input views for selecting enum values in the filter UI
    • Enum filters are defined separately due to runtime type indistinguishability from strings

Patch Changes

  • Updated dependencies [7a93fcd]:
    • @fn-sphere/core@1.1.0

@fn-sphere/core@1.1.0

07 Nov 20:21
aa8924f

Choose a tag to compare

Minor Changes

  • #185 7a93fcd Thanks @lawvs! - Add support for Zod enum types in filter predicates and UI components.
    • Added enumEquals and enumNotEqual filter functions for enum types
    • Extended contains and notContains functions to work with z.enum() schemas
    • Added enum and enum array data input views for selecting enum values in the filter UI
    • Enum filters are defined separately due to runtime type indistinguishability from strings

@fn-sphere/filter@1.0.0

08 Oct 15:51
ac88823

Choose a tag to compare

Major Changes

  • 15f2755 Thanks @lawvs! - ## Migrate to Zod 4

    • Upgrade all filtering utilities to Zod 4, adopting the new z.function({ input, output }) factory.
    • Update tests, docs, and playground examples to reflect the revised function schema API.
    • Surface tuple-based parameter metadata so filter UIs can materialise runtime validators without accessing private internals.
    • Prepare downstream apps for the breaking changes required when upgrading filter definitions to Zod 4.

    Migration guide

    • Make sure your project is already on Zod 4 before consuming this release. Review the upstream changes at https://zod.dev/v4/changelog to plan any schema updates.
    • Replace every z.function().args(...).returns(...) with the new factory signature.
    const equals = defineTypedFn({
      name: "equals",
    -  define: z.function().args(z.string(), z.string()).returns(z.boolean()),
    +  define: z.function({ input: [z.string(), z.string()], output: z.boolean() }),
      implement: (value, target) => value === target,
    });
    • getParametersExceptFirst now returns a $ZodTuple rather than a plain array. Use tuple._zod.def.items when you need to inspect or parse arguments at runtime.
    • DataInputViewProps/DataInputViewSpec consume tuple schemas instead of loose arrays:
    // Before
    type DataInputViewProps = {
      rule: SingleFilter;
      requiredDataSchema: [] | [z.ZodTypeAny, ...z.ZodTypeAny[]];
      updateInput: (...input: unknown[]) => void;
    };
    
    type DataInputViewSpec = {
      name: string;
      match:
        | []
        | [z.ZodTypeAny, ...z.ZodTypeAny[]]
        | ((
            parameterSchemas: [] | [z.ZodTypeAny, ...z.ZodTypeAny[]],
            fieldSchema?: z.ZodTypeAny,
          ) => boolean);
      view: ComponentType<DataInputViewProps>;
    };
    
    // After
    type DataInputViewProps = {
      rule: SingleFilter;
      requiredDataSchema: $ZodTuple;
      updateInput: (...input: unknown[]) => void;
    };
    
    type DataInputViewSpec = {
      name: string;
      match:
        | []
        | [$ZodType, ...$ZodType[]]
        | $ZodTuple
        | ((parameterSchemas: $ZodTuple, fieldSchema?: $ZodType) => boolean);
      view: ComponentType<DataInputViewProps>;
    };
    • Update all usages of DataInputViewSpec.match to handle the new tuple schema.
    const literalUnionView: DataInputViewSpec = {
        name: "literal union",
        match: (parameterSchemas) => {
    -     if (parameterSchemas.length !== 1) {
    +     if (parameterSchemas._zod.def.items.length !== 1) {
            return false;
          }
    -     const [item] = parameterSchemas;
    -     const isUnion = item instanceof z.ZodUnion;
    +     const theOnlyItem = parameterSchemas._zod.def.items.at(0);
    +     const schemaDef = (theOnlyItem as $ZodTypes)._zod.def;
    +     const isUnion = schemaDef.type === "union";
          if (!isUnion) {
            return false;
          }
    
    -     return item.options.every(
    -       (option: unknown) => option instanceof z.ZodLiteral,
    +     return schemaDef.options.every(
    +       (option) => option._zod.def.type === "literal",
    +     );
        },
        view: function View({ requiredDataSchema, rule, updateInput }) {
          const { Select } = useView("components");
          const { getLocaleText } = useRootRule();
    
          const options = useMemo(() => {
    -       const unionSchema = requiredDataSchema[0] as z.ZodUnion<
    -         [z.ZodLiteral<z.Primitive>]
    -       >;
    +       const unionSchema = requiredDataSchema._zod.def.items[0] as $ZodUnion<
    +         $ZodLiteral[]
    +       >;
    
    -       return unionSchema.options.map((item: z.ZodLiteral<z.Primitive>) => ({
    +       return unionSchema._zod.def.options.map((item) => {
              const value = item._zod.def.values[0];
              const meta = z.globalRegistry.get(item);
              const metaDesc =
                meta && meta.description ? meta.description : undefined;
              return {
                label: getLocaleText(metaDesc ?? String(value)),
                value,
              };
            });
          }, [getLocaleText, requiredDataSchema]);
          return (
            <Select
              options={options}
              value={rule.args[0]}
              onChange={(value) => {
                updateInput(value);
              }}
            />
          );
        },
      }

Patch Changes

  • Updated dependencies [15f2755]:
    • @fn-sphere/core@1.0.0

@fn-sphere/core@1.0.0

08 Oct 15:51
ac88823

Choose a tag to compare

Major Changes

  • 15f2755 Thanks @lawvs! - ## Migrate to Zod 4

    • Upgrade all filtering utilities to Zod 4, adopting the new z.function({ input, output }) factory.
    • Update tests, docs, and playground examples to reflect the revised function schema API.
    • Surface tuple-based parameter metadata so filter UIs can materialise runtime validators without accessing private internals.
    • Prepare downstream apps for the breaking changes required when upgrading filter definitions to Zod 4.

    Migration guide

    • Make sure your project is already on Zod 4 before consuming this release. Review the upstream changes at https://zod.dev/v4/changelog to plan any schema updates.
    • Replace every z.function().args(...).returns(...) with the new factory signature.
    const equals = defineTypedFn({
      name: "equals",
    -  define: z.function().args(z.string(), z.string()).returns(z.boolean()),
    +  define: z.function({ input: [z.string(), z.string()], output: z.boolean() }),
      implement: (value, target) => value === target,
    });
    • getParametersExceptFirst now returns a $ZodTuple rather than a plain array. Use tuple._zod.def.items when you need to inspect or parse arguments at runtime.
    • DataInputViewProps/DataInputViewSpec consume tuple schemas instead of loose arrays:
    // Before
    type DataInputViewProps = {
      rule: SingleFilter;
      requiredDataSchema: [] | [z.ZodTypeAny, ...z.ZodTypeAny[]];
      updateInput: (...input: unknown[]) => void;
    };
    
    type DataInputViewSpec = {
      name: string;
      match:
        | []
        | [z.ZodTypeAny, ...z.ZodTypeAny[]]
        | ((
            parameterSchemas: [] | [z.ZodTypeAny, ...z.ZodTypeAny[]],
            fieldSchema?: z.ZodTypeAny,
          ) => boolean);
      view: ComponentType<DataInputViewProps>;
    };
    
    // After
    type DataInputViewProps = {
      rule: SingleFilter;
      requiredDataSchema: $ZodTuple;
      updateInput: (...input: unknown[]) => void;
    };
    
    type DataInputViewSpec = {
      name: string;
      match:
        | []
        | [$ZodType, ...$ZodType[]]
        | $ZodTuple
        | ((parameterSchemas: $ZodTuple, fieldSchema?: $ZodType) => boolean);
      view: ComponentType<DataInputViewProps>;
    };
    • Update all usages of DataInputViewSpec.match to handle the new tuple schema.
    const literalUnionView: DataInputViewSpec = {
        name: "literal union",
        match: (parameterSchemas) => {
    -     if (parameterSchemas.length !== 1) {
    +     if (parameterSchemas._zod.def.items.length !== 1) {
            return false;
          }
    -     const [item] = parameterSchemas;
    -     const isUnion = item instanceof z.ZodUnion;
    +     const theOnlyItem = parameterSchemas._zod.def.items.at(0);
    +     const schemaDef = (theOnlyItem as $ZodTypes)._zod.def;
    +     const isUnion = schemaDef.type === "union";
          if (!isUnion) {
            return false;
          }
    
    -     return item.options.every(
    -       (option: unknown) => option instanceof z.ZodLiteral,
    +     return schemaDef.options.every(
    +       (option) => option._zod.def.type === "literal",
    +     );
        },
        view: function View({ requiredDataSchema, rule, updateInput }) {
          const { Select } = useView("components");
          const { getLocaleText } = useRootRule();
    
          const options = useMemo(() => {
    -       const unionSchema = requiredDataSchema[0] as z.ZodUnion<
    -         [z.ZodLiteral<z.Primitive>]
    -       >;
    +       const unionSchema = requiredDataSchema._zod.def.items[0] as $ZodUnion<
    +         $ZodLiteral[]
    +       >;
    
    -       return unionSchema.options.map((item: z.ZodLiteral<z.Primitive>) => ({
    +       return unionSchema._zod.def.options.map((item) => {
              const value = item._zod.def.values[0];
              const meta = z.globalRegistry.get(item);
              const metaDesc =
                meta && meta.description ? meta.description : undefined;
              return {
                label: getLocaleText(metaDesc ?? String(value)),
                value,
              };
            });
          }, [getLocaleText, requiredDataSchema]);
          return (
            <Select
              options={options}
              value={rule.args[0]}
              onChange={(value) => {
                updateInput(value);
              }}
            />
          );
        },
      }

@fn-sphere/theme-mui-material@0.1.3

27 Sep 16:28
955b829

Choose a tag to compare

Patch Changes

@fn-sphere/filter@0.8.0

27 Sep 16:28
955b829

Choose a tag to compare

Minor Changes

  • a915a9a Thanks @lawvs! - feat(filter)!: retain args by default when filter changes via tryRetainArgs

    • BREAKING: FieldSelect and FilterSelect now default tryRetainArgs (and tryRetainFilter for fields) to true. Previously, leaving these props undefined defaulted to resetting args. To restore the old behavior, explicitly pass tryRetainArgs={false} (and/or tryRetainFilter={false}).
    • When switching filters within the same field, if the new filter's parameter schema is compatible, existing args are preserved.
    • Data input "literal union" options are memoized for stability.

    This change improves UX by avoiding unnecessary argument resets when changing a filter, while still allowing users to opt out.

Patch Changes

  • 82696fa Thanks @lawvs! - Update dependencies

  • Updated dependencies [82696fa]:

    • @fn-sphere/core@0.8.0