relay_ui 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/relay_ui/version.rb +1 -1
- data/vendor/assets/javascripts/relay_ui/dist/relay_ui.js +2471 -0
- data/vendor/assets/stylesheets/relay_ui/relay_ui.css +2528 -0
- metadata +3 -1
@@ -0,0 +1,2471 @@
|
|
1
|
+
(() => {
|
2
|
+
// node_modules/@hotwired/stimulus/dist/stimulus.js
|
3
|
+
var EventListener = class {
|
4
|
+
constructor(eventTarget, eventName, eventOptions) {
|
5
|
+
this.eventTarget = eventTarget;
|
6
|
+
this.eventName = eventName;
|
7
|
+
this.eventOptions = eventOptions;
|
8
|
+
this.unorderedBindings = /* @__PURE__ */ new Set();
|
9
|
+
}
|
10
|
+
connect() {
|
11
|
+
this.eventTarget.addEventListener(this.eventName, this, this.eventOptions);
|
12
|
+
}
|
13
|
+
disconnect() {
|
14
|
+
this.eventTarget.removeEventListener(this.eventName, this, this.eventOptions);
|
15
|
+
}
|
16
|
+
bindingConnected(binding) {
|
17
|
+
this.unorderedBindings.add(binding);
|
18
|
+
}
|
19
|
+
bindingDisconnected(binding) {
|
20
|
+
this.unorderedBindings.delete(binding);
|
21
|
+
}
|
22
|
+
handleEvent(event) {
|
23
|
+
const extendedEvent = extendEvent(event);
|
24
|
+
for (const binding of this.bindings) {
|
25
|
+
if (extendedEvent.immediatePropagationStopped) {
|
26
|
+
break;
|
27
|
+
} else {
|
28
|
+
binding.handleEvent(extendedEvent);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
hasBindings() {
|
33
|
+
return this.unorderedBindings.size > 0;
|
34
|
+
}
|
35
|
+
get bindings() {
|
36
|
+
return Array.from(this.unorderedBindings).sort((left, right) => {
|
37
|
+
const leftIndex = left.index, rightIndex = right.index;
|
38
|
+
return leftIndex < rightIndex ? -1 : leftIndex > rightIndex ? 1 : 0;
|
39
|
+
});
|
40
|
+
}
|
41
|
+
};
|
42
|
+
function extendEvent(event) {
|
43
|
+
if ("immediatePropagationStopped" in event) {
|
44
|
+
return event;
|
45
|
+
} else {
|
46
|
+
const { stopImmediatePropagation } = event;
|
47
|
+
return Object.assign(event, {
|
48
|
+
immediatePropagationStopped: false,
|
49
|
+
stopImmediatePropagation() {
|
50
|
+
this.immediatePropagationStopped = true;
|
51
|
+
stopImmediatePropagation.call(this);
|
52
|
+
}
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
var Dispatcher = class {
|
57
|
+
constructor(application2) {
|
58
|
+
this.application = application2;
|
59
|
+
this.eventListenerMaps = /* @__PURE__ */ new Map();
|
60
|
+
this.started = false;
|
61
|
+
}
|
62
|
+
start() {
|
63
|
+
if (!this.started) {
|
64
|
+
this.started = true;
|
65
|
+
this.eventListeners.forEach((eventListener) => eventListener.connect());
|
66
|
+
}
|
67
|
+
}
|
68
|
+
stop() {
|
69
|
+
if (this.started) {
|
70
|
+
this.started = false;
|
71
|
+
this.eventListeners.forEach((eventListener) => eventListener.disconnect());
|
72
|
+
}
|
73
|
+
}
|
74
|
+
get eventListeners() {
|
75
|
+
return Array.from(this.eventListenerMaps.values()).reduce((listeners, map) => listeners.concat(Array.from(map.values())), []);
|
76
|
+
}
|
77
|
+
bindingConnected(binding) {
|
78
|
+
this.fetchEventListenerForBinding(binding).bindingConnected(binding);
|
79
|
+
}
|
80
|
+
bindingDisconnected(binding, clearEventListeners = false) {
|
81
|
+
this.fetchEventListenerForBinding(binding).bindingDisconnected(binding);
|
82
|
+
if (clearEventListeners)
|
83
|
+
this.clearEventListenersForBinding(binding);
|
84
|
+
}
|
85
|
+
handleError(error2, message, detail = {}) {
|
86
|
+
this.application.handleError(error2, `Error ${message}`, detail);
|
87
|
+
}
|
88
|
+
clearEventListenersForBinding(binding) {
|
89
|
+
const eventListener = this.fetchEventListenerForBinding(binding);
|
90
|
+
if (!eventListener.hasBindings()) {
|
91
|
+
eventListener.disconnect();
|
92
|
+
this.removeMappedEventListenerFor(binding);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
removeMappedEventListenerFor(binding) {
|
96
|
+
const { eventTarget, eventName, eventOptions } = binding;
|
97
|
+
const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);
|
98
|
+
const cacheKey = this.cacheKey(eventName, eventOptions);
|
99
|
+
eventListenerMap.delete(cacheKey);
|
100
|
+
if (eventListenerMap.size == 0)
|
101
|
+
this.eventListenerMaps.delete(eventTarget);
|
102
|
+
}
|
103
|
+
fetchEventListenerForBinding(binding) {
|
104
|
+
const { eventTarget, eventName, eventOptions } = binding;
|
105
|
+
return this.fetchEventListener(eventTarget, eventName, eventOptions);
|
106
|
+
}
|
107
|
+
fetchEventListener(eventTarget, eventName, eventOptions) {
|
108
|
+
const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);
|
109
|
+
const cacheKey = this.cacheKey(eventName, eventOptions);
|
110
|
+
let eventListener = eventListenerMap.get(cacheKey);
|
111
|
+
if (!eventListener) {
|
112
|
+
eventListener = this.createEventListener(eventTarget, eventName, eventOptions);
|
113
|
+
eventListenerMap.set(cacheKey, eventListener);
|
114
|
+
}
|
115
|
+
return eventListener;
|
116
|
+
}
|
117
|
+
createEventListener(eventTarget, eventName, eventOptions) {
|
118
|
+
const eventListener = new EventListener(eventTarget, eventName, eventOptions);
|
119
|
+
if (this.started) {
|
120
|
+
eventListener.connect();
|
121
|
+
}
|
122
|
+
return eventListener;
|
123
|
+
}
|
124
|
+
fetchEventListenerMapForEventTarget(eventTarget) {
|
125
|
+
let eventListenerMap = this.eventListenerMaps.get(eventTarget);
|
126
|
+
if (!eventListenerMap) {
|
127
|
+
eventListenerMap = /* @__PURE__ */ new Map();
|
128
|
+
this.eventListenerMaps.set(eventTarget, eventListenerMap);
|
129
|
+
}
|
130
|
+
return eventListenerMap;
|
131
|
+
}
|
132
|
+
cacheKey(eventName, eventOptions) {
|
133
|
+
const parts = [eventName];
|
134
|
+
Object.keys(eventOptions).sort().forEach((key) => {
|
135
|
+
parts.push(`${eventOptions[key] ? "" : "!"}${key}`);
|
136
|
+
});
|
137
|
+
return parts.join(":");
|
138
|
+
}
|
139
|
+
};
|
140
|
+
var defaultActionDescriptorFilters = {
|
141
|
+
stop({ event, value }) {
|
142
|
+
if (value)
|
143
|
+
event.stopPropagation();
|
144
|
+
return true;
|
145
|
+
},
|
146
|
+
prevent({ event, value }) {
|
147
|
+
if (value)
|
148
|
+
event.preventDefault();
|
149
|
+
return true;
|
150
|
+
},
|
151
|
+
self({ event, value, element }) {
|
152
|
+
if (value) {
|
153
|
+
return element === event.target;
|
154
|
+
} else {
|
155
|
+
return true;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
};
|
159
|
+
var descriptorPattern = /^(?:(?:([^.]+?)\+)?(.+?)(?:\.(.+?))?(?:@(window|document))?->)?(.+?)(?:#([^:]+?))(?::(.+))?$/;
|
160
|
+
function parseActionDescriptorString(descriptorString) {
|
161
|
+
const source = descriptorString.trim();
|
162
|
+
const matches = source.match(descriptorPattern) || [];
|
163
|
+
let eventName = matches[2];
|
164
|
+
let keyFilter = matches[3];
|
165
|
+
if (keyFilter && !["keydown", "keyup", "keypress"].includes(eventName)) {
|
166
|
+
eventName += `.${keyFilter}`;
|
167
|
+
keyFilter = "";
|
168
|
+
}
|
169
|
+
return {
|
170
|
+
eventTarget: parseEventTarget(matches[4]),
|
171
|
+
eventName,
|
172
|
+
eventOptions: matches[7] ? parseEventOptions(matches[7]) : {},
|
173
|
+
identifier: matches[5],
|
174
|
+
methodName: matches[6],
|
175
|
+
keyFilter: matches[1] || keyFilter
|
176
|
+
};
|
177
|
+
}
|
178
|
+
function parseEventTarget(eventTargetName) {
|
179
|
+
if (eventTargetName == "window") {
|
180
|
+
return window;
|
181
|
+
} else if (eventTargetName == "document") {
|
182
|
+
return document;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
function parseEventOptions(eventOptions) {
|
186
|
+
return eventOptions.split(":").reduce((options, token) => Object.assign(options, { [token.replace(/^!/, "")]: !/^!/.test(token) }), {});
|
187
|
+
}
|
188
|
+
function stringifyEventTarget(eventTarget) {
|
189
|
+
if (eventTarget == window) {
|
190
|
+
return "window";
|
191
|
+
} else if (eventTarget == document) {
|
192
|
+
return "document";
|
193
|
+
}
|
194
|
+
}
|
195
|
+
function camelize(value) {
|
196
|
+
return value.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase());
|
197
|
+
}
|
198
|
+
function namespaceCamelize(value) {
|
199
|
+
return camelize(value.replace(/--/g, "-").replace(/__/g, "_"));
|
200
|
+
}
|
201
|
+
function capitalize(value) {
|
202
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
203
|
+
}
|
204
|
+
function dasherize(value) {
|
205
|
+
return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
|
206
|
+
}
|
207
|
+
function tokenize(value) {
|
208
|
+
return value.match(/[^\s]+/g) || [];
|
209
|
+
}
|
210
|
+
function isSomething(object) {
|
211
|
+
return object !== null && object !== void 0;
|
212
|
+
}
|
213
|
+
function hasProperty(object, property) {
|
214
|
+
return Object.prototype.hasOwnProperty.call(object, property);
|
215
|
+
}
|
216
|
+
var allModifiers = ["meta", "ctrl", "alt", "shift"];
|
217
|
+
var Action = class {
|
218
|
+
constructor(element, index, descriptor, schema) {
|
219
|
+
this.element = element;
|
220
|
+
this.index = index;
|
221
|
+
this.eventTarget = descriptor.eventTarget || element;
|
222
|
+
this.eventName = descriptor.eventName || getDefaultEventNameForElement(element) || error("missing event name");
|
223
|
+
this.eventOptions = descriptor.eventOptions || {};
|
224
|
+
this.identifier = descriptor.identifier || error("missing identifier");
|
225
|
+
this.methodName = descriptor.methodName || error("missing method name");
|
226
|
+
this.keyFilter = descriptor.keyFilter || "";
|
227
|
+
this.schema = schema;
|
228
|
+
}
|
229
|
+
static forToken(token, schema) {
|
230
|
+
return new this(token.element, token.index, parseActionDescriptorString(token.content), schema);
|
231
|
+
}
|
232
|
+
toString() {
|
233
|
+
const eventFilter = this.keyFilter ? `.${this.keyFilter}` : "";
|
234
|
+
const eventTarget = this.eventTargetName ? `@${this.eventTargetName}` : "";
|
235
|
+
return `${this.eventName}${eventFilter}${eventTarget}->${this.identifier}#${this.methodName}`;
|
236
|
+
}
|
237
|
+
shouldIgnoreKeyboardEvent(event) {
|
238
|
+
if (!this.keyFilter) {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
const filters = this.keyFilter.split("+");
|
242
|
+
if (this.keyFilterDissatisfied(event, filters)) {
|
243
|
+
return true;
|
244
|
+
}
|
245
|
+
const standardFilter = filters.filter((key) => !allModifiers.includes(key))[0];
|
246
|
+
if (!standardFilter) {
|
247
|
+
return false;
|
248
|
+
}
|
249
|
+
if (!hasProperty(this.keyMappings, standardFilter)) {
|
250
|
+
error(`contains unknown key filter: ${this.keyFilter}`);
|
251
|
+
}
|
252
|
+
return this.keyMappings[standardFilter].toLowerCase() !== event.key.toLowerCase();
|
253
|
+
}
|
254
|
+
shouldIgnoreMouseEvent(event) {
|
255
|
+
if (!this.keyFilter) {
|
256
|
+
return false;
|
257
|
+
}
|
258
|
+
const filters = [this.keyFilter];
|
259
|
+
if (this.keyFilterDissatisfied(event, filters)) {
|
260
|
+
return true;
|
261
|
+
}
|
262
|
+
return false;
|
263
|
+
}
|
264
|
+
get params() {
|
265
|
+
const params = {};
|
266
|
+
const pattern = new RegExp(`^data-${this.identifier}-(.+)-param$`, "i");
|
267
|
+
for (const { name, value } of Array.from(this.element.attributes)) {
|
268
|
+
const match = name.match(pattern);
|
269
|
+
const key = match && match[1];
|
270
|
+
if (key) {
|
271
|
+
params[camelize(key)] = typecast(value);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
return params;
|
275
|
+
}
|
276
|
+
get eventTargetName() {
|
277
|
+
return stringifyEventTarget(this.eventTarget);
|
278
|
+
}
|
279
|
+
get keyMappings() {
|
280
|
+
return this.schema.keyMappings;
|
281
|
+
}
|
282
|
+
keyFilterDissatisfied(event, filters) {
|
283
|
+
const [meta, ctrl, alt, shift] = allModifiers.map((modifier) => filters.includes(modifier));
|
284
|
+
return event.metaKey !== meta || event.ctrlKey !== ctrl || event.altKey !== alt || event.shiftKey !== shift;
|
285
|
+
}
|
286
|
+
};
|
287
|
+
var defaultEventNames = {
|
288
|
+
a: () => "click",
|
289
|
+
button: () => "click",
|
290
|
+
form: () => "submit",
|
291
|
+
details: () => "toggle",
|
292
|
+
input: (e) => e.getAttribute("type") == "submit" ? "click" : "input",
|
293
|
+
select: () => "change",
|
294
|
+
textarea: () => "input"
|
295
|
+
};
|
296
|
+
function getDefaultEventNameForElement(element) {
|
297
|
+
const tagName = element.tagName.toLowerCase();
|
298
|
+
if (tagName in defaultEventNames) {
|
299
|
+
return defaultEventNames[tagName](element);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
function error(message) {
|
303
|
+
throw new Error(message);
|
304
|
+
}
|
305
|
+
function typecast(value) {
|
306
|
+
try {
|
307
|
+
return JSON.parse(value);
|
308
|
+
} catch (o_O) {
|
309
|
+
return value;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
var Binding = class {
|
313
|
+
constructor(context, action) {
|
314
|
+
this.context = context;
|
315
|
+
this.action = action;
|
316
|
+
}
|
317
|
+
get index() {
|
318
|
+
return this.action.index;
|
319
|
+
}
|
320
|
+
get eventTarget() {
|
321
|
+
return this.action.eventTarget;
|
322
|
+
}
|
323
|
+
get eventOptions() {
|
324
|
+
return this.action.eventOptions;
|
325
|
+
}
|
326
|
+
get identifier() {
|
327
|
+
return this.context.identifier;
|
328
|
+
}
|
329
|
+
handleEvent(event) {
|
330
|
+
const actionEvent = this.prepareActionEvent(event);
|
331
|
+
if (this.willBeInvokedByEvent(event) && this.applyEventModifiers(actionEvent)) {
|
332
|
+
this.invokeWithEvent(actionEvent);
|
333
|
+
}
|
334
|
+
}
|
335
|
+
get eventName() {
|
336
|
+
return this.action.eventName;
|
337
|
+
}
|
338
|
+
get method() {
|
339
|
+
const method = this.controller[this.methodName];
|
340
|
+
if (typeof method == "function") {
|
341
|
+
return method;
|
342
|
+
}
|
343
|
+
throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`);
|
344
|
+
}
|
345
|
+
applyEventModifiers(event) {
|
346
|
+
const { element } = this.action;
|
347
|
+
const { actionDescriptorFilters } = this.context.application;
|
348
|
+
const { controller } = this.context;
|
349
|
+
let passes = true;
|
350
|
+
for (const [name, value] of Object.entries(this.eventOptions)) {
|
351
|
+
if (name in actionDescriptorFilters) {
|
352
|
+
const filter = actionDescriptorFilters[name];
|
353
|
+
passes = passes && filter({ name, value, event, element, controller });
|
354
|
+
} else {
|
355
|
+
continue;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
return passes;
|
359
|
+
}
|
360
|
+
prepareActionEvent(event) {
|
361
|
+
return Object.assign(event, { params: this.action.params });
|
362
|
+
}
|
363
|
+
invokeWithEvent(event) {
|
364
|
+
const { target, currentTarget } = event;
|
365
|
+
try {
|
366
|
+
this.method.call(this.controller, event);
|
367
|
+
this.context.logDebugActivity(this.methodName, { event, target, currentTarget, action: this.methodName });
|
368
|
+
} catch (error2) {
|
369
|
+
const { identifier, controller, element, index } = this;
|
370
|
+
const detail = { identifier, controller, element, index, event };
|
371
|
+
this.context.handleError(error2, `invoking action "${this.action}"`, detail);
|
372
|
+
}
|
373
|
+
}
|
374
|
+
willBeInvokedByEvent(event) {
|
375
|
+
const eventTarget = event.target;
|
376
|
+
if (event instanceof KeyboardEvent && this.action.shouldIgnoreKeyboardEvent(event)) {
|
377
|
+
return false;
|
378
|
+
}
|
379
|
+
if (event instanceof MouseEvent && this.action.shouldIgnoreMouseEvent(event)) {
|
380
|
+
return false;
|
381
|
+
}
|
382
|
+
if (this.element === eventTarget) {
|
383
|
+
return true;
|
384
|
+
} else if (eventTarget instanceof Element && this.element.contains(eventTarget)) {
|
385
|
+
return this.scope.containsElement(eventTarget);
|
386
|
+
} else {
|
387
|
+
return this.scope.containsElement(this.action.element);
|
388
|
+
}
|
389
|
+
}
|
390
|
+
get controller() {
|
391
|
+
return this.context.controller;
|
392
|
+
}
|
393
|
+
get methodName() {
|
394
|
+
return this.action.methodName;
|
395
|
+
}
|
396
|
+
get element() {
|
397
|
+
return this.scope.element;
|
398
|
+
}
|
399
|
+
get scope() {
|
400
|
+
return this.context.scope;
|
401
|
+
}
|
402
|
+
};
|
403
|
+
var ElementObserver = class {
|
404
|
+
constructor(element, delegate) {
|
405
|
+
this.mutationObserverInit = { attributes: true, childList: true, subtree: true };
|
406
|
+
this.element = element;
|
407
|
+
this.started = false;
|
408
|
+
this.delegate = delegate;
|
409
|
+
this.elements = /* @__PURE__ */ new Set();
|
410
|
+
this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
|
411
|
+
}
|
412
|
+
start() {
|
413
|
+
if (!this.started) {
|
414
|
+
this.started = true;
|
415
|
+
this.mutationObserver.observe(this.element, this.mutationObserverInit);
|
416
|
+
this.refresh();
|
417
|
+
}
|
418
|
+
}
|
419
|
+
pause(callback) {
|
420
|
+
if (this.started) {
|
421
|
+
this.mutationObserver.disconnect();
|
422
|
+
this.started = false;
|
423
|
+
}
|
424
|
+
callback();
|
425
|
+
if (!this.started) {
|
426
|
+
this.mutationObserver.observe(this.element, this.mutationObserverInit);
|
427
|
+
this.started = true;
|
428
|
+
}
|
429
|
+
}
|
430
|
+
stop() {
|
431
|
+
if (this.started) {
|
432
|
+
this.mutationObserver.takeRecords();
|
433
|
+
this.mutationObserver.disconnect();
|
434
|
+
this.started = false;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
refresh() {
|
438
|
+
if (this.started) {
|
439
|
+
const matches = new Set(this.matchElementsInTree());
|
440
|
+
for (const element of Array.from(this.elements)) {
|
441
|
+
if (!matches.has(element)) {
|
442
|
+
this.removeElement(element);
|
443
|
+
}
|
444
|
+
}
|
445
|
+
for (const element of Array.from(matches)) {
|
446
|
+
this.addElement(element);
|
447
|
+
}
|
448
|
+
}
|
449
|
+
}
|
450
|
+
processMutations(mutations) {
|
451
|
+
if (this.started) {
|
452
|
+
for (const mutation of mutations) {
|
453
|
+
this.processMutation(mutation);
|
454
|
+
}
|
455
|
+
}
|
456
|
+
}
|
457
|
+
processMutation(mutation) {
|
458
|
+
if (mutation.type == "attributes") {
|
459
|
+
this.processAttributeChange(mutation.target, mutation.attributeName);
|
460
|
+
} else if (mutation.type == "childList") {
|
461
|
+
this.processRemovedNodes(mutation.removedNodes);
|
462
|
+
this.processAddedNodes(mutation.addedNodes);
|
463
|
+
}
|
464
|
+
}
|
465
|
+
processAttributeChange(element, attributeName) {
|
466
|
+
if (this.elements.has(element)) {
|
467
|
+
if (this.delegate.elementAttributeChanged && this.matchElement(element)) {
|
468
|
+
this.delegate.elementAttributeChanged(element, attributeName);
|
469
|
+
} else {
|
470
|
+
this.removeElement(element);
|
471
|
+
}
|
472
|
+
} else if (this.matchElement(element)) {
|
473
|
+
this.addElement(element);
|
474
|
+
}
|
475
|
+
}
|
476
|
+
processRemovedNodes(nodes) {
|
477
|
+
for (const node of Array.from(nodes)) {
|
478
|
+
const element = this.elementFromNode(node);
|
479
|
+
if (element) {
|
480
|
+
this.processTree(element, this.removeElement);
|
481
|
+
}
|
482
|
+
}
|
483
|
+
}
|
484
|
+
processAddedNodes(nodes) {
|
485
|
+
for (const node of Array.from(nodes)) {
|
486
|
+
const element = this.elementFromNode(node);
|
487
|
+
if (element && this.elementIsActive(element)) {
|
488
|
+
this.processTree(element, this.addElement);
|
489
|
+
}
|
490
|
+
}
|
491
|
+
}
|
492
|
+
matchElement(element) {
|
493
|
+
return this.delegate.matchElement(element);
|
494
|
+
}
|
495
|
+
matchElementsInTree(tree = this.element) {
|
496
|
+
return this.delegate.matchElementsInTree(tree);
|
497
|
+
}
|
498
|
+
processTree(tree, processor) {
|
499
|
+
for (const element of this.matchElementsInTree(tree)) {
|
500
|
+
processor.call(this, element);
|
501
|
+
}
|
502
|
+
}
|
503
|
+
elementFromNode(node) {
|
504
|
+
if (node.nodeType == Node.ELEMENT_NODE) {
|
505
|
+
return node;
|
506
|
+
}
|
507
|
+
}
|
508
|
+
elementIsActive(element) {
|
509
|
+
if (element.isConnected != this.element.isConnected) {
|
510
|
+
return false;
|
511
|
+
} else {
|
512
|
+
return this.element.contains(element);
|
513
|
+
}
|
514
|
+
}
|
515
|
+
addElement(element) {
|
516
|
+
if (!this.elements.has(element)) {
|
517
|
+
if (this.elementIsActive(element)) {
|
518
|
+
this.elements.add(element);
|
519
|
+
if (this.delegate.elementMatched) {
|
520
|
+
this.delegate.elementMatched(element);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
}
|
524
|
+
}
|
525
|
+
removeElement(element) {
|
526
|
+
if (this.elements.has(element)) {
|
527
|
+
this.elements.delete(element);
|
528
|
+
if (this.delegate.elementUnmatched) {
|
529
|
+
this.delegate.elementUnmatched(element);
|
530
|
+
}
|
531
|
+
}
|
532
|
+
}
|
533
|
+
};
|
534
|
+
var AttributeObserver = class {
|
535
|
+
constructor(element, attributeName, delegate) {
|
536
|
+
this.attributeName = attributeName;
|
537
|
+
this.delegate = delegate;
|
538
|
+
this.elementObserver = new ElementObserver(element, this);
|
539
|
+
}
|
540
|
+
get element() {
|
541
|
+
return this.elementObserver.element;
|
542
|
+
}
|
543
|
+
get selector() {
|
544
|
+
return `[${this.attributeName}]`;
|
545
|
+
}
|
546
|
+
start() {
|
547
|
+
this.elementObserver.start();
|
548
|
+
}
|
549
|
+
pause(callback) {
|
550
|
+
this.elementObserver.pause(callback);
|
551
|
+
}
|
552
|
+
stop() {
|
553
|
+
this.elementObserver.stop();
|
554
|
+
}
|
555
|
+
refresh() {
|
556
|
+
this.elementObserver.refresh();
|
557
|
+
}
|
558
|
+
get started() {
|
559
|
+
return this.elementObserver.started;
|
560
|
+
}
|
561
|
+
matchElement(element) {
|
562
|
+
return element.hasAttribute(this.attributeName);
|
563
|
+
}
|
564
|
+
matchElementsInTree(tree) {
|
565
|
+
const match = this.matchElement(tree) ? [tree] : [];
|
566
|
+
const matches = Array.from(tree.querySelectorAll(this.selector));
|
567
|
+
return match.concat(matches);
|
568
|
+
}
|
569
|
+
elementMatched(element) {
|
570
|
+
if (this.delegate.elementMatchedAttribute) {
|
571
|
+
this.delegate.elementMatchedAttribute(element, this.attributeName);
|
572
|
+
}
|
573
|
+
}
|
574
|
+
elementUnmatched(element) {
|
575
|
+
if (this.delegate.elementUnmatchedAttribute) {
|
576
|
+
this.delegate.elementUnmatchedAttribute(element, this.attributeName);
|
577
|
+
}
|
578
|
+
}
|
579
|
+
elementAttributeChanged(element, attributeName) {
|
580
|
+
if (this.delegate.elementAttributeValueChanged && this.attributeName == attributeName) {
|
581
|
+
this.delegate.elementAttributeValueChanged(element, attributeName);
|
582
|
+
}
|
583
|
+
}
|
584
|
+
};
|
585
|
+
function add(map, key, value) {
|
586
|
+
fetch(map, key).add(value);
|
587
|
+
}
|
588
|
+
function del(map, key, value) {
|
589
|
+
fetch(map, key).delete(value);
|
590
|
+
prune(map, key);
|
591
|
+
}
|
592
|
+
function fetch(map, key) {
|
593
|
+
let values = map.get(key);
|
594
|
+
if (!values) {
|
595
|
+
values = /* @__PURE__ */ new Set();
|
596
|
+
map.set(key, values);
|
597
|
+
}
|
598
|
+
return values;
|
599
|
+
}
|
600
|
+
function prune(map, key) {
|
601
|
+
const values = map.get(key);
|
602
|
+
if (values != null && values.size == 0) {
|
603
|
+
map.delete(key);
|
604
|
+
}
|
605
|
+
}
|
606
|
+
var Multimap = class {
|
607
|
+
constructor() {
|
608
|
+
this.valuesByKey = /* @__PURE__ */ new Map();
|
609
|
+
}
|
610
|
+
get keys() {
|
611
|
+
return Array.from(this.valuesByKey.keys());
|
612
|
+
}
|
613
|
+
get values() {
|
614
|
+
const sets = Array.from(this.valuesByKey.values());
|
615
|
+
return sets.reduce((values, set) => values.concat(Array.from(set)), []);
|
616
|
+
}
|
617
|
+
get size() {
|
618
|
+
const sets = Array.from(this.valuesByKey.values());
|
619
|
+
return sets.reduce((size, set) => size + set.size, 0);
|
620
|
+
}
|
621
|
+
add(key, value) {
|
622
|
+
add(this.valuesByKey, key, value);
|
623
|
+
}
|
624
|
+
delete(key, value) {
|
625
|
+
del(this.valuesByKey, key, value);
|
626
|
+
}
|
627
|
+
has(key, value) {
|
628
|
+
const values = this.valuesByKey.get(key);
|
629
|
+
return values != null && values.has(value);
|
630
|
+
}
|
631
|
+
hasKey(key) {
|
632
|
+
return this.valuesByKey.has(key);
|
633
|
+
}
|
634
|
+
hasValue(value) {
|
635
|
+
const sets = Array.from(this.valuesByKey.values());
|
636
|
+
return sets.some((set) => set.has(value));
|
637
|
+
}
|
638
|
+
getValuesForKey(key) {
|
639
|
+
const values = this.valuesByKey.get(key);
|
640
|
+
return values ? Array.from(values) : [];
|
641
|
+
}
|
642
|
+
getKeysForValue(value) {
|
643
|
+
return Array.from(this.valuesByKey).filter(([_key, values]) => values.has(value)).map(([key, _values]) => key);
|
644
|
+
}
|
645
|
+
};
|
646
|
+
var SelectorObserver = class {
|
647
|
+
constructor(element, selector, delegate, details) {
|
648
|
+
this._selector = selector;
|
649
|
+
this.details = details;
|
650
|
+
this.elementObserver = new ElementObserver(element, this);
|
651
|
+
this.delegate = delegate;
|
652
|
+
this.matchesByElement = new Multimap();
|
653
|
+
}
|
654
|
+
get started() {
|
655
|
+
return this.elementObserver.started;
|
656
|
+
}
|
657
|
+
get selector() {
|
658
|
+
return this._selector;
|
659
|
+
}
|
660
|
+
set selector(selector) {
|
661
|
+
this._selector = selector;
|
662
|
+
this.refresh();
|
663
|
+
}
|
664
|
+
start() {
|
665
|
+
this.elementObserver.start();
|
666
|
+
}
|
667
|
+
pause(callback) {
|
668
|
+
this.elementObserver.pause(callback);
|
669
|
+
}
|
670
|
+
stop() {
|
671
|
+
this.elementObserver.stop();
|
672
|
+
}
|
673
|
+
refresh() {
|
674
|
+
this.elementObserver.refresh();
|
675
|
+
}
|
676
|
+
get element() {
|
677
|
+
return this.elementObserver.element;
|
678
|
+
}
|
679
|
+
matchElement(element) {
|
680
|
+
const { selector } = this;
|
681
|
+
if (selector) {
|
682
|
+
const matches = element.matches(selector);
|
683
|
+
if (this.delegate.selectorMatchElement) {
|
684
|
+
return matches && this.delegate.selectorMatchElement(element, this.details);
|
685
|
+
}
|
686
|
+
return matches;
|
687
|
+
} else {
|
688
|
+
return false;
|
689
|
+
}
|
690
|
+
}
|
691
|
+
matchElementsInTree(tree) {
|
692
|
+
const { selector } = this;
|
693
|
+
if (selector) {
|
694
|
+
const match = this.matchElement(tree) ? [tree] : [];
|
695
|
+
const matches = Array.from(tree.querySelectorAll(selector)).filter((match2) => this.matchElement(match2));
|
696
|
+
return match.concat(matches);
|
697
|
+
} else {
|
698
|
+
return [];
|
699
|
+
}
|
700
|
+
}
|
701
|
+
elementMatched(element) {
|
702
|
+
const { selector } = this;
|
703
|
+
if (selector) {
|
704
|
+
this.selectorMatched(element, selector);
|
705
|
+
}
|
706
|
+
}
|
707
|
+
elementUnmatched(element) {
|
708
|
+
const selectors = this.matchesByElement.getKeysForValue(element);
|
709
|
+
for (const selector of selectors) {
|
710
|
+
this.selectorUnmatched(element, selector);
|
711
|
+
}
|
712
|
+
}
|
713
|
+
elementAttributeChanged(element, _attributeName) {
|
714
|
+
const { selector } = this;
|
715
|
+
if (selector) {
|
716
|
+
const matches = this.matchElement(element);
|
717
|
+
const matchedBefore = this.matchesByElement.has(selector, element);
|
718
|
+
if (matches && !matchedBefore) {
|
719
|
+
this.selectorMatched(element, selector);
|
720
|
+
} else if (!matches && matchedBefore) {
|
721
|
+
this.selectorUnmatched(element, selector);
|
722
|
+
}
|
723
|
+
}
|
724
|
+
}
|
725
|
+
selectorMatched(element, selector) {
|
726
|
+
this.delegate.selectorMatched(element, selector, this.details);
|
727
|
+
this.matchesByElement.add(selector, element);
|
728
|
+
}
|
729
|
+
selectorUnmatched(element, selector) {
|
730
|
+
this.delegate.selectorUnmatched(element, selector, this.details);
|
731
|
+
this.matchesByElement.delete(selector, element);
|
732
|
+
}
|
733
|
+
};
|
734
|
+
var StringMapObserver = class {
|
735
|
+
constructor(element, delegate) {
|
736
|
+
this.element = element;
|
737
|
+
this.delegate = delegate;
|
738
|
+
this.started = false;
|
739
|
+
this.stringMap = /* @__PURE__ */ new Map();
|
740
|
+
this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
|
741
|
+
}
|
742
|
+
start() {
|
743
|
+
if (!this.started) {
|
744
|
+
this.started = true;
|
745
|
+
this.mutationObserver.observe(this.element, { attributes: true, attributeOldValue: true });
|
746
|
+
this.refresh();
|
747
|
+
}
|
748
|
+
}
|
749
|
+
stop() {
|
750
|
+
if (this.started) {
|
751
|
+
this.mutationObserver.takeRecords();
|
752
|
+
this.mutationObserver.disconnect();
|
753
|
+
this.started = false;
|
754
|
+
}
|
755
|
+
}
|
756
|
+
refresh() {
|
757
|
+
if (this.started) {
|
758
|
+
for (const attributeName of this.knownAttributeNames) {
|
759
|
+
this.refreshAttribute(attributeName, null);
|
760
|
+
}
|
761
|
+
}
|
762
|
+
}
|
763
|
+
processMutations(mutations) {
|
764
|
+
if (this.started) {
|
765
|
+
for (const mutation of mutations) {
|
766
|
+
this.processMutation(mutation);
|
767
|
+
}
|
768
|
+
}
|
769
|
+
}
|
770
|
+
processMutation(mutation) {
|
771
|
+
const attributeName = mutation.attributeName;
|
772
|
+
if (attributeName) {
|
773
|
+
this.refreshAttribute(attributeName, mutation.oldValue);
|
774
|
+
}
|
775
|
+
}
|
776
|
+
refreshAttribute(attributeName, oldValue) {
|
777
|
+
const key = this.delegate.getStringMapKeyForAttribute(attributeName);
|
778
|
+
if (key != null) {
|
779
|
+
if (!this.stringMap.has(attributeName)) {
|
780
|
+
this.stringMapKeyAdded(key, attributeName);
|
781
|
+
}
|
782
|
+
const value = this.element.getAttribute(attributeName);
|
783
|
+
if (this.stringMap.get(attributeName) != value) {
|
784
|
+
this.stringMapValueChanged(value, key, oldValue);
|
785
|
+
}
|
786
|
+
if (value == null) {
|
787
|
+
const oldValue2 = this.stringMap.get(attributeName);
|
788
|
+
this.stringMap.delete(attributeName);
|
789
|
+
if (oldValue2)
|
790
|
+
this.stringMapKeyRemoved(key, attributeName, oldValue2);
|
791
|
+
} else {
|
792
|
+
this.stringMap.set(attributeName, value);
|
793
|
+
}
|
794
|
+
}
|
795
|
+
}
|
796
|
+
stringMapKeyAdded(key, attributeName) {
|
797
|
+
if (this.delegate.stringMapKeyAdded) {
|
798
|
+
this.delegate.stringMapKeyAdded(key, attributeName);
|
799
|
+
}
|
800
|
+
}
|
801
|
+
stringMapValueChanged(value, key, oldValue) {
|
802
|
+
if (this.delegate.stringMapValueChanged) {
|
803
|
+
this.delegate.stringMapValueChanged(value, key, oldValue);
|
804
|
+
}
|
805
|
+
}
|
806
|
+
stringMapKeyRemoved(key, attributeName, oldValue) {
|
807
|
+
if (this.delegate.stringMapKeyRemoved) {
|
808
|
+
this.delegate.stringMapKeyRemoved(key, attributeName, oldValue);
|
809
|
+
}
|
810
|
+
}
|
811
|
+
get knownAttributeNames() {
|
812
|
+
return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)));
|
813
|
+
}
|
814
|
+
get currentAttributeNames() {
|
815
|
+
return Array.from(this.element.attributes).map((attribute) => attribute.name);
|
816
|
+
}
|
817
|
+
get recordedAttributeNames() {
|
818
|
+
return Array.from(this.stringMap.keys());
|
819
|
+
}
|
820
|
+
};
|
821
|
+
var TokenListObserver = class {
|
822
|
+
constructor(element, attributeName, delegate) {
|
823
|
+
this.attributeObserver = new AttributeObserver(element, attributeName, this);
|
824
|
+
this.delegate = delegate;
|
825
|
+
this.tokensByElement = new Multimap();
|
826
|
+
}
|
827
|
+
get started() {
|
828
|
+
return this.attributeObserver.started;
|
829
|
+
}
|
830
|
+
start() {
|
831
|
+
this.attributeObserver.start();
|
832
|
+
}
|
833
|
+
pause(callback) {
|
834
|
+
this.attributeObserver.pause(callback);
|
835
|
+
}
|
836
|
+
stop() {
|
837
|
+
this.attributeObserver.stop();
|
838
|
+
}
|
839
|
+
refresh() {
|
840
|
+
this.attributeObserver.refresh();
|
841
|
+
}
|
842
|
+
get element() {
|
843
|
+
return this.attributeObserver.element;
|
844
|
+
}
|
845
|
+
get attributeName() {
|
846
|
+
return this.attributeObserver.attributeName;
|
847
|
+
}
|
848
|
+
elementMatchedAttribute(element) {
|
849
|
+
this.tokensMatched(this.readTokensForElement(element));
|
850
|
+
}
|
851
|
+
elementAttributeValueChanged(element) {
|
852
|
+
const [unmatchedTokens, matchedTokens] = this.refreshTokensForElement(element);
|
853
|
+
this.tokensUnmatched(unmatchedTokens);
|
854
|
+
this.tokensMatched(matchedTokens);
|
855
|
+
}
|
856
|
+
elementUnmatchedAttribute(element) {
|
857
|
+
this.tokensUnmatched(this.tokensByElement.getValuesForKey(element));
|
858
|
+
}
|
859
|
+
tokensMatched(tokens) {
|
860
|
+
tokens.forEach((token) => this.tokenMatched(token));
|
861
|
+
}
|
862
|
+
tokensUnmatched(tokens) {
|
863
|
+
tokens.forEach((token) => this.tokenUnmatched(token));
|
864
|
+
}
|
865
|
+
tokenMatched(token) {
|
866
|
+
this.delegate.tokenMatched(token);
|
867
|
+
this.tokensByElement.add(token.element, token);
|
868
|
+
}
|
869
|
+
tokenUnmatched(token) {
|
870
|
+
this.delegate.tokenUnmatched(token);
|
871
|
+
this.tokensByElement.delete(token.element, token);
|
872
|
+
}
|
873
|
+
refreshTokensForElement(element) {
|
874
|
+
const previousTokens = this.tokensByElement.getValuesForKey(element);
|
875
|
+
const currentTokens = this.readTokensForElement(element);
|
876
|
+
const firstDifferingIndex = zip(previousTokens, currentTokens).findIndex(([previousToken, currentToken]) => !tokensAreEqual(previousToken, currentToken));
|
877
|
+
if (firstDifferingIndex == -1) {
|
878
|
+
return [[], []];
|
879
|
+
} else {
|
880
|
+
return [previousTokens.slice(firstDifferingIndex), currentTokens.slice(firstDifferingIndex)];
|
881
|
+
}
|
882
|
+
}
|
883
|
+
readTokensForElement(element) {
|
884
|
+
const attributeName = this.attributeName;
|
885
|
+
const tokenString = element.getAttribute(attributeName) || "";
|
886
|
+
return parseTokenString(tokenString, element, attributeName);
|
887
|
+
}
|
888
|
+
};
|
889
|
+
function parseTokenString(tokenString, element, attributeName) {
|
890
|
+
return tokenString.trim().split(/\s+/).filter((content) => content.length).map((content, index) => ({ element, attributeName, content, index }));
|
891
|
+
}
|
892
|
+
function zip(left, right) {
|
893
|
+
const length = Math.max(left.length, right.length);
|
894
|
+
return Array.from({ length }, (_, index) => [left[index], right[index]]);
|
895
|
+
}
|
896
|
+
function tokensAreEqual(left, right) {
|
897
|
+
return left && right && left.index == right.index && left.content == right.content;
|
898
|
+
}
|
899
|
+
var ValueListObserver = class {
|
900
|
+
constructor(element, attributeName, delegate) {
|
901
|
+
this.tokenListObserver = new TokenListObserver(element, attributeName, this);
|
902
|
+
this.delegate = delegate;
|
903
|
+
this.parseResultsByToken = /* @__PURE__ */ new WeakMap();
|
904
|
+
this.valuesByTokenByElement = /* @__PURE__ */ new WeakMap();
|
905
|
+
}
|
906
|
+
get started() {
|
907
|
+
return this.tokenListObserver.started;
|
908
|
+
}
|
909
|
+
start() {
|
910
|
+
this.tokenListObserver.start();
|
911
|
+
}
|
912
|
+
stop() {
|
913
|
+
this.tokenListObserver.stop();
|
914
|
+
}
|
915
|
+
refresh() {
|
916
|
+
this.tokenListObserver.refresh();
|
917
|
+
}
|
918
|
+
get element() {
|
919
|
+
return this.tokenListObserver.element;
|
920
|
+
}
|
921
|
+
get attributeName() {
|
922
|
+
return this.tokenListObserver.attributeName;
|
923
|
+
}
|
924
|
+
tokenMatched(token) {
|
925
|
+
const { element } = token;
|
926
|
+
const { value } = this.fetchParseResultForToken(token);
|
927
|
+
if (value) {
|
928
|
+
this.fetchValuesByTokenForElement(element).set(token, value);
|
929
|
+
this.delegate.elementMatchedValue(element, value);
|
930
|
+
}
|
931
|
+
}
|
932
|
+
tokenUnmatched(token) {
|
933
|
+
const { element } = token;
|
934
|
+
const { value } = this.fetchParseResultForToken(token);
|
935
|
+
if (value) {
|
936
|
+
this.fetchValuesByTokenForElement(element).delete(token);
|
937
|
+
this.delegate.elementUnmatchedValue(element, value);
|
938
|
+
}
|
939
|
+
}
|
940
|
+
fetchParseResultForToken(token) {
|
941
|
+
let parseResult = this.parseResultsByToken.get(token);
|
942
|
+
if (!parseResult) {
|
943
|
+
parseResult = this.parseToken(token);
|
944
|
+
this.parseResultsByToken.set(token, parseResult);
|
945
|
+
}
|
946
|
+
return parseResult;
|
947
|
+
}
|
948
|
+
fetchValuesByTokenForElement(element) {
|
949
|
+
let valuesByToken = this.valuesByTokenByElement.get(element);
|
950
|
+
if (!valuesByToken) {
|
951
|
+
valuesByToken = /* @__PURE__ */ new Map();
|
952
|
+
this.valuesByTokenByElement.set(element, valuesByToken);
|
953
|
+
}
|
954
|
+
return valuesByToken;
|
955
|
+
}
|
956
|
+
parseToken(token) {
|
957
|
+
try {
|
958
|
+
const value = this.delegate.parseValueForToken(token);
|
959
|
+
return { value };
|
960
|
+
} catch (error2) {
|
961
|
+
return { error: error2 };
|
962
|
+
}
|
963
|
+
}
|
964
|
+
};
|
965
|
+
var BindingObserver = class {
|
966
|
+
constructor(context, delegate) {
|
967
|
+
this.context = context;
|
968
|
+
this.delegate = delegate;
|
969
|
+
this.bindingsByAction = /* @__PURE__ */ new Map();
|
970
|
+
}
|
971
|
+
start() {
|
972
|
+
if (!this.valueListObserver) {
|
973
|
+
this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this);
|
974
|
+
this.valueListObserver.start();
|
975
|
+
}
|
976
|
+
}
|
977
|
+
stop() {
|
978
|
+
if (this.valueListObserver) {
|
979
|
+
this.valueListObserver.stop();
|
980
|
+
delete this.valueListObserver;
|
981
|
+
this.disconnectAllActions();
|
982
|
+
}
|
983
|
+
}
|
984
|
+
get element() {
|
985
|
+
return this.context.element;
|
986
|
+
}
|
987
|
+
get identifier() {
|
988
|
+
return this.context.identifier;
|
989
|
+
}
|
990
|
+
get actionAttribute() {
|
991
|
+
return this.schema.actionAttribute;
|
992
|
+
}
|
993
|
+
get schema() {
|
994
|
+
return this.context.schema;
|
995
|
+
}
|
996
|
+
get bindings() {
|
997
|
+
return Array.from(this.bindingsByAction.values());
|
998
|
+
}
|
999
|
+
connectAction(action) {
|
1000
|
+
const binding = new Binding(this.context, action);
|
1001
|
+
this.bindingsByAction.set(action, binding);
|
1002
|
+
this.delegate.bindingConnected(binding);
|
1003
|
+
}
|
1004
|
+
disconnectAction(action) {
|
1005
|
+
const binding = this.bindingsByAction.get(action);
|
1006
|
+
if (binding) {
|
1007
|
+
this.bindingsByAction.delete(action);
|
1008
|
+
this.delegate.bindingDisconnected(binding);
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
disconnectAllActions() {
|
1012
|
+
this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding, true));
|
1013
|
+
this.bindingsByAction.clear();
|
1014
|
+
}
|
1015
|
+
parseValueForToken(token) {
|
1016
|
+
const action = Action.forToken(token, this.schema);
|
1017
|
+
if (action.identifier == this.identifier) {
|
1018
|
+
return action;
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
elementMatchedValue(element, action) {
|
1022
|
+
this.connectAction(action);
|
1023
|
+
}
|
1024
|
+
elementUnmatchedValue(element, action) {
|
1025
|
+
this.disconnectAction(action);
|
1026
|
+
}
|
1027
|
+
};
|
1028
|
+
var ValueObserver = class {
|
1029
|
+
constructor(context, receiver) {
|
1030
|
+
this.context = context;
|
1031
|
+
this.receiver = receiver;
|
1032
|
+
this.stringMapObserver = new StringMapObserver(this.element, this);
|
1033
|
+
this.valueDescriptorMap = this.controller.valueDescriptorMap;
|
1034
|
+
}
|
1035
|
+
start() {
|
1036
|
+
this.stringMapObserver.start();
|
1037
|
+
this.invokeChangedCallbacksForDefaultValues();
|
1038
|
+
}
|
1039
|
+
stop() {
|
1040
|
+
this.stringMapObserver.stop();
|
1041
|
+
}
|
1042
|
+
get element() {
|
1043
|
+
return this.context.element;
|
1044
|
+
}
|
1045
|
+
get controller() {
|
1046
|
+
return this.context.controller;
|
1047
|
+
}
|
1048
|
+
getStringMapKeyForAttribute(attributeName) {
|
1049
|
+
if (attributeName in this.valueDescriptorMap) {
|
1050
|
+
return this.valueDescriptorMap[attributeName].name;
|
1051
|
+
}
|
1052
|
+
}
|
1053
|
+
stringMapKeyAdded(key, attributeName) {
|
1054
|
+
const descriptor = this.valueDescriptorMap[attributeName];
|
1055
|
+
if (!this.hasValue(key)) {
|
1056
|
+
this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue));
|
1057
|
+
}
|
1058
|
+
}
|
1059
|
+
stringMapValueChanged(value, name, oldValue) {
|
1060
|
+
const descriptor = this.valueDescriptorNameMap[name];
|
1061
|
+
if (value === null)
|
1062
|
+
return;
|
1063
|
+
if (oldValue === null) {
|
1064
|
+
oldValue = descriptor.writer(descriptor.defaultValue);
|
1065
|
+
}
|
1066
|
+
this.invokeChangedCallback(name, value, oldValue);
|
1067
|
+
}
|
1068
|
+
stringMapKeyRemoved(key, attributeName, oldValue) {
|
1069
|
+
const descriptor = this.valueDescriptorNameMap[key];
|
1070
|
+
if (this.hasValue(key)) {
|
1071
|
+
this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), oldValue);
|
1072
|
+
} else {
|
1073
|
+
this.invokeChangedCallback(key, descriptor.writer(descriptor.defaultValue), oldValue);
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
invokeChangedCallbacksForDefaultValues() {
|
1077
|
+
for (const { key, name, defaultValue, writer } of this.valueDescriptors) {
|
1078
|
+
if (defaultValue != void 0 && !this.controller.data.has(key)) {
|
1079
|
+
this.invokeChangedCallback(name, writer(defaultValue), void 0);
|
1080
|
+
}
|
1081
|
+
}
|
1082
|
+
}
|
1083
|
+
invokeChangedCallback(name, rawValue, rawOldValue) {
|
1084
|
+
const changedMethodName = `${name}Changed`;
|
1085
|
+
const changedMethod = this.receiver[changedMethodName];
|
1086
|
+
if (typeof changedMethod == "function") {
|
1087
|
+
const descriptor = this.valueDescriptorNameMap[name];
|
1088
|
+
try {
|
1089
|
+
const value = descriptor.reader(rawValue);
|
1090
|
+
let oldValue = rawOldValue;
|
1091
|
+
if (rawOldValue) {
|
1092
|
+
oldValue = descriptor.reader(rawOldValue);
|
1093
|
+
}
|
1094
|
+
changedMethod.call(this.receiver, value, oldValue);
|
1095
|
+
} catch (error2) {
|
1096
|
+
if (error2 instanceof TypeError) {
|
1097
|
+
error2.message = `Stimulus Value "${this.context.identifier}.${descriptor.name}" - ${error2.message}`;
|
1098
|
+
}
|
1099
|
+
throw error2;
|
1100
|
+
}
|
1101
|
+
}
|
1102
|
+
}
|
1103
|
+
get valueDescriptors() {
|
1104
|
+
const { valueDescriptorMap } = this;
|
1105
|
+
return Object.keys(valueDescriptorMap).map((key) => valueDescriptorMap[key]);
|
1106
|
+
}
|
1107
|
+
get valueDescriptorNameMap() {
|
1108
|
+
const descriptors = {};
|
1109
|
+
Object.keys(this.valueDescriptorMap).forEach((key) => {
|
1110
|
+
const descriptor = this.valueDescriptorMap[key];
|
1111
|
+
descriptors[descriptor.name] = descriptor;
|
1112
|
+
});
|
1113
|
+
return descriptors;
|
1114
|
+
}
|
1115
|
+
hasValue(attributeName) {
|
1116
|
+
const descriptor = this.valueDescriptorNameMap[attributeName];
|
1117
|
+
const hasMethodName = `has${capitalize(descriptor.name)}`;
|
1118
|
+
return this.receiver[hasMethodName];
|
1119
|
+
}
|
1120
|
+
};
|
1121
|
+
var TargetObserver = class {
|
1122
|
+
constructor(context, delegate) {
|
1123
|
+
this.context = context;
|
1124
|
+
this.delegate = delegate;
|
1125
|
+
this.targetsByName = new Multimap();
|
1126
|
+
}
|
1127
|
+
start() {
|
1128
|
+
if (!this.tokenListObserver) {
|
1129
|
+
this.tokenListObserver = new TokenListObserver(this.element, this.attributeName, this);
|
1130
|
+
this.tokenListObserver.start();
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
stop() {
|
1134
|
+
if (this.tokenListObserver) {
|
1135
|
+
this.disconnectAllTargets();
|
1136
|
+
this.tokenListObserver.stop();
|
1137
|
+
delete this.tokenListObserver;
|
1138
|
+
}
|
1139
|
+
}
|
1140
|
+
tokenMatched({ element, content: name }) {
|
1141
|
+
if (this.scope.containsElement(element)) {
|
1142
|
+
this.connectTarget(element, name);
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
tokenUnmatched({ element, content: name }) {
|
1146
|
+
this.disconnectTarget(element, name);
|
1147
|
+
}
|
1148
|
+
connectTarget(element, name) {
|
1149
|
+
var _a;
|
1150
|
+
if (!this.targetsByName.has(name, element)) {
|
1151
|
+
this.targetsByName.add(name, element);
|
1152
|
+
(_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetConnected(element, name));
|
1153
|
+
}
|
1154
|
+
}
|
1155
|
+
disconnectTarget(element, name) {
|
1156
|
+
var _a;
|
1157
|
+
if (this.targetsByName.has(name, element)) {
|
1158
|
+
this.targetsByName.delete(name, element);
|
1159
|
+
(_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetDisconnected(element, name));
|
1160
|
+
}
|
1161
|
+
}
|
1162
|
+
disconnectAllTargets() {
|
1163
|
+
for (const name of this.targetsByName.keys) {
|
1164
|
+
for (const element of this.targetsByName.getValuesForKey(name)) {
|
1165
|
+
this.disconnectTarget(element, name);
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
get attributeName() {
|
1170
|
+
return `data-${this.context.identifier}-target`;
|
1171
|
+
}
|
1172
|
+
get element() {
|
1173
|
+
return this.context.element;
|
1174
|
+
}
|
1175
|
+
get scope() {
|
1176
|
+
return this.context.scope;
|
1177
|
+
}
|
1178
|
+
};
|
1179
|
+
function readInheritableStaticArrayValues(constructor, propertyName) {
|
1180
|
+
const ancestors = getAncestorsForConstructor(constructor);
|
1181
|
+
return Array.from(ancestors.reduce((values, constructor2) => {
|
1182
|
+
getOwnStaticArrayValues(constructor2, propertyName).forEach((name) => values.add(name));
|
1183
|
+
return values;
|
1184
|
+
}, /* @__PURE__ */ new Set()));
|
1185
|
+
}
|
1186
|
+
function readInheritableStaticObjectPairs(constructor, propertyName) {
|
1187
|
+
const ancestors = getAncestorsForConstructor(constructor);
|
1188
|
+
return ancestors.reduce((pairs, constructor2) => {
|
1189
|
+
pairs.push(...getOwnStaticObjectPairs(constructor2, propertyName));
|
1190
|
+
return pairs;
|
1191
|
+
}, []);
|
1192
|
+
}
|
1193
|
+
function getAncestorsForConstructor(constructor) {
|
1194
|
+
const ancestors = [];
|
1195
|
+
while (constructor) {
|
1196
|
+
ancestors.push(constructor);
|
1197
|
+
constructor = Object.getPrototypeOf(constructor);
|
1198
|
+
}
|
1199
|
+
return ancestors.reverse();
|
1200
|
+
}
|
1201
|
+
function getOwnStaticArrayValues(constructor, propertyName) {
|
1202
|
+
const definition = constructor[propertyName];
|
1203
|
+
return Array.isArray(definition) ? definition : [];
|
1204
|
+
}
|
1205
|
+
function getOwnStaticObjectPairs(constructor, propertyName) {
|
1206
|
+
const definition = constructor[propertyName];
|
1207
|
+
return definition ? Object.keys(definition).map((key) => [key, definition[key]]) : [];
|
1208
|
+
}
|
1209
|
+
var OutletObserver = class {
|
1210
|
+
constructor(context, delegate) {
|
1211
|
+
this.started = false;
|
1212
|
+
this.context = context;
|
1213
|
+
this.delegate = delegate;
|
1214
|
+
this.outletsByName = new Multimap();
|
1215
|
+
this.outletElementsByName = new Multimap();
|
1216
|
+
this.selectorObserverMap = /* @__PURE__ */ new Map();
|
1217
|
+
this.attributeObserverMap = /* @__PURE__ */ new Map();
|
1218
|
+
}
|
1219
|
+
start() {
|
1220
|
+
if (!this.started) {
|
1221
|
+
this.outletDefinitions.forEach((outletName) => {
|
1222
|
+
this.setupSelectorObserverForOutlet(outletName);
|
1223
|
+
this.setupAttributeObserverForOutlet(outletName);
|
1224
|
+
});
|
1225
|
+
this.started = true;
|
1226
|
+
this.dependentContexts.forEach((context) => context.refresh());
|
1227
|
+
}
|
1228
|
+
}
|
1229
|
+
refresh() {
|
1230
|
+
this.selectorObserverMap.forEach((observer) => observer.refresh());
|
1231
|
+
this.attributeObserverMap.forEach((observer) => observer.refresh());
|
1232
|
+
}
|
1233
|
+
stop() {
|
1234
|
+
if (this.started) {
|
1235
|
+
this.started = false;
|
1236
|
+
this.disconnectAllOutlets();
|
1237
|
+
this.stopSelectorObservers();
|
1238
|
+
this.stopAttributeObservers();
|
1239
|
+
}
|
1240
|
+
}
|
1241
|
+
stopSelectorObservers() {
|
1242
|
+
if (this.selectorObserverMap.size > 0) {
|
1243
|
+
this.selectorObserverMap.forEach((observer) => observer.stop());
|
1244
|
+
this.selectorObserverMap.clear();
|
1245
|
+
}
|
1246
|
+
}
|
1247
|
+
stopAttributeObservers() {
|
1248
|
+
if (this.attributeObserverMap.size > 0) {
|
1249
|
+
this.attributeObserverMap.forEach((observer) => observer.stop());
|
1250
|
+
this.attributeObserverMap.clear();
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
selectorMatched(element, _selector, { outletName }) {
|
1254
|
+
const outlet = this.getOutlet(element, outletName);
|
1255
|
+
if (outlet) {
|
1256
|
+
this.connectOutlet(outlet, element, outletName);
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
selectorUnmatched(element, _selector, { outletName }) {
|
1260
|
+
const outlet = this.getOutletFromMap(element, outletName);
|
1261
|
+
if (outlet) {
|
1262
|
+
this.disconnectOutlet(outlet, element, outletName);
|
1263
|
+
}
|
1264
|
+
}
|
1265
|
+
selectorMatchElement(element, { outletName }) {
|
1266
|
+
const selector = this.selector(outletName);
|
1267
|
+
const hasOutlet = this.hasOutlet(element, outletName);
|
1268
|
+
const hasOutletController = element.matches(`[${this.schema.controllerAttribute}~=${outletName}]`);
|
1269
|
+
if (selector) {
|
1270
|
+
return hasOutlet && hasOutletController && element.matches(selector);
|
1271
|
+
} else {
|
1272
|
+
return false;
|
1273
|
+
}
|
1274
|
+
}
|
1275
|
+
elementMatchedAttribute(_element, attributeName) {
|
1276
|
+
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
|
1277
|
+
if (outletName) {
|
1278
|
+
this.updateSelectorObserverForOutlet(outletName);
|
1279
|
+
}
|
1280
|
+
}
|
1281
|
+
elementAttributeValueChanged(_element, attributeName) {
|
1282
|
+
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
|
1283
|
+
if (outletName) {
|
1284
|
+
this.updateSelectorObserverForOutlet(outletName);
|
1285
|
+
}
|
1286
|
+
}
|
1287
|
+
elementUnmatchedAttribute(_element, attributeName) {
|
1288
|
+
const outletName = this.getOutletNameFromOutletAttributeName(attributeName);
|
1289
|
+
if (outletName) {
|
1290
|
+
this.updateSelectorObserverForOutlet(outletName);
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
connectOutlet(outlet, element, outletName) {
|
1294
|
+
var _a;
|
1295
|
+
if (!this.outletElementsByName.has(outletName, element)) {
|
1296
|
+
this.outletsByName.add(outletName, outlet);
|
1297
|
+
this.outletElementsByName.add(outletName, element);
|
1298
|
+
(_a = this.selectorObserverMap.get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletConnected(outlet, element, outletName));
|
1299
|
+
}
|
1300
|
+
}
|
1301
|
+
disconnectOutlet(outlet, element, outletName) {
|
1302
|
+
var _a;
|
1303
|
+
if (this.outletElementsByName.has(outletName, element)) {
|
1304
|
+
this.outletsByName.delete(outletName, outlet);
|
1305
|
+
this.outletElementsByName.delete(outletName, element);
|
1306
|
+
(_a = this.selectorObserverMap.get(outletName)) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.outletDisconnected(outlet, element, outletName));
|
1307
|
+
}
|
1308
|
+
}
|
1309
|
+
disconnectAllOutlets() {
|
1310
|
+
for (const outletName of this.outletElementsByName.keys) {
|
1311
|
+
for (const element of this.outletElementsByName.getValuesForKey(outletName)) {
|
1312
|
+
for (const outlet of this.outletsByName.getValuesForKey(outletName)) {
|
1313
|
+
this.disconnectOutlet(outlet, element, outletName);
|
1314
|
+
}
|
1315
|
+
}
|
1316
|
+
}
|
1317
|
+
}
|
1318
|
+
updateSelectorObserverForOutlet(outletName) {
|
1319
|
+
const observer = this.selectorObserverMap.get(outletName);
|
1320
|
+
if (observer) {
|
1321
|
+
observer.selector = this.selector(outletName);
|
1322
|
+
}
|
1323
|
+
}
|
1324
|
+
setupSelectorObserverForOutlet(outletName) {
|
1325
|
+
const selector = this.selector(outletName);
|
1326
|
+
const selectorObserver = new SelectorObserver(document.body, selector, this, { outletName });
|
1327
|
+
this.selectorObserverMap.set(outletName, selectorObserver);
|
1328
|
+
selectorObserver.start();
|
1329
|
+
}
|
1330
|
+
setupAttributeObserverForOutlet(outletName) {
|
1331
|
+
const attributeName = this.attributeNameForOutletName(outletName);
|
1332
|
+
const attributeObserver = new AttributeObserver(this.scope.element, attributeName, this);
|
1333
|
+
this.attributeObserverMap.set(outletName, attributeObserver);
|
1334
|
+
attributeObserver.start();
|
1335
|
+
}
|
1336
|
+
selector(outletName) {
|
1337
|
+
return this.scope.outlets.getSelectorForOutletName(outletName);
|
1338
|
+
}
|
1339
|
+
attributeNameForOutletName(outletName) {
|
1340
|
+
return this.scope.schema.outletAttributeForScope(this.identifier, outletName);
|
1341
|
+
}
|
1342
|
+
getOutletNameFromOutletAttributeName(attributeName) {
|
1343
|
+
return this.outletDefinitions.find((outletName) => this.attributeNameForOutletName(outletName) === attributeName);
|
1344
|
+
}
|
1345
|
+
get outletDependencies() {
|
1346
|
+
const dependencies = new Multimap();
|
1347
|
+
this.router.modules.forEach((module) => {
|
1348
|
+
const constructor = module.definition.controllerConstructor;
|
1349
|
+
const outlets = readInheritableStaticArrayValues(constructor, "outlets");
|
1350
|
+
outlets.forEach((outlet) => dependencies.add(outlet, module.identifier));
|
1351
|
+
});
|
1352
|
+
return dependencies;
|
1353
|
+
}
|
1354
|
+
get outletDefinitions() {
|
1355
|
+
return this.outletDependencies.getKeysForValue(this.identifier);
|
1356
|
+
}
|
1357
|
+
get dependentControllerIdentifiers() {
|
1358
|
+
return this.outletDependencies.getValuesForKey(this.identifier);
|
1359
|
+
}
|
1360
|
+
get dependentContexts() {
|
1361
|
+
const identifiers = this.dependentControllerIdentifiers;
|
1362
|
+
return this.router.contexts.filter((context) => identifiers.includes(context.identifier));
|
1363
|
+
}
|
1364
|
+
hasOutlet(element, outletName) {
|
1365
|
+
return !!this.getOutlet(element, outletName) || !!this.getOutletFromMap(element, outletName);
|
1366
|
+
}
|
1367
|
+
getOutlet(element, outletName) {
|
1368
|
+
return this.application.getControllerForElementAndIdentifier(element, outletName);
|
1369
|
+
}
|
1370
|
+
getOutletFromMap(element, outletName) {
|
1371
|
+
return this.outletsByName.getValuesForKey(outletName).find((outlet) => outlet.element === element);
|
1372
|
+
}
|
1373
|
+
get scope() {
|
1374
|
+
return this.context.scope;
|
1375
|
+
}
|
1376
|
+
get schema() {
|
1377
|
+
return this.context.schema;
|
1378
|
+
}
|
1379
|
+
get identifier() {
|
1380
|
+
return this.context.identifier;
|
1381
|
+
}
|
1382
|
+
get application() {
|
1383
|
+
return this.context.application;
|
1384
|
+
}
|
1385
|
+
get router() {
|
1386
|
+
return this.application.router;
|
1387
|
+
}
|
1388
|
+
};
|
1389
|
+
var Context = class {
|
1390
|
+
constructor(module, scope) {
|
1391
|
+
this.logDebugActivity = (functionName, detail = {}) => {
|
1392
|
+
const { identifier, controller, element } = this;
|
1393
|
+
detail = Object.assign({ identifier, controller, element }, detail);
|
1394
|
+
this.application.logDebugActivity(this.identifier, functionName, detail);
|
1395
|
+
};
|
1396
|
+
this.module = module;
|
1397
|
+
this.scope = scope;
|
1398
|
+
this.controller = new module.controllerConstructor(this);
|
1399
|
+
this.bindingObserver = new BindingObserver(this, this.dispatcher);
|
1400
|
+
this.valueObserver = new ValueObserver(this, this.controller);
|
1401
|
+
this.targetObserver = new TargetObserver(this, this);
|
1402
|
+
this.outletObserver = new OutletObserver(this, this);
|
1403
|
+
try {
|
1404
|
+
this.controller.initialize();
|
1405
|
+
this.logDebugActivity("initialize");
|
1406
|
+
} catch (error2) {
|
1407
|
+
this.handleError(error2, "initializing controller");
|
1408
|
+
}
|
1409
|
+
}
|
1410
|
+
connect() {
|
1411
|
+
this.bindingObserver.start();
|
1412
|
+
this.valueObserver.start();
|
1413
|
+
this.targetObserver.start();
|
1414
|
+
this.outletObserver.start();
|
1415
|
+
try {
|
1416
|
+
this.controller.connect();
|
1417
|
+
this.logDebugActivity("connect");
|
1418
|
+
} catch (error2) {
|
1419
|
+
this.handleError(error2, "connecting controller");
|
1420
|
+
}
|
1421
|
+
}
|
1422
|
+
refresh() {
|
1423
|
+
this.outletObserver.refresh();
|
1424
|
+
}
|
1425
|
+
disconnect() {
|
1426
|
+
try {
|
1427
|
+
this.controller.disconnect();
|
1428
|
+
this.logDebugActivity("disconnect");
|
1429
|
+
} catch (error2) {
|
1430
|
+
this.handleError(error2, "disconnecting controller");
|
1431
|
+
}
|
1432
|
+
this.outletObserver.stop();
|
1433
|
+
this.targetObserver.stop();
|
1434
|
+
this.valueObserver.stop();
|
1435
|
+
this.bindingObserver.stop();
|
1436
|
+
}
|
1437
|
+
get application() {
|
1438
|
+
return this.module.application;
|
1439
|
+
}
|
1440
|
+
get identifier() {
|
1441
|
+
return this.module.identifier;
|
1442
|
+
}
|
1443
|
+
get schema() {
|
1444
|
+
return this.application.schema;
|
1445
|
+
}
|
1446
|
+
get dispatcher() {
|
1447
|
+
return this.application.dispatcher;
|
1448
|
+
}
|
1449
|
+
get element() {
|
1450
|
+
return this.scope.element;
|
1451
|
+
}
|
1452
|
+
get parentElement() {
|
1453
|
+
return this.element.parentElement;
|
1454
|
+
}
|
1455
|
+
handleError(error2, message, detail = {}) {
|
1456
|
+
const { identifier, controller, element } = this;
|
1457
|
+
detail = Object.assign({ identifier, controller, element }, detail);
|
1458
|
+
this.application.handleError(error2, `Error ${message}`, detail);
|
1459
|
+
}
|
1460
|
+
targetConnected(element, name) {
|
1461
|
+
this.invokeControllerMethod(`${name}TargetConnected`, element);
|
1462
|
+
}
|
1463
|
+
targetDisconnected(element, name) {
|
1464
|
+
this.invokeControllerMethod(`${name}TargetDisconnected`, element);
|
1465
|
+
}
|
1466
|
+
outletConnected(outlet, element, name) {
|
1467
|
+
this.invokeControllerMethod(`${namespaceCamelize(name)}OutletConnected`, outlet, element);
|
1468
|
+
}
|
1469
|
+
outletDisconnected(outlet, element, name) {
|
1470
|
+
this.invokeControllerMethod(`${namespaceCamelize(name)}OutletDisconnected`, outlet, element);
|
1471
|
+
}
|
1472
|
+
invokeControllerMethod(methodName, ...args) {
|
1473
|
+
const controller = this.controller;
|
1474
|
+
if (typeof controller[methodName] == "function") {
|
1475
|
+
controller[methodName](...args);
|
1476
|
+
}
|
1477
|
+
}
|
1478
|
+
};
|
1479
|
+
function bless(constructor) {
|
1480
|
+
return shadow(constructor, getBlessedProperties(constructor));
|
1481
|
+
}
|
1482
|
+
function shadow(constructor, properties) {
|
1483
|
+
const shadowConstructor = extend(constructor);
|
1484
|
+
const shadowProperties = getShadowProperties(constructor.prototype, properties);
|
1485
|
+
Object.defineProperties(shadowConstructor.prototype, shadowProperties);
|
1486
|
+
return shadowConstructor;
|
1487
|
+
}
|
1488
|
+
function getBlessedProperties(constructor) {
|
1489
|
+
const blessings = readInheritableStaticArrayValues(constructor, "blessings");
|
1490
|
+
return blessings.reduce((blessedProperties, blessing) => {
|
1491
|
+
const properties = blessing(constructor);
|
1492
|
+
for (const key in properties) {
|
1493
|
+
const descriptor = blessedProperties[key] || {};
|
1494
|
+
blessedProperties[key] = Object.assign(descriptor, properties[key]);
|
1495
|
+
}
|
1496
|
+
return blessedProperties;
|
1497
|
+
}, {});
|
1498
|
+
}
|
1499
|
+
function getShadowProperties(prototype, properties) {
|
1500
|
+
return getOwnKeys(properties).reduce((shadowProperties, key) => {
|
1501
|
+
const descriptor = getShadowedDescriptor(prototype, properties, key);
|
1502
|
+
if (descriptor) {
|
1503
|
+
Object.assign(shadowProperties, { [key]: descriptor });
|
1504
|
+
}
|
1505
|
+
return shadowProperties;
|
1506
|
+
}, {});
|
1507
|
+
}
|
1508
|
+
function getShadowedDescriptor(prototype, properties, key) {
|
1509
|
+
const shadowingDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
1510
|
+
const shadowedByValue = shadowingDescriptor && "value" in shadowingDescriptor;
|
1511
|
+
if (!shadowedByValue) {
|
1512
|
+
const descriptor = Object.getOwnPropertyDescriptor(properties, key).value;
|
1513
|
+
if (shadowingDescriptor) {
|
1514
|
+
descriptor.get = shadowingDescriptor.get || descriptor.get;
|
1515
|
+
descriptor.set = shadowingDescriptor.set || descriptor.set;
|
1516
|
+
}
|
1517
|
+
return descriptor;
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
var getOwnKeys = (() => {
|
1521
|
+
if (typeof Object.getOwnPropertySymbols == "function") {
|
1522
|
+
return (object) => [...Object.getOwnPropertyNames(object), ...Object.getOwnPropertySymbols(object)];
|
1523
|
+
} else {
|
1524
|
+
return Object.getOwnPropertyNames;
|
1525
|
+
}
|
1526
|
+
})();
|
1527
|
+
var extend = (() => {
|
1528
|
+
function extendWithReflect(constructor) {
|
1529
|
+
function extended() {
|
1530
|
+
return Reflect.construct(constructor, arguments, new.target);
|
1531
|
+
}
|
1532
|
+
extended.prototype = Object.create(constructor.prototype, {
|
1533
|
+
constructor: { value: extended }
|
1534
|
+
});
|
1535
|
+
Reflect.setPrototypeOf(extended, constructor);
|
1536
|
+
return extended;
|
1537
|
+
}
|
1538
|
+
function testReflectExtension() {
|
1539
|
+
const a = function() {
|
1540
|
+
this.a.call(this);
|
1541
|
+
};
|
1542
|
+
const b = extendWithReflect(a);
|
1543
|
+
b.prototype.a = function() {
|
1544
|
+
};
|
1545
|
+
return new b();
|
1546
|
+
}
|
1547
|
+
try {
|
1548
|
+
testReflectExtension();
|
1549
|
+
return extendWithReflect;
|
1550
|
+
} catch (error2) {
|
1551
|
+
return (constructor) => class extended extends constructor {
|
1552
|
+
};
|
1553
|
+
}
|
1554
|
+
})();
|
1555
|
+
function blessDefinition(definition) {
|
1556
|
+
return {
|
1557
|
+
identifier: definition.identifier,
|
1558
|
+
controllerConstructor: bless(definition.controllerConstructor)
|
1559
|
+
};
|
1560
|
+
}
|
1561
|
+
var Module = class {
|
1562
|
+
constructor(application2, definition) {
|
1563
|
+
this.application = application2;
|
1564
|
+
this.definition = blessDefinition(definition);
|
1565
|
+
this.contextsByScope = /* @__PURE__ */ new WeakMap();
|
1566
|
+
this.connectedContexts = /* @__PURE__ */ new Set();
|
1567
|
+
}
|
1568
|
+
get identifier() {
|
1569
|
+
return this.definition.identifier;
|
1570
|
+
}
|
1571
|
+
get controllerConstructor() {
|
1572
|
+
return this.definition.controllerConstructor;
|
1573
|
+
}
|
1574
|
+
get contexts() {
|
1575
|
+
return Array.from(this.connectedContexts);
|
1576
|
+
}
|
1577
|
+
connectContextForScope(scope) {
|
1578
|
+
const context = this.fetchContextForScope(scope);
|
1579
|
+
this.connectedContexts.add(context);
|
1580
|
+
context.connect();
|
1581
|
+
}
|
1582
|
+
disconnectContextForScope(scope) {
|
1583
|
+
const context = this.contextsByScope.get(scope);
|
1584
|
+
if (context) {
|
1585
|
+
this.connectedContexts.delete(context);
|
1586
|
+
context.disconnect();
|
1587
|
+
}
|
1588
|
+
}
|
1589
|
+
fetchContextForScope(scope) {
|
1590
|
+
let context = this.contextsByScope.get(scope);
|
1591
|
+
if (!context) {
|
1592
|
+
context = new Context(this, scope);
|
1593
|
+
this.contextsByScope.set(scope, context);
|
1594
|
+
}
|
1595
|
+
return context;
|
1596
|
+
}
|
1597
|
+
};
|
1598
|
+
var ClassMap = class {
|
1599
|
+
constructor(scope) {
|
1600
|
+
this.scope = scope;
|
1601
|
+
}
|
1602
|
+
has(name) {
|
1603
|
+
return this.data.has(this.getDataKey(name));
|
1604
|
+
}
|
1605
|
+
get(name) {
|
1606
|
+
return this.getAll(name)[0];
|
1607
|
+
}
|
1608
|
+
getAll(name) {
|
1609
|
+
const tokenString = this.data.get(this.getDataKey(name)) || "";
|
1610
|
+
return tokenize(tokenString);
|
1611
|
+
}
|
1612
|
+
getAttributeName(name) {
|
1613
|
+
return this.data.getAttributeNameForKey(this.getDataKey(name));
|
1614
|
+
}
|
1615
|
+
getDataKey(name) {
|
1616
|
+
return `${name}-class`;
|
1617
|
+
}
|
1618
|
+
get data() {
|
1619
|
+
return this.scope.data;
|
1620
|
+
}
|
1621
|
+
};
|
1622
|
+
var DataMap = class {
|
1623
|
+
constructor(scope) {
|
1624
|
+
this.scope = scope;
|
1625
|
+
}
|
1626
|
+
get element() {
|
1627
|
+
return this.scope.element;
|
1628
|
+
}
|
1629
|
+
get identifier() {
|
1630
|
+
return this.scope.identifier;
|
1631
|
+
}
|
1632
|
+
get(key) {
|
1633
|
+
const name = this.getAttributeNameForKey(key);
|
1634
|
+
return this.element.getAttribute(name);
|
1635
|
+
}
|
1636
|
+
set(key, value) {
|
1637
|
+
const name = this.getAttributeNameForKey(key);
|
1638
|
+
this.element.setAttribute(name, value);
|
1639
|
+
return this.get(key);
|
1640
|
+
}
|
1641
|
+
has(key) {
|
1642
|
+
const name = this.getAttributeNameForKey(key);
|
1643
|
+
return this.element.hasAttribute(name);
|
1644
|
+
}
|
1645
|
+
delete(key) {
|
1646
|
+
if (this.has(key)) {
|
1647
|
+
const name = this.getAttributeNameForKey(key);
|
1648
|
+
this.element.removeAttribute(name);
|
1649
|
+
return true;
|
1650
|
+
} else {
|
1651
|
+
return false;
|
1652
|
+
}
|
1653
|
+
}
|
1654
|
+
getAttributeNameForKey(key) {
|
1655
|
+
return `data-${this.identifier}-${dasherize(key)}`;
|
1656
|
+
}
|
1657
|
+
};
|
1658
|
+
var Guide = class {
|
1659
|
+
constructor(logger) {
|
1660
|
+
this.warnedKeysByObject = /* @__PURE__ */ new WeakMap();
|
1661
|
+
this.logger = logger;
|
1662
|
+
}
|
1663
|
+
warn(object, key, message) {
|
1664
|
+
let warnedKeys = this.warnedKeysByObject.get(object);
|
1665
|
+
if (!warnedKeys) {
|
1666
|
+
warnedKeys = /* @__PURE__ */ new Set();
|
1667
|
+
this.warnedKeysByObject.set(object, warnedKeys);
|
1668
|
+
}
|
1669
|
+
if (!warnedKeys.has(key)) {
|
1670
|
+
warnedKeys.add(key);
|
1671
|
+
this.logger.warn(message, object);
|
1672
|
+
}
|
1673
|
+
}
|
1674
|
+
};
|
1675
|
+
function attributeValueContainsToken(attributeName, token) {
|
1676
|
+
return `[${attributeName}~="${token}"]`;
|
1677
|
+
}
|
1678
|
+
var TargetSet = class {
|
1679
|
+
constructor(scope) {
|
1680
|
+
this.scope = scope;
|
1681
|
+
}
|
1682
|
+
get element() {
|
1683
|
+
return this.scope.element;
|
1684
|
+
}
|
1685
|
+
get identifier() {
|
1686
|
+
return this.scope.identifier;
|
1687
|
+
}
|
1688
|
+
get schema() {
|
1689
|
+
return this.scope.schema;
|
1690
|
+
}
|
1691
|
+
has(targetName) {
|
1692
|
+
return this.find(targetName) != null;
|
1693
|
+
}
|
1694
|
+
find(...targetNames) {
|
1695
|
+
return targetNames.reduce((target, targetName) => target || this.findTarget(targetName) || this.findLegacyTarget(targetName), void 0);
|
1696
|
+
}
|
1697
|
+
findAll(...targetNames) {
|
1698
|
+
return targetNames.reduce((targets, targetName) => [
|
1699
|
+
...targets,
|
1700
|
+
...this.findAllTargets(targetName),
|
1701
|
+
...this.findAllLegacyTargets(targetName)
|
1702
|
+
], []);
|
1703
|
+
}
|
1704
|
+
findTarget(targetName) {
|
1705
|
+
const selector = this.getSelectorForTargetName(targetName);
|
1706
|
+
return this.scope.findElement(selector);
|
1707
|
+
}
|
1708
|
+
findAllTargets(targetName) {
|
1709
|
+
const selector = this.getSelectorForTargetName(targetName);
|
1710
|
+
return this.scope.findAllElements(selector);
|
1711
|
+
}
|
1712
|
+
getSelectorForTargetName(targetName) {
|
1713
|
+
const attributeName = this.schema.targetAttributeForScope(this.identifier);
|
1714
|
+
return attributeValueContainsToken(attributeName, targetName);
|
1715
|
+
}
|
1716
|
+
findLegacyTarget(targetName) {
|
1717
|
+
const selector = this.getLegacySelectorForTargetName(targetName);
|
1718
|
+
return this.deprecate(this.scope.findElement(selector), targetName);
|
1719
|
+
}
|
1720
|
+
findAllLegacyTargets(targetName) {
|
1721
|
+
const selector = this.getLegacySelectorForTargetName(targetName);
|
1722
|
+
return this.scope.findAllElements(selector).map((element) => this.deprecate(element, targetName));
|
1723
|
+
}
|
1724
|
+
getLegacySelectorForTargetName(targetName) {
|
1725
|
+
const targetDescriptor = `${this.identifier}.${targetName}`;
|
1726
|
+
return attributeValueContainsToken(this.schema.targetAttribute, targetDescriptor);
|
1727
|
+
}
|
1728
|
+
deprecate(element, targetName) {
|
1729
|
+
if (element) {
|
1730
|
+
const { identifier } = this;
|
1731
|
+
const attributeName = this.schema.targetAttribute;
|
1732
|
+
const revisedAttributeName = this.schema.targetAttributeForScope(identifier);
|
1733
|
+
this.guide.warn(element, `target:${targetName}`, `Please replace ${attributeName}="${identifier}.${targetName}" with ${revisedAttributeName}="${targetName}". The ${attributeName} attribute is deprecated and will be removed in a future version of Stimulus.`);
|
1734
|
+
}
|
1735
|
+
return element;
|
1736
|
+
}
|
1737
|
+
get guide() {
|
1738
|
+
return this.scope.guide;
|
1739
|
+
}
|
1740
|
+
};
|
1741
|
+
var OutletSet = class {
|
1742
|
+
constructor(scope, controllerElement) {
|
1743
|
+
this.scope = scope;
|
1744
|
+
this.controllerElement = controllerElement;
|
1745
|
+
}
|
1746
|
+
get element() {
|
1747
|
+
return this.scope.element;
|
1748
|
+
}
|
1749
|
+
get identifier() {
|
1750
|
+
return this.scope.identifier;
|
1751
|
+
}
|
1752
|
+
get schema() {
|
1753
|
+
return this.scope.schema;
|
1754
|
+
}
|
1755
|
+
has(outletName) {
|
1756
|
+
return this.find(outletName) != null;
|
1757
|
+
}
|
1758
|
+
find(...outletNames) {
|
1759
|
+
return outletNames.reduce((outlet, outletName) => outlet || this.findOutlet(outletName), void 0);
|
1760
|
+
}
|
1761
|
+
findAll(...outletNames) {
|
1762
|
+
return outletNames.reduce((outlets, outletName) => [...outlets, ...this.findAllOutlets(outletName)], []);
|
1763
|
+
}
|
1764
|
+
getSelectorForOutletName(outletName) {
|
1765
|
+
const attributeName = this.schema.outletAttributeForScope(this.identifier, outletName);
|
1766
|
+
return this.controllerElement.getAttribute(attributeName);
|
1767
|
+
}
|
1768
|
+
findOutlet(outletName) {
|
1769
|
+
const selector = this.getSelectorForOutletName(outletName);
|
1770
|
+
if (selector)
|
1771
|
+
return this.findElement(selector, outletName);
|
1772
|
+
}
|
1773
|
+
findAllOutlets(outletName) {
|
1774
|
+
const selector = this.getSelectorForOutletName(outletName);
|
1775
|
+
return selector ? this.findAllElements(selector, outletName) : [];
|
1776
|
+
}
|
1777
|
+
findElement(selector, outletName) {
|
1778
|
+
const elements = this.scope.queryElements(selector);
|
1779
|
+
return elements.filter((element) => this.matchesElement(element, selector, outletName))[0];
|
1780
|
+
}
|
1781
|
+
findAllElements(selector, outletName) {
|
1782
|
+
const elements = this.scope.queryElements(selector);
|
1783
|
+
return elements.filter((element) => this.matchesElement(element, selector, outletName));
|
1784
|
+
}
|
1785
|
+
matchesElement(element, selector, outletName) {
|
1786
|
+
const controllerAttribute = element.getAttribute(this.scope.schema.controllerAttribute) || "";
|
1787
|
+
return element.matches(selector) && controllerAttribute.split(" ").includes(outletName);
|
1788
|
+
}
|
1789
|
+
};
|
1790
|
+
var Scope = class _Scope {
|
1791
|
+
constructor(schema, element, identifier, logger) {
|
1792
|
+
this.targets = new TargetSet(this);
|
1793
|
+
this.classes = new ClassMap(this);
|
1794
|
+
this.data = new DataMap(this);
|
1795
|
+
this.containsElement = (element2) => {
|
1796
|
+
return element2.closest(this.controllerSelector) === this.element;
|
1797
|
+
};
|
1798
|
+
this.schema = schema;
|
1799
|
+
this.element = element;
|
1800
|
+
this.identifier = identifier;
|
1801
|
+
this.guide = new Guide(logger);
|
1802
|
+
this.outlets = new OutletSet(this.documentScope, element);
|
1803
|
+
}
|
1804
|
+
findElement(selector) {
|
1805
|
+
return this.element.matches(selector) ? this.element : this.queryElements(selector).find(this.containsElement);
|
1806
|
+
}
|
1807
|
+
findAllElements(selector) {
|
1808
|
+
return [
|
1809
|
+
...this.element.matches(selector) ? [this.element] : [],
|
1810
|
+
...this.queryElements(selector).filter(this.containsElement)
|
1811
|
+
];
|
1812
|
+
}
|
1813
|
+
queryElements(selector) {
|
1814
|
+
return Array.from(this.element.querySelectorAll(selector));
|
1815
|
+
}
|
1816
|
+
get controllerSelector() {
|
1817
|
+
return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier);
|
1818
|
+
}
|
1819
|
+
get isDocumentScope() {
|
1820
|
+
return this.element === document.documentElement;
|
1821
|
+
}
|
1822
|
+
get documentScope() {
|
1823
|
+
return this.isDocumentScope ? this : new _Scope(this.schema, document.documentElement, this.identifier, this.guide.logger);
|
1824
|
+
}
|
1825
|
+
};
|
1826
|
+
var ScopeObserver = class {
|
1827
|
+
constructor(element, schema, delegate) {
|
1828
|
+
this.element = element;
|
1829
|
+
this.schema = schema;
|
1830
|
+
this.delegate = delegate;
|
1831
|
+
this.valueListObserver = new ValueListObserver(this.element, this.controllerAttribute, this);
|
1832
|
+
this.scopesByIdentifierByElement = /* @__PURE__ */ new WeakMap();
|
1833
|
+
this.scopeReferenceCounts = /* @__PURE__ */ new WeakMap();
|
1834
|
+
}
|
1835
|
+
start() {
|
1836
|
+
this.valueListObserver.start();
|
1837
|
+
}
|
1838
|
+
stop() {
|
1839
|
+
this.valueListObserver.stop();
|
1840
|
+
}
|
1841
|
+
get controllerAttribute() {
|
1842
|
+
return this.schema.controllerAttribute;
|
1843
|
+
}
|
1844
|
+
parseValueForToken(token) {
|
1845
|
+
const { element, content: identifier } = token;
|
1846
|
+
return this.parseValueForElementAndIdentifier(element, identifier);
|
1847
|
+
}
|
1848
|
+
parseValueForElementAndIdentifier(element, identifier) {
|
1849
|
+
const scopesByIdentifier = this.fetchScopesByIdentifierForElement(element);
|
1850
|
+
let scope = scopesByIdentifier.get(identifier);
|
1851
|
+
if (!scope) {
|
1852
|
+
scope = this.delegate.createScopeForElementAndIdentifier(element, identifier);
|
1853
|
+
scopesByIdentifier.set(identifier, scope);
|
1854
|
+
}
|
1855
|
+
return scope;
|
1856
|
+
}
|
1857
|
+
elementMatchedValue(element, value) {
|
1858
|
+
const referenceCount = (this.scopeReferenceCounts.get(value) || 0) + 1;
|
1859
|
+
this.scopeReferenceCounts.set(value, referenceCount);
|
1860
|
+
if (referenceCount == 1) {
|
1861
|
+
this.delegate.scopeConnected(value);
|
1862
|
+
}
|
1863
|
+
}
|
1864
|
+
elementUnmatchedValue(element, value) {
|
1865
|
+
const referenceCount = this.scopeReferenceCounts.get(value);
|
1866
|
+
if (referenceCount) {
|
1867
|
+
this.scopeReferenceCounts.set(value, referenceCount - 1);
|
1868
|
+
if (referenceCount == 1) {
|
1869
|
+
this.delegate.scopeDisconnected(value);
|
1870
|
+
}
|
1871
|
+
}
|
1872
|
+
}
|
1873
|
+
fetchScopesByIdentifierForElement(element) {
|
1874
|
+
let scopesByIdentifier = this.scopesByIdentifierByElement.get(element);
|
1875
|
+
if (!scopesByIdentifier) {
|
1876
|
+
scopesByIdentifier = /* @__PURE__ */ new Map();
|
1877
|
+
this.scopesByIdentifierByElement.set(element, scopesByIdentifier);
|
1878
|
+
}
|
1879
|
+
return scopesByIdentifier;
|
1880
|
+
}
|
1881
|
+
};
|
1882
|
+
var Router = class {
|
1883
|
+
constructor(application2) {
|
1884
|
+
this.application = application2;
|
1885
|
+
this.scopeObserver = new ScopeObserver(this.element, this.schema, this);
|
1886
|
+
this.scopesByIdentifier = new Multimap();
|
1887
|
+
this.modulesByIdentifier = /* @__PURE__ */ new Map();
|
1888
|
+
}
|
1889
|
+
get element() {
|
1890
|
+
return this.application.element;
|
1891
|
+
}
|
1892
|
+
get schema() {
|
1893
|
+
return this.application.schema;
|
1894
|
+
}
|
1895
|
+
get logger() {
|
1896
|
+
return this.application.logger;
|
1897
|
+
}
|
1898
|
+
get controllerAttribute() {
|
1899
|
+
return this.schema.controllerAttribute;
|
1900
|
+
}
|
1901
|
+
get modules() {
|
1902
|
+
return Array.from(this.modulesByIdentifier.values());
|
1903
|
+
}
|
1904
|
+
get contexts() {
|
1905
|
+
return this.modules.reduce((contexts, module) => contexts.concat(module.contexts), []);
|
1906
|
+
}
|
1907
|
+
start() {
|
1908
|
+
this.scopeObserver.start();
|
1909
|
+
}
|
1910
|
+
stop() {
|
1911
|
+
this.scopeObserver.stop();
|
1912
|
+
}
|
1913
|
+
loadDefinition(definition) {
|
1914
|
+
this.unloadIdentifier(definition.identifier);
|
1915
|
+
const module = new Module(this.application, definition);
|
1916
|
+
this.connectModule(module);
|
1917
|
+
const afterLoad = definition.controllerConstructor.afterLoad;
|
1918
|
+
if (afterLoad) {
|
1919
|
+
afterLoad.call(definition.controllerConstructor, definition.identifier, this.application);
|
1920
|
+
}
|
1921
|
+
}
|
1922
|
+
unloadIdentifier(identifier) {
|
1923
|
+
const module = this.modulesByIdentifier.get(identifier);
|
1924
|
+
if (module) {
|
1925
|
+
this.disconnectModule(module);
|
1926
|
+
}
|
1927
|
+
}
|
1928
|
+
getContextForElementAndIdentifier(element, identifier) {
|
1929
|
+
const module = this.modulesByIdentifier.get(identifier);
|
1930
|
+
if (module) {
|
1931
|
+
return module.contexts.find((context) => context.element == element);
|
1932
|
+
}
|
1933
|
+
}
|
1934
|
+
proposeToConnectScopeForElementAndIdentifier(element, identifier) {
|
1935
|
+
const scope = this.scopeObserver.parseValueForElementAndIdentifier(element, identifier);
|
1936
|
+
if (scope) {
|
1937
|
+
this.scopeObserver.elementMatchedValue(scope.element, scope);
|
1938
|
+
} else {
|
1939
|
+
console.error(`Couldn't find or create scope for identifier: "${identifier}" and element:`, element);
|
1940
|
+
}
|
1941
|
+
}
|
1942
|
+
handleError(error2, message, detail) {
|
1943
|
+
this.application.handleError(error2, message, detail);
|
1944
|
+
}
|
1945
|
+
createScopeForElementAndIdentifier(element, identifier) {
|
1946
|
+
return new Scope(this.schema, element, identifier, this.logger);
|
1947
|
+
}
|
1948
|
+
scopeConnected(scope) {
|
1949
|
+
this.scopesByIdentifier.add(scope.identifier, scope);
|
1950
|
+
const module = this.modulesByIdentifier.get(scope.identifier);
|
1951
|
+
if (module) {
|
1952
|
+
module.connectContextForScope(scope);
|
1953
|
+
}
|
1954
|
+
}
|
1955
|
+
scopeDisconnected(scope) {
|
1956
|
+
this.scopesByIdentifier.delete(scope.identifier, scope);
|
1957
|
+
const module = this.modulesByIdentifier.get(scope.identifier);
|
1958
|
+
if (module) {
|
1959
|
+
module.disconnectContextForScope(scope);
|
1960
|
+
}
|
1961
|
+
}
|
1962
|
+
connectModule(module) {
|
1963
|
+
this.modulesByIdentifier.set(module.identifier, module);
|
1964
|
+
const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
|
1965
|
+
scopes.forEach((scope) => module.connectContextForScope(scope));
|
1966
|
+
}
|
1967
|
+
disconnectModule(module) {
|
1968
|
+
this.modulesByIdentifier.delete(module.identifier);
|
1969
|
+
const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
|
1970
|
+
scopes.forEach((scope) => module.disconnectContextForScope(scope));
|
1971
|
+
}
|
1972
|
+
};
|
1973
|
+
var defaultSchema = {
|
1974
|
+
controllerAttribute: "data-controller",
|
1975
|
+
actionAttribute: "data-action",
|
1976
|
+
targetAttribute: "data-target",
|
1977
|
+
targetAttributeForScope: (identifier) => `data-${identifier}-target`,
|
1978
|
+
outletAttributeForScope: (identifier, outlet) => `data-${identifier}-${outlet}-outlet`,
|
1979
|
+
keyMappings: Object.assign(Object.assign({ enter: "Enter", tab: "Tab", esc: "Escape", space: " ", up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight", home: "Home", end: "End", page_up: "PageUp", page_down: "PageDown" }, objectFromEntries("abcdefghijklmnopqrstuvwxyz".split("").map((c) => [c, c]))), objectFromEntries("0123456789".split("").map((n) => [n, n])))
|
1980
|
+
};
|
1981
|
+
function objectFromEntries(array) {
|
1982
|
+
return array.reduce((memo, [k, v]) => Object.assign(Object.assign({}, memo), { [k]: v }), {});
|
1983
|
+
}
|
1984
|
+
var Application = class {
|
1985
|
+
constructor(element = document.documentElement, schema = defaultSchema) {
|
1986
|
+
this.logger = console;
|
1987
|
+
this.debug = false;
|
1988
|
+
this.logDebugActivity = (identifier, functionName, detail = {}) => {
|
1989
|
+
if (this.debug) {
|
1990
|
+
this.logFormattedMessage(identifier, functionName, detail);
|
1991
|
+
}
|
1992
|
+
};
|
1993
|
+
this.element = element;
|
1994
|
+
this.schema = schema;
|
1995
|
+
this.dispatcher = new Dispatcher(this);
|
1996
|
+
this.router = new Router(this);
|
1997
|
+
this.actionDescriptorFilters = Object.assign({}, defaultActionDescriptorFilters);
|
1998
|
+
}
|
1999
|
+
static start(element, schema) {
|
2000
|
+
const application2 = new this(element, schema);
|
2001
|
+
application2.start();
|
2002
|
+
return application2;
|
2003
|
+
}
|
2004
|
+
async start() {
|
2005
|
+
await domReady();
|
2006
|
+
this.logDebugActivity("application", "starting");
|
2007
|
+
this.dispatcher.start();
|
2008
|
+
this.router.start();
|
2009
|
+
this.logDebugActivity("application", "start");
|
2010
|
+
}
|
2011
|
+
stop() {
|
2012
|
+
this.logDebugActivity("application", "stopping");
|
2013
|
+
this.dispatcher.stop();
|
2014
|
+
this.router.stop();
|
2015
|
+
this.logDebugActivity("application", "stop");
|
2016
|
+
}
|
2017
|
+
register(identifier, controllerConstructor) {
|
2018
|
+
this.load({ identifier, controllerConstructor });
|
2019
|
+
}
|
2020
|
+
registerActionOption(name, filter) {
|
2021
|
+
this.actionDescriptorFilters[name] = filter;
|
2022
|
+
}
|
2023
|
+
load(head, ...rest) {
|
2024
|
+
const definitions = Array.isArray(head) ? head : [head, ...rest];
|
2025
|
+
definitions.forEach((definition) => {
|
2026
|
+
if (definition.controllerConstructor.shouldLoad) {
|
2027
|
+
this.router.loadDefinition(definition);
|
2028
|
+
}
|
2029
|
+
});
|
2030
|
+
}
|
2031
|
+
unload(head, ...rest) {
|
2032
|
+
const identifiers = Array.isArray(head) ? head : [head, ...rest];
|
2033
|
+
identifiers.forEach((identifier) => this.router.unloadIdentifier(identifier));
|
2034
|
+
}
|
2035
|
+
get controllers() {
|
2036
|
+
return this.router.contexts.map((context) => context.controller);
|
2037
|
+
}
|
2038
|
+
getControllerForElementAndIdentifier(element, identifier) {
|
2039
|
+
const context = this.router.getContextForElementAndIdentifier(element, identifier);
|
2040
|
+
return context ? context.controller : null;
|
2041
|
+
}
|
2042
|
+
handleError(error2, message, detail) {
|
2043
|
+
var _a;
|
2044
|
+
this.logger.error(`%s
|
2045
|
+
|
2046
|
+
%o
|
2047
|
+
|
2048
|
+
%o`, message, error2, detail);
|
2049
|
+
(_a = window.onerror) === null || _a === void 0 ? void 0 : _a.call(window, message, "", 0, 0, error2);
|
2050
|
+
}
|
2051
|
+
logFormattedMessage(identifier, functionName, detail = {}) {
|
2052
|
+
detail = Object.assign({ application: this }, detail);
|
2053
|
+
this.logger.groupCollapsed(`${identifier} #${functionName}`);
|
2054
|
+
this.logger.log("details:", Object.assign({}, detail));
|
2055
|
+
this.logger.groupEnd();
|
2056
|
+
}
|
2057
|
+
};
|
2058
|
+
function domReady() {
|
2059
|
+
return new Promise((resolve) => {
|
2060
|
+
if (document.readyState == "loading") {
|
2061
|
+
document.addEventListener("DOMContentLoaded", () => resolve());
|
2062
|
+
} else {
|
2063
|
+
resolve();
|
2064
|
+
}
|
2065
|
+
});
|
2066
|
+
}
|
2067
|
+
function ClassPropertiesBlessing(constructor) {
|
2068
|
+
const classes = readInheritableStaticArrayValues(constructor, "classes");
|
2069
|
+
return classes.reduce((properties, classDefinition) => {
|
2070
|
+
return Object.assign(properties, propertiesForClassDefinition(classDefinition));
|
2071
|
+
}, {});
|
2072
|
+
}
|
2073
|
+
function propertiesForClassDefinition(key) {
|
2074
|
+
return {
|
2075
|
+
[`${key}Class`]: {
|
2076
|
+
get() {
|
2077
|
+
const { classes } = this;
|
2078
|
+
if (classes.has(key)) {
|
2079
|
+
return classes.get(key);
|
2080
|
+
} else {
|
2081
|
+
const attribute = classes.getAttributeName(key);
|
2082
|
+
throw new Error(`Missing attribute "${attribute}"`);
|
2083
|
+
}
|
2084
|
+
}
|
2085
|
+
},
|
2086
|
+
[`${key}Classes`]: {
|
2087
|
+
get() {
|
2088
|
+
return this.classes.getAll(key);
|
2089
|
+
}
|
2090
|
+
},
|
2091
|
+
[`has${capitalize(key)}Class`]: {
|
2092
|
+
get() {
|
2093
|
+
return this.classes.has(key);
|
2094
|
+
}
|
2095
|
+
}
|
2096
|
+
};
|
2097
|
+
}
|
2098
|
+
function OutletPropertiesBlessing(constructor) {
|
2099
|
+
const outlets = readInheritableStaticArrayValues(constructor, "outlets");
|
2100
|
+
return outlets.reduce((properties, outletDefinition) => {
|
2101
|
+
return Object.assign(properties, propertiesForOutletDefinition(outletDefinition));
|
2102
|
+
}, {});
|
2103
|
+
}
|
2104
|
+
function getOutletController(controller, element, identifier) {
|
2105
|
+
return controller.application.getControllerForElementAndIdentifier(element, identifier);
|
2106
|
+
}
|
2107
|
+
function getControllerAndEnsureConnectedScope(controller, element, outletName) {
|
2108
|
+
let outletController = getOutletController(controller, element, outletName);
|
2109
|
+
if (outletController)
|
2110
|
+
return outletController;
|
2111
|
+
controller.application.router.proposeToConnectScopeForElementAndIdentifier(element, outletName);
|
2112
|
+
outletController = getOutletController(controller, element, outletName);
|
2113
|
+
if (outletController)
|
2114
|
+
return outletController;
|
2115
|
+
}
|
2116
|
+
function propertiesForOutletDefinition(name) {
|
2117
|
+
const camelizedName = namespaceCamelize(name);
|
2118
|
+
return {
|
2119
|
+
[`${camelizedName}Outlet`]: {
|
2120
|
+
get() {
|
2121
|
+
const outletElement = this.outlets.find(name);
|
2122
|
+
const selector = this.outlets.getSelectorForOutletName(name);
|
2123
|
+
if (outletElement) {
|
2124
|
+
const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);
|
2125
|
+
if (outletController)
|
2126
|
+
return outletController;
|
2127
|
+
throw new Error(`The provided outlet element is missing an outlet controller "${name}" instance for host controller "${this.identifier}"`);
|
2128
|
+
}
|
2129
|
+
throw new Error(`Missing outlet element "${name}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${selector}".`);
|
2130
|
+
}
|
2131
|
+
},
|
2132
|
+
[`${camelizedName}Outlets`]: {
|
2133
|
+
get() {
|
2134
|
+
const outlets = this.outlets.findAll(name);
|
2135
|
+
if (outlets.length > 0) {
|
2136
|
+
return outlets.map((outletElement) => {
|
2137
|
+
const outletController = getControllerAndEnsureConnectedScope(this, outletElement, name);
|
2138
|
+
if (outletController)
|
2139
|
+
return outletController;
|
2140
|
+
console.warn(`The provided outlet element is missing an outlet controller "${name}" instance for host controller "${this.identifier}"`, outletElement);
|
2141
|
+
}).filter((controller) => controller);
|
2142
|
+
}
|
2143
|
+
return [];
|
2144
|
+
}
|
2145
|
+
},
|
2146
|
+
[`${camelizedName}OutletElement`]: {
|
2147
|
+
get() {
|
2148
|
+
const outletElement = this.outlets.find(name);
|
2149
|
+
const selector = this.outlets.getSelectorForOutletName(name);
|
2150
|
+
if (outletElement) {
|
2151
|
+
return outletElement;
|
2152
|
+
} else {
|
2153
|
+
throw new Error(`Missing outlet element "${name}" for host controller "${this.identifier}". Stimulus couldn't find a matching outlet element using selector "${selector}".`);
|
2154
|
+
}
|
2155
|
+
}
|
2156
|
+
},
|
2157
|
+
[`${camelizedName}OutletElements`]: {
|
2158
|
+
get() {
|
2159
|
+
return this.outlets.findAll(name);
|
2160
|
+
}
|
2161
|
+
},
|
2162
|
+
[`has${capitalize(camelizedName)}Outlet`]: {
|
2163
|
+
get() {
|
2164
|
+
return this.outlets.has(name);
|
2165
|
+
}
|
2166
|
+
}
|
2167
|
+
};
|
2168
|
+
}
|
2169
|
+
function TargetPropertiesBlessing(constructor) {
|
2170
|
+
const targets = readInheritableStaticArrayValues(constructor, "targets");
|
2171
|
+
return targets.reduce((properties, targetDefinition) => {
|
2172
|
+
return Object.assign(properties, propertiesForTargetDefinition(targetDefinition));
|
2173
|
+
}, {});
|
2174
|
+
}
|
2175
|
+
function propertiesForTargetDefinition(name) {
|
2176
|
+
return {
|
2177
|
+
[`${name}Target`]: {
|
2178
|
+
get() {
|
2179
|
+
const target = this.targets.find(name);
|
2180
|
+
if (target) {
|
2181
|
+
return target;
|
2182
|
+
} else {
|
2183
|
+
throw new Error(`Missing target element "${name}" for "${this.identifier}" controller`);
|
2184
|
+
}
|
2185
|
+
}
|
2186
|
+
},
|
2187
|
+
[`${name}Targets`]: {
|
2188
|
+
get() {
|
2189
|
+
return this.targets.findAll(name);
|
2190
|
+
}
|
2191
|
+
},
|
2192
|
+
[`has${capitalize(name)}Target`]: {
|
2193
|
+
get() {
|
2194
|
+
return this.targets.has(name);
|
2195
|
+
}
|
2196
|
+
}
|
2197
|
+
};
|
2198
|
+
}
|
2199
|
+
function ValuePropertiesBlessing(constructor) {
|
2200
|
+
const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values");
|
2201
|
+
const propertyDescriptorMap = {
|
2202
|
+
valueDescriptorMap: {
|
2203
|
+
get() {
|
2204
|
+
return valueDefinitionPairs.reduce((result, valueDefinitionPair) => {
|
2205
|
+
const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair, this.identifier);
|
2206
|
+
const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);
|
2207
|
+
return Object.assign(result, { [attributeName]: valueDescriptor });
|
2208
|
+
}, {});
|
2209
|
+
}
|
2210
|
+
}
|
2211
|
+
};
|
2212
|
+
return valueDefinitionPairs.reduce((properties, valueDefinitionPair) => {
|
2213
|
+
return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair));
|
2214
|
+
}, propertyDescriptorMap);
|
2215
|
+
}
|
2216
|
+
function propertiesForValueDefinitionPair(valueDefinitionPair, controller) {
|
2217
|
+
const definition = parseValueDefinitionPair(valueDefinitionPair, controller);
|
2218
|
+
const { key, name, reader: read, writer: write } = definition;
|
2219
|
+
return {
|
2220
|
+
[name]: {
|
2221
|
+
get() {
|
2222
|
+
const value = this.data.get(key);
|
2223
|
+
if (value !== null) {
|
2224
|
+
return read(value);
|
2225
|
+
} else {
|
2226
|
+
return definition.defaultValue;
|
2227
|
+
}
|
2228
|
+
},
|
2229
|
+
set(value) {
|
2230
|
+
if (value === void 0) {
|
2231
|
+
this.data.delete(key);
|
2232
|
+
} else {
|
2233
|
+
this.data.set(key, write(value));
|
2234
|
+
}
|
2235
|
+
}
|
2236
|
+
},
|
2237
|
+
[`has${capitalize(name)}`]: {
|
2238
|
+
get() {
|
2239
|
+
return this.data.has(key) || definition.hasCustomDefaultValue;
|
2240
|
+
}
|
2241
|
+
}
|
2242
|
+
};
|
2243
|
+
}
|
2244
|
+
function parseValueDefinitionPair([token, typeDefinition], controller) {
|
2245
|
+
return valueDescriptorForTokenAndTypeDefinition({
|
2246
|
+
controller,
|
2247
|
+
token,
|
2248
|
+
typeDefinition
|
2249
|
+
});
|
2250
|
+
}
|
2251
|
+
function parseValueTypeConstant(constant) {
|
2252
|
+
switch (constant) {
|
2253
|
+
case Array:
|
2254
|
+
return "array";
|
2255
|
+
case Boolean:
|
2256
|
+
return "boolean";
|
2257
|
+
case Number:
|
2258
|
+
return "number";
|
2259
|
+
case Object:
|
2260
|
+
return "object";
|
2261
|
+
case String:
|
2262
|
+
return "string";
|
2263
|
+
}
|
2264
|
+
}
|
2265
|
+
function parseValueTypeDefault(defaultValue) {
|
2266
|
+
switch (typeof defaultValue) {
|
2267
|
+
case "boolean":
|
2268
|
+
return "boolean";
|
2269
|
+
case "number":
|
2270
|
+
return "number";
|
2271
|
+
case "string":
|
2272
|
+
return "string";
|
2273
|
+
}
|
2274
|
+
if (Array.isArray(defaultValue))
|
2275
|
+
return "array";
|
2276
|
+
if (Object.prototype.toString.call(defaultValue) === "[object Object]")
|
2277
|
+
return "object";
|
2278
|
+
}
|
2279
|
+
function parseValueTypeObject(payload) {
|
2280
|
+
const { controller, token, typeObject } = payload;
|
2281
|
+
const hasType = isSomething(typeObject.type);
|
2282
|
+
const hasDefault = isSomething(typeObject.default);
|
2283
|
+
const fullObject = hasType && hasDefault;
|
2284
|
+
const onlyType = hasType && !hasDefault;
|
2285
|
+
const onlyDefault = !hasType && hasDefault;
|
2286
|
+
const typeFromObject = parseValueTypeConstant(typeObject.type);
|
2287
|
+
const typeFromDefaultValue = parseValueTypeDefault(payload.typeObject.default);
|
2288
|
+
if (onlyType)
|
2289
|
+
return typeFromObject;
|
2290
|
+
if (onlyDefault)
|
2291
|
+
return typeFromDefaultValue;
|
2292
|
+
if (typeFromObject !== typeFromDefaultValue) {
|
2293
|
+
const propertyPath = controller ? `${controller}.${token}` : token;
|
2294
|
+
throw new Error(`The specified default value for the Stimulus Value "${propertyPath}" must match the defined type "${typeFromObject}". The provided default value of "${typeObject.default}" is of type "${typeFromDefaultValue}".`);
|
2295
|
+
}
|
2296
|
+
if (fullObject)
|
2297
|
+
return typeFromObject;
|
2298
|
+
}
|
2299
|
+
function parseValueTypeDefinition(payload) {
|
2300
|
+
const { controller, token, typeDefinition } = payload;
|
2301
|
+
const typeObject = { controller, token, typeObject: typeDefinition };
|
2302
|
+
const typeFromObject = parseValueTypeObject(typeObject);
|
2303
|
+
const typeFromDefaultValue = parseValueTypeDefault(typeDefinition);
|
2304
|
+
const typeFromConstant = parseValueTypeConstant(typeDefinition);
|
2305
|
+
const type = typeFromObject || typeFromDefaultValue || typeFromConstant;
|
2306
|
+
if (type)
|
2307
|
+
return type;
|
2308
|
+
const propertyPath = controller ? `${controller}.${typeDefinition}` : token;
|
2309
|
+
throw new Error(`Unknown value type "${propertyPath}" for "${token}" value`);
|
2310
|
+
}
|
2311
|
+
function defaultValueForDefinition(typeDefinition) {
|
2312
|
+
const constant = parseValueTypeConstant(typeDefinition);
|
2313
|
+
if (constant)
|
2314
|
+
return defaultValuesByType[constant];
|
2315
|
+
const hasDefault = hasProperty(typeDefinition, "default");
|
2316
|
+
const hasType = hasProperty(typeDefinition, "type");
|
2317
|
+
const typeObject = typeDefinition;
|
2318
|
+
if (hasDefault)
|
2319
|
+
return typeObject.default;
|
2320
|
+
if (hasType) {
|
2321
|
+
const { type } = typeObject;
|
2322
|
+
const constantFromType = parseValueTypeConstant(type);
|
2323
|
+
if (constantFromType)
|
2324
|
+
return defaultValuesByType[constantFromType];
|
2325
|
+
}
|
2326
|
+
return typeDefinition;
|
2327
|
+
}
|
2328
|
+
function valueDescriptorForTokenAndTypeDefinition(payload) {
|
2329
|
+
const { token, typeDefinition } = payload;
|
2330
|
+
const key = `${dasherize(token)}-value`;
|
2331
|
+
const type = parseValueTypeDefinition(payload);
|
2332
|
+
return {
|
2333
|
+
type,
|
2334
|
+
key,
|
2335
|
+
name: camelize(key),
|
2336
|
+
get defaultValue() {
|
2337
|
+
return defaultValueForDefinition(typeDefinition);
|
2338
|
+
},
|
2339
|
+
get hasCustomDefaultValue() {
|
2340
|
+
return parseValueTypeDefault(typeDefinition) !== void 0;
|
2341
|
+
},
|
2342
|
+
reader: readers[type],
|
2343
|
+
writer: writers[type] || writers.default
|
2344
|
+
};
|
2345
|
+
}
|
2346
|
+
var defaultValuesByType = {
|
2347
|
+
get array() {
|
2348
|
+
return [];
|
2349
|
+
},
|
2350
|
+
boolean: false,
|
2351
|
+
number: 0,
|
2352
|
+
get object() {
|
2353
|
+
return {};
|
2354
|
+
},
|
2355
|
+
string: ""
|
2356
|
+
};
|
2357
|
+
var readers = {
|
2358
|
+
array(value) {
|
2359
|
+
const array = JSON.parse(value);
|
2360
|
+
if (!Array.isArray(array)) {
|
2361
|
+
throw new TypeError(`expected value of type "array" but instead got value "${value}" of type "${parseValueTypeDefault(array)}"`);
|
2362
|
+
}
|
2363
|
+
return array;
|
2364
|
+
},
|
2365
|
+
boolean(value) {
|
2366
|
+
return !(value == "0" || String(value).toLowerCase() == "false");
|
2367
|
+
},
|
2368
|
+
number(value) {
|
2369
|
+
return Number(value.replace(/_/g, ""));
|
2370
|
+
},
|
2371
|
+
object(value) {
|
2372
|
+
const object = JSON.parse(value);
|
2373
|
+
if (object === null || typeof object != "object" || Array.isArray(object)) {
|
2374
|
+
throw new TypeError(`expected value of type "object" but instead got value "${value}" of type "${parseValueTypeDefault(object)}"`);
|
2375
|
+
}
|
2376
|
+
return object;
|
2377
|
+
},
|
2378
|
+
string(value) {
|
2379
|
+
return value;
|
2380
|
+
}
|
2381
|
+
};
|
2382
|
+
var writers = {
|
2383
|
+
default: writeString,
|
2384
|
+
array: writeJSON,
|
2385
|
+
object: writeJSON
|
2386
|
+
};
|
2387
|
+
function writeJSON(value) {
|
2388
|
+
return JSON.stringify(value);
|
2389
|
+
}
|
2390
|
+
function writeString(value) {
|
2391
|
+
return `${value}`;
|
2392
|
+
}
|
2393
|
+
var Controller = class {
|
2394
|
+
constructor(context) {
|
2395
|
+
this.context = context;
|
2396
|
+
}
|
2397
|
+
static get shouldLoad() {
|
2398
|
+
return true;
|
2399
|
+
}
|
2400
|
+
static afterLoad(_identifier, _application) {
|
2401
|
+
return;
|
2402
|
+
}
|
2403
|
+
get application() {
|
2404
|
+
return this.context.application;
|
2405
|
+
}
|
2406
|
+
get scope() {
|
2407
|
+
return this.context.scope;
|
2408
|
+
}
|
2409
|
+
get element() {
|
2410
|
+
return this.scope.element;
|
2411
|
+
}
|
2412
|
+
get identifier() {
|
2413
|
+
return this.scope.identifier;
|
2414
|
+
}
|
2415
|
+
get targets() {
|
2416
|
+
return this.scope.targets;
|
2417
|
+
}
|
2418
|
+
get outlets() {
|
2419
|
+
return this.scope.outlets;
|
2420
|
+
}
|
2421
|
+
get classes() {
|
2422
|
+
return this.scope.classes;
|
2423
|
+
}
|
2424
|
+
get data() {
|
2425
|
+
return this.scope.data;
|
2426
|
+
}
|
2427
|
+
initialize() {
|
2428
|
+
}
|
2429
|
+
connect() {
|
2430
|
+
}
|
2431
|
+
disconnect() {
|
2432
|
+
}
|
2433
|
+
dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
|
2434
|
+
const type = prefix ? `${prefix}:${eventName}` : eventName;
|
2435
|
+
const event = new CustomEvent(type, { detail, bubbles, cancelable });
|
2436
|
+
target.dispatchEvent(event);
|
2437
|
+
return event;
|
2438
|
+
}
|
2439
|
+
};
|
2440
|
+
Controller.blessings = [
|
2441
|
+
ClassPropertiesBlessing,
|
2442
|
+
TargetPropertiesBlessing,
|
2443
|
+
ValuePropertiesBlessing,
|
2444
|
+
OutletPropertiesBlessing
|
2445
|
+
];
|
2446
|
+
Controller.targets = [];
|
2447
|
+
Controller.outlets = [];
|
2448
|
+
Controller.values = {};
|
2449
|
+
|
2450
|
+
// app/assets/javascripts/relay_ui/controllers/toggle_controller.js
|
2451
|
+
var toggle_controller_default = class extends Controller {
|
2452
|
+
connect() {
|
2453
|
+
console.log("RelayUI Toggle initialized");
|
2454
|
+
const firstOption = this.element.querySelector('[data-action="click->rui_toggle#switch"]');
|
2455
|
+
if (firstOption) {
|
2456
|
+
firstOption.classList.add("bg-white", "text-zinc-700");
|
2457
|
+
}
|
2458
|
+
}
|
2459
|
+
switch(event) {
|
2460
|
+
const options = this.element.querySelectorAll('[data-action="click->rui_toggle#switch"]');
|
2461
|
+
options.forEach((option) => {
|
2462
|
+
option.classList.remove("bg-white", "text-zinc-700");
|
2463
|
+
});
|
2464
|
+
event.currentTarget.classList.add("bg-white", "text-zinc-700");
|
2465
|
+
}
|
2466
|
+
};
|
2467
|
+
|
2468
|
+
// app/assets/javascripts/relay_ui/index.js
|
2469
|
+
var application = Application.start();
|
2470
|
+
application.register("toggle", toggle_controller_default);
|
2471
|
+
})();
|