elegance-js 2.1.23 → 2.1.26

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 (103) hide show
  1. package/dist/client/effect.d.ts +27 -0
  2. package/dist/client/effect.js +37 -0
  3. package/dist/client/eventListener.d.ts +39 -0
  4. package/dist/client/eventListener.js +52 -0
  5. package/dist/client/loadHook.d.ts +34 -0
  6. package/dist/client/loadHook.js +52 -0
  7. package/dist/client/observer.d.ts +36 -0
  8. package/dist/client/observer.js +66 -0
  9. package/dist/client/runtime.d.ts +105 -0
  10. package/dist/client/runtime.js +620 -0
  11. package/dist/client/state.d.ts +40 -0
  12. package/dist/client/state.js +110 -0
  13. package/dist/compilation/compiler.d.ts +155 -0
  14. package/dist/compilation/compiler.js +1153 -0
  15. package/dist/components/ClientComponent.d.ts +22 -0
  16. package/dist/components/ClientComponent.js +55 -0
  17. package/dist/components/Link.d.ts +16 -1
  18. package/dist/components/Link.js +22 -0
  19. package/dist/components/Portal.d.ts +2 -0
  20. package/dist/components/Portal.js +2 -0
  21. package/dist/elements/element.d.ts +87 -0
  22. package/dist/elements/element.js +33 -0
  23. package/dist/elements/element_list.d.ts +7 -0
  24. package/dist/elements/element_list.js +65 -0
  25. package/dist/elements/raw.d.ts +14 -0
  26. package/dist/elements/raw.js +78 -0
  27. package/dist/elements/specific_props.d.ts +750 -0
  28. package/dist/global.d.ts +221 -327
  29. package/dist/index.d.ts +15 -3
  30. package/dist/index.js +11 -0
  31. package/dist/server/layout.d.ts +34 -3
  32. package/dist/server/layout.js +6 -0
  33. package/dist/server/log.d.ts +12 -0
  34. package/dist/server/log.js +64 -0
  35. package/dist/server/page.d.ts +32 -0
  36. package/dist/server/page.js +6 -0
  37. package/dist/server/runtime.d.ts +6 -0
  38. package/dist/server/runtime.js +72 -0
  39. package/dist/server/server.d.ts +103 -11
  40. package/dist/server/server.js +709 -0
  41. package/package.json +13 -13
  42. package/scripts/bootstrap.js +37 -273
  43. package/scripts/bootstrap_files/elegance.txt +40 -0
  44. package/scripts/bootstrap_files/index.txt +3 -0
  45. package/scripts/bootstrap_files/layout.txt +46 -0
  46. package/scripts/bootstrap_files/middleware.txt +18 -0
  47. package/scripts/bootstrap_files/page.txt +123 -0
  48. package/scripts/bootstrap_files/route.txt +6 -0
  49. package/scripts/elegance_dev.ts +40 -0
  50. package/scripts/elegance_prod.ts +40 -0
  51. package/scripts/elegance_static.ts +24 -0
  52. package/scripts/prod.js +9 -26
  53. package/scripts/run.js +13 -0
  54. package/scripts/static.js +13 -0
  55. package/dist/build.d.ts +0 -2
  56. package/dist/build.mjs +0 -202
  57. package/dist/client/client.d.ts +0 -1
  58. package/dist/client/client.mjs +0 -574
  59. package/dist/client/processPageElements.d.ts +0 -1
  60. package/dist/client/processPageElements.mjs +0 -117
  61. package/dist/client/render.d.ts +0 -1
  62. package/dist/client/render.mjs +0 -40
  63. package/dist/client/watcher.d.ts +0 -1
  64. package/dist/client/watcher.mjs +0 -26
  65. package/dist/compilation/compilation.d.ts +0 -139
  66. package/dist/compilation/compilation.mjs +0 -751
  67. package/dist/compilation/compiler_process.d.ts +0 -3
  68. package/dist/compilation/compiler_process.mjs +0 -102
  69. package/dist/compilation/dynamic_compiler.d.ts +0 -10
  70. package/dist/compilation/dynamic_compiler.mjs +0 -93
  71. package/dist/compile_docs.mjs +0 -34
  72. package/dist/components/Link.mjs +0 -65
  73. package/dist/global.mjs +0 -0
  74. package/dist/helpers/ObjectAttributeType.d.ts +0 -7
  75. package/dist/helpers/ObjectAttributeType.mjs +0 -11
  76. package/dist/helpers/camelToKebab.d.ts +0 -1
  77. package/dist/helpers/camelToKebab.mjs +0 -6
  78. package/dist/index.mjs +0 -3
  79. package/dist/internal/deprecate.d.ts +0 -1
  80. package/dist/internal/deprecate.mjs +0 -7
  81. package/dist/log.d.ts +0 -10
  82. package/dist/log.mjs +0 -38
  83. package/dist/server/generateHTMLTemplate.d.ts +0 -12
  84. package/dist/server/generateHTMLTemplate.mjs +0 -41
  85. package/dist/server/layout.mjs +0 -19
  86. package/dist/server/loadHook.d.ts +0 -30
  87. package/dist/server/loadHook.mjs +0 -50
  88. package/dist/server/observe.d.ts +0 -19
  89. package/dist/server/observe.mjs +0 -16
  90. package/dist/server/render.d.ts +0 -5
  91. package/dist/server/render.mjs +0 -61
  92. package/dist/server/server.mjs +0 -429
  93. package/dist/server/state.d.ts +0 -61
  94. package/dist/server/state.mjs +0 -146
  95. package/dist/shared/bindServerElements.mjs +0 -3
  96. package/dist/shared/serverElements.d.ts +0 -11
  97. package/dist/shared/serverElements.mjs +0 -164
  98. package/scripts/dev.js +0 -33
  99. package/scripts/export.js +0 -20
  100. package/scripts/ts-arc-dev.js +0 -9
  101. package/scripts/ts-arc-prod.js +0 -9
  102. /package/dist/{compile_docs.d.ts → elements/specific_props.js} +0 -0
  103. /package/dist/{shared/bindServerElements.d.ts → global.js} +0 -0
@@ -1,40 +0,0 @@
1
- const renderRecursively = (element) => {
2
- if (typeof element === "boolean") {
3
- return null;
4
- }
5
- if (typeof element === "number" || typeof element === "string") {
6
- return document.createTextNode(element.toString());
7
- }
8
- if (Array.isArray(element)) {
9
- const fragment = document.createDocumentFragment();
10
- element.forEach((item) => {
11
- const childNode = renderRecursively(item);
12
- if (childNode) fragment.appendChild(childNode);
13
- });
14
- return fragment;
15
- }
16
- const domElement = document.createElement(element.tag);
17
- if (typeof element.options === "object" && element.options !== null) {
18
- for (const [attrName, attrValue] of Object.entries(element.options)) {
19
- if (typeof attrValue === "object") {
20
- throw new Error(`Attr ${attrName} for element ${element.tag} has object type. Got: ${JSON.stringify(element)}`);
21
- }
22
- domElement.setAttribute(attrName.toLowerCase(), attrValue);
23
- }
24
- }
25
- if (element.children !== null) {
26
- if (Array.isArray(element.children)) {
27
- element.children.forEach((child) => {
28
- const childNode = renderRecursively(child);
29
- if (childNode) domElement.appendChild(childNode);
30
- });
31
- } else {
32
- const childNode = renderRecursively(element.children);
33
- if (childNode) domElement.appendChild(childNode);
34
- }
35
- }
36
- return domElement;
37
- };
38
- export {
39
- renderRecursively
40
- };
@@ -1 +0,0 @@
1
- declare const eventSource: EventSource;
@@ -1,26 +0,0 @@
1
- const eventSource = new EventSource(`http://localhost:${watchServerPort}/events`);
2
- eventSource.onerror = async () => {
3
- };
4
- eventSource.onmessage = async (event) => {
5
- if (event.data === "reload") {
6
- for (const cleanupProcedure of cleanupProcedures) {
7
- cleanupProcedure.cleanupFunction();
8
- }
9
- cleanupProcedures = [];
10
- pd[sanitizePathname(loc.pathname)].stateManager.subjects.map((subj) => ({ ...subj, observers: [] }));
11
- const newHTML = await fetch(window.location.href);
12
- const newDOM = domParser.parseFromString(
13
- await newHTML.text(),
14
- "text/html"
15
- );
16
- document.body.replaceWith(newDOM.body);
17
- document.head.replaceWith(newDOM.head);
18
- const link = document.querySelector("[rel=stylesheet]");
19
- if (!link) return;
20
- const href = link.getAttribute("href");
21
- link.setAttribute("href", href.split("?")[0] + "?" + (/* @__PURE__ */ new Date()).getTime());
22
- loadPage();
23
- } else if (event.data === "hard-reload") {
24
- window.location.reload();
25
- }
26
- };
@@ -1,139 +0,0 @@
1
- import { ObjectAttributeType } from "../helpers/ObjectAttributeType";
2
- import { LoadHook } from "../server/loadHook";
3
- type CompilationOptions = {
4
- postCompile?: () => any;
5
- preCompile?: () => any;
6
- environment: "production" | "development";
7
- pagesDirectory: string;
8
- outputDirectory: string;
9
- /** Suppress native elegance logs. */
10
- quiet?: boolean;
11
- publicDirectory?: {
12
- path: string;
13
- };
14
- server?: {
15
- runServer: boolean;
16
- root?: string;
17
- port?: number;
18
- host?: string;
19
- };
20
- hotReload?: {
21
- port: number;
22
- hostname: string;
23
- /** Directories to watch for hot-reloading other than just the pagesDirectory. */
24
- extraWatchDirectories?: string[];
25
- };
26
- };
27
- declare let PAGE_MAP: Map<string, PageInformation>;
28
- declare let LAYOUT_MAP: Map<string, LayoutInformation>;
29
- /** The parent process calls this in order to set the LAYOUT_MAP and PAGE_MAP to the ones that that compiler process ended up with. */
30
- declare function populateServerMaps(pageMap: Map<any, any>, layoutMap: Map<any, any>): void;
31
- /** A list of modules that are yet to be built. */
32
- declare let modulesToShip: Array<{
33
- path: string;
34
- globalName: string;
35
- }>;
36
- declare function setCompilationOptions(newOptions: CompilationOptions, distDir: string): void;
37
- declare function getAllSubdirectories(dir: string, baseDir?: string): string[];
38
- declare function buildClient(DIST_DIR: string): Promise<void>;
39
- /**
40
- * Recursively iterate through the elements of a given page, and "process them".
41
- * This involves separating all non-serializable data into an object attributes array,
42
- * and mutating `element` into something that can be serialized into HTML.
43
- */
44
- declare function processPageElements(element: Child, objectAttributes: Array<any>, recursionLevel: number, stack?: any[]): Child;
45
- /**
46
- * Takes in a page, and turns it into HTML.
47
- * If doWrite is false, the page's HTML will be returned.
48
- */
49
- declare function pageToHTML(pageLocation: string, pageElements: Child, metadata: () => BuiltElement<"html">, DIST_DIR: string, pageName: string, doWrite: boolean | undefined, requiredClientModules: ShippedModules | undefined, layout: BuiltLayout, pathname?: string): Promise<string | ({
50
- type: ObjectAttributeType;
51
- id: string | number;
52
- value: any;
53
- bind?: string;
54
- } | {
55
- type: ObjectAttributeType;
56
- refs: {
57
- id: number;
58
- bind?: string;
59
- }[];
60
- initialValues: any[];
61
- update: (...value: any) => any;
62
- } | {
63
- type: ObjectAttributeType;
64
- })[]>;
65
- /**
66
- * This uses string interpolation to generate the:
67
- * page_data.js file that the browser receives.
68
- *
69
- * It's *very* error-prone, so be careful if you edit this!
70
- */
71
- declare function generateClientPageData(pageLocation: string, state: typeof globalThis.__SERVER_CURRENT_STATE__, objectAttributes: Array<ObjectAttribute<any>>, pageLoadHooks: Array<LoadHook>, DIST_DIR: string, pageName: string, globalVariableName?: string, write?: boolean): Promise<{
72
- sendHardReloadInstruction: boolean;
73
- result?: undefined;
74
- } | {
75
- sendHardReloadInstruction: boolean;
76
- result: string;
77
- }>;
78
- declare function generateLayout(DIST_DIR: string,
79
- /** The absolute path of the layout.ts file. */
80
- filePath: string,
81
- /** Path relative to pagesDirectory. */
82
- directory: string,
83
- /** What to squish between the start and end HTML (aka the split point). */
84
- childIndicator: Child,
85
- /** Whether or not to generate the layout if it is dynamic */
86
- generateDynamic?: boolean): Promise<false | {
87
- pageContentHTML: string;
88
- metadataHTML: string;
89
- }>;
90
- type BuiltLayout = {
91
- pageContent: {
92
- startHTML: string;
93
- endHTML: string;
94
- };
95
- metadata: {
96
- startHTML: string;
97
- endHTML: string;
98
- };
99
- scriptTag: string;
100
- };
101
- declare function buildLayouts(): Promise<{
102
- shouldClientHardReload: boolean;
103
- }>;
104
- declare function buildLayout(filePath: string, directory: string, generateDynamic?: boolean): Promise<false | {
105
- pageContent: {
106
- startHTML: string;
107
- endHTML: string;
108
- };
109
- metadata: {
110
- startHTML: string;
111
- endHTML: string;
112
- };
113
- scriptTag: string;
114
- }>;
115
- /**
116
- * Iterate through the found layouts, and construct the necessary wrapper HTML for a given page.
117
- */
118
- declare function fetchPageLayoutHTML(dirname: string): Promise<{
119
- pageContent: {
120
- startHTML: string;
121
- endHTML: string;
122
- };
123
- metadata: {
124
- startHTML: string;
125
- endHTML: string;
126
- };
127
- scriptTag: string;
128
- }>;
129
- declare function buildPages(DIST_DIR: string): Promise<{
130
- shouldClientHardReload: boolean;
131
- }>;
132
- declare function buildPage(DIST_DIR: string, directory: string, filePath: string, name: string): Promise<boolean>;
133
- declare function shipModules(): Promise<void>;
134
- /** Retrieve a list of the pages and layouts that were found during the original compilation process. */
135
- declare function retrievePageAndLayoutMaps(): {
136
- LAYOUT_MAP: Map<string, LayoutInformation>;
137
- PAGE_MAP: Map<string, PageInformation>;
138
- };
139
- export { CompilationOptions, setCompilationOptions, getAllSubdirectories, retrievePageAndLayoutMaps, buildClient, processPageElements, pageToHTML, generateClientPageData, generateLayout, buildLayouts, buildLayout, fetchPageLayoutHTML, buildPages, buildPage, shipModules, PAGE_MAP, LAYOUT_MAP, populateServerMaps, modulesToShip, };