elegance-js 2.0.17 → 2.0.19
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/package.json +1 -1
- package/scripts/prod.js +1 -0
- package/dist/docs/components/Header.d.ts +0 -1
- package/dist/docs/components/Header.mjs +0 -249
- package/dist/docs/components/RootLayout.d.ts +0 -1
- package/dist/docs/components/RootLayout.mjs +0 -10
- package/dist/docs/docs/basics/page.d.ts +0 -2
- package/dist/docs/docs/basics/page.mjs +0 -1057
- package/dist/docs/docs/compilations/page.d.ts +0 -2
- package/dist/docs/docs/compilations/page.mjs +0 -15
- package/dist/docs/docs/components/CodeBlock.d.ts +0 -2
- package/dist/docs/docs/components/CodeBlock.mjs +0 -324
- package/dist/docs/docs/components/DocsLayout.d.ts +0 -1
- package/dist/docs/docs/components/DocsLayout.mjs +0 -527
- package/dist/docs/docs/components/Header.d.ts +0 -1
- package/dist/docs/docs/components/Header.mjs +0 -160
- package/dist/docs/docs/components/Mono.d.ts +0 -1
- package/dist/docs/docs/components/Mono.mjs +0 -7
- package/dist/docs/docs/components/PageHeading.d.ts +0 -1
- package/dist/docs/docs/components/PageHeading.mjs +0 -9
- package/dist/docs/docs/components/Paragraph.d.ts +0 -1
- package/dist/docs/docs/components/Paragraph.mjs +0 -10
- package/dist/docs/docs/components/Separator.d.ts +0 -1
- package/dist/docs/docs/components/Separator.mjs +0 -7
- package/dist/docs/docs/components/SubHeading.d.ts +0 -1
- package/dist/docs/docs/components/SubHeading.mjs +0 -8
- package/dist/docs/docs/components/SubSeparator.d.ts +0 -1
- package/dist/docs/docs/components/SubSeparator.mjs +0 -7
- package/dist/docs/docs/components/Subtext.d.ts +0 -1
- package/dist/docs/docs/components/Subtext.mjs +0 -8
- package/dist/docs/docs/concepts/page.d.ts +0 -2
- package/dist/docs/docs/concepts/page.mjs +0 -954
- package/dist/docs/docs/page-files/page.d.ts +0 -2
- package/dist/docs/docs/page-files/page.mjs +0 -1206
- package/dist/docs/docs/route.d.ts +0 -2
- package/dist/docs/docs/route.mjs +0 -8
- package/dist/docs/docs/running/page.d.ts +0 -2
- package/dist/docs/docs/running/page.mjs +0 -7
- package/dist/docs/nullpage/page.d.ts +0 -2
- package/dist/docs/nullpage/page.mjs +0 -58
- package/dist/docs/page.d.ts +0 -2
- package/dist/docs/page.mjs +0 -437
- package/dist/docs/utils/MEGALEXER.d.ts +0 -1
- package/dist/docs/utils/MEGALEXER.mjs +0 -171
- package/dist/types/Metadata.d.ts +0 -19
- package/dist/types/Metadata.mjs +0 -15
|
@@ -1,1206 +0,0 @@
|
|
|
1
|
-
// src/internal/deprecate.ts
|
|
2
|
-
var ShowDeprecationWarning = (msg) => {
|
|
3
|
-
console.warn("\x1B[31m", msg, "\x1B[0m");
|
|
4
|
-
console.trace("Stack Trace:");
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/server/loadHook.ts
|
|
8
|
-
var loadHook = (deps, fn, bind) => {
|
|
9
|
-
const stringFn = fn.toString();
|
|
10
|
-
const depsArray = (deps || []).map((dep) => ({
|
|
11
|
-
id: dep.id,
|
|
12
|
-
bind: dep.bind
|
|
13
|
-
}));
|
|
14
|
-
let dependencyString = "[";
|
|
15
|
-
for (const dep of depsArray) {
|
|
16
|
-
dependencyString += `{id:${dep.id}`;
|
|
17
|
-
if (dep.bind) dependencyString += `,bind:${dep.bind}`;
|
|
18
|
-
dependencyString += `},`;
|
|
19
|
-
}
|
|
20
|
-
dependencyString += "]";
|
|
21
|
-
const isAsync = fn.constructor.name === "AsyncFunction";
|
|
22
|
-
const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
|
|
23
|
-
globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
|
|
24
|
-
fn: wrapperFn,
|
|
25
|
-
bind: bind || ""
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var createLoadHook = (options) => {
|
|
29
|
-
ShowDeprecationWarning("WARNING: createLoadHook() is a deprecated function. Use loadHook() from elegance-js/loadHook instead.");
|
|
30
|
-
const stringFn = options.fn.toString();
|
|
31
|
-
const deps = (options.deps || []).map((dep) => ({
|
|
32
|
-
id: dep.id,
|
|
33
|
-
bind: dep.bind
|
|
34
|
-
}));
|
|
35
|
-
let dependencyString = "[";
|
|
36
|
-
for (const dep of deps) {
|
|
37
|
-
dependencyString += `{id:${dep.id}`;
|
|
38
|
-
if (dep.bind) dependencyString += `,bind:${dep.bind}`;
|
|
39
|
-
dependencyString += `},`;
|
|
40
|
-
}
|
|
41
|
-
dependencyString += "]";
|
|
42
|
-
const isAsync = options.fn.constructor.name === "AsyncFunction";
|
|
43
|
-
const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
|
|
44
|
-
globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
|
|
45
|
-
fn: wrapperFn,
|
|
46
|
-
bind: options.bind || ""
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// src/server/state.ts
|
|
51
|
-
if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
|
|
52
|
-
globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
|
|
53
|
-
}
|
|
54
|
-
var eventListener = (dependencies, eventListener2) => {
|
|
55
|
-
const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
|
|
56
|
-
let dependencyString = "[";
|
|
57
|
-
for (const dep of deps) {
|
|
58
|
-
dependencyString += `{id:${dep.id}`;
|
|
59
|
-
if (dep.bind) dependencyString += `,bind:${dep.bind}`;
|
|
60
|
-
dependencyString += `},`;
|
|
61
|
-
}
|
|
62
|
-
dependencyString += "]";
|
|
63
|
-
const value = {
|
|
64
|
-
id: __SERVER_CURRENT_STATE_ID__ += 1,
|
|
65
|
-
type: 1 /* STATE */,
|
|
66
|
-
value: new Function(
|
|
67
|
-
"state",
|
|
68
|
-
"event",
|
|
69
|
-
`(${eventListener2.toString()})(event, ...state.getAll(${dependencyString}))`
|
|
70
|
-
)
|
|
71
|
-
};
|
|
72
|
-
globalThis.__SERVER_CURRENT_STATE__.push(value);
|
|
73
|
-
return value;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// src/server/observe.ts
|
|
77
|
-
var observe = (refs, update) => {
|
|
78
|
-
const returnValue = {
|
|
79
|
-
type: 2 /* OBSERVER */,
|
|
80
|
-
initialValues: refs.map((ref) => ref.value),
|
|
81
|
-
update,
|
|
82
|
-
refs: refs.map((ref) => ({
|
|
83
|
-
id: ref.id,
|
|
84
|
-
bind: ref.bind
|
|
85
|
-
}))
|
|
86
|
-
};
|
|
87
|
-
return returnValue;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// src/components/Link.ts
|
|
91
|
-
loadHook(
|
|
92
|
-
[],
|
|
93
|
-
() => {
|
|
94
|
-
const anchors = Array.from(document.querySelectorAll("a[prefetch]"));
|
|
95
|
-
const elsToClear = [];
|
|
96
|
-
for (const anchor of anchors) {
|
|
97
|
-
const prefetch = anchor.getAttribute("prefetch");
|
|
98
|
-
const href = new URL(anchor.href);
|
|
99
|
-
switch (prefetch) {
|
|
100
|
-
case "load":
|
|
101
|
-
client.fetchPage(href);
|
|
102
|
-
break;
|
|
103
|
-
case "hover":
|
|
104
|
-
const fn = () => {
|
|
105
|
-
client.fetchPage(href);
|
|
106
|
-
};
|
|
107
|
-
anchor.addEventListener("mouseenter", fn);
|
|
108
|
-
elsToClear.push({
|
|
109
|
-
el: anchor,
|
|
110
|
-
fn
|
|
111
|
-
});
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return () => {
|
|
116
|
-
for (const listener of elsToClear) {
|
|
117
|
-
listener.el.removeEventListener("mouseenter", listener.fn);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
var navigate = eventListener(
|
|
123
|
-
[],
|
|
124
|
-
(event) => {
|
|
125
|
-
const target = new URL(event.currentTarget.href);
|
|
126
|
-
const client2 = globalThis.client;
|
|
127
|
-
const sanitizedTarget = client2.sanitizePathname(target.pathname);
|
|
128
|
-
const sanitizedCurrent = client2.sanitizePathname(window.location.pathname);
|
|
129
|
-
if (sanitizedTarget === sanitizedCurrent) {
|
|
130
|
-
if (target.hash === window.location.hash) return event.preventDefault();
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
event.preventDefault();
|
|
134
|
-
client2.navigateLocally(target.href);
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
var Link = (options, ...children) => {
|
|
138
|
-
if (!options.href) {
|
|
139
|
-
throw `Link elements must have a HREF attribute set.`;
|
|
140
|
-
}
|
|
141
|
-
if (!options.href.startsWith("/")) {
|
|
142
|
-
throw `Link elements may only navigate to local pages. "/"`;
|
|
143
|
-
}
|
|
144
|
-
return a(
|
|
145
|
-
{
|
|
146
|
-
...options,
|
|
147
|
-
onClick: navigate
|
|
148
|
-
},
|
|
149
|
-
...children
|
|
150
|
-
);
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// src/docs/components/RootLayout.ts
|
|
154
|
-
var RootLayout = (...children) => body(
|
|
155
|
-
{
|
|
156
|
-
class: "bg-background-900 text-text-50 font-inter select-none text-text-50"
|
|
157
|
-
},
|
|
158
|
-
...children
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
// src/server/createState.ts
|
|
162
|
-
if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
|
|
163
|
-
globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
|
|
164
|
-
}
|
|
165
|
-
var createState = (value, options) => {
|
|
166
|
-
ShowDeprecationWarning("WARNING: The createState() and function is deprecated. Please use state() instead, from elegance-js/state.");
|
|
167
|
-
const serverStateEntry = {
|
|
168
|
-
id: __SERVER_CURRENT_STATE_ID__ += 1,
|
|
169
|
-
value,
|
|
170
|
-
type: 1 /* STATE */,
|
|
171
|
-
bind: options?.bind
|
|
172
|
-
};
|
|
173
|
-
globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
|
|
174
|
-
return serverStateEntry;
|
|
175
|
-
};
|
|
176
|
-
var createEventListener = ({
|
|
177
|
-
eventListener: eventListener2,
|
|
178
|
-
dependencies = [],
|
|
179
|
-
params
|
|
180
|
-
}) => {
|
|
181
|
-
ShowDeprecationWarning("WARNING: The createEventListener() and function is deprecated. Please use eventListener() instead, from elegance-js/state.");
|
|
182
|
-
const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
|
|
183
|
-
let dependencyString = "[";
|
|
184
|
-
for (const dep of deps) {
|
|
185
|
-
dependencyString += `{id:${dep.id}`;
|
|
186
|
-
if (dep.bind) dependencyString += `,bind:${dep.bind}`;
|
|
187
|
-
dependencyString += `},`;
|
|
188
|
-
}
|
|
189
|
-
dependencyString += "]";
|
|
190
|
-
const value = {
|
|
191
|
-
id: __SERVER_CURRENT_STATE_ID__ += 1,
|
|
192
|
-
type: 1 /* STATE */,
|
|
193
|
-
value: new Function(
|
|
194
|
-
"state",
|
|
195
|
-
"event",
|
|
196
|
-
`(${eventListener2.toString()})({ event, ...${JSON.stringify(params || {})} }, ...state.getAll(${dependencyString}))`
|
|
197
|
-
)
|
|
198
|
-
};
|
|
199
|
-
globalThis.__SERVER_CURRENT_STATE__.push(value);
|
|
200
|
-
return value;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
// src/docs/utils/MEGALEXER.ts
|
|
204
|
-
var tokenize = (input) => {
|
|
205
|
-
const tokens = [];
|
|
206
|
-
const length = input.length;
|
|
207
|
-
let index = 0;
|
|
208
|
-
const keywords = /* @__PURE__ */ new Set([
|
|
209
|
-
"if",
|
|
210
|
-
"else",
|
|
211
|
-
"for",
|
|
212
|
-
"while",
|
|
213
|
-
"function",
|
|
214
|
-
"return",
|
|
215
|
-
"class",
|
|
216
|
-
"const",
|
|
217
|
-
"let",
|
|
218
|
-
"var",
|
|
219
|
-
"interface",
|
|
220
|
-
"extends",
|
|
221
|
-
"implements",
|
|
222
|
-
"export",
|
|
223
|
-
"import",
|
|
224
|
-
"from"
|
|
225
|
-
]);
|
|
226
|
-
const operatorChars = /* @__PURE__ */ new Set([
|
|
227
|
-
"+",
|
|
228
|
-
"-",
|
|
229
|
-
"*",
|
|
230
|
-
"/",
|
|
231
|
-
"%",
|
|
232
|
-
"=",
|
|
233
|
-
">",
|
|
234
|
-
"<",
|
|
235
|
-
"!",
|
|
236
|
-
"&",
|
|
237
|
-
"|",
|
|
238
|
-
"^",
|
|
239
|
-
"~",
|
|
240
|
-
"?",
|
|
241
|
-
":"
|
|
242
|
-
]);
|
|
243
|
-
const punctuationChars = /* @__PURE__ */ new Set([
|
|
244
|
-
";",
|
|
245
|
-
",",
|
|
246
|
-
".",
|
|
247
|
-
"(",
|
|
248
|
-
")",
|
|
249
|
-
"{",
|
|
250
|
-
"}",
|
|
251
|
-
"[",
|
|
252
|
-
"]"
|
|
253
|
-
]);
|
|
254
|
-
const peek = (offset = 1) => index + offset < length ? input[index + offset] : "";
|
|
255
|
-
const readWhile = (predicate) => {
|
|
256
|
-
const start = index;
|
|
257
|
-
while (index < length && predicate(input[index])) {
|
|
258
|
-
index++;
|
|
259
|
-
}
|
|
260
|
-
return input.slice(start, index);
|
|
261
|
-
};
|
|
262
|
-
const readString = (quoteType) => {
|
|
263
|
-
let value = input[index++];
|
|
264
|
-
while (index < length && input[index] !== quoteType) {
|
|
265
|
-
if (input[index] === "\\") {
|
|
266
|
-
value += input[index++];
|
|
267
|
-
if (index < length) {
|
|
268
|
-
value += input[index++];
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
value += input[index++];
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (index < length) {
|
|
275
|
-
value += input[index++];
|
|
276
|
-
}
|
|
277
|
-
return value;
|
|
278
|
-
};
|
|
279
|
-
const readLineComment = () => {
|
|
280
|
-
const start = index;
|
|
281
|
-
index += 2;
|
|
282
|
-
while (index < length && input[index] !== "\n") {
|
|
283
|
-
index++;
|
|
284
|
-
}
|
|
285
|
-
return input.slice(start, index);
|
|
286
|
-
};
|
|
287
|
-
const readBlockComment = () => {
|
|
288
|
-
const start = index;
|
|
289
|
-
index += 2;
|
|
290
|
-
while (index < length && !(input[index] === "*" && peek() === "/")) {
|
|
291
|
-
index++;
|
|
292
|
-
}
|
|
293
|
-
if (index < length) {
|
|
294
|
-
index += 2;
|
|
295
|
-
}
|
|
296
|
-
return input.slice(start, index);
|
|
297
|
-
};
|
|
298
|
-
while (index < length) {
|
|
299
|
-
const char = input[index];
|
|
300
|
-
const startPos = index;
|
|
301
|
-
if (/\s/.test(char)) {
|
|
302
|
-
const value = readWhile((c) => /\s/.test(c));
|
|
303
|
-
tokens.push({ type: "" /* Whitespace */, value, position: startPos });
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (char === "/") {
|
|
307
|
-
if (peek() === "/") {
|
|
308
|
-
const value = readLineComment();
|
|
309
|
-
tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
|
|
310
|
-
continue;
|
|
311
|
-
} else if (peek() === "*") {
|
|
312
|
-
const value = readBlockComment();
|
|
313
|
-
tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (char === '"' || char === "'") {
|
|
318
|
-
const value = readString(char);
|
|
319
|
-
tokens.push({ type: "text-green-200" /* String */, value, position: startPos });
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
if (/\d/.test(char)) {
|
|
323
|
-
const value = readWhile((c) => /[\d\.]/.test(c));
|
|
324
|
-
tokens.push({ type: "text-blue-400" /* Number */, value, position: startPos });
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
if (/[a-zA-Z_$]/.test(char)) {
|
|
328
|
-
const value = readWhile((c) => /[a-zA-Z0-9_$]/.test(c));
|
|
329
|
-
let type = "text-orange-300" /* Identifier */;
|
|
330
|
-
if (keywords.has(value)) {
|
|
331
|
-
type = "text-amber-100 font-semibold" /* Keyword */;
|
|
332
|
-
} else if (value === "true" || value === "false") {
|
|
333
|
-
type = "text-blue-200" /* Boolean */;
|
|
334
|
-
}
|
|
335
|
-
let tempIndex = index;
|
|
336
|
-
while (tempIndex < length && /\s/.test(input[tempIndex])) {
|
|
337
|
-
tempIndex++;
|
|
338
|
-
}
|
|
339
|
-
if (tempIndex < length && input[tempIndex] === "(") {
|
|
340
|
-
type = "text-red-300" /* FunctionCall */;
|
|
341
|
-
}
|
|
342
|
-
tokens.push({ type, value, position: startPos });
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
if (operatorChars.has(char)) {
|
|
346
|
-
let value = char;
|
|
347
|
-
index++;
|
|
348
|
-
if (index < length && operatorChars.has(input[index])) {
|
|
349
|
-
value += input[index++];
|
|
350
|
-
}
|
|
351
|
-
tokens.push({ type: "" /* Operator */, value, position: startPos });
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
if (punctuationChars.has(char)) {
|
|
355
|
-
tokens.push({ type: "text-gray-400" /* Punctuation */, value: char, position: startPos });
|
|
356
|
-
index++;
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
tokens.push({ type: "" /* Unknown */, value: char, position: startPos });
|
|
360
|
-
index++;
|
|
361
|
-
}
|
|
362
|
-
return tokens;
|
|
363
|
-
};
|
|
364
|
-
var escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
365
|
-
var highlightCode = (code) => {
|
|
366
|
-
const tokens = tokenize(code);
|
|
367
|
-
return tokens.map(
|
|
368
|
-
(token) => token.type === "" /* Whitespace */ ? token.value : `<span class="${token.type}">${escapeHtml(token.value)}</span>`
|
|
369
|
-
).join("");
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// src/docs/docs/components/CodeBlock.ts
|
|
373
|
-
var isToastShowing = createState(false);
|
|
374
|
-
var toastTimeoutId = createState(0);
|
|
375
|
-
var copyCode = createEventListener({
|
|
376
|
-
dependencies: [
|
|
377
|
-
isToastShowing,
|
|
378
|
-
toastTimeoutId
|
|
379
|
-
],
|
|
380
|
-
eventListener: async (params, isToastShowing2, toastTimeoutId2) => {
|
|
381
|
-
const children = params.event.currentTarget.children;
|
|
382
|
-
const pre2 = children.item(0);
|
|
383
|
-
const content = pre2.innerText;
|
|
384
|
-
await navigator.clipboard.writeText(content);
|
|
385
|
-
if (toastTimeoutId2.value !== 0) clearTimeout(toastTimeoutId2.value);
|
|
386
|
-
isToastShowing2.value = true;
|
|
387
|
-
isToastShowing2.signal();
|
|
388
|
-
const timeoutId = window.setTimeout(() => {
|
|
389
|
-
isToastShowing2.value = false;
|
|
390
|
-
isToastShowing2.signal();
|
|
391
|
-
}, 3e3);
|
|
392
|
-
toastTimeoutId2.value = timeoutId;
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
var Toast = (bind) => {
|
|
396
|
-
createLoadHook({
|
|
397
|
-
bind,
|
|
398
|
-
deps: [
|
|
399
|
-
toastTimeoutId,
|
|
400
|
-
isToastShowing
|
|
401
|
-
],
|
|
402
|
-
fn: (state2, toastTimeoutId2, isToastShowing2) => {
|
|
403
|
-
return () => {
|
|
404
|
-
clearTimeout(toastTimeoutId2.value);
|
|
405
|
-
isToastShowing2.value = false;
|
|
406
|
-
isToastShowing2.signal();
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
return div(
|
|
411
|
-
{
|
|
412
|
-
class: observe(
|
|
413
|
-
[isToastShowing],
|
|
414
|
-
(isShowing) => {
|
|
415
|
-
const modularClass = isShowing ? "right-8" : "right-0 translate-x-full";
|
|
416
|
-
return `fixed z-50 shadow-lg rounded-sm duration-200 bottom-4 px-4 py-2 w-max bg-background-950 ` + modularClass;
|
|
417
|
-
}
|
|
418
|
-
)
|
|
419
|
-
},
|
|
420
|
-
h1({
|
|
421
|
-
class: "font-mono uppercase"
|
|
422
|
-
}, "copied to clipboard")
|
|
423
|
-
);
|
|
424
|
-
};
|
|
425
|
-
var escapeHtml2 = (str) => {
|
|
426
|
-
const replaced = str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
427
|
-
return replaced;
|
|
428
|
-
};
|
|
429
|
-
var CodeBlock = (value, parse = true) => div(
|
|
430
|
-
{
|
|
431
|
-
class: `bg-background-950 hover:cursor-pointer p-2 rounded-sm
|
|
432
|
-
border-[1px] border-background-800 w-max my-3 max-w-full
|
|
433
|
-
overflow-scroll`,
|
|
434
|
-
onClick: copyCode
|
|
435
|
-
},
|
|
436
|
-
pre({}, parse ? highlightCode(value) : escapeHtml2(value))
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
// src/components/Breakpoint.ts
|
|
440
|
-
var Breakpoint = (options, ...children) => {
|
|
441
|
-
process.emitWarning(
|
|
442
|
-
"Function Breakpoint() is deprecated. Prefer layout.ts files instead.",
|
|
443
|
-
{ type: "DeprecationWarning" }
|
|
444
|
-
);
|
|
445
|
-
if (options.id === void 0) throw `Breakpoints must set a name attribute.`;
|
|
446
|
-
const id = options.id;
|
|
447
|
-
delete options.id;
|
|
448
|
-
return div(
|
|
449
|
-
{
|
|
450
|
-
bp: id,
|
|
451
|
-
...options
|
|
452
|
-
},
|
|
453
|
-
...children
|
|
454
|
-
);
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
// src/docs/docs/components/Header.ts
|
|
458
|
-
var Header = () => header(
|
|
459
|
-
{
|
|
460
|
-
class: "sticky z-10 lef-0 right-0 top-0 text-text-50 font-inter overflow-hidden duration-300 border-b-[1px] border-b-transparent"
|
|
461
|
-
},
|
|
462
|
-
div(
|
|
463
|
-
{
|
|
464
|
-
class: "group duration-300 border-b-[1px] hover:border-b-transparent pointer-fine:hover:bg-accent-400 border-b-background-800 bg-background-950"
|
|
465
|
-
},
|
|
466
|
-
div(
|
|
467
|
-
{
|
|
468
|
-
class: "max-w-[1200px] w-full mx-auto flex pr-2 px-3 sm:px-5 sm:min-[calc(1200px+1rem)]:px-0"
|
|
469
|
-
},
|
|
470
|
-
div(
|
|
471
|
-
{
|
|
472
|
-
class: "flex min-w-max w-full items-center z-10"
|
|
473
|
-
},
|
|
474
|
-
Link(
|
|
475
|
-
{
|
|
476
|
-
href: "/",
|
|
477
|
-
class: "flex items-center gap-1 h-full"
|
|
478
|
-
},
|
|
479
|
-
p({
|
|
480
|
-
class: "font-niconne pointer-fine:group-hover:text-background-950 font-bold text-xl sm:text-3xl relative top-0 z-20 duration-300 pointer-events-none",
|
|
481
|
-
innerText: "Elegance"
|
|
482
|
-
}),
|
|
483
|
-
p({
|
|
484
|
-
innerText: "JS",
|
|
485
|
-
class: "font-bold pointer-fine:group-hover:text-background-950 relative top-0 text-xl sm:text-3xl z-10 text-accent-400 duration-300 pointer-events-none"
|
|
486
|
-
})
|
|
487
|
-
)
|
|
488
|
-
),
|
|
489
|
-
div(
|
|
490
|
-
{
|
|
491
|
-
class: "flex py-2 sm:py-4 flex relative items-center justify-end w-full"
|
|
492
|
-
},
|
|
493
|
-
Link({
|
|
494
|
-
prefetch: "hover",
|
|
495
|
-
class: "z-10 text-xs uppercase font-bold px-4 py-2 rounded-full duration-300 bg-accent-400 text-primary-900 pointer-fine:group-hover:bg-background-950 pointer-fine:group-hover:text-accent-400 group-hover:hover:bg-text-50 group-hover:hover:text-background-950",
|
|
496
|
-
href: "/docs",
|
|
497
|
-
innerText: "Docs"
|
|
498
|
-
})
|
|
499
|
-
)
|
|
500
|
-
)
|
|
501
|
-
)
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
// src/server/layout.ts
|
|
505
|
-
if (!globalThis.__SERVER_CURRENT_LAYOUT_ID__) globalThis.__SERVER_CURRENT_LAYOUT_ID__ = 1;
|
|
506
|
-
var createLayout = (name) => {
|
|
507
|
-
process.emitWarning(
|
|
508
|
-
"Function createLayout() is deprecated. Prefer layout.ts files instead.",
|
|
509
|
-
{ type: "DeprecationWarning" }
|
|
510
|
-
);
|
|
511
|
-
const layouts = globalThis.__SERVER_CURRENT_LAYOUTS__;
|
|
512
|
-
if (layouts.has(name)) return layouts.get(name);
|
|
513
|
-
const id = globalThis.__SERVER_CURRENT_LAYOUT_ID__ += 1;
|
|
514
|
-
layouts.set(name, id);
|
|
515
|
-
return id;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
// src/docs/docs/components/DocsLayout.ts
|
|
519
|
-
var docsLayoutId = createLayout("docs-layout");
|
|
520
|
-
var secondsSpentOnPage = createState(0, {
|
|
521
|
-
bind: docsLayoutId
|
|
522
|
-
});
|
|
523
|
-
createLoadHook({
|
|
524
|
-
deps: [secondsSpentOnPage],
|
|
525
|
-
bind: docsLayoutId,
|
|
526
|
-
fn: (state2, time) => {
|
|
527
|
-
const storedTime = localStorage.getItem("time-on-page");
|
|
528
|
-
if (storedTime) {
|
|
529
|
-
time.value = parseInt(storedTime);
|
|
530
|
-
time.signal();
|
|
531
|
-
}
|
|
532
|
-
let intervalId;
|
|
533
|
-
intervalId = setInterval(() => {
|
|
534
|
-
time.value++;
|
|
535
|
-
time.signal();
|
|
536
|
-
}, 1e3);
|
|
537
|
-
const handlePageLeave = () => {
|
|
538
|
-
localStorage.setItem("time-on-page", `${time.value}`);
|
|
539
|
-
};
|
|
540
|
-
window.addEventListener("beforeunload", handlePageLeave);
|
|
541
|
-
return () => {
|
|
542
|
-
window.removeEventListener("beforeunload", handlePageLeave);
|
|
543
|
-
handlePageLeave();
|
|
544
|
-
clearInterval(intervalId);
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
var NavSubLink = (href, innerText) => Link({
|
|
549
|
-
class: "text-sm font-normal flex flex-col gap-2 opacity-80 hover:opacity-60 duration-200",
|
|
550
|
-
innerText,
|
|
551
|
-
href,
|
|
552
|
-
prefetch: "hover"
|
|
553
|
-
});
|
|
554
|
-
var Sidebar = () => nav(
|
|
555
|
-
{
|
|
556
|
-
class: "w-1/5"
|
|
557
|
-
},
|
|
558
|
-
ul(
|
|
559
|
-
{
|
|
560
|
-
class: "flex flex-col gap-4"
|
|
561
|
-
},
|
|
562
|
-
li(
|
|
563
|
-
{},
|
|
564
|
-
h2(
|
|
565
|
-
{
|
|
566
|
-
class: "text-lg font-semibold"
|
|
567
|
-
},
|
|
568
|
-
"Quick Nav"
|
|
569
|
-
),
|
|
570
|
-
span(
|
|
571
|
-
{
|
|
572
|
-
class: "text-xs opacity-75"
|
|
573
|
-
},
|
|
574
|
-
"Elapsed: ",
|
|
575
|
-
span({
|
|
576
|
-
class: "font-mono",
|
|
577
|
-
innerText: observe(
|
|
578
|
-
[secondsSpentOnPage],
|
|
579
|
-
(secondsSpentOnPage2) => {
|
|
580
|
-
const hours = Math.floor(secondsSpentOnPage2 / 60 / 60);
|
|
581
|
-
const minutes = Math.floor(secondsSpentOnPage2 / 60 % 60);
|
|
582
|
-
const seconds = secondsSpentOnPage2 % 60;
|
|
583
|
-
return `${hours}h:${minutes}m:${seconds}s`;
|
|
584
|
-
}
|
|
585
|
-
)
|
|
586
|
-
})
|
|
587
|
-
)
|
|
588
|
-
),
|
|
589
|
-
li(
|
|
590
|
-
{
|
|
591
|
-
class: "flex flex-col gap-1"
|
|
592
|
-
},
|
|
593
|
-
h4({
|
|
594
|
-
class: "text-base font-medium",
|
|
595
|
-
innerText: "The Basics"
|
|
596
|
-
}),
|
|
597
|
-
ol(
|
|
598
|
-
{
|
|
599
|
-
class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
|
|
600
|
-
},
|
|
601
|
-
NavSubLink(
|
|
602
|
-
"/docs/basics#preamble",
|
|
603
|
-
"Preamble"
|
|
604
|
-
),
|
|
605
|
-
NavSubLink(
|
|
606
|
-
"/docs/basics#how-elegance-works",
|
|
607
|
-
"How Elegance Works"
|
|
608
|
-
),
|
|
609
|
-
NavSubLink(
|
|
610
|
-
"/docs/basics#installation",
|
|
611
|
-
"Installation"
|
|
612
|
-
),
|
|
613
|
-
NavSubLink(
|
|
614
|
-
"/docs/basics#your-first-page",
|
|
615
|
-
"Your First Page"
|
|
616
|
-
)
|
|
617
|
-
)
|
|
618
|
-
),
|
|
619
|
-
li(
|
|
620
|
-
{
|
|
621
|
-
class: "flex flex-col gap-1"
|
|
622
|
-
},
|
|
623
|
-
h4({
|
|
624
|
-
class: "text-base font-medium",
|
|
625
|
-
innerText: "Concepts"
|
|
626
|
-
}),
|
|
627
|
-
ol(
|
|
628
|
-
{
|
|
629
|
-
class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
|
|
630
|
-
},
|
|
631
|
-
NavSubLink(
|
|
632
|
-
"/docs/concepts#elements",
|
|
633
|
-
"Elements"
|
|
634
|
-
),
|
|
635
|
-
NavSubLink(
|
|
636
|
-
"/docs/concepts#object-attributes",
|
|
637
|
-
"Object Attributes"
|
|
638
|
-
)
|
|
639
|
-
)
|
|
640
|
-
),
|
|
641
|
-
li(
|
|
642
|
-
{
|
|
643
|
-
class: "flex flex-col gap-1"
|
|
644
|
-
},
|
|
645
|
-
h4({
|
|
646
|
-
class: "text-base font-medium",
|
|
647
|
-
innerText: "Page Files"
|
|
648
|
-
}),
|
|
649
|
-
ol(
|
|
650
|
-
{
|
|
651
|
-
class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
|
|
652
|
-
},
|
|
653
|
-
NavSubLink(
|
|
654
|
-
"/docs/page-files#state",
|
|
655
|
-
"State"
|
|
656
|
-
),
|
|
657
|
-
NavSubLink(
|
|
658
|
-
"/docs/page-files#load-hooks",
|
|
659
|
-
"Load Hooks"
|
|
660
|
-
),
|
|
661
|
-
NavSubLink(
|
|
662
|
-
"/docs/page-files#event-listeners",
|
|
663
|
-
"Event Listeners"
|
|
664
|
-
),
|
|
665
|
-
NavSubLink(
|
|
666
|
-
"/docs/page-files#layouts",
|
|
667
|
-
"Layouts"
|
|
668
|
-
)
|
|
669
|
-
)
|
|
670
|
-
),
|
|
671
|
-
li(
|
|
672
|
-
{
|
|
673
|
-
class: "flex flex-col gap-1"
|
|
674
|
-
},
|
|
675
|
-
h4({
|
|
676
|
-
class: "text-base font-medium",
|
|
677
|
-
innerText: "Compilation"
|
|
678
|
-
}),
|
|
679
|
-
ol(
|
|
680
|
-
{
|
|
681
|
-
class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
|
|
682
|
-
},
|
|
683
|
-
NavSubLink(
|
|
684
|
-
"/docs/compilation#options",
|
|
685
|
-
"Compilation Options"
|
|
686
|
-
)
|
|
687
|
-
)
|
|
688
|
-
)
|
|
689
|
-
)
|
|
690
|
-
);
|
|
691
|
-
var DocsLayout = (...children) => div(
|
|
692
|
-
{
|
|
693
|
-
class: "h-screen overflow-clip"
|
|
694
|
-
},
|
|
695
|
-
Header(),
|
|
696
|
-
Toast(docsLayoutId),
|
|
697
|
-
div(
|
|
698
|
-
{
|
|
699
|
-
class: "max-w-[1200px] h-full w-full mx-auto flex pt-8 px-3 sm:px-5 sm:min-[calc(1200px+1rem)]:px-0"
|
|
700
|
-
},
|
|
701
|
-
Sidebar(),
|
|
702
|
-
article(
|
|
703
|
-
{
|
|
704
|
-
class: "h-full w-full overflow-y-scroll pb-[250px] pl-6 ml-6"
|
|
705
|
-
},
|
|
706
|
-
Breakpoint(
|
|
707
|
-
{
|
|
708
|
-
id: docsLayoutId
|
|
709
|
-
},
|
|
710
|
-
...children
|
|
711
|
-
)
|
|
712
|
-
)
|
|
713
|
-
)
|
|
714
|
-
);
|
|
715
|
-
|
|
716
|
-
// src/docs/docs/components/Mono.ts
|
|
717
|
-
var Mono = (text) => span({
|
|
718
|
-
class: "font-mono select-text"
|
|
719
|
-
}, text);
|
|
720
|
-
|
|
721
|
-
// src/docs/docs/components/PageHeading.ts
|
|
722
|
-
var PageHeading = (title2, id) => h2({
|
|
723
|
-
class: "text-3xl font-semibold mb-4",
|
|
724
|
-
id,
|
|
725
|
-
innerText: title2
|
|
726
|
-
});
|
|
727
|
-
|
|
728
|
-
// src/docs/docs/components/Paragraph.ts
|
|
729
|
-
var Paragraph = (...children) => p(
|
|
730
|
-
{
|
|
731
|
-
class: "opacity-80"
|
|
732
|
-
},
|
|
733
|
-
...children
|
|
734
|
-
);
|
|
735
|
-
|
|
736
|
-
// src/docs/docs/components/Separator.ts
|
|
737
|
-
var Separator = () => div({
|
|
738
|
-
class: "my-20"
|
|
739
|
-
}, []);
|
|
740
|
-
|
|
741
|
-
// src/docs/docs/components/SubHeading.ts
|
|
742
|
-
var SubHeading = (content) => h3({
|
|
743
|
-
class: "text-lg font-medium mb-1",
|
|
744
|
-
innerText: content
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
// src/docs/docs/components/SubSeparator.ts
|
|
748
|
-
var SubSeparator = () => div({
|
|
749
|
-
class: "my-10"
|
|
750
|
-
}, []);
|
|
751
|
-
|
|
752
|
-
// src/docs/docs/components/Subtext.ts
|
|
753
|
-
var Subtext = (text) => span({
|
|
754
|
-
class: "text-xs opacity-60",
|
|
755
|
-
innerText: text
|
|
756
|
-
});
|
|
757
|
-
|
|
758
|
-
// src/docs/docs/page-files/page.ts
|
|
759
|
-
var exampleLoadHook = `
|
|
760
|
-
createLoadHook({
|
|
761
|
-
fn: () => {
|
|
762
|
-
console.log("The page has loaded!");
|
|
763
|
-
},
|
|
764
|
-
});
|
|
765
|
-
`;
|
|
766
|
-
var exampleCleanupFunction = `
|
|
767
|
-
const counter = createState(0);
|
|
768
|
-
|
|
769
|
-
createLoadHook({
|
|
770
|
-
deps: [counter],
|
|
771
|
-
fn: (state, counter) => {
|
|
772
|
-
const timer = setInterval(() => {
|
|
773
|
-
counter.value++;
|
|
774
|
-
counter.signal();
|
|
775
|
-
}, 100);
|
|
776
|
-
|
|
777
|
-
return () => {
|
|
778
|
-
// Begone, timer!
|
|
779
|
-
clearInterval(timer);
|
|
780
|
-
}
|
|
781
|
-
},
|
|
782
|
-
});
|
|
783
|
-
`;
|
|
784
|
-
var exampleLoadHookBind = `
|
|
785
|
-
const layout = createLayout("epic-layout");
|
|
786
|
-
|
|
787
|
-
createLoadHook({
|
|
788
|
-
bind: layout,
|
|
789
|
-
fn: () => {
|
|
790
|
-
alert("epic layout was just rendered")
|
|
791
|
-
|
|
792
|
-
return () => {
|
|
793
|
-
alert ("epic layout is no longer with us :(")
|
|
794
|
-
};
|
|
795
|
-
},
|
|
796
|
-
})
|
|
797
|
-
`;
|
|
798
|
-
var exampleStateCreation = `
|
|
799
|
-
const superEpicState = createState("MMMMMMM STATE");
|
|
800
|
-
`;
|
|
801
|
-
var exampleStateCreationReturn = `
|
|
802
|
-
{
|
|
803
|
-
type: ObjectAttributeType.STATE,
|
|
804
|
-
id: 0,
|
|
805
|
-
value: "MMMMMMM STATE",
|
|
806
|
-
bind: undefined,
|
|
807
|
-
}
|
|
808
|
-
`;
|
|
809
|
-
var exampleStateReference = `
|
|
810
|
-
const isUsingDarkMode = createState(false);
|
|
811
|
-
|
|
812
|
-
div ({
|
|
813
|
-
class: observe(
|
|
814
|
-
[isUsingDarkMode],
|
|
815
|
-
(value) => value ? "bg-black" : "bg-white",
|
|
816
|
-
),
|
|
817
|
-
})
|
|
818
|
-
`;
|
|
819
|
-
var exampleStateLayoutBind = `
|
|
820
|
-
const docsLayout = createLayout("docs-layout");
|
|
821
|
-
|
|
822
|
-
const timeSpentOnPage = createState(0, {
|
|
823
|
-
bind: docsLayout
|
|
824
|
-
});
|
|
825
|
-
`;
|
|
826
|
-
var exampleCreateEventListener = `
|
|
827
|
-
const handleClick = createEventListener({
|
|
828
|
-
eventListener: (params: SetEvent<MouseEvent, HTMLDivElement>) => {
|
|
829
|
-
console.log(params.event);
|
|
830
|
-
console.log(params.event.currentTarget);
|
|
831
|
-
},
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
div ({
|
|
835
|
-
onClick: handleClick,
|
|
836
|
-
});
|
|
837
|
-
`;
|
|
838
|
-
var exampleCreateEventListenerDependencies = `
|
|
839
|
-
const counter = createState(0);
|
|
840
|
-
|
|
841
|
-
const handleClick = createEventListener({
|
|
842
|
-
dependencies: [counter],
|
|
843
|
-
eventListener: (params, counter) => {
|
|
844
|
-
counter++;
|
|
845
|
-
counter.signal();
|
|
846
|
-
},
|
|
847
|
-
});
|
|
848
|
-
`;
|
|
849
|
-
var exampleCreateEventListenerParams = `
|
|
850
|
-
const reference = createReference();
|
|
851
|
-
|
|
852
|
-
createEventListener({
|
|
853
|
-
params: {
|
|
854
|
-
someElementReference: reference,
|
|
855
|
-
pageCompiledAt: new Date(),
|
|
856
|
-
},
|
|
857
|
-
|
|
858
|
-
eventListener: (params) => {
|
|
859
|
-
console.log("i am now aware of: ", params.someElementReference);
|
|
860
|
-
console.log("This page was originally compiled at: ", pageCompiledAt);
|
|
861
|
-
},
|
|
862
|
-
});
|
|
863
|
-
`;
|
|
864
|
-
var exampleCreateLayout = `
|
|
865
|
-
const superAwesomeLayoutID = createLayout("super-awesome-layout");
|
|
866
|
-
`;
|
|
867
|
-
var exampleSimpleLayout = `
|
|
868
|
-
const superAwesomeLayoutID = createLayout("super-awesome-layout");
|
|
869
|
-
|
|
870
|
-
const SuperAwesomeLayout = (...children: Child[]) => div ({
|
|
871
|
-
style: "background-color: #000; color: #fff",
|
|
872
|
-
},
|
|
873
|
-
...children
|
|
874
|
-
);
|
|
875
|
-
`;
|
|
876
|
-
var exampleBreakpoint = `
|
|
877
|
-
const superAwesomeLayoutID = createLayout("super-awesome-layout");
|
|
878
|
-
|
|
879
|
-
const SuperAwesomeLayout = (...children: Child[]) => div ({
|
|
880
|
-
style: "background-color: #000; color: #fff",
|
|
881
|
-
},
|
|
882
|
-
Breakpoint ({
|
|
883
|
-
id: superAwesomeLayoutID
|
|
884
|
-
},
|
|
885
|
-
...children
|
|
886
|
-
),
|
|
887
|
-
);
|
|
888
|
-
`;
|
|
889
|
-
var metadata = () => head(
|
|
890
|
-
{},
|
|
891
|
-
link({
|
|
892
|
-
rel: "stylesheet",
|
|
893
|
-
href: "/index.css"
|
|
894
|
-
}),
|
|
895
|
-
title("Hi There!")
|
|
896
|
-
);
|
|
897
|
-
var page = RootLayout(
|
|
898
|
-
DocsLayout(
|
|
899
|
-
PageHeading("State", "state"),
|
|
900
|
-
Subtext("Available Via: elegance-js/server/state"),
|
|
901
|
-
Paragraph(
|
|
902
|
-
"State is, simply put, a collection of variables.",
|
|
903
|
-
br(),
|
|
904
|
-
"You initialize it on the server using the ",
|
|
905
|
-
Mono("createState()"),
|
|
906
|
-
" function."
|
|
907
|
-
),
|
|
908
|
-
CodeBlock(exampleStateCreation),
|
|
909
|
-
SubSeparator(),
|
|
910
|
-
SubHeading("Usage"),
|
|
911
|
-
Paragraph(
|
|
912
|
-
"The ",
|
|
913
|
-
Mono("createState()"),
|
|
914
|
-
" function takes in two values.",
|
|
915
|
-
br(),
|
|
916
|
-
"The initial value of the state, and an options object.",
|
|
917
|
-
br(),
|
|
918
|
-
"The options object may currently only define a bind to the state (more on this later)",
|
|
919
|
-
br(),
|
|
920
|
-
br(),
|
|
921
|
-
"The function stores the created state in the servers current state store,",
|
|
922
|
-
br(),
|
|
923
|
-
"so that upon completion of compilation, it may be serialized into page_data."
|
|
924
|
-
),
|
|
925
|
-
SubSeparator(),
|
|
926
|
-
SubHeading("Return Value"),
|
|
927
|
-
Paragraph(
|
|
928
|
-
"The return value of ",
|
|
929
|
-
Mono("createState()"),
|
|
930
|
-
" is a State ",
|
|
931
|
-
Link(
|
|
932
|
-
{
|
|
933
|
-
href: "/docs/concepts#object-attributes",
|
|
934
|
-
class: "border-b-2"
|
|
935
|
-
},
|
|
936
|
-
"Object Attribute, "
|
|
937
|
-
),
|
|
938
|
-
br(),
|
|
939
|
-
"which you can use to refer back to the created state."
|
|
940
|
-
),
|
|
941
|
-
CodeBlock(exampleStateCreationReturn),
|
|
942
|
-
CodeBlock(exampleStateReference),
|
|
943
|
-
Paragraph(
|
|
944
|
-
"Many functions like load hooks, event listeners, and observe, take in optional SOAs."
|
|
945
|
-
),
|
|
946
|
-
SubSeparator(),
|
|
947
|
-
SubHeading("Bind"),
|
|
948
|
-
Paragraph(
|
|
949
|
-
"State, in the browser, is kept in the global ",
|
|
950
|
-
Mono("pd"),
|
|
951
|
-
" object, and indexed via pathnames.",
|
|
952
|
-
br(),
|
|
953
|
-
"All state for the pathname ",
|
|
954
|
-
Mono("/recipes/apple-pie"),
|
|
955
|
-
" will be in ",
|
|
956
|
-
Mono('pd["/recipes/apple-pie"]'),
|
|
957
|
-
br(),
|
|
958
|
-
br(),
|
|
959
|
-
"However, in some scenarios you may want to reference the same state on multiple pages. ",
|
|
960
|
-
br(),
|
|
961
|
-
"For this, you may ",
|
|
962
|
-
b("bind "),
|
|
963
|
-
"the state to a ",
|
|
964
|
-
Link({
|
|
965
|
-
href: "/docs/page-files#layouts",
|
|
966
|
-
class: "border-b-2"
|
|
967
|
-
}, "Layout."),
|
|
968
|
-
br(),
|
|
969
|
-
br(),
|
|
970
|
-
"Then, the state will go into ",
|
|
971
|
-
Mono("pd[layout_id]"),
|
|
972
|
-
", instead of the pathname of the page."
|
|
973
|
-
),
|
|
974
|
-
CodeBlock(exampleStateLayoutBind),
|
|
975
|
-
SubSeparator(),
|
|
976
|
-
SubHeading("Important Considerations"),
|
|
977
|
-
Paragraph(
|
|
978
|
-
"State persists it's value during page navigation.",
|
|
979
|
-
br(),
|
|
980
|
-
"Meaning if you want it to reset it's value, you must do so yourself."
|
|
981
|
-
),
|
|
982
|
-
Separator(),
|
|
983
|
-
PageHeading("Load Hooks", "load-hooks"),
|
|
984
|
-
Subtext(
|
|
985
|
-
"Available Via: elegance-js/server/loadHook"
|
|
986
|
-
),
|
|
987
|
-
br(),
|
|
988
|
-
br(),
|
|
989
|
-
SubHeading("Basic Usage"),
|
|
990
|
-
Paragraph(
|
|
991
|
-
"Load hooks are functions that are called on the initial page load, and subsequent navigations.",
|
|
992
|
-
br(),
|
|
993
|
-
"A load hook is registered using the ",
|
|
994
|
-
Mono("createLoadHook()"),
|
|
995
|
-
" function."
|
|
996
|
-
),
|
|
997
|
-
CodeBlock(exampleLoadHook),
|
|
998
|
-
SubSeparator(),
|
|
999
|
-
SubHeading("Cleanup Function"),
|
|
1000
|
-
Paragraph(
|
|
1001
|
-
"The return value of a load hook is referred to as a cleanup function.",
|
|
1002
|
-
br(),
|
|
1003
|
-
"It is called whenever the load hook goes out of scope.",
|
|
1004
|
-
br(),
|
|
1005
|
-
br(),
|
|
1006
|
-
"You'll want to do things like ",
|
|
1007
|
-
Mono("clearInterval() & element.removeEventListener()"),
|
|
1008
|
-
br(),
|
|
1009
|
-
" here, so you don't get any unintended/undefined behavior."
|
|
1010
|
-
),
|
|
1011
|
-
CodeBlock(exampleCleanupFunction),
|
|
1012
|
-
SubSeparator(),
|
|
1013
|
-
SubHeading("Load Hook Scope"),
|
|
1014
|
-
Paragraph(
|
|
1015
|
-
"The scope of a load hook is either the page it is on, or the layout it is bound to.",
|
|
1016
|
-
br(),
|
|
1017
|
-
"If a load hook is bound to layout, it is called when that layout first appears.",
|
|
1018
|
-
br(),
|
|
1019
|
-
"Subsequently, its cleanup function will get called once it's bound layout no longer exists on the page.",
|
|
1020
|
-
br(),
|
|
1021
|
-
br(),
|
|
1022
|
-
"To bind a load hook to a layout, use the ",
|
|
1023
|
-
Mono("bind"),
|
|
1024
|
-
" attribute, and pass in a ",
|
|
1025
|
-
Link(
|
|
1026
|
-
{
|
|
1027
|
-
href: "/docs/page-files#layouts",
|
|
1028
|
-
class: "border-b-2"
|
|
1029
|
-
},
|
|
1030
|
-
"Layout ID"
|
|
1031
|
-
),
|
|
1032
|
-
CodeBlock(exampleLoadHookBind)
|
|
1033
|
-
),
|
|
1034
|
-
SubSeparator(),
|
|
1035
|
-
SubHeading("Important Considerations"),
|
|
1036
|
-
Paragraph(
|
|
1037
|
-
"It's important to note that the load hook function body exists in ",
|
|
1038
|
-
br(),
|
|
1039
|
-
b("browser land "),
|
|
1040
|
-
" not server land. Therefore the code is ",
|
|
1041
|
-
b("untrusted.")
|
|
1042
|
-
),
|
|
1043
|
-
Separator(),
|
|
1044
|
-
PageHeading("Event Listener", "event-listeners"),
|
|
1045
|
-
Subtext("Available Via: elegance-js/server/createState"),
|
|
1046
|
-
br(),
|
|
1047
|
-
br(),
|
|
1048
|
-
SubHeading("Basic Usage"),
|
|
1049
|
-
Paragraph(
|
|
1050
|
-
"Event listeners are a type of state, that you can create with the",
|
|
1051
|
-
br(),
|
|
1052
|
-
Mono("createEventListener()"),
|
|
1053
|
-
" function."
|
|
1054
|
-
),
|
|
1055
|
-
CodeBlock(exampleCreateEventListener),
|
|
1056
|
-
Paragraph(
|
|
1057
|
-
"This function returns an SOA, which can then be put on any event listener option of an element.",
|
|
1058
|
-
br(),
|
|
1059
|
-
br(),
|
|
1060
|
-
"The eventListener parameter of ",
|
|
1061
|
-
Mono("createEventListener()"),
|
|
1062
|
-
" takes in two types values.",
|
|
1063
|
-
br(),
|
|
1064
|
-
"First, a params object, which by default contains the native event which was triggered."
|
|
1065
|
-
),
|
|
1066
|
-
SubSeparator(),
|
|
1067
|
-
SubHeading("Dependencies"),
|
|
1068
|
-
Paragraph(
|
|
1069
|
-
"The second parameter, is a spread parameter, containing the dependencies of the event listener."
|
|
1070
|
-
),
|
|
1071
|
-
CodeBlock(exampleCreateEventListenerDependencies),
|
|
1072
|
-
SubSeparator(),
|
|
1073
|
-
SubHeading("Extra Params"),
|
|
1074
|
-
Paragraph(
|
|
1075
|
-
"You may also extend the params object parameter of the event listener,",
|
|
1076
|
-
br(),
|
|
1077
|
-
"With the ",
|
|
1078
|
-
Mono("params"),
|
|
1079
|
-
" attribute.",
|
|
1080
|
-
br(),
|
|
1081
|
-
br(),
|
|
1082
|
-
"This is handy for when you need to pass some value to the client, ",
|
|
1083
|
-
br(),
|
|
1084
|
-
"that is not necessarily a state variable, but it can change per compilation."
|
|
1085
|
-
),
|
|
1086
|
-
CodeBlock(exampleCreateEventListenerParams),
|
|
1087
|
-
SubSeparator(),
|
|
1088
|
-
SubHeading("Important Considerations"),
|
|
1089
|
-
Paragraph(
|
|
1090
|
-
"It's important to note that the event listener function body exists in ",
|
|
1091
|
-
br(),
|
|
1092
|
-
b("browser land "),
|
|
1093
|
-
" not server land. Therefore the code is ",
|
|
1094
|
-
b("untrusted.")
|
|
1095
|
-
),
|
|
1096
|
-
Separator(),
|
|
1097
|
-
PageHeading("Layouts", "layouts"),
|
|
1098
|
-
Subtext("Available Via: elegance-js/server/layout"),
|
|
1099
|
-
br(),
|
|
1100
|
-
br(),
|
|
1101
|
-
Paragraph(
|
|
1102
|
-
"A layout is a section of a page that is not re-rendered between",
|
|
1103
|
-
br(),
|
|
1104
|
-
"page navigations, to pages that share the same layout order.",
|
|
1105
|
-
br(),
|
|
1106
|
-
br(),
|
|
1107
|
-
"Instead, the layouts ",
|
|
1108
|
-
b("children"),
|
|
1109
|
-
" are replaced.",
|
|
1110
|
-
br(),
|
|
1111
|
-
br(),
|
|
1112
|
-
"This has a few advantages. The main one being, that since the elements themselves,",
|
|
1113
|
-
br(),
|
|
1114
|
-
"are not re-rendered, they maintain things like their hover state."
|
|
1115
|
-
),
|
|
1116
|
-
SubSeparator(),
|
|
1117
|
-
SubHeading("Basic Usage"),
|
|
1118
|
-
Paragraph(
|
|
1119
|
-
"Layouts work a bit differently in Elegance than you may perhaps be used to.",
|
|
1120
|
-
br(),
|
|
1121
|
-
"For example, in Next.JS, layouts are ",
|
|
1122
|
-
b("inherited "),
|
|
1123
|
-
"to every subsequent page.",
|
|
1124
|
-
br(),
|
|
1125
|
-
br(),
|
|
1126
|
-
"So a layout defined at ",
|
|
1127
|
-
Mono("/"),
|
|
1128
|
-
" would apply to ",
|
|
1129
|
-
b("every"),
|
|
1130
|
-
" single page.",
|
|
1131
|
-
br(),
|
|
1132
|
-
"Which you may think is nice and saves time, but almost always I find myself in a situation",
|
|
1133
|
-
br(),
|
|
1134
|
-
"where I want a layout for every page of a given depth, except one.",
|
|
1135
|
-
br(),
|
|
1136
|
-
br(),
|
|
1137
|
-
"And then, I have to either move the special page one depth upward",
|
|
1138
|
-
br(),
|
|
1139
|
-
"or the others one-depth downward.",
|
|
1140
|
-
br(),
|
|
1141
|
-
br(),
|
|
1142
|
-
"Conversly, layouts in Elegance are ",
|
|
1143
|
-
b("not "),
|
|
1144
|
-
"inherited, and are are ",
|
|
1145
|
-
b("opt-in."),
|
|
1146
|
-
br(),
|
|
1147
|
-
br(),
|
|
1148
|
-
"To create a layout, use the ",
|
|
1149
|
-
Mono("createLayout()"),
|
|
1150
|
-
" function, and pass in a name.",
|
|
1151
|
-
br(),
|
|
1152
|
-
"The name is used so any subsequent calls to this function by other pages will get the same ID."
|
|
1153
|
-
),
|
|
1154
|
-
CodeBlock(exampleCreateLayout),
|
|
1155
|
-
Paragraph(
|
|
1156
|
-
"This layout ID can then be passed to state, load hooks, etc."
|
|
1157
|
-
),
|
|
1158
|
-
SubSeparator(),
|
|
1159
|
-
SubHeading("Breakpoints"),
|
|
1160
|
-
Paragraph(
|
|
1161
|
-
"Creating the actual layout element is simple.",
|
|
1162
|
-
br(),
|
|
1163
|
-
"Just make a function that takes in child elements, and have it return some kind of simple layout."
|
|
1164
|
-
),
|
|
1165
|
-
CodeBlock(exampleSimpleLayout),
|
|
1166
|
-
Paragraph(
|
|
1167
|
-
"Then, wrap the children with the built-in ",
|
|
1168
|
-
Mono("Breakpoint()"),
|
|
1169
|
-
" element."
|
|
1170
|
-
),
|
|
1171
|
-
CodeBlock(exampleBreakpoint),
|
|
1172
|
-
SubSeparator(),
|
|
1173
|
-
SubHeading("Important Considerations"),
|
|
1174
|
-
Paragraph(
|
|
1175
|
-
"The ",
|
|
1176
|
-
Mono("Breakpoint()"),
|
|
1177
|
-
" element is the one that gets replaced",
|
|
1178
|
-
br(),
|
|
1179
|
-
"when navigating within any given layout.",
|
|
1180
|
-
br(),
|
|
1181
|
-
br(),
|
|
1182
|
-
"All sibling and parent elements stay untouched.",
|
|
1183
|
-
br(),
|
|
1184
|
-
br(),
|
|
1185
|
-
"Also note, that in complex pages where there are multiple nested layouts,",
|
|
1186
|
-
br(),
|
|
1187
|
-
"the one that has its children replaced, is the layout that is ",
|
|
1188
|
-
b("last shared."),
|
|
1189
|
-
br(),
|
|
1190
|
-
br(),
|
|
1191
|
-
b("For example:"),
|
|
1192
|
-
br(),
|
|
1193
|
-
"Page 1 Layouts: A,B,C,D,E",
|
|
1194
|
-
br(),
|
|
1195
|
-
"Page 2 Layouts: A,B,D,C,E",
|
|
1196
|
-
br(),
|
|
1197
|
-
"In this instance, the ",
|
|
1198
|
-
b("B"),
|
|
1199
|
-
" layout is the last shared layout."
|
|
1200
|
-
)
|
|
1201
|
-
)
|
|
1202
|
-
);
|
|
1203
|
-
export {
|
|
1204
|
-
metadata,
|
|
1205
|
-
page
|
|
1206
|
-
};
|