@hamur/adapter-solid 0.0.0-stage → 0.0.1

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.
Files changed (72) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +35 -2
  3. package/dist/chunks/browser-index-8rhv2s58.js +14 -0
  4. package/dist/chunks/browser-index-b05qbzsh.js +165 -0
  5. package/dist/chunks/browser-index-n80jt19y.js +114 -0
  6. package/dist/chunks/browser-index-ncnkshd9.js +39 -0
  7. package/dist/chunks/browser-index-r4jwfgh7.js +407 -0
  8. package/dist/src/adapter.js +556 -0
  9. package/dist/src/error-page.js +466 -0
  10. package/dist/src/index.js +1535 -0
  11. package/dist/src/keepalive.js +6 -0
  12. package/dist/src/runtime/client.js +174 -0
  13. package/dist/src/runtime/island.js +58 -0
  14. package/dist/src/runtime/server.js +138 -0
  15. package/dist/types/src/activation.d.ts +15 -0
  16. package/dist/types/src/adapter.d.ts +4 -0
  17. package/dist/types/src/async-data.d.ts +21 -0
  18. package/dist/types/src/client-component.d.ts +10 -0
  19. package/dist/types/src/client-fallback.d.ts +2 -0
  20. package/dist/types/src/context.d.ts +89 -0
  21. package/dist/types/src/error-page.d.ts +1 -0
  22. package/dist/types/src/index.d.ts +392 -0
  23. package/dist/types/src/island-html.d.ts +13 -0
  24. package/dist/types/src/island.d.ts +20 -0
  25. package/dist/types/src/jsx-locator.d.ts +6 -0
  26. package/dist/types/src/keepalive.d.ts +30 -0
  27. package/dist/types/src/lazy-hydration.d.ts +13 -0
  28. package/dist/types/src/markdown-page.d.ts +9 -0
  29. package/dist/types/src/markdown.d.ts +13 -0
  30. package/dist/types/src/plugin.d.ts +44 -0
  31. package/dist/types/src/runtime/client.d.ts +13 -0
  32. package/dist/types/src/runtime/hmr-solid.d.ts +5 -0
  33. package/dist/types/src/runtime/hmr.d.ts +27 -0
  34. package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
  35. package/dist/types/src/runtime/hydration.d.ts +10 -0
  36. package/dist/types/src/runtime/island.d.ts +8 -0
  37. package/dist/types/src/runtime/portal.d.ts +13 -0
  38. package/dist/types/src/runtime/server.d.ts +14 -0
  39. package/dist/types/src/runtime/trusted.d.ts +2 -0
  40. package/dist/types/src/server-island.d.ts +10 -0
  41. package/dist/types/src/svg.d.ts +10 -0
  42. package/package.json +53 -4
  43. package/src/activation.ts +51 -0
  44. package/src/adapter.ts +42 -0
  45. package/src/async-data.ts +105 -0
  46. package/src/client-component.ts +40 -0
  47. package/src/client-fallback.ts +2 -0
  48. package/src/context.ts +495 -0
  49. package/src/env.d.ts +3 -0
  50. package/src/error-page.ts +1 -0
  51. package/src/index.ts +1900 -0
  52. package/src/island-html.ts +58 -0
  53. package/src/island.ts +55 -0
  54. package/src/jsx-locator.ts +199 -0
  55. package/src/keepalive.ts +147 -0
  56. package/src/lazy-hydration.ts +146 -0
  57. package/src/markdown-page.ts +18 -0
  58. package/src/markdown.ts +70 -0
  59. package/src/plugin.ts +310 -0
  60. package/src/runtime/client.ts +175 -0
  61. package/src/runtime/hmr-solid.ts +19 -0
  62. package/src/runtime/hmr.ts +231 -0
  63. package/src/runtime/hydration-dev.ts +41 -0
  64. package/src/runtime/hydration.ts +9 -0
  65. package/src/runtime/island.ts +66 -0
  66. package/src/runtime/portal.ts +64 -0
  67. package/src/runtime/server.ts +160 -0
  68. package/src/runtime/trusted.ts +16 -0
  69. package/src/server-island.ts +47 -0
  70. package/src/solid.d.ts +4 -0
  71. package/src/svg.ts +53 -0
  72. package/src/webmcp.d.ts +20 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 productdevbook
4
+ Copyright (c) 2019 Material-UI SAS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @hamur/adapter-solid
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Solid 2 adapter for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. It renders pages and layouts with Solid (server rendering streams) and gives you `useData`, `useHead`, `useState` and the other hooks; values are read through accessors. Routing, loaders, head, state and the server come from `hamur`.
4
+
5
+ One app uses one library. Set `framework: "solid"` in `hamur.config.ts`, or install only this adapter and Hamur detects it.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add hamur @hamur/adapter-solid solid-js @solidjs/web @solidjs/babel-plugin @babel/core @babel/preset-typescript
11
+ ```
12
+
13
+ Or start from a template: `bunx hamur init my-app --framework solid`.
14
+
15
+ ## Example
16
+
17
+ `app/pages/post.tsx`:
18
+
19
+ ```tsx
20
+ import { useData, useHead, useState } from "@hamur/adapter-solid"
21
+
22
+ export default function Post() {
23
+ const data = useData<{ title: string }>()
24
+ const [likes, setLikes] = useState("likes", 0)
25
+ useHead(() => ({ title: data().title }))
26
+ return (
27
+ <button onClick={() => setLikes(likes() + 1)}>
28
+ {data().title}: {likes()}
29
+ </button>
30
+ )
31
+ }
32
+ ```
33
+
34
+ ## Docs
35
+
36
+ [Documentation](https://docs.productdevbook.com/) and the [adapters page](https://docs.productdevbook.com/adapters). MIT license.
@@ -0,0 +1,14 @@
1
+ // packages/adapter-solid/src/runtime/trusted.ts
2
+ import { setTrustedTypesPolicy } from "@solidjs/web";
3
+ var trusted = false;
4
+ function trustTemplates() {
5
+ if (trusted || import.meta.trustedTypes !== true)
6
+ return;
7
+ const factory = globalThis.trustedTypes;
8
+ if (!factory)
9
+ return;
10
+ trusted = true;
11
+ setTrustedTypesPolicy(factory.createPolicy("solid-trusted-html", { createHTML: (html) => html }));
12
+ }
13
+
14
+ export { trustTemplates };
@@ -0,0 +1,165 @@
1
+ import {
2
+ AppContext,
3
+ NeverHydratedContext
4
+ } from "./browser-index-r4jwfgh7.js";
5
+
6
+ // packages/adapter-solid/src/lazy-hydration.ts
7
+ import {
8
+ createComponent,
9
+ createEffect,
10
+ createMemo,
11
+ createSignal,
12
+ flush,
13
+ isHydrating,
14
+ omit,
15
+ onCleanup,
16
+ untrack,
17
+ useContext
18
+ } from "solid-js";
19
+ import { enableServerComponentHydration, sharedConfig } from "solid-js/internal";
20
+ import { dynamic, isServer } from "@solidjs/web";
21
+ import { HYDRATE_ELEMENT, hydrateOnAttribute, markWaiting, replayInteraction, whenTriggered } from "hamur/adapter";
22
+ var pending = new Set;
23
+ var HydrateElement = dynamic(() => HYDRATE_ELEMENT, { static: true });
24
+ function hydrateLate(wrapper, fn) {
25
+ enableServerComponentHydration();
26
+ const registry = new Map;
27
+ for (const node of wrapper.querySelectorAll("[_hk]")) {
28
+ const key = node.getAttribute("_hk");
29
+ if (!registry.has(key))
30
+ registry.set(key, node);
31
+ }
32
+ return sharedConfig.hydrateWindow(0, fn, { registry });
33
+ }
34
+ function lazyModules() {
35
+ return pending.size ? Promise.allSettled(pending) : undefined;
36
+ }
37
+ function defineLazyHydrationComponent2(on, loader, options = {}) {
38
+ const attribute = hydrateOnAttribute(on);
39
+ let resolved;
40
+ let failed;
41
+ let loading;
42
+ const load = () => {
43
+ if (loading)
44
+ return loading;
45
+ const current = loading = loader().then((loaded) => resolved = loaded, (error) => {
46
+ if (isServer)
47
+ failed = { error };
48
+ loading = undefined;
49
+ throw error;
50
+ });
51
+ if (isServer) {
52
+ pending.add(current);
53
+ current.then(() => pending.delete(current), () => pending.delete(current));
54
+ }
55
+ return current;
56
+ };
57
+ if (isServer)
58
+ load().catch(() => {});
59
+ return (props) => {
60
+ const rest = omit(props, "onHydrated");
61
+ if (isServer) {
62
+ const state = useContext(AppContext);
63
+ return createComponent(HydrateElement, {
64
+ on: attribute,
65
+ children: createMemo(() => {
66
+ if (failed)
67
+ throw failed.error;
68
+ if (resolved) {
69
+ const part = resolved.default;
70
+ if (on !== "never")
71
+ return createComponent(part, rest);
72
+ return createComponent(NeverHydratedContext, {
73
+ value: true,
74
+ get children() {
75
+ return createComponent(part, rest);
76
+ }
77
+ });
78
+ }
79
+ if (state)
80
+ markWaiting(state().app.asyncData);
81
+ load().catch(() => {});
82
+ return "";
83
+ })
84
+ });
85
+ }
86
+ let wrapper;
87
+ let served;
88
+ const [shown, setShown] = createSignal(isHydrating() ? undefined : resolved);
89
+ const controller = new AbortController;
90
+ onCleanup(() => controller.abort());
91
+ const show = (loaded) => {
92
+ if (controller.signal.aborted)
93
+ return;
94
+ setShown(() => loaded);
95
+ flush();
96
+ props.onHydrated?.();
97
+ if (wrapper)
98
+ replayInteraction(wrapper);
99
+ };
100
+ createEffect(() => {
101
+ return;
102
+ }, () => {
103
+ if (untrack(shown)) {
104
+ props.onHydrated?.();
105
+ return;
106
+ }
107
+ (served && wrapper ? whenTriggered(wrapper, on, { ...options, signal: controller.signal }).then(load) : load()).then(show);
108
+ }, { transparent: true });
109
+ const child = () => {
110
+ const loaded = shown();
111
+ if (!loaded) {
112
+ served ??= isHydrating();
113
+ return "";
114
+ }
115
+ const render = () => createComponent(loaded.default, rest);
116
+ return served && wrapper && !isHydrating() ? hydrateLate(wrapper, render) : render();
117
+ };
118
+ return createComponent(HydrateElement, {
119
+ on: attribute,
120
+ ref: (element) => wrapper = element,
121
+ children: createMemo(child)
122
+ });
123
+ };
124
+ }
125
+
126
+ // packages/adapter-solid/src/island-html.ts
127
+ import { markWaiting as markWaiting2 } from "hamur/adapter";
128
+ var outcomes = new WeakMap;
129
+ var current;
130
+ function settledIsland(promise, pending = current) {
131
+ const outcome = outcomes.get(promise);
132
+ if (outcome) {
133
+ if ("error" in outcome)
134
+ throw outcome.error;
135
+ return outcome.value;
136
+ }
137
+ pending?.push(promise.then((value) => void outcomes.set(promise, { value }), (error) => void outcomes.set(promise, { error })));
138
+ return;
139
+ }
140
+ function collectingIslands(pending, render) {
141
+ const outer = current;
142
+ current = pending;
143
+ try {
144
+ return render();
145
+ } finally {
146
+ current = outer;
147
+ }
148
+ }
149
+ async function islandsSettled(app, pending) {
150
+ if (!pending.length)
151
+ return;
152
+ await Promise.all(pending);
153
+ markWaiting2(app.asyncData);
154
+ }
155
+ async function renderSettled(render) {
156
+ for (;; ) {
157
+ const pending = [];
158
+ const result = await collectingIslands(pending, () => render(pending));
159
+ if (!pending.length)
160
+ return result;
161
+ await Promise.all(pending);
162
+ }
163
+ }
164
+
165
+ export { lazyModules, defineLazyHydrationComponent2, settledIsland, collectingIslands, islandsSettled, renderSettled };
@@ -0,0 +1,114 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ // packages/adapter-solid/src/keepalive.ts
17
+ var exports_keepalive = {};
18
+ __export(exports_keepalive, {
19
+ createKeptOutlet: () => createKeptOutlet2
20
+ });
21
+ var SHOWN = "\x00shown";
22
+ function createKeptOutlet2({
23
+ createComponent,
24
+ createEffect,
25
+ createMemo,
26
+ mapArray,
27
+ onCleanup,
28
+ untrack,
29
+ useContext,
30
+ dynamic,
31
+ ActivationContext,
32
+ AppContext,
33
+ activation,
34
+ detach,
35
+ setHidden,
36
+ routeValue,
37
+ holderOf,
38
+ Nest
39
+ }) {
40
+ const keptStates = new WeakMap;
41
+ const Div = dynamic(() => "div", { static: true });
42
+ function keptState(state, unit) {
43
+ let own = keptStates.get(unit);
44
+ if (!own) {
45
+ const { data = {}, handlerState } = unit.payload;
46
+ keptStates.set(unit, own = {
47
+ ...state,
48
+ route: routeValue({ route: unit.route, payload: unit.payload, tree: unit.tree, app: state.app }),
49
+ components: unit.tree.components,
50
+ data,
51
+ handlerState,
52
+ tree: unit.tree
53
+ });
54
+ }
55
+ return own;
56
+ }
57
+ function KeptPage(props, key) {
58
+ const unit = createMemo(() => holderOf(props.state(), props.index)?.kept?.find((item) => item.key === key));
59
+ const state = createMemo(() => {
60
+ const current = unit();
61
+ return current ? keptState(untrack(props.state), current) : props.state();
62
+ });
63
+ const own = activation(useContext(ActivationContext) ?? undefined, untrack(unit) !== undefined);
64
+ createEffect(() => unit() !== undefined, (hidden) => setHidden(own, hidden));
65
+ onCleanup(() => detach(own));
66
+ return createComponent(ActivationContext, {
67
+ value: own,
68
+ get children() {
69
+ return createComponent(AppContext, {
70
+ value: state,
71
+ get children() {
72
+ return createComponent(Div, {
73
+ "data-hamur-keepalive": key,
74
+ get hidden() {
75
+ return unit() ? true : undefined;
76
+ },
77
+ get style() {
78
+ return unit() ? undefined : "display:contents";
79
+ },
80
+ get children() {
81
+ return createComponent(Nest, {
82
+ state,
83
+ get index() {
84
+ return unit() ? 0 : props.index;
85
+ },
86
+ bare: true
87
+ });
88
+ }
89
+ });
90
+ }
91
+ });
92
+ }
93
+ });
94
+ }
95
+ return (props) => {
96
+ const keys = createMemo(() => {
97
+ const state = props.state();
98
+ const list = (holderOf(state, props.index)?.kept ?? []).map((unit) => unit.key);
99
+ const entry = state.components[props.index];
100
+ if (entry)
101
+ list.push(entry.keepalive ?? SHOWN);
102
+ return list;
103
+ });
104
+ return createMemo(mapArray(keys, (key) => key === SHOWN ? createComponent(Nest, {
105
+ state: props.state,
106
+ get index() {
107
+ return props.index;
108
+ },
109
+ bare: true
110
+ }) : KeptPage(props, key)));
111
+ };
112
+ }
113
+
114
+ export { createKeptOutlet2, exports_keepalive };
@@ -0,0 +1,39 @@
1
+ // packages/adapter-solid/src/client-fallback.ts
2
+ var clientFallbackIds = new Set;
3
+
4
+ // packages/adapter-solid/src/client-component.ts
5
+ import {
6
+ Loading,
7
+ createComponent,
8
+ createContext,
9
+ createMemo,
10
+ createSignal,
11
+ lazy,
12
+ onSettled,
13
+ useContext
14
+ } from "solid-js";
15
+ var ClientOnlyContext = createContext(null);
16
+ function clientComponent2(load) {
17
+ const Loaded = lazy(load);
18
+ return (props) => {
19
+ const scope = useContext(ClientOnlyContext);
20
+ const [hydrated, setHydrated] = createSignal(scope !== null);
21
+ onSettled(() => {
22
+ setHydrated(true);
23
+ });
24
+ return createMemo(() => {
25
+ if (!hydrated())
26
+ return null;
27
+ return createComponent(Loading, {
28
+ get fallback() {
29
+ return scope?.fallback ?? null;
30
+ },
31
+ get children() {
32
+ return createComponent(Loaded, props);
33
+ }
34
+ });
35
+ });
36
+ };
37
+ }
38
+
39
+ export { clientFallbackIds, ClientOnlyContext, clientComponent2 };