@spirobel/mininext 0.2.15 → 0.2.16
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/dist/html.d.ts +1 -0
- package/dist/html.js +22 -13
- package/dist/mininext.d.ts +3 -2
- package/dist/mininext.js +3 -2
- package/mininext/html.ts +19 -13
- package/mininext/mininext.ts +12 -2
- package/package.json +1 -1
package/dist/html.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class HtmlString extends Array {
|
|
|
7
7
|
/**
|
|
8
8
|
* a HtmlString is by default resolved.
|
|
9
9
|
* if we we pass a function as a value to the html`` template string, it will be unresolved.
|
|
10
|
+
* it can also become unresolved if an unresolved HtmlString is passed into it as a value
|
|
10
11
|
*/
|
|
11
12
|
resolved: boolean;
|
|
12
13
|
resolve<T>(mini: Mini<T>): Promise<this>;
|
package/dist/html.js
CHANGED
|
@@ -2,19 +2,29 @@ export class HtmlString extends Array {
|
|
|
2
2
|
/**
|
|
3
3
|
* a HtmlString is by default resolved.
|
|
4
4
|
* if we we pass a function as a value to the html`` template string, it will be unresolved.
|
|
5
|
+
* it can also become unresolved if an unresolved HtmlString is passed into it as a value
|
|
5
6
|
*/
|
|
6
7
|
resolved = true;
|
|
7
8
|
async resolve(mini) {
|
|
8
9
|
if (this.resolved)
|
|
9
10
|
return this;
|
|
10
11
|
for (const [index, htmlPiece] of this.entries()) {
|
|
11
|
-
if (
|
|
12
|
+
if (htmlPiece instanceof HtmlString) {
|
|
13
|
+
let resolvedHtmlPiece = await htmlPiece.resolve(mini);
|
|
14
|
+
if (this instanceof JsonString || this instanceof DangerJsonInHtml) {
|
|
15
|
+
this[index] = JSON.stringify(resolvedHtmlPiece);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this[index] = resolvedHtmlPiece;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (typeof htmlPiece === "function") {
|
|
12
22
|
let resolvedHtmlPiece = await htmlPiece(mini); //passing mini
|
|
13
23
|
if (resolvedHtmlPiece instanceof HtmlString) {
|
|
14
24
|
resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
|
|
15
25
|
}
|
|
16
26
|
else {
|
|
17
|
-
if (this instanceof JsonString) {
|
|
27
|
+
if (this instanceof JsonString || this instanceof DangerJsonInHtml) {
|
|
18
28
|
resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
|
|
19
29
|
}
|
|
20
30
|
else {
|
|
@@ -45,7 +55,7 @@ export function html(strings, ...values) {
|
|
|
45
55
|
htmlStringArray.push(string);
|
|
46
56
|
if (index < values.length) {
|
|
47
57
|
const value = values[index];
|
|
48
|
-
// we can pass arrays of HtmlString and they will get flattened
|
|
58
|
+
// we can pass arrays of HtmlString and they will get flattened in the HtmlResponder
|
|
49
59
|
if (Array.isArray(value) &&
|
|
50
60
|
value.every((val) => val instanceof HtmlString)) {
|
|
51
61
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
@@ -76,8 +86,7 @@ export function html(strings, ...values) {
|
|
|
76
86
|
htmlStringArray.push(values[index]);
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
|
-
|
|
80
|
-
return htmlStringArray.flat();
|
|
89
|
+
return htmlStringArray;
|
|
81
90
|
}
|
|
82
91
|
export class JsonString extends HtmlString {
|
|
83
92
|
}
|
|
@@ -95,7 +104,7 @@ function JsonTemplateProcessor(danger = false) {
|
|
|
95
104
|
jsonStringArray.push(string);
|
|
96
105
|
if (index < values.length) {
|
|
97
106
|
const value = values[index];
|
|
98
|
-
// we can pass arrays of HtmlString and they will get flattened
|
|
107
|
+
// we can pass arrays of HtmlString and they will get flattened in the HtmlResponder
|
|
99
108
|
if (Array.isArray(value) &&
|
|
100
109
|
value.every((val) => val instanceof HtmlString)) {
|
|
101
110
|
// If the value is an array of HtmlString objects, add the whole array as a single value
|
|
@@ -106,21 +115,21 @@ function JsonTemplateProcessor(danger = false) {
|
|
|
106
115
|
jsonStringArray.resolved = false;
|
|
107
116
|
values[index] = value;
|
|
108
117
|
}
|
|
109
|
-
else if (!(value instanceof JsonString)) {
|
|
110
|
-
const notEmpty = value || "";
|
|
111
|
-
// values will be turned into a JSON string
|
|
112
|
-
values[index] = JSON.stringify(notEmpty);
|
|
113
|
-
}
|
|
114
118
|
else if (value instanceof HtmlString) {
|
|
115
119
|
if (!value.resolved) {
|
|
116
120
|
jsonStringArray.resolved = false;
|
|
117
121
|
}
|
|
122
|
+
values[index] = value;
|
|
123
|
+
}
|
|
124
|
+
else if (!(value instanceof JsonString)) {
|
|
125
|
+
const notEmpty = value || "";
|
|
126
|
+
// values will be turned into a JSON string
|
|
127
|
+
values[index] = JSON.stringify(notEmpty);
|
|
118
128
|
}
|
|
119
129
|
jsonStringArray.push(values[index]);
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
|
-
|
|
123
|
-
return jsonStringArray.flat();
|
|
132
|
+
return jsonStringArray;
|
|
124
133
|
};
|
|
125
134
|
}
|
|
126
135
|
export const json = JsonTemplateProcessor();
|
package/dist/mininext.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
2
|
-
import { html, isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
2
|
+
import { html, json, isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
3
3
|
declare global {
|
|
4
4
|
var PROJECT_ROOT: string | undefined;
|
|
5
5
|
}
|
|
6
6
|
declare function build(backendPath?: string): Promise<void>;
|
|
7
7
|
declare const standardDevReloader: HtmlString;
|
|
8
8
|
declare function makeEntrypoint(): Promise<(w: any) => Promise<Response>>;
|
|
9
|
-
|
|
9
|
+
declare const css: typeof html;
|
|
10
|
+
export { url, css, json, html, head, build, makeEntrypoint, isError, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/mininext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { url, Mini } from "./url";
|
|
2
|
-
import { html, isError, HtmlString, head, commonHead, cssReset } from "./html";
|
|
2
|
+
import { html, json, isError, HtmlString, head, commonHead, cssReset, } from "./html";
|
|
3
3
|
import { watch } from "fs/promises";
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
function projectRoot() {
|
|
@@ -158,4 +158,5 @@ async function makeEntrypoint() {
|
|
|
158
158
|
}
|
|
159
159
|
return module.default;
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
const css = html;
|
|
162
|
+
export { url, css, json, html, head, build, makeEntrypoint, isError, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
package/mininext/html.ts
CHANGED
|
@@ -20,18 +20,26 @@ export class HtmlString extends Array {
|
|
|
20
20
|
/**
|
|
21
21
|
* a HtmlString is by default resolved.
|
|
22
22
|
* if we we pass a function as a value to the html`` template string, it will be unresolved.
|
|
23
|
+
* it can also become unresolved if an unresolved HtmlString is passed into it as a value
|
|
23
24
|
*/
|
|
24
25
|
resolved = true;
|
|
25
26
|
async resolve<T>(mini: Mini<T>) {
|
|
26
27
|
if (this.resolved) return this;
|
|
27
28
|
|
|
28
29
|
for (const [index, htmlPiece] of this.entries()) {
|
|
29
|
-
if (
|
|
30
|
+
if (htmlPiece instanceof HtmlString) {
|
|
31
|
+
let resolvedHtmlPiece = await htmlPiece.resolve(mini);
|
|
32
|
+
if (this instanceof JsonString || this instanceof DangerJsonInHtml) {
|
|
33
|
+
this[index] = JSON.stringify(resolvedHtmlPiece);
|
|
34
|
+
} else {
|
|
35
|
+
this[index] = resolvedHtmlPiece;
|
|
36
|
+
}
|
|
37
|
+
} else if (typeof htmlPiece === "function") {
|
|
30
38
|
let resolvedHtmlPiece = await htmlPiece(mini); //passing mini
|
|
31
39
|
if (resolvedHtmlPiece instanceof HtmlString) {
|
|
32
40
|
resolvedHtmlPiece = await resolvedHtmlPiece.resolve(mini);
|
|
33
41
|
} else {
|
|
34
|
-
if (this instanceof JsonString) {
|
|
42
|
+
if (this instanceof JsonString || this instanceof DangerJsonInHtml) {
|
|
35
43
|
resolvedHtmlPiece = JSON.stringify(resolvedHtmlPiece);
|
|
36
44
|
} else {
|
|
37
45
|
const notEmpty = resolvedHtmlPiece || "";
|
|
@@ -68,7 +76,7 @@ export function html<X = undefined>(
|
|
|
68
76
|
if (index < values.length) {
|
|
69
77
|
const value = values[index];
|
|
70
78
|
|
|
71
|
-
// we can pass arrays of HtmlString and they will get flattened
|
|
79
|
+
// we can pass arrays of HtmlString and they will get flattened in the HtmlResponder
|
|
72
80
|
if (
|
|
73
81
|
Array.isArray(value) &&
|
|
74
82
|
value.every((val) => val instanceof HtmlString)
|
|
@@ -97,8 +105,7 @@ export function html<X = undefined>(
|
|
|
97
105
|
htmlStringArray.push(values[index]);
|
|
98
106
|
}
|
|
99
107
|
}
|
|
100
|
-
|
|
101
|
-
return htmlStringArray.flat();
|
|
108
|
+
return htmlStringArray;
|
|
102
109
|
}
|
|
103
110
|
export class JsonString extends HtmlString {}
|
|
104
111
|
export class DangerJsonInHtml extends HtmlString {}
|
|
@@ -133,8 +140,7 @@ function JsonTemplateProcessor(danger: boolean = false) {
|
|
|
133
140
|
|
|
134
141
|
if (index < values.length) {
|
|
135
142
|
const value = values[index];
|
|
136
|
-
|
|
137
|
-
// we can pass arrays of HtmlString and they will get flattened automatically
|
|
143
|
+
// we can pass arrays of HtmlString and they will get flattened in the HtmlResponder
|
|
138
144
|
if (
|
|
139
145
|
Array.isArray(value) &&
|
|
140
146
|
value.every((val) => val instanceof HtmlString)
|
|
@@ -145,20 +151,20 @@ function JsonTemplateProcessor(danger: boolean = false) {
|
|
|
145
151
|
} else if (typeof value === "function") {
|
|
146
152
|
jsonStringArray.resolved = false;
|
|
147
153
|
values[index] = value;
|
|
148
|
-
} else if (!(value instanceof JsonString)) {
|
|
149
|
-
const notEmpty = value || "";
|
|
150
|
-
// values will be turned into a JSON string
|
|
151
|
-
values[index] = JSON.stringify(notEmpty);
|
|
152
154
|
} else if (value instanceof HtmlString) {
|
|
153
155
|
if (!value.resolved) {
|
|
154
156
|
jsonStringArray.resolved = false;
|
|
155
157
|
}
|
|
158
|
+
values[index] = value;
|
|
159
|
+
} else if (!(value instanceof JsonString)) {
|
|
160
|
+
const notEmpty = value || "";
|
|
161
|
+
// values will be turned into a JSON string
|
|
162
|
+
values[index] = JSON.stringify(notEmpty);
|
|
156
163
|
}
|
|
157
164
|
jsonStringArray.push(values[index]);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
|
-
|
|
161
|
-
return jsonStringArray.flat();
|
|
167
|
+
return jsonStringArray;
|
|
162
168
|
};
|
|
163
169
|
}
|
|
164
170
|
export const json = JsonTemplateProcessor();
|
package/mininext/mininext.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { url, Mini, type HtmlHandler } from "./url";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
html,
|
|
4
|
+
json,
|
|
5
|
+
isError,
|
|
6
|
+
HtmlString,
|
|
7
|
+
head,
|
|
8
|
+
commonHead,
|
|
9
|
+
cssReset,
|
|
10
|
+
} from "./html";
|
|
3
11
|
import { watch } from "fs/promises";
|
|
4
12
|
import * as path from "path";
|
|
5
13
|
function projectRoot() {
|
|
@@ -170,9 +178,11 @@ async function makeEntrypoint() {
|
|
|
170
178
|
}
|
|
171
179
|
return module.default as (w: any) => Promise<Response>;
|
|
172
180
|
}
|
|
173
|
-
|
|
181
|
+
const css = html;
|
|
174
182
|
export {
|
|
175
183
|
url,
|
|
184
|
+
css,
|
|
185
|
+
json,
|
|
176
186
|
html,
|
|
177
187
|
head,
|
|
178
188
|
build,
|