Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
12db2c1
fix: updated start package to work with `@solidjs/start` version 1
eagerestwolf Jul 14, 2024
bc14fff
docs: updated README to remove outdated example, added myself to cont…
eagerestwolf Jul 14, 2024
eb09399
chore: added changeset
eagerestwolf Jul 14, 2024
4e2d161
feat: Add dirtyAll to TriggerCache
Exelord Sep 8, 2024
cea0f93
fix: Clear ReactiveSet before dirtying keys
Exelord Sep 8, 2024
8500819
fix: Don't assume iterators will always break on specific iteration
Exelord Sep 8, 2024
a3038c2
chore: Unify variables names with Set interface in ReactiveSet
Exelord Sep 8, 2024
34b6e45
Merge branch 'main' into fix-set
thetarnav Sep 9, 2024
98743c3
chore: Apply feedback
Exelord Sep 28, 2024
4fdff9e
Merge branch 'main' of https://github.com/solidjs-community/solid-pri…
Exelord Sep 28, 2024
aa596ec
Add changeset for set
thetarnav Sep 29, 2024
32fcb81
Create swift-points-dance.md
thetarnav Sep 29, 2024
31f8723
Fixes for ReactiveSet (#688)
thetarnav Sep 29, 2024
489793e
Format
thetarnav Sep 29, 2024
dbe9540
Version Packages
github-actions[bot] Sep 29, 2024
debb49f
Version Packages (#700)
thetarnav Sep 29, 2024
69cd152
Rename start package to cookies
thetarnav Sep 30, 2024
16d8f87
Merge branch 'main' of github.com:Tommypop2/solid-primitives into Tom…
thetarnav Sep 30, 2024
712cf55
Add `getCookiesString`
thetarnav Sep 30, 2024
739e005
Merge from main
thetarnav Sep 30, 2024
a04bb61
Remove changeset for start package
thetarnav Sep 30, 2024
4338fa9
[FIX] Update start package (#660)
thetarnav Sep 30, 2024
3ac52fa
Format
thetarnav Sep 30, 2024
423dbfa
Update Readme
thetarnav Sep 30, 2024
8238e9e
cookies: Set category to Network
thetarnav Sep 30, 2024
dceb380
Update Readme
thetarnav Sep 30, 2024
f4699bc
Replace gzip-size package with a simple function
thetarnav Oct 7, 2024
7433e48
Format
thetarnav Oct 7, 2024
38b88ed
docs: input mask money example
atk Oct 10, 2024
f619f79
Entries takes key's type as a generic
AlexErrant Oct 24, 2024
9749071
Add changeset
thetarnav Oct 24, 2024
cc834cf
Entries takes key's type as a generic (#709)
thetarnav Oct 24, 2024
f88faf1
Add a ts-ignore to storage/tauri
thetarnav Oct 24, 2024
bec6251
docs: input mask money example (#706)
thetarnav Oct 24, 2024
1edec44
Format
thetarnav Oct 24, 2024
4654db7
Version Packages
github-actions[bot] Oct 24, 2024
75e3f8e
Version Packages (#710)
thetarnav Oct 24, 2024
392b650
Update index.ts
cherealnice Oct 27, 2024
57a3078
Create fresh-points-join.md
thetarnav Oct 27, 2024
5f9c6cd
Update packages/scheduled/src/index.ts
cherealnice Oct 27, 2024
c60852d
schedule - Add check for typeof window, fallback to throttle if undef…
thetarnav Oct 27, 2024
d6c619b
Format
thetarnav Oct 27, 2024
4822f41
Version Packages
github-actions[bot] Oct 27, 2024
351b6fa
Version Packages (#713)
thetarnav Oct 27, 2024
582fe92
Make eslint work again and fix lint issues
thetarnav Oct 29, 2024
f6d165b
Format
thetarnav Oct 29, 2024
4e3925f
make row heights in tests more realistic
SpencerWhitehead7 Sep 28, 2024
32de139
fix snake vs camel casing in tests
SpencerWhitehead7 Sep 28, 2024
0575a8f
tests and docs for fallback behavior when list is empty
SpencerWhitehead7 Sep 28, 2024
9c9bc42
headless createVirtualList utility function
SpencerWhitehead7 Sep 30, 2024
e1ebe61
Add changeset
SpencerWhitehead7 Oct 7, 2024
83bfbee
address PR feedback
SpencerWhitehead7 Oct 7, 2024
7b5a3b5
fix types
SpencerWhitehead7 Oct 9, 2024
f63753a
add links in readme
SpencerWhitehead7 Oct 17, 2024
ee1d42a
address PR feedback
SpencerWhitehead7 Oct 28, 2024
2911fcd
address PR feedback
SpencerWhitehead7 Oct 29, 2024
0a6d281
fix: no-op if onScroll applied to incorrect element
SpencerWhitehead7 Oct 29, 2024
d4763fe
Headless virtual list (#702)
thetarnav Oct 29, 2024
b9e945d
Update Readme
thetarnav Oct 29, 2024
970509d
Version Packages
github-actions[bot] Oct 29, 2024
bc09516
Version Packages (#714)
thetarnav Oct 29, 2024
8d22833
site switch package.json version value from to
aquaductape Nov 2, 2024
7d96347
update lockfile
aquaductape Nov 2, 2024
f9e6694
Fix Site: Switch package.json version value from `workspace:^` to `la…
thetarnav Nov 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import noOnlyTests from "eslint-plugin-no-only-tests";
import eslintComments from "eslint-plugin-eslint-comments";
import tsParser from "@typescript-eslint/parser";

export default [{
ignores: ["packages/*/dist/**/*", "packages/*/dev/**/*", "**/*/__snapshots__/**/*"],
}, {
/** @type {import("eslint").Linter.Config} */
export default {

files: ["**/*.{js,mjs,jsx,ts,tsx}"],
ignores: ["**/{dist,node_modules,__snapshots__}/**/*", "packages/*/dev/**/*", "site/**/*"],

plugins: {
"@typescript-eslint": typescriptEslint,
"no-only-tests": noOnlyTests,
Expand Down Expand Up @@ -44,4 +47,4 @@ export default [{
"eslint-comments/no-unused-disable": "warn",
"no-only-tests/no-only-tests": "warn",
},
}];
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"scripts": {
"dev": "pnpm -dir site run dev",
"format": "prettier --cache -w {site,packages,scripts,template}/**/*.{js,ts,json,css,tsx,jsx,md,html} --ignore-path .gitignore",
"lint:packages": "echo \"DISABLED: eslint --max-warnings 0 packages/*/src/**/*\"",
"lint:tests": "echo \"DISABLED: eslint packages/*/test/** --rule \"no-only-tests/no-only-tests: error\"\"",
"lint:packages": "eslint --max-warnings 0 \"packages/*/src/**/*\"",
"lint:tests": "eslint \"packages/*/test/**\" --rule \"no-only-tests/no-only-tests: error\"",
"lint": "pnpm run \"/^lint:.*/\"",
"test:client": "vitest -c ./configs/vitest.config.ts",
"test:ssr": "pnpm run test:client --mode ssr",
Expand All @@ -37,7 +37,6 @@
"eslint": "^9.10.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-no-only-tests": "^3.3.0",
"gzip-size": "^7.0.0",
"jsdom": "^25.0.0",
"json-to-markdown-table": "^1.0.0",
"prettier": "^3.3.3",
Expand Down
File renamed without changes.
98 changes: 98 additions & 0 deletions packages/cookies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<p>
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=cookies" alt="Solid Primitives cookies">
</p>

# @solid-primitives/cookies

[![turborepo](https://img.shields.io/badge/built%20with-turborepo-cc00ff.svg?style=for-the-badge&logo=turborepo)](https://turborepo.org/)
[![size](https://img.shields.io/bundlephobia/minzip/@solid-primitives/cookies?style=for-the-badge&label=size)](https://bundlephobia.com/package/@solid-primitives/cookies)
[![version](https://img.shields.io/npm/v/@solid-primitives/cookies?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/cookies)
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-0.json)](https://github.com/solidjs-community/solid-primitives#contribution-process)

A set of primitives for handling cookies in solid

- [`createServerCookie`](#createservercookie) - Provides a getter and setter for a reactive cookie, which works isomorphically.
- [`createUserTheme`](#createusertheme) - Creates a Server Cookie providing a type safe way to store a theme and access it on the server or client.
- [`getCookiesString`](#getCookiesString) - A primitive that allows for the cookie string to be accessed isomorphically on the client, or on the server

## Installation

```bash
npm install @solid-primitives/cookies
# or
yarn add @solid-primitives/cookies
# or
pnpm add @solid-primitives/cookies
```

## How to use it

## `createServerCookie`

A primitive for creating a cookie that can be accessed isomorphically on the client, or the server.

```ts
import { createServerCookie } from "@solid-primitives/cookies";

const [cookie, setCookie] = createServerCookie("cookieName");

cookie(); // => string | undefined
```

### Custom serialization

Custom cookie serializers and deserializers can also be implemented

```ts
import { createServerCookie } from "@solid-primitives/cookies";

const [serverCookie, setServerCookie] = createServerCookie("coolCookie", {
deserialize: str => (str ? str.split(" ") : []), // Deserializes cookie into a string[]
serialize: val => (val ? val.join(" ") : ""), // serializes the value back into a string
});

serverCookie(); // => string[]
```

## `createUserTheme`

Composes `createServerCookie` to provide a type safe way to store a theme and access it on the server or client.

```ts
import { createUserTheme } from "@solid-primitives/cookies";

const [theme, setTheme] = createUserTheme("cookieName");

theme(); // => "light" | "dark" | undefined

// with default value
const [theme, setTheme] = createUserTheme("cookieName", {
defaultValue: "light",
});

theme(); // => "light" | "dark"
```

## `getCookiesString`

A primitive that allows for the cookie string to be accessed isomorphically on the client, or on the server.
Uses `getRequestEvent` on the server and `document.cookie` on the client.

```ts
import { getCookiesString, parseCookie } from "@solid-primitives/cookies";

const string = getCookiesString();
const cookie = parseCookie(string, "cookie_name");
```

## Examples

PRs welcome :)

## Demo

You can view a demo of this primitive here: <https://codesandbox.io/p/sandbox/amazing-easley-wqk38i?file=%2Fsrc%2Fcookies_primitive%2Findex.ts%3A36%2C20>

## Changelog

See [CHANGELOG.md](./CHANGELOG.md)
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Component, createSignal } from "solid-js";
import { Component } from "solid-js";
import { createUserTheme } from "../src/index.js";

const App: Component = () => {
const [count, setCount] = createSignal(0);
const increment = () => setCount(count() + 1);
const [theme, setTheme] = createUserTheme();
const increment = () => setTheme(theme() === "light" ? "dark" : "light");
return (
<div class={`min-h-screen ${"dark" == "dark" ? "dark" : ""}`}>
<div class="box-border flex min-h-screen w-full flex-col items-center justify-center space-y-4 bg-gray-800 p-24 text-white">
<div class="wrapper-v">
<h4>Counter component</h4>
<p class="caption">it's very important...</p>
<button class="btn" onClick={increment}>
{count()}
{theme()}
</button>
</div>
</div>
Expand Down
27 changes: 13 additions & 14 deletions packages/start/package.json → packages/cookies/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@solid-primitives/start",
"version": "0.0.4",
"description": "A set of primitives for Solid Start",
"author": "Thomas",
"name": "@solid-primitives/cookies",
"version": "0.0.1",
"description": "A set of primitives for handling cookies in solid",
"author": "Thomas Beer (https://github.com/Tommypop2)",
"contributors": [
"Damian Tarnawski <[email protected]>"
"Damian Tarnawski <[email protected]>",
"Seth Murphy (https://github.com/eagerestwolf)"
],
"license": "MIT",
"homepage": "https://primitives.solidjs.community/package/start",
"homepage": "https://primitives.solidjs.community/package/cookies",
"repository": {
"type": "git",
"url": "git+https://github.com/solidjs-community/solid-primitives.git"
Expand All @@ -16,18 +17,18 @@
"url": "https://github.com/solidjs-community/solid-primitives/issues"
},
"primitive": {
"name": "start",
"name": "cookies",
"stage": 0,
"list": [
"createServerCookie",
"createUserTheme"
"createUserTheme",
"getCookiesString"
],
"category": "Solid Start"
"category": "Network"
},
"keywords": [
"solid",
"primitives",
"solid-start",
"ssr"
],
"private": false,
Expand Down Expand Up @@ -59,11 +60,9 @@
"test:ssr": "pnpm run vitest --mode ssr"
},
"peerDependencies": {
"solid-js": "^1.6.12",
"solid-start": ">=0.2.26"
"solid-js": "^1.8.18"
},
"devDependencies": {
"solid-js": "^1.8.7",
"solid-start": "^0.3.10"
"solid-js": "^1.8.18"
}
}
57 changes: 33 additions & 24 deletions packages/start/src/index.ts → packages/cookies/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
import { createSignal, createEffect, Signal } from "solid-js";
import { isServer } from "solid-js/web";
import { parseCookie } from "solid-start";
import { useRequest } from "solid-start/server/ServerContext.jsx";
import { getRequestEvent, isServer } from "solid-js/web";

const YEAR = 365 * 24 * 60 * 60;

/*
Original code by Chakra UI
MIT Licensed, Copyright (c) 2019 Segun Adebayo.

Credits to the Chakra UI team:
https://github.com/chakra-ui/chakra-ui/blob/%40chakra-ui/toast%401.2.0/packages/color-mode/src/storage-manager.ts
*/

export function parseCookie(cookie: string, key: string): string | undefined {
return cookie.match(new RegExp(`(^| )${key}=([^;]+)`))?.[2];
}

/**
* A primitive that allows for the cookie string to be accessed isomorphically on the client, or on the server
* @return Returns the cookie string
*/
export function getCookiesString(): string {
if (isServer) {
return getRequestEvent()?.request.headers.get("cookie") ?? "";
}
return document.cookie;
}

export type MaxAgeOptions = {
/**
* The maximum age of the cookie in seconds. Defaults to 1 year.
*/
/** The maximum age of the cookie in seconds. Defaults to 1 year. */
cookieMaxAge?: number;
};

export type ServerCookieOptions<T = string> = MaxAgeOptions & {
/**
* A function to deserialize the cookie value to be used as signal value
*/
/** A function to deserialize the cookie value to be used as signal value */
deserialize?: (str: string | undefined) => T;
/**
* A function to serialize the signal value to be used as cookie value
*/
/** A function to serialize the signal value to be used as cookie value */
serialize?: (value: T) => string;
};

const YEAR = 365 * 24 * 60 * 60;

/**
* A primitive for creating a cookie that can be accessed isomorphically on the client, or the server
*
Expand Down Expand Up @@ -51,13 +66,7 @@ export function createServerCookie<T>(
cookieMaxAge = YEAR,
} = options ?? {};

const [cookie, setCookie] = createSignal(
deserialize(
parseCookie(isServer ? (useRequest().request.headers.get("cookie") ?? "") : document.cookie)[
name
],
),
);
const [cookie, setCookie] = createSignal(deserialize(parseCookie(getCookiesString(), name)));

createEffect(p => {
const string = serialize(cookie());
Expand Down Expand Up @@ -91,10 +100,10 @@ export function createUserTheme(
name?: string,
options?: UserThemeOptions,
): Signal<Theme | undefined>;
export function createUserTheme(name = "theme", options?: UserThemeOptions): Signal<any> {
const defaultValue = options?.defaultValue;
export function createUserTheme(name = "theme", options: UserThemeOptions = {}): Signal<any> {
const { defaultValue, cookieMaxAge } = options;
return createServerCookie(name, {
...options,
cookieMaxAge,
deserialize: str => (str === "light" || str === "dark" ? str : defaultValue),
serialize: String,
});
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/date/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @solid-primitives/date

## 2.0.24

### Patch Changes

- @solid-primitives/[email protected]

## 2.0.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/date/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-primitives/date",
"version": "2.0.23",
"version": "2.0.24",
"description": "Collection of reactive primitives and utility functions, providing easier ways to deal with dates in SolidJS",
"author": "Damian Tarnawski @thetarnav <[email protected]>",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions packages/deep/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @solid-primitives/deep

## 0.2.10

### Patch Changes

- @solid-primitives/[email protected]

## 0.2.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/deep/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-primitives/deep",
"version": "0.2.9",
"version": "0.2.10",
"description": "Primitives for tracking and observing nested reactive objects in Solid.",
"author": "Samuel Burbano <[email protected]>",
"contributors": [
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/src/adapter-vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const makeVirtualFileSystem = (
const storageValue = storage?.getItem(key);
try {
storedValue = JSON.parse(typeof storageValue === "string" ? storageValue : "null");
} catch (e) {}
} catch (_) {}
let fs = storedValue || initial || {};
if ((storageValue as unknown) instanceof Promise) {
(storageValue as unknown as Promise<string>).then(storedValue => {
Expand Down Expand Up @@ -57,7 +57,7 @@ export const makeVirtualFileSystem = (
typeof ref === "object" &&
Object.keys(ref).forEach((item: string) =>
typeof ref[item] === "string"
? files.push(filter(`${path}${item}`, ref[item] as string))
? files.push(filter(`${path}${item}`, ref[item]))
: walker(ref[item], `${path}${item}/`),
);
};
Expand Down Expand Up @@ -181,7 +181,7 @@ export const makeVirtualFileSystem = (
get: path => {
try {
return ofs.readFile(path);
} catch (e) {}
} catch (_) {}
},
has: path => ofs.getType(path) === "file",
keys: () => getFiles(path => path)[Symbol.iterator](),
Expand Down
7 changes: 7 additions & 0 deletions packages/immutable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @solid-primitives/immutable

## 1.0.10

### Patch Changes

- Updated dependencies [9749071]
- @solid-primitives/[email protected]

## 1.0.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/immutable/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solid-primitives/immutable",
"version": "1.0.9",
"version": "1.0.10",
"description": "Primitive for rectifying immutable values and dealing with immutability in Solid.",
"author": "Damian Tarnawski <[email protected]>",
"contributors": [],
Expand Down
Loading
Loading