@corvu-next/persistent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2025 Jasmin Noetzli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ <div align="center">
2
+ <a href="https://corvu.dev/docs/utilities/persistent">
3
+ <img src="https://corvu.dev/readme/solid-persistent.png" width=1000 alt="Solid Persistent" />
4
+ </a>
5
+ </div>
6
+ <br />
7
+
8
+ SolidJS utility to create persistent components that keep their state and elements cached when removed from the DOM.
9
+
10
+ ## Features
11
+
12
+ - Persists both JavaScript state and HTML elements
13
+ - Supports SSR
14
+
15
+ ## Usage
16
+
17
+ Import the `createPersistent` utility and pass your component to it. Make sure to call the utility inside a component that doesn't unmount. Then use the returned Accessor in your JSX where it can unmount.
18
+
19
+ ```tsx
20
+ import createPersistent from 'solid-persistent'
21
+ ```
22
+
23
+ ```tsx
24
+ const PersistedDialogContent = () => {
25
+ const persistedContent = createPersistent(() => {
26
+ return <input />
27
+ })
28
+
29
+ return (
30
+ <Dialog>
31
+ <Dialog.Trigger>
32
+ Open
33
+ </Dialog.Trigger>
34
+ <Dialog.Portal>
35
+ <Dialog.Content>
36
+ {persistedContent()}
37
+ </Dialog.Content>
38
+ </Dialog.Portal>
39
+ </Dialog>
40
+ )
41
+ }
42
+ ```
43
+
44
+ ## Further Reading
45
+ This utility is from the maintainers of [corvu](https://corvu.dev), a collection of unstyled, accessible and customizable UI primitives for SolidJS. It is also documented in the corvu docs under [Persistent](https://corvu.dev/docs/utilities/persistent).
@@ -0,0 +1,14 @@
1
+ import { JSX } from '@solidjs/web';
2
+
3
+ /**
4
+ * Creates a persistent component that keeps its state and elements cached
5
+ * when removed from the DOM. Call the returned accessor to get the cached
6
+ * element tree — on first call it materializes; subsequent calls return
7
+ * the same memoized tree.
8
+ *
9
+ * @param component - Render function producing the element tree to persist.
10
+ * @returns An accessor returning the persisted JSX element.
11
+ */
12
+ declare const createPersistent: (component: () => JSX.Element) => (() => JSX.Element);
13
+
14
+ export { createPersistent as default };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { getOwner, runWithOwner, createMemo } from 'solid-js';
2
+
3
+ // src/persistent.ts
4
+ var createPersistent = (component) => {
5
+ let owner = null;
6
+ let memoizedComponent;
7
+ return () => {
8
+ if (!memoizedComponent) {
9
+ owner = getOwner();
10
+ memoizedComponent = runWithOwner(owner, () => createMemo(component));
11
+ }
12
+ return memoizedComponent();
13
+ };
14
+ };
15
+ var persistent_default = createPersistent;
16
+
17
+ // src/index.ts
18
+ var index_default = persistent_default;
19
+
20
+ export { index_default as default };
package/dist/index.jsx ADDED
@@ -0,0 +1,20 @@
1
+ // src/persistent.ts
2
+ import { createMemo, getOwner, runWithOwner } from "solid-js";
3
+ var createPersistent = (component) => {
4
+ let owner = null;
5
+ let memoizedComponent;
6
+ return () => {
7
+ if (!memoizedComponent) {
8
+ owner = getOwner();
9
+ memoizedComponent = runWithOwner(owner, () => createMemo(component));
10
+ }
11
+ return memoizedComponent();
12
+ };
13
+ };
14
+ var persistent_default = createPersistent;
15
+
16
+ // src/index.ts
17
+ var index_default = persistent_default;
18
+ export {
19
+ index_default as default
20
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@corvu-next/persistent",
3
+ "version": "0.1.0",
4
+ "description": "SolidJS 2 utility for keeping elements in DOM while hidden.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Jasmin Noetzli (upstream), @corvu-next contributors (fork)"
8
+ },
9
+ "type": "module",
10
+ "sideEffects": false,
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "solid": "./dist/index.jsx",
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ "*": [
26
+ "./dist/index.d.ts"
27
+ ]
28
+ }
29
+ },
30
+ "peerDependencies": {
31
+ "solid-js": "2.0.0-beta.15",
32
+ "@solidjs/web": "2.0.0-beta.15"
33
+ },
34
+ "devDependencies": {
35
+ "@solidjs/web": "2.0.0-beta.15",
36
+ "esbuild-plugin-solid": "^0.6.0",
37
+ "solid-js": "2.0.0-beta.15",
38
+ "tsup": "^8.5.0",
39
+ "typescript": "^5.9.2"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "clean": "rm -rf .turbo dist node_modules",
44
+ "lint": "tsc --noEmit"
45
+ }
46
+ }