Skip to content

Commit 851f194

Browse files
committed
feat(toolkit)!: 🏗️ split monorepo into separate packages 📦
BREAKING CHANGE: The toolkit package has been split into separate packages for better organization and maintainability: - @zayne-labs/toolkit-core - @zayne-labs/toolkit-react - @zayne-labs/toolkit-type-helpers The main toolkit package now acts as an aggregator that re-exports from these new packages.
1 parent a63569e commit 851f194

File tree

135 files changed

+1182
-2490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1182
-2490
lines changed

dev/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
"preview": "vite preview"
1212
},
1313
"dependencies": {
14-
"@types/react": "19.0.1",
15-
"@types/react-dom": "19.0.1",
14+
"@types/react": "19.0.2",
15+
"@types/react-dom": "19.0.2",
1616
"@zayne-labs/toolkit": "workspace:*",
1717
"react": "19.0.0",
1818
"react-dom": "19.0.0"
1919
},
2020
"devDependencies": {
21-
"@types/node": "^22.7.5",
21+
"@types/node": "^22.10.3",
2222
"@vitejs/plugin-react-swc": "^3.7.2",
2323
"@zayne-labs/tsconfig": "catalog:",
2424
"tsx": "^4.19.1",
2525
"typescript": "catalog:",
26-
"vite": "^5.4.8"
26+
"vite": "^6.0.6"
2727
}
2828
}

dev/src/client/AnotherApp.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useStorageState } from "@zayne-labs/toolkit/react";
22

3-
export default function AnotherApp() {
3+
function AnotherApp() {
44
const [stateTwo] = useStorageState("test");
55

66
console.info(stateTwo);
77

88
return null;
99
}
10+
export default AnotherApp;

dev/src/client/App.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useSearchParamsObject } from "@zayne-labs/toolkit/react";
2-
import { DropZone } from "@zayne-labs/toolkit/react/ui/drop-zone";
3-
import "@zayne-labs/toolkit/tailwind.css";
42

5-
export default function App() {
3+
function App() {
64
const [searchParams, setSearchParams] = useSearchParamsObject();
75

86
console.info(searchParams.test);
@@ -12,9 +10,8 @@ export default function App() {
1210
<button type="button" onClick={() => setSearchParams({ test: "clay" })}>
1311
Click me
1412
</button>
15-
<DropZone>
16-
<p>foo</p>
17-
</DropZone>
1813
</div>
1914
);
2015
}
16+
17+
export default App;

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
},
2727
"devDependencies": {
2828
"@changesets/cli": "^2.27.11",
29-
"@eslint-react/eslint-plugin": "^1.22.1",
30-
"@types/node": "^22.10.2",
31-
"@zayne-labs/eslint-config": "^0.4.2",
29+
"@eslint-react/eslint-plugin": "^1.23.0",
30+
"@types/node": "^22.10.3",
31+
"@zayne-labs/eslint-config": "^0.4.3",
3232
"@zayne-labs/tsconfig": "catalog:",
3333
"bumpp": "^9.9.2",
3434
"eslint": "^9.17.0",
3535
"eslint-plugin-react-hooks": "^5.1.0",
3636
"eslint-plugin-react-refresh": "^0.4.16",
3737
"eslint-plugin-tailwindcss": "^3.17.5",
3838
"husky": "^9.1.7",
39-
"lint-staged": "^15.2.11",
39+
"lint-staged": "^15.3.0",
4040
"pkg-pr-new": "^0.0.39",
4141
"prettier": "^3.4.2",
4242
"typescript": "catalog:"

packages/toolkit-core/package.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "@zayne-labs/toolkit-core",
3+
"type": "module",
4+
"version": "0.8.21",
5+
"packageManager": "[email protected]",
6+
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
7+
"author": "Ryan Zayne",
8+
"license": "MIT",
9+
"homepage": "https://github.com/zayne-labs/toolkit#readme",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/zayne-labs/toolkit.git"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/zayne-labs/toolkit/issues"
16+
},
17+
"keywords": [
18+
"utilities",
19+
"types",
20+
"hooks"
21+
],
22+
"sideEffects": false,
23+
"exports": {
24+
".": "./dist/esm/index.js"
25+
},
26+
"main": "./dist/esm/index.js",
27+
"module": "./dist/esm/index.js",
28+
"types": "./dist/esm/index.d.ts",
29+
"files": [
30+
"dist"
31+
],
32+
"engines": {
33+
"node": ">=18.x"
34+
},
35+
"scripts": {
36+
"build": "tsup",
37+
"build:dev": "cross-env NODE_ENV=development tsup",
38+
"build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
39+
"lint:attw": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
40+
"lint:check-types": "tsc --pretty --incremental -p tsconfig.json",
41+
"lint:publint": "publint --strict .",
42+
"lint:size": "size-limit",
43+
"release": "pnpm publish --no-git-checks",
44+
"test:release": "pkg-pr-new publish"
45+
},
46+
"dependencies": {
47+
"@zayne-labs/toolkit-type-helpers": "workspace:*"
48+
},
49+
"devDependencies": {
50+
"@arethetypeswrong/cli": "^0.17.2",
51+
"@changesets/cli": "^2.27.11",
52+
"@size-limit/esbuild-why": "^11.1.6",
53+
"@size-limit/preset-small-lib": "^11.1.6",
54+
"@total-typescript/ts-reset": "^0.6.1",
55+
"@types/node": "^22.10.3",
56+
"@zayne-labs/tsconfig": "catalog:",
57+
"clsx": "^2.1.1",
58+
"concurrently": "^9.1.2",
59+
"cross-env": "^7.0.3",
60+
"publint": "^0.2.12",
61+
"size-limit": "^11.1.6",
62+
"terser": "^5.37.0",
63+
"tsup": "^8.3.5",
64+
"typescript": "catalog:"
65+
},
66+
"publishConfig": {
67+
"access": "public",
68+
"registry": "https://registry.npmjs.org/",
69+
"provenance": true
70+
},
71+
"size-limit": [
72+
{
73+
"path": "./src/index.ts",
74+
"limit": "3.5 kb"
75+
}
76+
]
77+
}

packages/toolkit-core/reset.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "@total-typescript/ts-reset";
2+
import "@total-typescript/ts-reset/dom";
File renamed without changes.

packages/toolkit/src/core/createDragScroll.ts packages/toolkit-core/src/createDragScroll.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyFunction } from "@/type-helpers";
1+
import type { AnyFunction } from "@zayne-labs/toolkit-type-helpers";
22
import { checkIsDeviceMobileOrTablet } from "./checkIsDeviceMobileOrTablet";
33
import { off, on } from "./on";
44

packages/toolkit/src/core/createExternalStore/new-implementation.ts packages/toolkit-core/src/createExternalStore/new-implementation.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { createStore, on, parseJSON } from "@/core";
2-
import { isFunction, isObject } from "@/type-helpers";
1+
import { createStore } from "@/createStore";
2+
import { on } from "@/on";
3+
import { parseJSON } from "@/parseJSON";
4+
import { isFunction, isObject } from "@zayne-labs/toolkit-type-helpers";
35
import type { RemoveStorageState, SetStorageState, StorageOptions } from "./types";
46
import { setAndDispatchStorageEvent } from "./utils";
57

packages/toolkit/src/core/createExternalStore/old-implementation.ts packages/toolkit-core/src/createExternalStore/old-implementation.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { type StoreApi, on, parseJSON } from "@/core";
2-
import { isFunction, isObject } from "@/type-helpers";
1+
import type { StoreApi } from "@/createStore";
2+
import { on } from "@/on";
3+
import { parseJSON } from "@/parseJSON";
4+
import { isFunction, isObject } from "@zayne-labs/toolkit-type-helpers";
35
import type { RemoveStorageState, SetStorageState, StorageOptions } from "./types";
46
import { setAndDispatchStorageEvent } from "./utils";
57

packages/toolkit/src/core/createExternalStore/types.ts packages/toolkit-core/src/createExternalStore/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { StoreStateSetter } from "@/core";
2-
import type { UnmaskType } from "@/type-helpers";
1+
import type { StoreStateSetter } from "@/createStore";
2+
import type { UnmaskType } from "@zayne-labs/toolkit-type-helpers";
33

44
export type StorageOptions<TState> = {
55
equalityFn?: (nextState: Partial<TState>, previousState: Partial<TState>) => boolean;

packages/toolkit/src/core/createStore/createStore.ts packages/toolkit-core/src/createStore/createStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFunction, isObject } from "@/type-helpers/guard";
1+
import { isFunction, isObject } from "@zayne-labs/toolkit-type-helpers";
22
import type { EqualityFn, Listener, StoreApi } from "./types";
33

44
export type StateInitializer<TState, TResult = TState> = (

packages/toolkit/src/core/createStore/types.ts packages/toolkit-core/src/createStore/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UnmaskType } from "@/type-helpers";
1+
import type { UnmaskType } from "@zayne-labs/toolkit-type-helpers";
22

33
export type StoreStateSetter<TState, TResult = TState> = UnmaskType<(prevState: TState) => TResult>;
44

packages/toolkit/src/core/debounce.ts packages/toolkit-core/src/debounce.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type CallbackFn, isArray, isObject } from "@/type-helpers";
1+
import { type CallbackFn, isArray, isObject } from "@zayne-labs/toolkit-type-helpers";
22

33
type DebouncedFnParams<TParams> =
44
| [params: TParams | TParams[], overrideOptions: { $delay: number }]

packages/toolkit/src/core/handleImagePreview.ts packages/toolkit-core/src/handleImagePreview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isFile } from "@/type-helpers";
1+
import { isFile } from "@zayne-labs/toolkit-type-helpers";
22

33
export type ImagePreviewOptions = {
44
file: File | undefined;

packages/toolkit-core/src/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export { checkIsDeviceMobileOrTablet } from "./checkIsDeviceMobileOrTablet";
2+
export * from "./constants";
3+
export { copyToClipboard } from "./copyToClipboard";
4+
export * from "./createExternalStore";
5+
export * from "./createLocationStore";
6+
export * from "./createStore";
7+
export { debounce } from "./debounce";
8+
export * from "./handleFileValidation";
9+
export * from "./handleImagePreview";
10+
export { lockScroll } from "./lockScroll";
11+
export * from "./omitKeys";
12+
export * from "./on";
13+
export { parseJSON } from "./parseJSON";
14+
export * from "./pickKeys";
15+
export { PromiseWithResolvers } from "./promiseWithResolvers";
16+
export * from "./setAnimationInterval";
17+
export { syncStateWithStorage } from "./syncStateWithStorage";
18+
export * from "./throttle";
19+
export { toArray } from "./toArray";
20+
export * from "./navigation";
21+
export * from "./wait";
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { checkIsDeviceMobileOrTablet } from "./checkIsDeviceMobileOrTablet";
2+
3+
type LockScrollOptions = {
4+
isActive: boolean;
5+
};
6+
7+
const getScrollbarWidth = () => {
8+
// == Store the initial overflow style
9+
const initialOverflowValue = document.documentElement.style.overflow;
10+
11+
// == Get width without scrollbar
12+
document.documentElement.style.overflow = "hidden";
13+
const widthWithoutScrollbar = document.documentElement.clientWidth;
14+
15+
// == Get width with scrollbar
16+
document.documentElement.style.overflow = "scroll";
17+
const widthWithScrollbar = document.documentElement.clientWidth;
18+
19+
// == Restore the original overflow
20+
document.documentElement.style.overflow = initialOverflowValue;
21+
22+
return widthWithoutScrollbar - widthWithScrollbar;
23+
};
24+
25+
const lockScroll = ({ isActive }: LockScrollOptions) => {
26+
const isMobileOrTablet = checkIsDeviceMobileOrTablet();
27+
const isDesktop = !isMobileOrTablet;
28+
29+
if (!isActive) {
30+
document.body.style.setProperty("--overflow-y", null);
31+
isDesktop && document.body.style.setProperty("--scrollbar-padding", null);
32+
return;
33+
}
34+
35+
document.body.style.setProperty("--overflow-y", "hidden");
36+
37+
const scrollbarWidth = getScrollbarWidth();
38+
39+
isDesktop && document.body.style.setProperty("--scrollbar-padding", `${scrollbarWidth}px`);
40+
};
41+
42+
export { lockScroll };

packages/toolkit/src/core/navigation.ts packages/toolkit-core/src/navigation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineEnum, isArray, isIterable, isString } from "@/type-helpers";
1+
import { defineEnum, isArray, isIterable, isString } from "@zayne-labs/toolkit-type-helpers";
22

33
type KeyValuePair = [string, string];
44

packages/toolkit/src/core/omitKeys.ts packages/toolkit-core/src/omitKeys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyObject } from "@/type-helpers";
1+
import type { AnyObject } from "@zayne-labs/toolkit-type-helpers";
22

33
type OmitKeys<TKeys extends keyof TObject, TObject extends AnyObject> = Omit<TObject, TKeys>;
44

File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/toolkit/src/core/on/registerEvent.ts packages/toolkit-core/src/on/registerEvent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isString } from "@/type-helpers";
1+
import { isArray, isString } from "@zayne-labs/toolkit-type-helpers";
22
import type { ElementOrSelectorArray, PossibleNodes, RegisterConfig } from "./types";
33

44
const registerSingleElement = (element: PossibleNodes, config: RegisterConfig) => {

packages/toolkit/src/core/on/types.ts packages/toolkit-core/src/on/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NonEmptyArray } from "@/type-helpers";
1+
import type { NonEmptyArray } from "@zayne-labs/toolkit-type-helpers";
22

33
export type PossibleNodes = string | Document | HTMLElement | MediaQueryList | Window | null;
44

File renamed without changes.

packages/toolkit/src/core/pickKeys.ts packages/toolkit-core/src/pickKeys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyObject } from "@/type-helpers";
1+
import type { AnyObject } from "@zayne-labs/toolkit-type-helpers";
22

33
type PickKeys<TKeys extends keyof TObject, TObject extends AnyObject> = Pick<TObject, TKeys>;
44

packages/toolkit/src/core/shallow.ts packages/toolkit-core/src/shallow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copied from https://github.com/pmndrs/zustand/blob/main/src/vanilla/shallow.ts
33
*/
44

5-
import { isIterable, isObject } from "@/type-helpers";
5+
import { isIterable, isObject } from "@zayne-labs/toolkit-type-helpers";
66

77
type RecordWithEntries = {
88
entries: () => Iterable<[unknown, unknown]>;

packages/toolkit/src/core/syncStateWithStorage.ts packages/toolkit-core/src/syncStateWithStorage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isPlainObject } from "@/type-helpers";
1+
import { isArray, isPlainObject } from "@zayne-labs/toolkit-type-helpers";
22
import { pickKeys } from "./pickKeys";
33

44
type SyncStorageParams =

packages/toolkit/src/core/throttle.ts packages/toolkit-core/src/throttle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CallbackFn } from "@/type-helpers";
1+
import type { CallbackFn } from "@zayne-labs/toolkit-type-helpers";
22

33
export const throttleBySetTimeout = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {
44
let timeoutId: number | null = null;

packages/toolkit/src/core/toArray.ts packages/toolkit-core/src/toArray.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray } from "@/type-helpers";
1+
import { isArray } from "@zayne-labs/toolkit-type-helpers";
22

33
const toArray = <TValue>(value: TValue | TValue[]): TValue[] => (isArray(value) ? value : [value]);
44

File renamed without changes.

packages/toolkit-core/tsconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "@zayne-labs/tsconfig/bundler/dom/library",
3+
4+
"compilerOptions": {
5+
"baseUrl": ".",
6+
"paths": {
7+
"@/*": ["src/*"]
8+
}
9+
// "declaration": true,
10+
// "isolatedDeclarations": true
11+
},
12+
13+
"include": ["src/**/*", "**/*"],
14+
"exclude": ["dist", "node_modules/**"]
15+
}

packages/toolkit-core/tsup.config.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { type Options, defineConfig } from "tsup";
2+
3+
const isDevMode = process.env.NODE_ENV === "development";
4+
5+
const sharedOptions = {
6+
clean: true, // clean up dist folder,
7+
dts: true, // generate d.ts
8+
entry: ["src/index.ts"],
9+
format: ["esm"],
10+
platform: "browser",
11+
sourcemap: !isDevMode,
12+
splitting: true,
13+
target: "esnext",
14+
treeshake: true,
15+
tsconfig: "tsconfig.json",
16+
} satisfies Options;
17+
18+
const config = defineConfig([
19+
{
20+
...sharedOptions,
21+
name: "ESM",
22+
outDir: "./dist/esm",
23+
},
24+
]);
25+
26+
export default config;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"plugins": ["prettier-plugin-tailwindcss", "prettier-plugin-classnames", "prettier-plugin-merge"],
3+
"tailwindFunctions": ["cnMerge", "cnJoin", "cn", "tv"],
4+
"tailwindStylesheet": "./src/react/tailwind.css",
5+
"tailwindConfig": "./tailwind.config.ts",
6+
"customFunctions": ["cnMerge", "cnJoin", "cn", "tv"],
7+
"tailwindAttributes": ["classNames"],
8+
"customAttributes": ["classNames"],
9+
"endingPosition": "absolute-with-indent",
10+
"jsxSingleQuote": false,
11+
"printWidth": 107,
12+
"singleQuote": false,
13+
"tabWidth": 3,
14+
"trailingComma": "es5",
15+
"useTabs": true
16+
}

0 commit comments

Comments
 (0)