@brandup/ui 1.0.44 → 2.0.2
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/README.md +482 -33
- package/dist/cjs/constants.js +14 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/dom/bind-each.js +90 -0
- package/dist/cjs/dom/bind-each.js.map +1 -0
- package/dist/cjs/dom/bind.js +29 -0
- package/dist/cjs/dom/bind.js.map +1 -0
- package/dist/cjs/dom/binding-cleanup.js +162 -0
- package/dist/cjs/dom/binding-cleanup.js.map +1 -0
- package/dist/cjs/dom/dom.js +184 -0
- package/dist/cjs/dom/dom.js.map +1 -0
- package/dist/cjs/dom/helpers.js +33 -0
- package/dist/cjs/dom/helpers.js.map +1 -0
- package/dist/cjs/dom/index.js +14 -0
- package/dist/cjs/dom/index.js.map +1 -0
- package/dist/cjs/dom/tag.js +207 -0
- package/dist/cjs/dom/tag.js.map +1 -0
- package/dist/cjs/element.js +265 -0
- package/dist/cjs/element.js.map +1 -0
- package/dist/cjs/events.js +204 -0
- package/dist/cjs/events.js.map +1 -0
- package/dist/cjs/ext.js +20 -0
- package/dist/cjs/ext.js.map +1 -0
- package/dist/cjs/index.js +37 -313
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/reactive/computed.js +36 -0
- package/dist/cjs/reactive/computed.js.map +1 -0
- package/dist/cjs/reactive/effect.js +197 -0
- package/dist/cjs/reactive/effect.js.map +1 -0
- package/dist/cjs/reactive/reactive.js +106 -0
- package/dist/cjs/reactive/reactive.js.map +1 -0
- package/dist/mjs/constants.js +10 -0
- package/dist/mjs/constants.js.map +1 -0
- package/dist/mjs/dom/bind-each.js +86 -0
- package/dist/mjs/dom/bind-each.js.map +1 -0
- package/dist/mjs/dom/bind.js +26 -0
- package/dist/mjs/dom/bind.js.map +1 -0
- package/dist/mjs/dom/binding-cleanup.js +156 -0
- package/dist/mjs/dom/binding-cleanup.js.map +1 -0
- package/dist/mjs/dom/dom.js +169 -0
- package/dist/mjs/dom/dom.js.map +1 -0
- package/dist/mjs/dom/helpers.js +29 -0
- package/dist/mjs/dom/helpers.js.map +1 -0
- package/dist/mjs/dom/index.js +12 -0
- package/dist/mjs/dom/index.js.map +1 -0
- package/dist/mjs/dom/tag.js +203 -0
- package/dist/mjs/dom/tag.js.map +1 -0
- package/dist/mjs/element.js +260 -0
- package/dist/mjs/element.js.map +1 -0
- package/dist/mjs/events.js +202 -0
- package/dist/mjs/events.js.map +1 -0
- package/dist/mjs/ext.js +18 -0
- package/dist/mjs/ext.js.map +1 -0
- package/dist/mjs/index.js +11 -314
- package/dist/mjs/index.js.map +1 -1
- package/dist/mjs/reactive/computed.js +33 -0
- package/dist/mjs/reactive/computed.js.map +1 -0
- package/dist/mjs/reactive/effect.js +187 -0
- package/dist/mjs/reactive/effect.js.map +1 -0
- package/dist/mjs/reactive/reactive.js +102 -0
- package/dist/mjs/reactive/reactive.js.map +1 -0
- package/dist/types.d.ts +489 -14
- package/package.json +9 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var events = require('./events.js');
|
|
4
|
+
var effect = require('./reactive/effect.js');
|
|
5
|
+
var bindingCleanup = require('./dom/binding-cleanup.js');
|
|
6
|
+
var constants = require('./constants.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wraps an `HTMLElement` and binds business logic, commands and events to it.
|
|
10
|
+
*
|
|
11
|
+
* The optional `TEvents` event map is merged with {@link UIElementEvents}, so subclasses
|
|
12
|
+
* can declare their own typed events in addition to the built-in `command`/`destroy`.
|
|
13
|
+
*/
|
|
14
|
+
class UIElement extends events.EventEmitter {
|
|
15
|
+
__element;
|
|
16
|
+
__events;
|
|
17
|
+
__commands;
|
|
18
|
+
__destroyed;
|
|
19
|
+
// Element members
|
|
20
|
+
/** The bound DOM element, or `undefined` until `setElement` is called. */
|
|
21
|
+
get element() { return this.__element; }
|
|
22
|
+
/**
|
|
23
|
+
* Bind a DOM element to this instance and run render logic. Can be called only once.
|
|
24
|
+
* @param elem Element to bind; throws if already bound or owned by another `UIElement`.
|
|
25
|
+
*/
|
|
26
|
+
setElement(elem) {
|
|
27
|
+
if (!elem)
|
|
28
|
+
throw new Error("Not set value elem.");
|
|
29
|
+
if (this.__element || UIElement.hasElement(elem))
|
|
30
|
+
throw new Error("UIElement already defined");
|
|
31
|
+
this.__element = elem;
|
|
32
|
+
elem[constants.default.ElemPropertyName] = this;
|
|
33
|
+
elem.dataset[constants.default.ElemAttributeName] = this.typeName;
|
|
34
|
+
bindingCleanup.trackAutoDestroy(elem, () => this.destroy());
|
|
35
|
+
this._onRenderElement(elem);
|
|
36
|
+
this.__raise("rendered", this);
|
|
37
|
+
}
|
|
38
|
+
// static members
|
|
39
|
+
/**
|
|
40
|
+
* Whether the given element is already bound to a `UIElement`.
|
|
41
|
+
* @param elem Element to test.
|
|
42
|
+
*/
|
|
43
|
+
static hasElement(elem) {
|
|
44
|
+
return !!elem.dataset[constants.default.ElemAttributeName];
|
|
45
|
+
}
|
|
46
|
+
// Command members
|
|
47
|
+
/**
|
|
48
|
+
* Register a handler for a command declared in markup via the `data-command` attribute.
|
|
49
|
+
* @param name Command name (case-insensitive); throws if already registered.
|
|
50
|
+
* @param execute Handler run when the command fires; may return a `Promise` for async commands.
|
|
51
|
+
* @param canExecute Optional predicate gating whether the command may run.
|
|
52
|
+
* @returns This instance for chaining.
|
|
53
|
+
*/
|
|
54
|
+
registerCommand(name, execute, canExecute) {
|
|
55
|
+
if (this.__destroyed)
|
|
56
|
+
return this;
|
|
57
|
+
const commands = this.__commands || (this.__commands = {});
|
|
58
|
+
const normalizedName = name.toLowerCase();
|
|
59
|
+
if (normalizedName in commands)
|
|
60
|
+
throw new Error(`Command "${name}" already registered.`);
|
|
61
|
+
commands[normalizedName] = {
|
|
62
|
+
name: name,
|
|
63
|
+
execute,
|
|
64
|
+
canExecute
|
|
65
|
+
};
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Whether a command with the given name is registered.
|
|
70
|
+
* @param name Command name (case-insensitive).
|
|
71
|
+
*/
|
|
72
|
+
hasCommand(name) {
|
|
73
|
+
return !!this.__commands && name.toLowerCase() in this.__commands;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Execute a registered command against a target element.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
__execCommand(name, target) {
|
|
80
|
+
if (this.__destroyed || !this.__element)
|
|
81
|
+
throw new Error("UIElement is destroyed or has no element.");
|
|
82
|
+
const key = name.toLowerCase();
|
|
83
|
+
const command = this.__commands?.[key];
|
|
84
|
+
if (!command)
|
|
85
|
+
throw new Error(`Command "${name}" is not registered.`);
|
|
86
|
+
const context = {
|
|
87
|
+
target,
|
|
88
|
+
uiElem: this
|
|
89
|
+
};
|
|
90
|
+
if (command.isExecuting)
|
|
91
|
+
return { status: "already", context };
|
|
92
|
+
command.isExecuting = true;
|
|
93
|
+
// keep isExecuting cleanup inside finally so a throw in the
|
|
94
|
+
// guards/trigger/execute can never leave the command stuck.
|
|
95
|
+
let isAsync = false;
|
|
96
|
+
try {
|
|
97
|
+
if (!this._onCanExecCommand(name, target))
|
|
98
|
+
return { status: "disallow", context };
|
|
99
|
+
if (command.canExecute && !command.canExecute(context))
|
|
100
|
+
return { status: "disallow", context };
|
|
101
|
+
this.__raise("command", { element: this, name: command.name });
|
|
102
|
+
const commandResult = command.execute(context);
|
|
103
|
+
if (commandResult instanceof Promise) {
|
|
104
|
+
isAsync = true;
|
|
105
|
+
target.classList.add(constants.default.CommandExecutingCssClassName);
|
|
106
|
+
commandResult
|
|
107
|
+
// command owns its errors; log so failures aren't silent, and avoid unhandled rejection
|
|
108
|
+
.catch((reason) => console.error(`Command "${command.name}" failed.`, reason))
|
|
109
|
+
.finally(() => {
|
|
110
|
+
target.classList.remove(constants.default.CommandExecutingCssClassName);
|
|
111
|
+
delete command.isExecuting;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return { status: "success", context };
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (!isAsync)
|
|
118
|
+
delete command.isExecuting;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Hook invoked when an element is bound via `setElement`. Override to render or wire up the element.
|
|
123
|
+
* @param _elem The newly bound element.
|
|
124
|
+
*/
|
|
125
|
+
/** Trigger a built-in event. Typed by {@link UIElementEvents}; bypasses the generic trigger overload internally. */
|
|
126
|
+
__raise(name, ...args) {
|
|
127
|
+
this.trigger(name, ...args);
|
|
128
|
+
}
|
|
129
|
+
_onRenderElement(_elem) { }
|
|
130
|
+
/**
|
|
131
|
+
* Hook deciding whether a command may execute. Override to add element-wide gating.
|
|
132
|
+
* @param _name Command name being executed.
|
|
133
|
+
* @param _elem Target element of the command.
|
|
134
|
+
* @returns `true` to allow execution (default), `false` to disallow.
|
|
135
|
+
*/
|
|
136
|
+
_onCanExecCommand(_name, _elem) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create an {@link EffectScope} whose reactive effects are stopped automatically when
|
|
141
|
+
* this element is destroyed. Use it to scope `bind`/`effect` to the element's lifetime.
|
|
142
|
+
*/
|
|
143
|
+
effectScope() {
|
|
144
|
+
const scope = effect.effectScope();
|
|
145
|
+
this.on("destroy", () => scope.stop());
|
|
146
|
+
return scope;
|
|
147
|
+
}
|
|
148
|
+
/** Returns the `typeName` of this element. */
|
|
149
|
+
toString() { return this.typeName; }
|
|
150
|
+
/** Destroy the element: trigger the `destroy` event, release events/commands and detach from the DOM element. */
|
|
151
|
+
destroy() {
|
|
152
|
+
if (this.__destroyed)
|
|
153
|
+
return;
|
|
154
|
+
this.__destroyed = true;
|
|
155
|
+
this.__raise("destroy", this);
|
|
156
|
+
super.stopEvents();
|
|
157
|
+
const elem = this.__element;
|
|
158
|
+
if (elem) {
|
|
159
|
+
bindingCleanup.destroyUIElementsWithin(elem); // cascade to nested UIElements, deepest first
|
|
160
|
+
bindingCleanup.untrackAutoDestroy(elem);
|
|
161
|
+
bindingCleanup.disposeBindingsWithin(elem);
|
|
162
|
+
delete elem.dataset[constants.default.ElemAttributeName];
|
|
163
|
+
delete elem[constants.default.ElemPropertyName];
|
|
164
|
+
}
|
|
165
|
+
delete this.__element;
|
|
166
|
+
delete this.__events;
|
|
167
|
+
delete this.__commands;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A {@link UIElement} whose DOM element is bound in the constructor, so its `element`
|
|
172
|
+
* is always defined (typed `HTMLElement`, never `undefined`). Subclasses pass their
|
|
173
|
+
* `typeName` and the element to `super`.
|
|
174
|
+
*
|
|
175
|
+
* Use {@link UIElement} directly when the element is bound later (e.g. an application
|
|
176
|
+
* that binds its element on run).
|
|
177
|
+
*/
|
|
178
|
+
class UIElementBound extends UIElement {
|
|
179
|
+
__typeName;
|
|
180
|
+
/** @param typeName Unique type name of this element. @param elem Element to bind. */
|
|
181
|
+
constructor(typeName, elem) {
|
|
182
|
+
super();
|
|
183
|
+
this.__typeName = typeName; // set before setElement (no field-initializer race)
|
|
184
|
+
this.setElement(elem);
|
|
185
|
+
}
|
|
186
|
+
get typeName() { return this.__typeName; }
|
|
187
|
+
/** The bound DOM element; always defined since it is set in the constructor. */
|
|
188
|
+
get element() { return super.element; }
|
|
189
|
+
}
|
|
190
|
+
const findUiElementByCommand = (elem, commandName) => {
|
|
191
|
+
let current = elem;
|
|
192
|
+
while (current) {
|
|
193
|
+
if (current.dataset[constants.default.ElemAttributeName]) {
|
|
194
|
+
const uiElem = current[constants.default.ElemPropertyName];
|
|
195
|
+
if (uiElem.hasCommand(commandName))
|
|
196
|
+
return uiElem;
|
|
197
|
+
}
|
|
198
|
+
current = current.parentElement;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
};
|
|
202
|
+
const commandClickHandler = (e) => {
|
|
203
|
+
// walk up from the clicked element to the nearest ancestor declaring a command
|
|
204
|
+
let commandElem = e.target;
|
|
205
|
+
while (commandElem && !commandElem.dataset[constants.default.CommandAttributeName])
|
|
206
|
+
commandElem = commandElem.parentElement;
|
|
207
|
+
if (!commandElem)
|
|
208
|
+
return;
|
|
209
|
+
const commandName = commandElem.dataset[constants.default.CommandAttributeName];
|
|
210
|
+
if (!commandName)
|
|
211
|
+
throw new Error("Command data attribute does not have a value.");
|
|
212
|
+
const uiElem = findUiElementByCommand(commandElem, commandName);
|
|
213
|
+
// A click on a data-command element is owned by the library: prevent the element's
|
|
214
|
+
// default action (e.g. <a> navigation) and stop the click chain — UNLESS the command
|
|
215
|
+
// completed successfully and asked to stay transparent. This runs in `finally`, so a
|
|
216
|
+
// throwing command can never skip preventDefault and let the page navigate/reload.
|
|
217
|
+
let transparent = false;
|
|
218
|
+
try {
|
|
219
|
+
if (uiElem) {
|
|
220
|
+
const result = uiElem.__execCommand(commandName, commandElem);
|
|
221
|
+
transparent = result.status === "success" && !!result.context.transparent;
|
|
222
|
+
}
|
|
223
|
+
else
|
|
224
|
+
console.warn(`Not find handler for command "${commandName}".`);
|
|
225
|
+
}
|
|
226
|
+
catch (reason) {
|
|
227
|
+
console.error(`Command "${commandName}" failed.`, reason);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
if (!transparent) {
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
e.stopImmediatePropagation();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
let __commandsInited = false;
|
|
238
|
+
/**
|
|
239
|
+
* Register the global click handler that dispatches {@link UIElement} commands declared in
|
|
240
|
+
* markup via `data-command`. Call once during application startup. Idempotent and a no-op in
|
|
241
|
+
* a non-DOM environment. {@link Application.run} (in `@brandup/ui-app`) calls this automatically;
|
|
242
|
+
* call it yourself only when using `UIElement` commands without an `Application`.
|
|
243
|
+
*
|
|
244
|
+
* Making this explicit (instead of a side effect on import) lets bundlers tree-shake the
|
|
245
|
+
* command system away for consumers that don't use it.
|
|
246
|
+
*/
|
|
247
|
+
function initUICommands() {
|
|
248
|
+
if (__commandsInited || typeof window === "undefined")
|
|
249
|
+
return;
|
|
250
|
+
__commandsInited = true;
|
|
251
|
+
window.addEventListener("click", commandClickHandler);
|
|
252
|
+
}
|
|
253
|
+
/** Remove the global command click handler registered by {@link initUICommands} (e.g. on HMR disposal or teardown). */
|
|
254
|
+
function destroyUI() {
|
|
255
|
+
if (!__commandsInited || typeof window === "undefined")
|
|
256
|
+
return;
|
|
257
|
+
__commandsInited = false;
|
|
258
|
+
window.removeEventListener("click", commandClickHandler);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
exports.UIElement = UIElement;
|
|
262
|
+
exports.UIElementBound = UIElementBound;
|
|
263
|
+
exports.destroyUI = destroyUI;
|
|
264
|
+
exports.initUICommands = initUICommands;
|
|
265
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sources":["../../../source/element.ts"],"sourcesContent":[null],"names":["EventEmitter","UICONSTANTS","trackAutoDestroy","createEffectScope","destroyUIElementsWithin","untrackAutoDestroy","disposeBindingsWithin"],"mappings":";;;;;;;AAuBA;;;;;AAKG;AACG,MAAgB,SAAwB,SAAQA,mBAAmC,CAAA;AAChF,IAAA,SAAS;AACT,IAAA,QAAQ;AACR,IAAA,UAAU;AACV,IAAA,WAAW;;;IAQnB,IAAI,OAAO,KAA8B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;AAEhE;;;AAGG;AACO,IAAA,UAAU,CAAC,IAAiB,EAAA;AACrC,QAAA,IAAI,CAAC,IAAI;AACR,YAAA,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC;QAEvC,IAAI,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC;AAC/C,YAAA,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC;AA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C,gBAAgB,IAAI,OAAO,MAAM,KAAK,WAAW;QACrD;IACD,gBAAgB,GAAG,KAAK;AACxB,IAAA,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,CAAC;AACzD;;;;;;;"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let ListenCounter = 1;
|
|
4
|
+
/**
|
|
5
|
+
* Minimal event emitter with support for one-off listeners and cross-emitter listening.
|
|
6
|
+
*
|
|
7
|
+
* The optional `TEvents` type parameter is an event map (`{ eventName: (args) => void }`)
|
|
8
|
+
* that gives subclasses strongly-typed event names, callback signatures and `trigger` arguments.
|
|
9
|
+
* When omitted it defaults to a loose map, so untyped usage keeps working.
|
|
10
|
+
*/
|
|
11
|
+
class EventEmitter {
|
|
12
|
+
_events;
|
|
13
|
+
_listenId;
|
|
14
|
+
_listeningTo;
|
|
15
|
+
on(eventName, callback, context) {
|
|
16
|
+
const events = this._getOrCreateEvents(eventName);
|
|
17
|
+
events.push({ callback, context: context || undefined, ctx: context || this });
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
once(eventName, callback, context) {
|
|
21
|
+
const wrapper = (...args) => {
|
|
22
|
+
this.off(eventName, wrapper, context);
|
|
23
|
+
callback.apply(context || this, args);
|
|
24
|
+
};
|
|
25
|
+
return this.on(eventName, wrapper, context);
|
|
26
|
+
}
|
|
27
|
+
off(eventName, callback, context) {
|
|
28
|
+
if (!eventName && !callback && !context)
|
|
29
|
+
throw new Error("Require off arguments.");
|
|
30
|
+
const events = this._events;
|
|
31
|
+
if (!events)
|
|
32
|
+
return this;
|
|
33
|
+
callback = callback || undefined;
|
|
34
|
+
context = context || undefined;
|
|
35
|
+
const eventNames = eventName ? [eventName.toLowerCase()] : Object.keys(events);
|
|
36
|
+
for (let i = 0; i < eventNames.length; i++) {
|
|
37
|
+
const name = eventNames[i];
|
|
38
|
+
const currentCallbacks = events[name];
|
|
39
|
+
if (!currentCallbacks)
|
|
40
|
+
continue;
|
|
41
|
+
// reset callback list
|
|
42
|
+
const newCallbacks = events[name] = [];
|
|
43
|
+
if (callback || context) {
|
|
44
|
+
currentCallbacks.forEach(c => {
|
|
45
|
+
const callbackMatch = !callback || c.callback === callback;
|
|
46
|
+
const contextMatch = !context || c.context === context;
|
|
47
|
+
if (callbackMatch && contextMatch)
|
|
48
|
+
return;
|
|
49
|
+
newCallbacks.push(c);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!newCallbacks.length)
|
|
53
|
+
delete events[name];
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Listen to an event on another emitter, tracking the subscription so it can be released via `stopListening`.
|
|
59
|
+
* @param source Emitter to subscribe to.
|
|
60
|
+
* @param eventName Event name to listen for.
|
|
61
|
+
* @param callback Handler invoked when the event is triggered.
|
|
62
|
+
*/
|
|
63
|
+
listenTo(source, eventName, callback) {
|
|
64
|
+
this._addListeningTo(source, eventName, callback, callback);
|
|
65
|
+
source.on(eventName, callback, this);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Listen once to an event on another emitter; the subscription is tracked and auto-removed after it fires.
|
|
70
|
+
* @param source Emitter to subscribe to.
|
|
71
|
+
* @param eventName Event name to listen for.
|
|
72
|
+
* @param callback Handler invoked once when the event is triggered.
|
|
73
|
+
*/
|
|
74
|
+
listenToOnce(source, eventName, callback) {
|
|
75
|
+
// Use our own one-shot wrapper instead of source.once so that, when it fires,
|
|
76
|
+
// we can drop this exact subscription from BOTH sides — the source and our
|
|
77
|
+
// own _listeningTo registry — keeping the two in sync (no dangling tracking).
|
|
78
|
+
const wrapper = (...args) => {
|
|
79
|
+
source.off(eventName, wrapper, this);
|
|
80
|
+
this._removeListeningSubscription(source, eventName, wrapper);
|
|
81
|
+
callback.apply(this, args);
|
|
82
|
+
};
|
|
83
|
+
this._addListeningTo(source, eventName, wrapper, callback);
|
|
84
|
+
source.on(eventName, wrapper, this);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Release subscriptions previously established with `listenTo`/`listenToOnce`.
|
|
89
|
+
* Omitted arguments broaden the match (e.g. no `source` releases all tracked emitters).
|
|
90
|
+
* @param source Limit to a specific emitter, or omit for all.
|
|
91
|
+
* @param eventName Limit to a specific event, or omit for all.
|
|
92
|
+
* @param callback Limit to a specific handler, or omit for all.
|
|
93
|
+
*/
|
|
94
|
+
stopListening(source, eventName, callback) {
|
|
95
|
+
if (!this._listeningTo)
|
|
96
|
+
return this;
|
|
97
|
+
// A source we never listened to has no tracked subscriptions — nothing to do.
|
|
98
|
+
const listenings = source
|
|
99
|
+
? (source._listenId && this._listeningTo[source._listenId] ? [this._listeningTo[source._listenId]] : [])
|
|
100
|
+
: Object.values(this._listeningTo);
|
|
101
|
+
const targetEvent = eventName ? eventName.toLowerCase() : undefined;
|
|
102
|
+
listenings.forEach(listening => {
|
|
103
|
+
// snapshot: the loop splices listening.subscriptions
|
|
104
|
+
listening.subscriptions.slice().forEach(sub => {
|
|
105
|
+
if (targetEvent && sub.eventName !== targetEvent)
|
|
106
|
+
return;
|
|
107
|
+
// match the user-supplied callback against both the registered
|
|
108
|
+
// callback and the original (so a listenToOnce can be stopped by
|
|
109
|
+
// the callback the caller passed, not the internal wrapper)
|
|
110
|
+
if (callback && sub.callback !== callback && sub.origin !== callback)
|
|
111
|
+
return;
|
|
112
|
+
listening.emitter.off(sub.eventName, sub.callback, this);
|
|
113
|
+
const index = listening.subscriptions.indexOf(sub);
|
|
114
|
+
if (index >= 0)
|
|
115
|
+
listening.subscriptions.splice(index, 1);
|
|
116
|
+
});
|
|
117
|
+
if (!listening.subscriptions.length && listening.emitter._listenId)
|
|
118
|
+
delete this._listeningTo[listening.emitter._listenId];
|
|
119
|
+
});
|
|
120
|
+
if (!this._listeningTo || Object.keys(this._listeningTo).length === 0)
|
|
121
|
+
delete this._listeningTo;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
_addListeningTo(source, eventName, callback, origin) {
|
|
125
|
+
const listeningTo = this._listeningTo || (this._listeningTo = {});
|
|
126
|
+
const listenId = source._listenId || (source._listenId = `l${ListenCounter++}`);
|
|
127
|
+
const listenTo = listeningTo[listenId] || (listeningTo[listenId] = { emitter: source, subscriptions: [] });
|
|
128
|
+
// one entry per subscription (not per event name) so each can be removed
|
|
129
|
+
// independently — e.g. a listenToOnce dropping itself without disturbing
|
|
130
|
+
// a co-registered persistent listenTo on the same source+event.
|
|
131
|
+
listenTo.subscriptions.push({ eventName: eventName.toLowerCase(), callback, origin });
|
|
132
|
+
}
|
|
133
|
+
/** Remove a single tracked subscription (matched by event + registered callback). @internal */
|
|
134
|
+
_removeListeningSubscription(source, eventName, callback) {
|
|
135
|
+
const listenId = source._listenId;
|
|
136
|
+
if (!this._listeningTo || !listenId)
|
|
137
|
+
return;
|
|
138
|
+
const listening = this._listeningTo[listenId];
|
|
139
|
+
if (!listening)
|
|
140
|
+
return;
|
|
141
|
+
eventName = eventName.toLowerCase();
|
|
142
|
+
const index = listening.subscriptions.findIndex(s => s.eventName === eventName && s.callback === callback);
|
|
143
|
+
if (index >= 0)
|
|
144
|
+
listening.subscriptions.splice(index, 1);
|
|
145
|
+
if (!listening.subscriptions.length)
|
|
146
|
+
delete this._listeningTo[listenId];
|
|
147
|
+
if (Object.keys(this._listeningTo).length === 0)
|
|
148
|
+
delete this._listeningTo;
|
|
149
|
+
}
|
|
150
|
+
stopAllListeners() {
|
|
151
|
+
if (!this._events)
|
|
152
|
+
return;
|
|
153
|
+
Object.values(this._events).forEach(callbacks => {
|
|
154
|
+
callbacks.forEach(callback => {
|
|
155
|
+
if (callback.context instanceof EventEmitter)
|
|
156
|
+
callback.context.stopListening(this);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
delete this._events;
|
|
160
|
+
}
|
|
161
|
+
trigger(eventName, ...args) {
|
|
162
|
+
eventName = eventName.toLowerCase();
|
|
163
|
+
if (eventName === "all")
|
|
164
|
+
throw new Error('Not allow trigger all event.');
|
|
165
|
+
if (!this._events)
|
|
166
|
+
return this;
|
|
167
|
+
const events = this._getEvents(eventName);
|
|
168
|
+
const allEvents = this._getEvents("all");
|
|
169
|
+
this._triggerEvent(events, ...args);
|
|
170
|
+
this._triggerEvent(allEvents, ...args);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
_triggerEvent(events, ...args) {
|
|
174
|
+
if (!events || !events.length)
|
|
175
|
+
return;
|
|
176
|
+
// snapshot so callbacks added/removed during dispatch don't affect this trigger
|
|
177
|
+
const snapshot = events.slice();
|
|
178
|
+
for (let i = 0; i < snapshot.length; i++) {
|
|
179
|
+
const event = snapshot[i];
|
|
180
|
+
event.callback.apply(event.ctx, args);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
_getOrCreateEvents(eventName) {
|
|
184
|
+
eventName = eventName.toLowerCase();
|
|
185
|
+
const events = this._events || (this._events = {});
|
|
186
|
+
return events[eventName] || (events[eventName] = []);
|
|
187
|
+
}
|
|
188
|
+
_getEvents(eventName) {
|
|
189
|
+
if (!eventName)
|
|
190
|
+
return;
|
|
191
|
+
const events = this._events;
|
|
192
|
+
if (!events)
|
|
193
|
+
return;
|
|
194
|
+
return events[eventName];
|
|
195
|
+
}
|
|
196
|
+
/** Release every subscription: both events this emitter listens to and listeners registered on it. */
|
|
197
|
+
stopEvents() {
|
|
198
|
+
this.stopListening();
|
|
199
|
+
this.stopAllListeners();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
exports.EventEmitter = EventEmitter;
|
|
204
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sources":["../../../source/events.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA,IAAI,aAAa,GAAG,CAAC;AAErB;;;;;;AAMG;MACU,YAAY,CAAA;AA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A,OAAO,MAAM,CAAC,SAAS,CAAC;IACzB;;IAGU,UAAU,GAAA;QACnB,IAAI,CAAC,aAAa,EAAE;QACpB,IAAI,CAAC,gBAAgB,EAAE;IACxB;AACA;;;;"}
|
package/dist/cjs/ext.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let __inited = false;
|
|
4
|
+
/**
|
|
5
|
+
* Install the `HTMLElement.prototype.ui(factory)` convenience binder. Opt-in (no longer a
|
|
6
|
+
* side effect on import) so bundlers can tree-shake it away for consumers that don't use it.
|
|
7
|
+
* Idempotent and a no-op in a non-DOM environment.
|
|
8
|
+
*/
|
|
9
|
+
function enableElementExtensions() {
|
|
10
|
+
if (__inited || typeof HTMLElement === "undefined")
|
|
11
|
+
return;
|
|
12
|
+
__inited = true;
|
|
13
|
+
HTMLElement.prototype.ui = function (factory) {
|
|
14
|
+
factory(this);
|
|
15
|
+
return this;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.enableElementExtensions = enableElementExtensions;
|
|
20
|
+
//# sourceMappingURL=ext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ext.js","sources":["../../../source/ext.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAiBA,IAAI,QAAQ,GAAG,KAAK;AAEpB;;;;AAIG;SACa,uBAAuB,GAAA;AACtC,IAAA,IAAI,QAAQ,IAAI,OAAO,WAAW,KAAK,WAAW;QACjD;IACD,QAAQ,GAAG,IAAI;AAEf,IAAA,WAAW,CAAC,SAAS,CAAC,EAAE,GAAG,UAAU,OAAyC,EAAA;QAC7E,OAAO,CAAC,IAAI,CAAC;AACb,QAAA,OAAO,IAAI;AACZ,IAAA,CAAC;AACF;;;;"}
|