elegance-js 2.1.9 → 2.1.11

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.
@@ -1,52 +1,4 @@
1
- // src/server/loadHook.ts
2
- var loadHook = (deps, fn, bind) => {
3
- const stringFn = fn.toString();
4
- const depsArray = (deps || []).map((dep) => ({
5
- id: dep.id,
6
- bind: dep.bind
7
- }));
8
- let dependencyString = "[";
9
- for (const dep of depsArray) {
10
- dependencyString += `{id:${dep.id}`;
11
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
12
- dependencyString += `},`;
13
- }
14
- dependencyString += "]";
15
- const isAsync = fn.constructor.name === "AsyncFunction";
16
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
17
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
18
- fn: wrapperFn,
19
- bind: bind || ""
20
- });
21
- };
22
-
23
- // src/server/state.ts
24
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
25
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
26
- }
27
- var eventListener = (dependencies, eventListener2) => {
28
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
29
- let dependencyString = "[";
30
- for (const dep of deps) {
31
- dependencyString += `{id:${dep.id}`;
32
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
33
- dependencyString += `},`;
34
- }
35
- dependencyString += "]";
36
- const value = {
37
- id: __SERVER_CURRENT_STATE_ID__ += 1,
38
- type: 1 /* STATE */,
39
- value: new Function(
40
- "state",
41
- "event",
42
- `(${eventListener2.toString()})(event, ...state.getAll(${dependencyString}))`
43
- )
44
- };
45
- globalThis.__SERVER_CURRENT_STATE__.push(value);
46
- return value;
47
- };
48
-
49
- // src/components/Link.ts
1
+ import { loadHook, eventListener } from "../index";
50
2
  loadHook(
51
3
  [],
52
4
  () => {
@@ -78,7 +30,7 @@ loadHook(
78
30
  };
79
31
  }
80
32
  );
81
- var navigate = eventListener(
33
+ const navigate = eventListener(
82
34
  [],
83
35
  (event) => {
84
36
  const target = new URL(event.currentTarget.href);
@@ -93,7 +45,7 @@ var navigate = eventListener(
93
45
  client2.navigateLocally(target.href);
94
46
  }
95
47
  );
96
- var Link = (options, ...children) => {
48
+ const Link = (options, ...children) => {
97
49
  if (!options.href) {
98
50
  throw `Link elements must have a HREF attribute set.`;
99
51
  }
@@ -1,4 +1,3 @@
1
- // src/helpers/ObjectAttributeType.ts
2
1
  var ObjectAttributeType = /* @__PURE__ */ ((ObjectAttributeType2) => {
3
2
  ObjectAttributeType2[ObjectAttributeType2["GENERIC"] = 0] = "GENERIC";
4
3
  ObjectAttributeType2[ObjectAttributeType2["STATE"] = 1] = "STATE";
@@ -1,5 +1,4 @@
1
- // src/helpers/camelToKebab.ts
2
- var camelToKebabCase = (input) => {
1
+ const camelToKebabCase = (input) => {
3
2
  return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
4
3
  };
5
4
  export {
package/dist/index.mjs CHANGED
@@ -1,215 +1,3 @@
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 resetLoadHooks = () => globalThis.__SERVER_CURRENT_LOADHOOKS__ = [];
9
- var getLoadHooks = () => globalThis.__SERVER_CURRENT_LOADHOOKS__;
10
- var loadHook = (deps, fn, bind) => {
11
- const stringFn = fn.toString();
12
- const depsArray = (deps || []).map((dep) => ({
13
- id: dep.id,
14
- bind: dep.bind
15
- }));
16
- let dependencyString = "[";
17
- for (const dep of depsArray) {
18
- dependencyString += `{id:${dep.id}`;
19
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
20
- dependencyString += `},`;
21
- }
22
- dependencyString += "]";
23
- const isAsync = fn.constructor.name === "AsyncFunction";
24
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
25
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
26
- fn: wrapperFn,
27
- bind: bind || ""
28
- });
29
- };
30
- var createLoadHook = (options) => {
31
- ShowDeprecationWarning("WARNING: createLoadHook() is a deprecated function. Use loadHook() from elegance-js/loadHook instead.");
32
- const stringFn = options.fn.toString();
33
- const deps = (options.deps || []).map((dep) => ({
34
- id: dep.id,
35
- bind: dep.bind
36
- }));
37
- let dependencyString = "[";
38
- for (const dep of deps) {
39
- dependencyString += `{id:${dep.id}`;
40
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
41
- dependencyString += `},`;
42
- }
43
- dependencyString += "]";
44
- const isAsync = options.fn.constructor.name === "AsyncFunction";
45
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
46
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
47
- fn: wrapperFn,
48
- bind: options.bind || ""
49
- });
50
- };
51
-
52
- // src/server/state.ts
53
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
54
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
55
- }
56
- var state = (value, options) => {
57
- const serverStateEntry = {
58
- id: __SERVER_CURRENT_STATE_ID__ += 1,
59
- value,
60
- type: 1 /* STATE */
61
- };
62
- globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
63
- if (Array.isArray(value)) {
64
- serverStateEntry.reactiveMap = reactiveMap;
65
- }
66
- return serverStateEntry;
67
- };
68
- var reactiveMap = function(template, deps) {
69
- const subject = this;
70
- const dependencies = state(deps || []);
71
- const templateFn = state(template);
72
- loadHook(
73
- [subject, templateFn, dependencies],
74
- (state2, subject2, templateFn2, dependencies2) => {
75
- const el = document.querySelector(
76
- `[map-id="${subject2.id}"]`
77
- );
78
- if (!el) {
79
- console.error(`Couldn't find map tag with map-id=${subject2.id}`);
80
- return;
81
- }
82
- const parentElement = el.parentElement;
83
- const nextSibling = el.nextSibling;
84
- el.remove();
85
- const value = subject2.value;
86
- const deps2 = state2.getAll(dependencies2.value.map((dep) => ({ id: dep.id, bind: dep.bind })));
87
- const attributes = [];
88
- const currentlyWatched = [];
89
- const createElements = () => {
90
- for (let i = 0; i < value.length; i += 1) {
91
- const htmlElement = client.renderRecursively(templateFn2.value(value[i], i, ...deps2), attributes);
92
- htmlElement.setAttribute("map-id", subject2.id.toString());
93
- const elementKey = ((i - 1) * -1).toString();
94
- htmlElement.setAttribute("key", elementKey);
95
- for (const attribute of attributes) {
96
- let values = {};
97
- const type = attribute.type;
98
- switch (type) {
99
- case 2 /* OBSERVER */: {
100
- const { field, subjects, updateCallback } = attribute;
101
- for (const reference of subjects) {
102
- const subject3 = state2.get(reference.id, reference.bind);
103
- const updateFunction = (value2) => {
104
- values[subject3.id] = value2;
105
- try {
106
- const newValue = updateCallback(...Object.values(values));
107
- let attribute2 = field === "class" ? "className" : field;
108
- htmlElement[attribute2] = newValue;
109
- } catch (e) {
110
- console.error(e);
111
- return;
112
- }
113
- };
114
- updateFunction(subject3.value);
115
- state2.observe(subject3, updateFunction, elementKey);
116
- currentlyWatched.push({
117
- key: elementKey,
118
- subject: subject3
119
- });
120
- }
121
- break;
122
- }
123
- case 1 /* STATE */: {
124
- const { field, element, subjects, eventListener: eventListener2 } = attribute;
125
- const lc = field.toLowerCase();
126
- const fn = (event) => {
127
- eventListener2(event, ...subjects);
128
- };
129
- element[lc] = fn;
130
- break;
131
- }
132
- }
133
- }
134
- parentElement.insertBefore(htmlElement, nextSibling);
135
- attributes.splice(0, attributes.length);
136
- }
137
- };
138
- const removeOldElements = () => {
139
- const list = Array.from(document.querySelectorAll(`[map-id="${subject2.id}"]`));
140
- for (const el2 of list) {
141
- el2.remove();
142
- }
143
- for (const watched of currentlyWatched) {
144
- state2.unobserve(watched.subject, watched.key);
145
- }
146
- currentlyWatched.splice(0, currentlyWatched.length);
147
- };
148
- createElements();
149
- const uniqueId = `${Date.now()}`;
150
- state2.observe(subject2, (value2) => {
151
- removeOldElements();
152
- createElements();
153
- }, uniqueId);
154
- }
155
- );
156
- return globalThis.template({
157
- "map-id": subject.id
158
- });
159
- };
160
- var eventListener = (dependencies, eventListener2) => {
161
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
162
- let dependencyString = "[";
163
- for (const dep of deps) {
164
- dependencyString += `{id:${dep.id}`;
165
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
166
- dependencyString += `},`;
167
- }
168
- dependencyString += "]";
169
- const value = {
170
- id: __SERVER_CURRENT_STATE_ID__ += 1,
171
- type: 1 /* STATE */,
172
- value: new Function(
173
- "state",
174
- "event",
175
- `(${eventListener2.toString()})(event, ...state.getAll(${dependencyString}))`
176
- )
177
- };
178
- globalThis.__SERVER_CURRENT_STATE__.push(value);
179
- return value;
180
- };
181
- var initializeState = () => globalThis.__SERVER_CURRENT_STATE__ = [];
182
- var getState = () => {
183
- return globalThis.__SERVER_CURRENT_STATE__;
184
- };
185
- var initializeObjectAttributes = () => globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__ = [];
186
- var getObjectAttributes = () => {
187
- return globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__;
188
- };
189
-
190
- // src/server/observe.ts
191
- var observe = (refs, update) => {
192
- const returnValue = {
193
- type: 2 /* OBSERVER */,
194
- initialValues: refs.map((ref) => ref.value),
195
- update,
196
- refs: refs.map((ref) => ({
197
- id: ref.id,
198
- bind: ref.bind
199
- }))
200
- };
201
- return returnValue;
202
- };
203
- export {
204
- createLoadHook,
205
- eventListener,
206
- getLoadHooks,
207
- getObjectAttributes,
208
- getState,
209
- initializeObjectAttributes,
210
- initializeState,
211
- loadHook,
212
- observe,
213
- resetLoadHooks,
214
- state
215
- };
1
+ export * from "./server/state";
2
+ export * from "./server/loadHook";
3
+ export * from "./server/observe";
@@ -1,5 +1,4 @@
1
- // src/internal/deprecate.ts
2
- var ShowDeprecationWarning = (msg) => {
1
+ const ShowDeprecationWarning = (msg) => {
3
2
  console.warn("\x1B[31m", msg, "\x1B[0m");
4
3
  console.trace("Stack Trace:");
5
4
  };
package/dist/log.mjs CHANGED
@@ -1,5 +1,4 @@
1
- // src/log.ts
2
- var quiet = false;
1
+ let quiet = false;
3
2
  function setQuiet(value) {
4
3
  quiet = value;
5
4
  }
@@ -28,7 +27,7 @@ function logWarn(...args) {
28
27
  function logError(...args) {
29
28
  console.error(`Elegance.JS: ${getTimestamp()} ${color("[ERROR]:", 31)}`, ...args);
30
29
  }
31
- var log = {
30
+ const log = {
32
31
  info: logInfo,
33
32
  warn: logWarn,
34
33
  error: logError