@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.84

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 (177) hide show
  1. package/dist/cdn/core.global.js +2 -1
  2. package/dist/cli/generate.cjs +4117 -292
  3. package/dist/cli/generate.mjs +4122 -292
  4. package/dist/cli/index.cjs +4117 -292
  5. package/dist/cli/index.mjs +4122 -292
  6. package/dist/cli/run.cjs +63 -1
  7. package/dist/cli/run.mjs +39 -1
  8. package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
  9. package/dist/src/cdn/core.cjs +1279 -1
  10. package/dist/src/cdn/core.d.ts +3 -3
  11. package/dist/src/cdn/core.js +3 -3
  12. package/dist/src/cdn/core.mjs +642 -1
  13. package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
  14. package/dist/src/index.cjs +1201 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +1 -11
  17. package/dist/src/index.mjs +1313 -1
  18. package/dist/src/jsx-dev-runtime.cjs +26 -1
  19. package/dist/src/jsx-dev-runtime.mjs +24 -1
  20. package/dist/src/jsx-runtime.cjs +26 -1
  21. package/dist/src/jsx-runtime.js +0 -9
  22. package/dist/src/jsx-runtime.mjs +24 -1
  23. package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +870 -1
  25. package/dist/src/lib/client/index.d.ts +17 -6
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +26 -19
  28. package/dist/src/lib/client/index.mjs +222 -1
  29. package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
  30. package/dist/src/lib/context/context.cjs +118 -1
  31. package/dist/src/lib/context/context.d.ts +19 -37
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +8 -45
  34. package/dist/src/lib/context/context.mjs +99 -1
  35. package/dist/src/lib/context/index.cjs +120 -1
  36. package/dist/src/lib/context/index.mjs +99 -1
  37. package/dist/src/lib/control-flow.cjs +35 -1
  38. package/dist/src/lib/control-flow.mjs +25 -1
  39. package/dist/src/lib/core.cjs +1200 -1
  40. package/dist/src/lib/core.d.ts +0 -2
  41. package/dist/src/lib/core.d.ts.map +1 -1
  42. package/dist/src/lib/core.js +14 -48
  43. package/dist/src/lib/core.mjs +1313 -1
  44. package/dist/src/lib/env/index.cjs +60 -1
  45. package/dist/src/lib/env/index.d.ts +5 -5
  46. package/dist/src/lib/env/index.js +5 -5
  47. package/dist/src/lib/env/index.mjs +39 -1
  48. package/dist/src/lib/i18n/index.cjs +108 -1
  49. package/dist/src/lib/i18n/index.d.ts +31 -10
  50. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  51. package/dist/src/lib/i18n/index.js +31 -10
  52. package/dist/src/lib/i18n/index.mjs +88 -1
  53. package/dist/src/lib/index.cjs +633 -1
  54. package/dist/src/lib/index.d.ts +0 -2
  55. package/dist/src/lib/index.d.ts.map +1 -1
  56. package/dist/src/lib/index.js +5 -11
  57. package/dist/src/lib/index.mjs +721 -1
  58. package/dist/src/lib/isomorphic.cjs +85 -1
  59. package/dist/src/lib/isomorphic.d.ts +41 -8
  60. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  61. package/dist/src/lib/isomorphic.js +38 -5
  62. package/dist/src/lib/isomorphic.mjs +64 -1
  63. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  64. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  65. package/dist/src/lib/jsx-runtime/index.js +1 -11
  66. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  67. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  69. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  74. package/dist/src/lib/plugins/index.cjs +311 -8
  75. package/dist/src/lib/plugins/index.mjs +279 -8
  76. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  77. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  78. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  79. package/dist/src/lib/plugins/route-codegen.js +4 -5
  80. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  81. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  82. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  83. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  84. package/dist/src/lib/plugins/route-scanner.js +7 -8
  85. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  86. package/dist/src/lib/plugins/vite.cjs +27 -1
  87. package/dist/src/lib/plugins/vite.mjs +6 -1
  88. package/dist/src/lib/render/await.cjs +38 -1
  89. package/dist/src/lib/render/await.d.ts +18 -0
  90. package/dist/src/lib/render/await.d.ts.map +1 -1
  91. package/dist/src/lib/render/await.js +20 -2
  92. package/dist/src/lib/render/await.mjs +17 -1
  93. package/dist/src/lib/render/component.cjs +221 -1
  94. package/dist/src/lib/render/component.d.ts +3 -44
  95. package/dist/src/lib/render/component.d.ts.map +1 -1
  96. package/dist/src/lib/render/component.js +23 -55
  97. package/dist/src/lib/render/component.mjs +214 -1
  98. package/dist/src/lib/render/deferred.cjs +175 -1
  99. package/dist/src/lib/render/deferred.js +5 -5
  100. package/dist/src/lib/render/deferred.mjs +158 -1
  101. package/dist/src/lib/render/index.cjs +573 -1
  102. package/dist/src/lib/render/index.d.ts +3 -17
  103. package/dist/src/lib/render/index.d.ts.map +1 -1
  104. package/dist/src/lib/render/index.js +8 -22
  105. package/dist/src/lib/render/index.mjs +590 -1
  106. package/dist/src/lib/render/lazy.cjs +67 -1
  107. package/dist/src/lib/render/lazy.d.ts +22 -1
  108. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  109. package/dist/src/lib/render/lazy.js +26 -5
  110. package/dist/src/lib/render/lazy.mjs +50 -1
  111. package/dist/src/lib/render/suspense.cjs +141 -1
  112. package/dist/src/lib/render/suspense.d.ts +40 -0
  113. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  114. package/dist/src/lib/render/suspense.js +46 -6
  115. package/dist/src/lib/render/suspense.mjs +136 -1
  116. package/dist/src/lib/render/versions.cjs +35 -1
  117. package/dist/src/lib/render/versions.js +6 -6
  118. package/dist/src/lib/render/versions.mjs +14 -1
  119. package/dist/src/lib/router/data.cjs +230 -1
  120. package/dist/src/lib/router/data.d.ts +1 -13
  121. package/dist/src/lib/router/data.d.ts.map +1 -1
  122. package/dist/src/lib/router/data.js +0 -12
  123. package/dist/src/lib/router/data.mjs +214 -1
  124. package/dist/src/lib/router/index.cjs +627 -1
  125. package/dist/src/lib/router/index.d.ts +62 -10
  126. package/dist/src/lib/router/index.d.ts.map +1 -1
  127. package/dist/src/lib/router/index.js +85 -33
  128. package/dist/src/lib/router/index.mjs +639 -1
  129. package/dist/src/lib/server/hydration.cjs +169 -1
  130. package/dist/src/lib/server/hydration.d.ts +15 -55
  131. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  132. package/dist/src/lib/server/hydration.js +23 -62
  133. package/dist/src/lib/server/hydration.mjs +148 -1
  134. package/dist/src/lib/server/index.cjs +401 -11
  135. package/dist/src/lib/server/index.d.ts +30 -6
  136. package/dist/src/lib/server/index.d.ts.map +1 -1
  137. package/dist/src/lib/server/index.js +34 -11
  138. package/dist/src/lib/server/index.mjs +379 -11
  139. package/dist/src/lib/server/reactive.cjs +197 -1
  140. package/dist/src/lib/server/reactive.d.ts +18 -77
  141. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  142. package/dist/src/lib/server/reactive.js +19 -78
  143. package/dist/src/lib/server/reactive.mjs +176 -1
  144. package/dist/src/lib/theme/index.cjs +110 -1
  145. package/dist/src/lib/theme/index.d.ts +19 -4
  146. package/dist/src/lib/theme/index.d.ts.map +1 -1
  147. package/dist/src/lib/theme/index.js +17 -2
  148. package/dist/src/lib/theme/index.mjs +89 -1
  149. package/dist/src/lib/utils/index.cjs +209 -1
  150. package/dist/src/lib/utils/index.d.ts +0 -93
  151. package/dist/src/lib/utils/index.d.ts.map +1 -1
  152. package/dist/src/lib/utils/index.js +0 -93
  153. package/dist/src/lib/utils/index.mjs +188 -1
  154. package/dist/src/routes.cjs +37 -1
  155. package/dist/src/routes.d.ts +1 -1
  156. package/dist/src/routes.js +2 -2
  157. package/dist/src/routes.mjs +17 -1
  158. package/dist/src/server.cjs +400 -11
  159. package/dist/src/server.d.ts +0 -1
  160. package/dist/src/server.d.ts.map +1 -1
  161. package/dist/src/server.js +0 -1
  162. package/dist/src/server.mjs +377 -11
  163. package/dist/src/utils.cjs +21 -1
  164. package/dist/src/utils.d.ts +1 -1
  165. package/dist/src/utils.js +1 -1
  166. package/dist/src/utils.mjs +4 -1
  167. package/dist/src/version.generated.cjs +26 -1
  168. package/dist/src/version.generated.d.ts +1 -1
  169. package/dist/src/version.generated.js +2 -2
  170. package/dist/src/version.generated.mjs +5 -1
  171. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  172. package/package.json +17 -16
  173. package/src/index.ts +2 -14
  174. package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
  175. package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
  176. package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
  177. package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
@@ -1 +1,189 @@
1
- "use strict";var P=Object.create;var S=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var $=(t,n)=>{for(var s in n)S(t,s,{get:n[s],enumerable:!0})},L=(t,n,s,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of O(n))!v.call(t,o)&&o!==s&&S(t,o,{get:()=>n[o],enumerable:!(i=G(n,o))||i.enumerable});return t};var b=(t,n,s)=>(s=t!=null?P(T(t)):{},L(n||!t||!t.__esModule?S(s,"default",{value:t,enumerable:!0}):s,t)),w=t=>L(S({},"__esModule",{value:!0}),t);var z={};$(z,{scanRoutes:()=>V});module.exports=w(z);var g=b(require("fs"),1),u=b(require("path"),1),N=[".tsx",".ts",".jsx",".js"];function V(t,n={}){let s=n.extensions??N,i=u.resolve(t);return g.existsSync(i)?F(i,i,"",s):[]}function F(t,n,s,i){let o=g.readdirSync(t,{withFileTypes:!0}),r=[],W=null,h=[],d=[];for(let e of o)e.isDirectory()?d.push(e):e.isFile()&&X(e.name,i)&&h.push(e);let l,c=[];for(let e of h)j(e.name)==="layout"?l=I(e.name,t,n,s,!0):c.push(e);let y=[];for(let e of c)y.push(I(e.name,t,n,s,!1));let f=[];for(let e of d){let a=e.name,A=_(a),C=A?"":k(a),R=C?E(s,C):s,x=F(u.join(t,a),n,R,i);if(A)f.push(...x);else{let m=x.find(p=>p.isLayout&&p.urlPath===R),D=x.filter(p=>!p.isLayout||p.urlPath!==R);m?(m.children=[...m.children,...D],f.push(m)):D.length>0&&f.push(...D)}}return l?(l.children=[...y,...f],r.push(l)):r.push(...y,...f),q(r)}function I(t,n,s,i,o){let r=j(t),W=u.relative(s,u.join(n,t)),h=r==="index",d=r.startsWith("[..."),l=!d&&r.startsWith("[")&&r.endsWith("]"),c;o?c="":h?c="/":d?c=`*${r.slice(4,-1)}`:l?c=`:${r.slice(1,-1)}`:c=r;let y=o||h?i||"/":E(i,c),f=u.join(n,t),e=!1;try{let a=g.readFileSync(f,"utf-8");e=/export\s+(const|function|async\s+function)\s+routeData\b/.test(a)}catch{}return{filePath:W.replace(/\\/g,"/"),urlSegment:c,urlPath:y,isLayout:o,isIndex:h,isDynamic:l,isCatchAll:d,isGroup:!1,children:[],parentUrlPath:i,hasRouteData:e,rootDir:s,dir:n}}function X(t,n){return n.some(s=>t.endsWith(s))}function j(t){let n=t.lastIndexOf(".");return n>0?t.slice(0,n):t}function _(t){return t.startsWith("(")&&t.endsWith(")")}function k(t){return t.startsWith("[...")&&t.endsWith("]")?"*"+t.slice(4,-1):t.startsWith("[")&&t.endsWith("]")?":"+t.slice(1,-1):t}function E(t,n){return(t.endsWith("/")?t:t+"/")+n}function q(t){return t.sort((n,s)=>n.isLayout&&!s.isLayout?-1:!n.isLayout&&s.isLayout?1:n.isIndex&&!s.isIndex?-1:!n.isIndex&&s.isIndex?1:!n.isDynamic&&!n.isCatchAll&&(s.isDynamic||s.isCatchAll)?-1:(n.isDynamic||n.isCatchAll)&&!s.isDynamic&&!s.isCatchAll?1:n.isDynamic&&s.isCatchAll?-1:n.isCatchAll&&s.isDynamic?1:n.urlSegment.localeCompare(s.urlSegment))}
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/plugins/route-scanner.ts
31
+ var route_scanner_exports = {};
32
+ __export(route_scanner_exports, {
33
+ scanRoutes: () => scanRoutes
34
+ });
35
+ module.exports = __toCommonJS(route_scanner_exports);
36
+ var fs = __toESM(require("fs"), 1);
37
+ var path = __toESM(require("path"), 1);
38
+ var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
39
+ function scanRoutes(routesDir, options = {}) {
40
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
41
+ const absDir = path.resolve(routesDir);
42
+ if (!fs.existsSync(absDir)) {
43
+ return [];
44
+ }
45
+ return scanDirectory(absDir, absDir, "", extensions);
46
+ }
47
+ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
48
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
49
+ const routes = [];
50
+ const layoutRoute = null;
51
+ const files = [];
52
+ const dirs = [];
53
+ for (const entry of entries) {
54
+ if (entry.isDirectory()) {
55
+ dirs.push(entry);
56
+ } else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
57
+ files.push(entry);
58
+ }
59
+ }
60
+ let layout;
61
+ const nonLayoutFiles = [];
62
+ for (const file of files) {
63
+ const baseName = stripExtension(file.name);
64
+ if (baseName === "layout") {
65
+ layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
66
+ } else {
67
+ nonLayoutFiles.push(file);
68
+ }
69
+ }
70
+ const fileRoutes = [];
71
+ for (const file of nonLayoutFiles) {
72
+ fileRoutes.push(
73
+ buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
74
+ );
75
+ }
76
+ const dirRoutes = [];
77
+ for (const d of dirs) {
78
+ const dirName = d.name;
79
+ const isGroup = isRouteGroup(dirName);
80
+ const segment = isGroup ? "" : dirNameToSegment(dirName);
81
+ const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
82
+ const children = scanDirectory(
83
+ path.join(dir, dirName),
84
+ rootDir,
85
+ childUrlPath,
86
+ extensions
87
+ );
88
+ if (isGroup) {
89
+ dirRoutes.push(...children);
90
+ } else {
91
+ const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
92
+ const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
93
+ if (childLayout) {
94
+ childLayout.children = [...childLayout.children, ...childNonLayout];
95
+ dirRoutes.push(childLayout);
96
+ } else if (childNonLayout.length > 0) {
97
+ dirRoutes.push(...childNonLayout);
98
+ }
99
+ }
100
+ }
101
+ if (layout) {
102
+ layout.children = [...fileRoutes, ...dirRoutes];
103
+ routes.push(layout);
104
+ } else {
105
+ routes.push(...fileRoutes, ...dirRoutes);
106
+ }
107
+ return sortRoutes(routes);
108
+ }
109
+ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
110
+ const baseName = stripExtension(fileName);
111
+ const filePath = path.relative(rootDir, path.join(dir, fileName));
112
+ const isIndex = baseName === "index";
113
+ const isCatchAll = baseName.startsWith("[...");
114
+ const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
115
+ let urlSegment;
116
+ if (isLayout) {
117
+ urlSegment = "";
118
+ } else if (isIndex) {
119
+ urlSegment = "/";
120
+ } else if (isCatchAll) {
121
+ const paramName = baseName.slice(4, -1);
122
+ urlSegment = `*${paramName}`;
123
+ } else if (isDynamic) {
124
+ const paramName = baseName.slice(1, -1);
125
+ urlSegment = `:${paramName}`;
126
+ } else {
127
+ urlSegment = baseName;
128
+ }
129
+ const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
130
+ const absoluteFilePath = path.join(dir, fileName);
131
+ let hasRouteData = false;
132
+ try {
133
+ const content = fs.readFileSync(absoluteFilePath, "utf-8");
134
+ hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
135
+ } catch {
136
+ }
137
+ return {
138
+ filePath: filePath.replace(/\\/g, "/"),
139
+ // normalize to forward slashes
140
+ urlSegment,
141
+ urlPath,
142
+ isLayout,
143
+ isIndex,
144
+ isDynamic,
145
+ isCatchAll,
146
+ isGroup: false,
147
+ children: [],
148
+ parentUrlPath,
149
+ hasRouteData,
150
+ rootDir,
151
+ dir
152
+ };
153
+ }
154
+ function hasValidExtension(fileName, extensions) {
155
+ return extensions.some((ext) => fileName.endsWith(ext));
156
+ }
157
+ function stripExtension(fileName) {
158
+ const lastDot = fileName.lastIndexOf(".");
159
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
160
+ }
161
+ function isRouteGroup(dirName) {
162
+ return dirName.startsWith("(") && dirName.endsWith(")");
163
+ }
164
+ function dirNameToSegment(dirName) {
165
+ if (dirName.startsWith("[...") && dirName.endsWith("]")) {
166
+ return "*" + dirName.slice(4, -1);
167
+ }
168
+ if (dirName.startsWith("[") && dirName.endsWith("]")) {
169
+ return ":" + dirName.slice(1, -1);
170
+ }
171
+ return dirName;
172
+ }
173
+ function joinUrlPath(parent, segment) {
174
+ const base = parent.endsWith("/") ? parent : parent + "/";
175
+ return base + segment;
176
+ }
177
+ function sortRoutes(routes) {
178
+ return routes.sort((a, b) => {
179
+ if (a.isLayout && !b.isLayout) return -1;
180
+ if (!a.isLayout && b.isLayout) return 1;
181
+ if (a.isIndex && !b.isIndex) return -1;
182
+ if (!a.isIndex && b.isIndex) return 1;
183
+ if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
184
+ if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
185
+ if (a.isDynamic && b.isCatchAll) return -1;
186
+ if (a.isCatchAll && b.isDynamic) return 1;
187
+ return a.urlSegment.localeCompare(b.urlSegment);
188
+ });
189
+ }
@@ -1,9 +1,8 @@
1
1
  /**
2
- * @fileoverview File-system route scanner
3
2
  * @module @fluixi/core/plugins/route-scanner
4
3
  *
5
4
  * Scans a routes directory and builds a route tree following SolidStart conventions.
6
- * Pure utility no bundler dependency.
5
+ * Pure utility, no bundler dependency.
7
6
  */
8
7
  export interface ScannedRoute {
9
8
  /** Relative file path from routes dir: 'users/[id].tsx' */
@@ -1 +1 @@
1
- {"version":3,"file":"route-scanner.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAC;IACnB,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAQD;;GAEG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,WAAgB,GACxB,YAAY,EAAE,CAShB"}
1
+ {"version":3,"file":"route-scanner.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-scanner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAC;IACnB,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAQD;;GAEG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,WAAgB,GACxB,YAAY,EAAE,CAShB"}
@@ -1,9 +1,8 @@
1
1
  /**
2
- * @fileoverview File-system route scanner
3
2
  * @module @fluixi/core/plugins/route-scanner
4
3
  *
5
4
  * Scans a routes directory and builds a route tree following SolidStart conventions.
6
- * Pure utility no bundler dependency.
5
+ * Pure utility, no bundler dependency.
7
6
  */
8
7
  import * as fs from 'fs';
9
8
  import * as path from 'path';
@@ -71,7 +70,7 @@ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
71
70
  else {
72
71
  // Regular directory: becomes a nested route
73
72
  // If there's a DIRECT layout in the children (urlPath matches this dir's path),
74
- // it becomes the parent route. We must NOT pick up layouts from deeper descendants
73
+ // it becomes the parent route. We must not pick up layouts from deeper descendants
75
74
  // (e.g. campaigns/[id]/workspace/layout.tsx must not be the layout for campaigns/).
76
75
  const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
77
76
  const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
@@ -81,7 +80,7 @@ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
81
80
  dirRoutes.push(childLayout);
82
81
  }
83
82
  else if (childNonLayout.length > 0) {
84
- // No layout just add children with their full paths
83
+ // No layout, just add children with their full paths
85
84
  dirRoutes.push(...childNonLayout);
86
85
  }
87
86
  }
@@ -114,12 +113,12 @@ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
114
113
  urlSegment = '/';
115
114
  }
116
115
  else if (isCatchAll) {
117
- // [...rest] *rest
116
+ // [...rest] -> *rest
118
117
  const paramName = baseName.slice(4, -1); // remove '[...' and ']'
119
118
  urlSegment = `*${paramName}`;
120
119
  }
121
120
  else if (isDynamic) {
122
- // [id] :id
121
+ // [id] -> :id
123
122
  const paramName = baseName.slice(1, -1); // remove '[' and ']'
124
123
  urlSegment = `:${paramName}`;
125
124
  }
@@ -173,10 +172,10 @@ function isRouteGroup(dirName) {
173
172
  /** Convert a directory name to its URL segment, matching the same rules as file names. */
174
173
  function dirNameToSegment(dirName) {
175
174
  if (dirName.startsWith('[...') && dirName.endsWith(']')) {
176
- return '*' + dirName.slice(4, -1); // [...rest] *rest
175
+ return '*' + dirName.slice(4, -1); // [...rest] -> *rest
177
176
  }
178
177
  if (dirName.startsWith('[') && dirName.endsWith(']')) {
179
- return ':' + dirName.slice(1, -1); // [id] :id
178
+ return ':' + dirName.slice(1, -1); // [id] -> :id
180
179
  }
181
180
  return dirName;
182
181
  }
@@ -1 +1,158 @@
1
- import*as d from"fs";import*as a from"path";var F=[".tsx",".ts",".jsx",".js"];function O(t,n={}){let s=n.extensions??F,i=a.resolve(t);return d.existsSync(i)?L(i,i,"",s):[]}function L(t,n,s,i){let g=d.readdirSync(t,{withFileTypes:!0}),o=[],D=null,f=[],h=[];for(let e of g)e.isDirectory()?h.push(e):e.isFile()&&j(e.name,i)&&f.push(e);let u,r=[];for(let e of f)b(e.name)==="layout"?u=C(e.name,t,n,s,!0):r.push(e);let y=[];for(let e of r)y.push(C(e.name,t,n,s,!1));let l=[];for(let e of h){let c=e.name,W=E(c),A=W?"":P(c),S=A?I(s,A):s,R=L(a.join(t,c),n,S,i);if(W)l.push(...R);else{let m=R.find(p=>p.isLayout&&p.urlPath===S),x=R.filter(p=>!p.isLayout||p.urlPath!==S);m?(m.children=[...m.children,...x],l.push(m)):x.length>0&&l.push(...x)}}return u?(u.children=[...y,...l],o.push(u)):o.push(...y,...l),G(o)}function C(t,n,s,i,g){let o=b(t),D=a.relative(s,a.join(n,t)),f=o==="index",h=o.startsWith("[..."),u=!h&&o.startsWith("[")&&o.endsWith("]"),r;g?r="":f?r="/":h?r=`*${o.slice(4,-1)}`:u?r=`:${o.slice(1,-1)}`:r=o;let y=g||f?i||"/":I(i,r),l=a.join(n,t),e=!1;try{let c=d.readFileSync(l,"utf-8");e=/export\s+(const|function|async\s+function)\s+routeData\b/.test(c)}catch{}return{filePath:D.replace(/\\/g,"/"),urlSegment:r,urlPath:y,isLayout:g,isIndex:f,isDynamic:u,isCatchAll:h,isGroup:!1,children:[],parentUrlPath:i,hasRouteData:e,rootDir:s,dir:n}}function j(t,n){return n.some(s=>t.endsWith(s))}function b(t){let n=t.lastIndexOf(".");return n>0?t.slice(0,n):t}function E(t){return t.startsWith("(")&&t.endsWith(")")}function P(t){return t.startsWith("[...")&&t.endsWith("]")?"*"+t.slice(4,-1):t.startsWith("[")&&t.endsWith("]")?":"+t.slice(1,-1):t}function I(t,n){return(t.endsWith("/")?t:t+"/")+n}function G(t){return t.sort((n,s)=>n.isLayout&&!s.isLayout?-1:!n.isLayout&&s.isLayout?1:n.isIndex&&!s.isIndex?-1:!n.isIndex&&s.isIndex?1:!n.isDynamic&&!n.isCatchAll&&(s.isDynamic||s.isCatchAll)?-1:(n.isDynamic||n.isCatchAll)&&!s.isDynamic&&!s.isCatchAll?1:n.isDynamic&&s.isCatchAll?-1:n.isCatchAll&&s.isDynamic?1:n.urlSegment.localeCompare(s.urlSegment))}export{O as scanRoutes};
1
+ // src/lib/plugins/route-scanner.ts
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
5
+ function scanRoutes(routesDir, options = {}) {
6
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
7
+ const absDir = path.resolve(routesDir);
8
+ if (!fs.existsSync(absDir)) {
9
+ return [];
10
+ }
11
+ return scanDirectory(absDir, absDir, "", extensions);
12
+ }
13
+ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
14
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
15
+ const routes = [];
16
+ const layoutRoute = null;
17
+ const files = [];
18
+ const dirs = [];
19
+ for (const entry of entries) {
20
+ if (entry.isDirectory()) {
21
+ dirs.push(entry);
22
+ } else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
23
+ files.push(entry);
24
+ }
25
+ }
26
+ let layout;
27
+ const nonLayoutFiles = [];
28
+ for (const file of files) {
29
+ const baseName = stripExtension(file.name);
30
+ if (baseName === "layout") {
31
+ layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
32
+ } else {
33
+ nonLayoutFiles.push(file);
34
+ }
35
+ }
36
+ const fileRoutes = [];
37
+ for (const file of nonLayoutFiles) {
38
+ fileRoutes.push(
39
+ buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
40
+ );
41
+ }
42
+ const dirRoutes = [];
43
+ for (const d of dirs) {
44
+ const dirName = d.name;
45
+ const isGroup = isRouteGroup(dirName);
46
+ const segment = isGroup ? "" : dirNameToSegment(dirName);
47
+ const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
48
+ const children = scanDirectory(
49
+ path.join(dir, dirName),
50
+ rootDir,
51
+ childUrlPath,
52
+ extensions
53
+ );
54
+ if (isGroup) {
55
+ dirRoutes.push(...children);
56
+ } else {
57
+ const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
58
+ const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
59
+ if (childLayout) {
60
+ childLayout.children = [...childLayout.children, ...childNonLayout];
61
+ dirRoutes.push(childLayout);
62
+ } else if (childNonLayout.length > 0) {
63
+ dirRoutes.push(...childNonLayout);
64
+ }
65
+ }
66
+ }
67
+ if (layout) {
68
+ layout.children = [...fileRoutes, ...dirRoutes];
69
+ routes.push(layout);
70
+ } else {
71
+ routes.push(...fileRoutes, ...dirRoutes);
72
+ }
73
+ return sortRoutes(routes);
74
+ }
75
+ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
76
+ const baseName = stripExtension(fileName);
77
+ const filePath = path.relative(rootDir, path.join(dir, fileName));
78
+ const isIndex = baseName === "index";
79
+ const isCatchAll = baseName.startsWith("[...");
80
+ const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
81
+ let urlSegment;
82
+ if (isLayout) {
83
+ urlSegment = "";
84
+ } else if (isIndex) {
85
+ urlSegment = "/";
86
+ } else if (isCatchAll) {
87
+ const paramName = baseName.slice(4, -1);
88
+ urlSegment = `*${paramName}`;
89
+ } else if (isDynamic) {
90
+ const paramName = baseName.slice(1, -1);
91
+ urlSegment = `:${paramName}`;
92
+ } else {
93
+ urlSegment = baseName;
94
+ }
95
+ const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
96
+ const absoluteFilePath = path.join(dir, fileName);
97
+ let hasRouteData = false;
98
+ try {
99
+ const content = fs.readFileSync(absoluteFilePath, "utf-8");
100
+ hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
101
+ } catch {
102
+ }
103
+ return {
104
+ filePath: filePath.replace(/\\/g, "/"),
105
+ // normalize to forward slashes
106
+ urlSegment,
107
+ urlPath,
108
+ isLayout,
109
+ isIndex,
110
+ isDynamic,
111
+ isCatchAll,
112
+ isGroup: false,
113
+ children: [],
114
+ parentUrlPath,
115
+ hasRouteData,
116
+ rootDir,
117
+ dir
118
+ };
119
+ }
120
+ function hasValidExtension(fileName, extensions) {
121
+ return extensions.some((ext) => fileName.endsWith(ext));
122
+ }
123
+ function stripExtension(fileName) {
124
+ const lastDot = fileName.lastIndexOf(".");
125
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
126
+ }
127
+ function isRouteGroup(dirName) {
128
+ return dirName.startsWith("(") && dirName.endsWith(")");
129
+ }
130
+ function dirNameToSegment(dirName) {
131
+ if (dirName.startsWith("[...") && dirName.endsWith("]")) {
132
+ return "*" + dirName.slice(4, -1);
133
+ }
134
+ if (dirName.startsWith("[") && dirName.endsWith("]")) {
135
+ return ":" + dirName.slice(1, -1);
136
+ }
137
+ return dirName;
138
+ }
139
+ function joinUrlPath(parent, segment) {
140
+ const base = parent.endsWith("/") ? parent : parent + "/";
141
+ return base + segment;
142
+ }
143
+ function sortRoutes(routes) {
144
+ return routes.sort((a, b) => {
145
+ if (a.isLayout && !b.isLayout) return -1;
146
+ if (!a.isLayout && b.isLayout) return 1;
147
+ if (a.isIndex && !b.isIndex) return -1;
148
+ if (!a.isIndex && b.isIndex) return 1;
149
+ if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
150
+ if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
151
+ if (a.isDynamic && b.isCatchAll) return -1;
152
+ if (a.isCatchAll && b.isDynamic) return 1;
153
+ return a.urlSegment.localeCompare(b.urlSegment);
154
+ });
155
+ }
156
+ export {
157
+ scanRoutes
158
+ };
@@ -1 +1,27 @@
1
- "use strict";var p=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var n=(e,i)=>{for(var l in i)p(e,l,{get:i[l],enumerable:!0})},g=(e,i,l,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of x(i))!f.call(e,t)&&t!==l&&p(e,t,{get:()=>i[t],enumerable:!(r=u(i,t))||r.enumerable});return e};var m=e=>g(p({},"__esModule",{value:!0}),e);var V={};n(V,{createVitePlugin:()=>o.createVitePlugin,fluixi:()=>o.fluixi});module.exports=m(V);var o=require("@fluixi/vite-plugin");
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/plugins/vite.ts
21
+ var vite_exports = {};
22
+ __export(vite_exports, {
23
+ createVitePlugin: () => import_vite_plugin.createVitePlugin,
24
+ fluixi: () => import_vite_plugin.fluixi
25
+ });
26
+ module.exports = __toCommonJS(vite_exports);
27
+ var import_vite_plugin = require("@fluixi/vite-plugin");
@@ -1 +1,6 @@
1
- import{fluixi as t,createVitePlugin as l}from"@fluixi/vite-plugin";export{l as createVitePlugin,t as fluixi};
1
+ // src/lib/plugins/vite.ts
2
+ import { fluixi, createVitePlugin } from "@fluixi/vite-plugin";
3
+ export {
4
+ createVitePlugin,
5
+ fluixi
6
+ };
@@ -1 +1,38 @@
1
- "use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var T=(n,e)=>{for(var t in e)a(n,t,{get:e[t],enumerable:!0})},l=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c(e))!s.call(n,r)&&r!==t&&a(n,r,{get:()=>e[r],enumerable:!(o=u(e,r))||o.enumerable});return n};var f=n=>l(a({},"__esModule",{value:!0}),n);var P={};T(P,{Await:()=>w});module.exports=f(P);var i=require("@fluixi/reactive/signal");function w(n){let e=()=>{let o=n.value;return typeof o=="function"?o():o},[t]=(0,i.createResource)(e);return()=>{if(t.loading)return n.fallback;let o=n.children;return typeof o=="function"?o(t()):o}}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/render/await.ts
21
+ var await_exports = {};
22
+ __export(await_exports, {
23
+ Await: () => Await
24
+ });
25
+ module.exports = __toCommonJS(await_exports);
26
+ var import_signal = require("@fluixi/reactive/signal");
27
+ function Await(props) {
28
+ const fetcher = () => {
29
+ const v = props.value;
30
+ return typeof v === "function" ? v() : v;
31
+ };
32
+ const [data] = (0, import_signal.createResource)(fetcher);
33
+ return () => {
34
+ if (data.loading) return props.fallback;
35
+ const child = props.children;
36
+ return typeof child === "function" ? child(data()) : child;
37
+ };
38
+ }
@@ -4,5 +4,23 @@ export interface AwaitProps<T> {
4
4
  /** Render prop called with the resolved value (or plain children). */
5
5
  children?: ((value: T) => unknown) | unknown;
6
6
  }
7
+ /**
8
+ * Render the result of a promise, with a fallback while it is pending.
9
+ *
10
+ * `value` may be a promise or a function returning one. Pass a function when the promise
11
+ * should be created by the component rather than by whoever wrote the tag, which is what
12
+ * keeps a re-render from firing the request again.
13
+ *
14
+ * `children` is either a render prop called with the resolved value, or plain children
15
+ * that ignore it.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * html`
20
+ * <${Await} value=${() => fetchUser(id)} fallback=${html`<p>loading...</p>`}>
21
+ * ${(user) => html`<h1>${user.name}</h1>`}
22
+ * </${Await}>`;
23
+ * ```
24
+ */
7
25
  export declare function Await<T>(props: AwaitProps<T>): () => unknown;
8
26
  //# sourceMappingURL=await.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"await.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/await.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC;CAC9C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAW5D"}
1
+ {"version":3,"file":"await.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/await.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAW5D"}
@@ -1,9 +1,9 @@
1
1
  /**
2
- * `<Await value=${promise}>` resolve a promise and render its value.
2
+ * `<Await value=${promise}>`: resolve a promise and render its value.
3
3
  *
4
4
  * A thin, Suspense-free helper for the common "await one promise" case:
5
5
  *
6
- * <Await value=${fetchUser(id)} fallback=${html`<p>loading…</p>`}>
6
+ * <Await value=${fetchUser(id)} fallback=${html`<p>loading...</p>`}>
7
7
  * ${(user) => html`<span>${user.name}</span>`}
8
8
  * </Await>
9
9
  *
@@ -12,6 +12,24 @@
12
12
  * resource read is guarded by `.loading`, so it never throws/suspends.
13
13
  */
14
14
  import { createResource } from '@fluixi/reactive/signal';
15
+ /**
16
+ * Render the result of a promise, with a fallback while it is pending.
17
+ *
18
+ * `value` may be a promise or a function returning one. Pass a function when the promise
19
+ * should be created by the component rather than by whoever wrote the tag, which is what
20
+ * keeps a re-render from firing the request again.
21
+ *
22
+ * `children` is either a render prop called with the resolved value, or plain children
23
+ * that ignore it.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * html`
28
+ * <${Await} value=${() => fetchUser(id)} fallback=${html`<p>loading...</p>`}>
29
+ * ${(user) => html`<h1>${user.name}</h1>`}
30
+ * </${Await}>`;
31
+ * ```
32
+ */
15
33
  export function Await(props) {
16
34
  const fetcher = () => {
17
35
  const v = props.value;
@@ -1 +1,17 @@
1
- import{createResource as r}from"@fluixi/reactive/signal";function i(e){let t=()=>{let n=e.value;return typeof n=="function"?n():n},[o]=r(t);return()=>{if(o.loading)return e.fallback;let n=e.children;return typeof n=="function"?n(o()):n}}export{i as Await};
1
+ // src/lib/render/await.ts
2
+ import { createResource } from "@fluixi/reactive/signal";
3
+ function Await(props) {
4
+ const fetcher = () => {
5
+ const v = props.value;
6
+ return typeof v === "function" ? v() : v;
7
+ };
8
+ const [data] = createResource(fetcher);
9
+ return () => {
10
+ if (data.loading) return props.fallback;
11
+ const child = props.children;
12
+ return typeof child === "function" ? child(data()) : child;
13
+ };
14
+ }
15
+ export {
16
+ Await
17
+ };