@zyrab/domo 1.4.0 → 1.5.0
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/src/client/base.client.js +2 -1
- package/src/server/base.server.js +11 -42
package/package.json
CHANGED
|
@@ -20,7 +20,8 @@ class BaseClient {
|
|
|
20
20
|
constructor(el = "div") {
|
|
21
21
|
this.element = document.createElement(String(el || "div").toLowerCase());
|
|
22
22
|
}
|
|
23
|
-
island(enabled =
|
|
23
|
+
island(component, enabled = true) {
|
|
24
|
+
this.element.appendChild(this._handleElementInstance(component()));
|
|
24
25
|
return this;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
// import { fileURLToPath } from "url";
|
|
2
2
|
/**
|
|
3
3
|
* @class BaseServer
|
|
4
4
|
* @description Foundational class for Server-side (Virtual) Domo elements.
|
|
@@ -30,8 +30,8 @@ class BaseServer {
|
|
|
30
30
|
_events: [],
|
|
31
31
|
_refs: [],
|
|
32
32
|
_island: false,
|
|
33
|
+
__island: null,
|
|
33
34
|
_state: {},
|
|
34
|
-
__file: null,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -39,12 +39,14 @@ class BaseServer {
|
|
|
39
39
|
* Manually mark this element/component as an island.
|
|
40
40
|
* This signals the SSG to bundle the Domo client runtime.
|
|
41
41
|
*/
|
|
42
|
-
island(enabled = true) {
|
|
42
|
+
island(component, enabled = true) {
|
|
43
43
|
this.element._island = enabled;
|
|
44
44
|
this._getOrSetId();
|
|
45
|
+
|
|
45
46
|
if (enabled) {
|
|
46
|
-
this.element.
|
|
47
|
+
this.element.__island = component;
|
|
47
48
|
}
|
|
49
|
+
|
|
48
50
|
return this;
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -56,10 +58,12 @@ class BaseServer {
|
|
|
56
58
|
ref(callback) {
|
|
57
59
|
if (typeof callback === "function") {
|
|
58
60
|
this.element._refs.push({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
// 2. Use callback.name, or fallback to "anonymous"
|
|
62
|
+
// (Removed 'meta' reference which caused the crash)
|
|
63
|
+
name: callback.name || "anonymous",
|
|
61
64
|
handler: callback,
|
|
62
65
|
});
|
|
66
|
+
|
|
63
67
|
// Ensure element has a stable ID if it has a ref
|
|
64
68
|
this._getOrSetId();
|
|
65
69
|
}
|
|
@@ -72,50 +76,15 @@ class BaseServer {
|
|
|
72
76
|
* @returns {string} The data-domo-id.
|
|
73
77
|
*/
|
|
74
78
|
_getOrSetId() {
|
|
75
|
-
const existing = this.element._attr["data-domo-id"]
|
|
79
|
+
const existing = this.element._attr["data-domo-id"];
|
|
76
80
|
if (existing) {
|
|
77
81
|
return existing;
|
|
78
82
|
}
|
|
79
|
-
|
|
80
|
-
// Simple stable hash based on tag and current metadata state
|
|
81
83
|
const hash = Math.random().toString(36).substring(2, 7);
|
|
82
84
|
const id = `d-${hash}`;
|
|
83
85
|
this.element._attr["data-domo-id"] = id;
|
|
84
86
|
return id;
|
|
85
87
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Gets the file path of the caller in the stack trace.
|
|
88
|
-
* @param {number} depth - How many steps back to look (default 2: the caller of the caller)
|
|
89
|
-
*/
|
|
90
|
-
_getCallerFile(depth = 2) {
|
|
91
|
-
const originalPrepare = Error.prepareStackTrace;
|
|
92
|
-
Error.prepareStackTrace = (_, stack) => stack;
|
|
93
|
-
const stack = new Error().stack;
|
|
94
|
-
Error.prepareStackTrace = originalPrepare;
|
|
95
|
-
|
|
96
|
-
if (!stack || !stack[depth]) return null;
|
|
97
|
-
|
|
98
|
-
const filename = stack[depth].getFileName();
|
|
99
|
-
|
|
100
|
-
// Clean up "file://" prefixes for Windows/ESM compatibility
|
|
101
|
-
if (filename && filename.startsWith("file://")) {
|
|
102
|
-
return fileURLToPath(filename);
|
|
103
|
-
}
|
|
104
|
-
return filename;
|
|
105
|
-
}
|
|
106
|
-
_getExternalPath(fn, currentFile) {
|
|
107
|
-
// If the function has no name and is very short, it's likely an inline arrow fn
|
|
108
|
-
// However, the most reliable way in Node is checking the stack
|
|
109
|
-
const caller = getCallerFile(3); // Adjust depth based on where this is called
|
|
110
|
-
|
|
111
|
-
// Logic: If we can't find a source, or the source is the same as the
|
|
112
|
-
// component currently being built, we treat it as "inline".
|
|
113
|
-
if (!caller || caller === currentFile) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return caller;
|
|
118
|
-
}
|
|
119
88
|
}
|
|
120
89
|
|
|
121
90
|
export default BaseServer;
|