🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@codedazur/react-select

Package Overview
Dependencies
Maintainers
19
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codedazur/react-select - npm Package Compare versions

Comparing version
0.0.2
to
0.0.3
+5
.turbo/turbo-audit.log
> @codedazur/react-select@0.0.3 audit
> npm audit --omit dev
found 0 vulnerabilities
> @codedazur/react-select@0.0.3 build
> tsup index.ts --format esm,cjs --dts
CLI Building entry: index.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v7.1.0
CLI Target: es6
ESM Build start
CJS Build start
CJS dist/index.js 6.56 KB
CJS ⚡️ Build success in 74ms
ESM dist/index.mjs 5.31 KB
ESM ⚡️ Build success in 99ms
DTS Build start
DTS ⚡️ Build success in 7595ms
DTS dist/index.d.mts 1.66 KB
DTS dist/index.d.ts 1.66 KB
> @codedazur/react-select@0.0.3 lint
> TIMING=1 eslint "**/*.ts*"
Rule | Time (ms) | Relative
:------------------------------|----------:|--------:
react/display-name | 59.347 | 39.4%
react-hooks/rules-of-hooks | 35.763 | 23.8%
react/require-render-return | 26.493 | 17.6%
react/no-danger-with-children | 10.187 | 6.8%
react/no-direct-mutation-state | 6.166 | 4.1%
react-hooks/exhaustive-deps | 5.151 | 3.4%
turbo/no-undeclared-env-vars | 1.488 | 1.0%
react/no-deprecated | 1.329 | 0.9%
react/no-render-return-value | 0.583 | 0.4%
react/jsx-no-comment-textnodes | 0.420 | 0.3%
> @codedazur/react-select@0.0.3 test
> vitest run
 RUN  v0.34.1 /home/runner/work/toolkit/toolkit/packages/react-select
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*
watch exclude: **/node_modules/**, **/dist/**
No test files found, exiting with code 0
interface UseSuggestionsProps<T extends string | Identifiable> {
options: T[];
initialQuery?: string;
filter?: (query: string, options: T[], defaultFilterFn: DefaultFilterFunction<T>) => T[] | Promise<T[]>;
debounce?: false | number;
}
interface Identifiable {
id: string;
}
type DefaultFilterFunction<T extends string | Identifiable> = (query: string, options: T[], defaultValidator: (query: string) => T[]) => T[] | Promise<T[]>;
interface UseSuggestionsResult<T> {
query: string;
setQuery: (value: string) => void;
suggestions: T[];
}
declare const useSuggestions: <T extends string | Identifiable>({ options, initialQuery, filter, debounce, }: UseSuggestionsProps<T>) => UseSuggestionsResult<T>;
interface UseSelectProps<T extends string | Identifiable> {
options: T[];
initialSelected?: T | T[];
}
interface UseSelectResult<T> {
selected: T[];
isSelected: (item: T) => boolean;
select: (item: T) => void;
deselect: (item: T) => void;
toggle: (item: T) => void;
clear: () => void;
}
declare const useSelect: <T extends string | Identifiable>({ options, initialSelected, }: UseSelectProps<T>) => UseSelectResult<T>;
interface UseSingleSelectProps<T extends string | Identifiable> extends UseSelectProps<T> {
initialSelected?: T;
}
interface SingleSelectResult<T> extends Omit<UseSelectResult<T>, "selected"> {
selected: T | null;
}
declare const useSingleSelect: <T extends string | Identifiable>(props: UseSingleSelectProps<T>) => SingleSelectResult<T>;
export { Identifiable, UseSelectProps, UseSelectResult, UseSingleSelectProps, UseSuggestionsProps, UseSuggestionsResult, useSelect, useSingleSelect, useSuggestions };
interface UseSuggestionsProps<T extends string | Identifiable> {
options: T[];
initialQuery?: string;
filter?: (query: string, options: T[], defaultFilterFn: DefaultFilterFunction<T>) => T[] | Promise<T[]>;
debounce?: false | number;
}
interface Identifiable {
id: string;
}
type DefaultFilterFunction<T extends string | Identifiable> = (query: string, options: T[], defaultValidator: (query: string) => T[]) => T[] | Promise<T[]>;
interface UseSuggestionsResult<T> {
query: string;
setQuery: (value: string) => void;
suggestions: T[];
}
declare const useSuggestions: <T extends string | Identifiable>({ options, initialQuery, filter, debounce, }: UseSuggestionsProps<T>) => UseSuggestionsResult<T>;
interface UseSelectProps<T extends string | Identifiable> {
options: T[];
initialSelected?: T | T[];
}
interface UseSelectResult<T> {
selected: T[];
isSelected: (item: T) => boolean;
select: (item: T) => void;
deselect: (item: T) => void;
toggle: (item: T) => void;
clear: () => void;
}
declare const useSelect: <T extends string | Identifiable>({ options, initialSelected, }: UseSelectProps<T>) => UseSelectResult<T>;
interface UseSingleSelectProps<T extends string | Identifiable> extends UseSelectProps<T> {
initialSelected?: T;
}
interface SingleSelectResult<T> extends Omit<UseSelectResult<T>, "selected"> {
selected: T | null;
}
declare const useSingleSelect: <T extends string | Identifiable>(props: UseSingleSelectProps<T>) => SingleSelectResult<T>;
export { Identifiable, UseSelectProps, UseSelectResult, UseSingleSelectProps, UseSuggestionsProps, UseSuggestionsResult, useSelect, useSingleSelect, useSuggestions };
"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// index.ts
var react_select_exports = {};
__export(react_select_exports, {
useSelect: () => useSelect,
useSingleSelect: () => useSingleSelect,
useSuggestions: () => useSuggestions
});
module.exports = __toCommonJS(react_select_exports);
// hooks/useSelect.ts
var import_react = require("react");
var useSelect = ({
options,
initialSelected
}) => {
const [selected, setSelected] = (0, import_react.useState)(() => {
if (initialSelected) {
return Array.isArray(initialSelected) ? initialSelected : [initialSelected];
}
return [];
});
const assertOption = (0, import_react.useCallback)(
(item) => {
if (!options.includes(item)) {
throw new Error(`The option "${JSON.stringify(item)}" does not exist.`);
}
},
[options]
);
const isSelected = (0, import_react.useCallback)(
(item) => selected.includes(item),
[selected]
);
const select = (0, import_react.useCallback)(
(item) => {
assertOption(item);
if (!isSelected(item)) {
setSelected((prev) => prev.concat(item));
}
},
[assertOption, isSelected]
);
const deselect = (0, import_react.useCallback)(
(item) => {
if (isSelected(item)) {
setSelected((prev) => prev.filter((prevItem) => prevItem !== item));
}
},
[isSelected]
);
const toggle = (0, import_react.useCallback)(
(item) => {
assertOption(item);
if (isSelected(item)) {
deselect(item);
} else {
select(item);
}
},
[assertOption, isSelected, deselect, select]
);
const clear = (0, import_react.useCallback)(() => {
setSelected([]);
}, []);
return {
selected,
isSelected,
select,
deselect,
toggle,
clear
};
};
// hooks/useSingleSelect.ts
var import_react2 = require("react");
var useSingleSelect = (props) => {
var _b;
const _a = useSelect(props), { selected, isSelected, select, clear } = _a, result = __objRest(_a, ["selected", "isSelected", "select", "clear"]);
return __spreadProps(__spreadValues({}, result), {
selected: (_b = selected[0]) != null ? _b : null,
isSelected,
select: (0, import_react2.useCallback)(
(item) => {
clear();
select(item);
},
[clear, select]
),
toggle: (0, import_react2.useCallback)(
(item) => {
if (!isSelected(item)) {
clear();
select(item);
} else {
clear();
}
},
[clear, isSelected, select]
),
clear
});
};
// hooks/useSuggestions.ts
var import_react3 = require("react");
var import_essentials = require("@codedazur/essentials");
var import_react_essentials = require("@codedazur/react-essentials");
var defaultFilterFn = (query, options) => options.filter((option) => {
const pattern = new RegExp(`^${query}`, "i");
return typeof option === "string" ? option.match(pattern) : option.id.match(pattern);
});
var useSuggestions = ({
options,
initialQuery = "",
filter = defaultFilterFn,
debounce = false
}) => {
const [debouncedFilter, cancelDebouncedFilter] = (0, import_react3.useMemo)(
() => (0, import_essentials.debounce)(filter, debounce !== false ? debounce : 0),
[debounce, filter]
);
const cancelDebouncedFilterRef = (0, import_react_essentials.useSynchronizedRef)(cancelDebouncedFilter);
const filterFn = debounce !== false ? debouncedFilter : filter;
const [query, setQuery] = (0, import_react3.useState)(initialQuery);
const [suggestions, setSuggestions] = (0, import_react3.useState)([]);
(0, import_react3.useEffect)(() => {
void (() => __async(void 0, null, function* () {
return setSuggestions(yield filterFn(query, options, defaultFilterFn));
}))();
}, [query, options, filterFn]);
(0, import_react3.useEffect)(
() => () => {
var _a;
(_a = cancelDebouncedFilterRef.current) == null ? void 0 : _a.call(cancelDebouncedFilterRef);
},
[cancelDebouncedFilterRef]
);
return {
query,
setQuery,
suggestions
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useSelect,
useSingleSelect,
useSuggestions
});
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// hooks/useSelect.ts
import { useCallback, useState } from "react";
var useSelect = ({
options,
initialSelected
}) => {
const [selected, setSelected] = useState(() => {
if (initialSelected) {
return Array.isArray(initialSelected) ? initialSelected : [initialSelected];
}
return [];
});
const assertOption = useCallback(
(item) => {
if (!options.includes(item)) {
throw new Error(`The option "${JSON.stringify(item)}" does not exist.`);
}
},
[options]
);
const isSelected = useCallback(
(item) => selected.includes(item),
[selected]
);
const select = useCallback(
(item) => {
assertOption(item);
if (!isSelected(item)) {
setSelected((prev) => prev.concat(item));
}
},
[assertOption, isSelected]
);
const deselect = useCallback(
(item) => {
if (isSelected(item)) {
setSelected((prev) => prev.filter((prevItem) => prevItem !== item));
}
},
[isSelected]
);
const toggle = useCallback(
(item) => {
assertOption(item);
if (isSelected(item)) {
deselect(item);
} else {
select(item);
}
},
[assertOption, isSelected, deselect, select]
);
const clear = useCallback(() => {
setSelected([]);
}, []);
return {
selected,
isSelected,
select,
deselect,
toggle,
clear
};
};
// hooks/useSingleSelect.ts
import { useCallback as useCallback2 } from "react";
var useSingleSelect = (props) => {
var _b;
const _a = useSelect(props), { selected, isSelected, select, clear } = _a, result = __objRest(_a, ["selected", "isSelected", "select", "clear"]);
return __spreadProps(__spreadValues({}, result), {
selected: (_b = selected[0]) != null ? _b : null,
isSelected,
select: useCallback2(
(item) => {
clear();
select(item);
},
[clear, select]
),
toggle: useCallback2(
(item) => {
if (!isSelected(item)) {
clear();
select(item);
} else {
clear();
}
},
[clear, isSelected, select]
),
clear
});
};
// hooks/useSuggestions.ts
import { useEffect, useMemo, useState as useState2 } from "react";
import { debounce as debounceFn } from "@codedazur/essentials";
import { useSynchronizedRef } from "@codedazur/react-essentials";
var defaultFilterFn = (query, options) => options.filter((option) => {
const pattern = new RegExp(`^${query}`, "i");
return typeof option === "string" ? option.match(pattern) : option.id.match(pattern);
});
var useSuggestions = ({
options,
initialQuery = "",
filter = defaultFilterFn,
debounce = false
}) => {
const [debouncedFilter, cancelDebouncedFilter] = useMemo(
() => debounceFn(filter, debounce !== false ? debounce : 0),
[debounce, filter]
);
const cancelDebouncedFilterRef = useSynchronizedRef(cancelDebouncedFilter);
const filterFn = debounce !== false ? debouncedFilter : filter;
const [query, setQuery] = useState2(initialQuery);
const [suggestions, setSuggestions] = useState2([]);
useEffect(() => {
void (() => __async(void 0, null, function* () {
return setSuggestions(yield filterFn(query, options, defaultFilterFn));
}))();
}, [query, options, filterFn]);
useEffect(
() => () => {
var _a;
(_a = cancelDebouncedFilterRef.current) == null ? void 0 : _a.call(cancelDebouncedFilterRef);
},
[cancelDebouncedFilterRef]
);
return {
query,
setQuery,
suggestions
};
};
export {
useSelect,
useSingleSelect,
useSuggestions
};
+7
-1
# @codedazur/react-select
## 0.0.1
## 0.0.3
### Patch Changes
- [`55b7ca8`](https://github.com/codedazur/toolkit/commit/55b7ca83ad971962e4a76da0e2ff9088e64e8e26) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - The dist folder is now included.
## 0.0.2
### Patch Changes
- [`477ea5e`](https://github.com/codedazur/toolkit/commit/477ea5ecc00368750cefefec9455e7a41834122c) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Experimental release.

@@ -8,0 +14,0 @@

+1
-1
{
"name": "@codedazur/react-select",
"version": "0.0.2",
"version": "0.0.3",
"main": ".dist/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/index.mjs",