@zyrab/domo 1.4.0 → 1.5.1
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
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
|
/**
|
|
@@ -47,7 +47,9 @@ class PropertiesClient extends BaseClient {
|
|
|
47
47
|
if (typeof force === "boolean") {
|
|
48
48
|
force ? this.element.setAttribute(attrName, "") : this.element.removeAttribute(attrName);
|
|
49
49
|
} else {
|
|
50
|
-
this.element.hasAttribute(attrName)
|
|
50
|
+
this.element.hasAttribute(attrName)
|
|
51
|
+
? this.element.removeAttribute(attrName)
|
|
52
|
+
: this.element.setAttribute(attrName, "");
|
|
51
53
|
}
|
|
52
54
|
return this;
|
|
53
55
|
}
|
|
@@ -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
|
-
this._getOrSetId();
|
|
44
|
+
this._getOrSetId(component.name);
|
|
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,65 +58,39 @@ 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
|
-
this._getOrSetId();
|
|
68
|
+
this._getOrSetId(callback);
|
|
65
69
|
}
|
|
66
70
|
return this;
|
|
67
71
|
}
|
|
68
|
-
|
|
69
72
|
/**
|
|
70
73
|
* Generates or retrieves a stable, hash-based ID for metadata association.
|
|
71
74
|
* @protected
|
|
72
75
|
* @returns {string} The data-domo-id.
|
|
73
76
|
*/
|
|
74
|
-
_getOrSetId() {
|
|
75
|
-
const existing = this.element._attr["data-domo-id"]
|
|
76
|
-
if (existing)
|
|
77
|
-
return existing;
|
|
78
|
-
}
|
|
77
|
+
_getOrSetId(handler) {
|
|
78
|
+
const existing = this.element._attr["data-domo-id"];
|
|
79
|
+
if (existing) return existing;
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
const hash =
|
|
81
|
+
let funcName = handler.name || handler.toString();
|
|
82
|
+
const hash = this._fastHash(funcName);
|
|
82
83
|
const id = `d-${hash}`;
|
|
83
84
|
this.element._attr["data-domo-id"] = id;
|
|
84
85
|
return id;
|
|
85
86
|
}
|
|
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
87
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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;
|
|
88
|
+
_fastHash(str) {
|
|
89
|
+
let hash = 5381;
|
|
90
|
+
for (let i = 0; i < str.length; i++) {
|
|
91
|
+
hash = (hash * 33) ^ str.charCodeAt(i);
|
|
115
92
|
}
|
|
116
|
-
|
|
117
|
-
return caller;
|
|
93
|
+
return (hash >>> 0).toString(36);
|
|
118
94
|
}
|
|
119
95
|
}
|
|
120
96
|
|
|
@@ -12,40 +12,35 @@ class EventsServer extends ClassesServer {
|
|
|
12
12
|
* @param {object} [meta={}] - Injected by plugin: { _source, _name, ssg: boolean }
|
|
13
13
|
*/
|
|
14
14
|
on(eventMapOrName, callback, meta = {}) {
|
|
15
|
-
// If user passed options (meta), check if ssg is explicitly disabled
|
|
16
15
|
if (meta.ssg === false) return this;
|
|
17
16
|
|
|
18
|
-
const id = this._getOrSetId();
|
|
19
|
-
|
|
20
17
|
if (typeof eventMapOrName === "object" && eventMapOrName !== null) {
|
|
21
18
|
// In object mode: .on({ click: fn }, { _source: '...', _name: '...' })
|
|
22
19
|
// callback actually acts as the 'meta' argument here
|
|
23
20
|
const metadata = callback || {};
|
|
24
21
|
for (const [event, value] of Object.entries(eventMapOrName)) {
|
|
25
22
|
const handler = Array.isArray(value) ? value[0] : value;
|
|
26
|
-
this._pushEvent(
|
|
23
|
+
this._pushEvent("direct", event, handler, null, metadata);
|
|
27
24
|
}
|
|
28
25
|
} else if (typeof callback === "function") {
|
|
29
26
|
// In single mode: .on('click', fn, { _source: '...', _name: '...' })
|
|
30
|
-
this._pushEvent(
|
|
27
|
+
this._pushEvent("direct", eventMapOrName, callback, null, meta);
|
|
31
28
|
}
|
|
32
29
|
return this;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
onClosest(event, selectors = {}, meta = {}) {
|
|
36
33
|
if (meta.ssg === false) return this;
|
|
37
|
-
const id = this._getOrSetId();
|
|
38
34
|
for (const [selector, handler] of Object.entries(selectors)) {
|
|
39
|
-
this._pushEvent(
|
|
35
|
+
this._pushEvent("closest", event, handler, selector, meta);
|
|
40
36
|
}
|
|
41
37
|
return this;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
onMatch(event, selectors = {}, meta = {}) {
|
|
45
41
|
if (meta.ssg === false) return this;
|
|
46
|
-
const id = this._getOrSetId();
|
|
47
42
|
for (const [selector, handler] of Object.entries(selectors)) {
|
|
48
|
-
this._pushEvent(
|
|
43
|
+
this._pushEvent("match", event, handler, selector, meta);
|
|
49
44
|
}
|
|
50
45
|
return this;
|
|
51
46
|
}
|
|
@@ -54,25 +49,22 @@ class EventsServer extends ClassesServer {
|
|
|
54
49
|
* Internal helper to push event metadata.
|
|
55
50
|
* @private
|
|
56
51
|
*/
|
|
57
|
-
_pushEvent(
|
|
52
|
+
_pushEvent(type, event, handler, selector = null, meta = {}) {
|
|
58
53
|
const evArr = (this.element._events ??= []);
|
|
54
|
+
const id = this._getOrSetId(handler);
|
|
59
55
|
let existing = evArr.find((e) => e.id === id && e.event === event);
|
|
60
56
|
|
|
61
57
|
if (!existing) {
|
|
62
58
|
existing = { id, event, handlers: [] };
|
|
63
59
|
evArr.push(existing);
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
// Capture path and name from the 'meta' object stamped by the plugin
|
|
61
|
+
console.log("testing", existing);
|
|
67
62
|
existing.handlers.push({
|
|
68
63
|
type,
|
|
69
64
|
name: meta._name || handler.name || "anonymous",
|
|
70
65
|
handler,
|
|
71
|
-
path: meta._source || null, // STAMPED PATH
|
|
72
66
|
...(selector && { selector }),
|
|
73
67
|
});
|
|
74
|
-
|
|
75
|
-
// Tag as island so SSG knows to include domo.client.js
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
|