material_view_components 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +17 -0
  5. data/app/assets/builds/material_view_components/application.css +218048 -0
  6. data/app/assets/builds/material_view_components/application.js +1958 -0
  7. data/app/assets/config/material_view_components_manifest.js +1 -0
  8. data/app/assets/stylesheets/material_view_components/application.tailwind.css +182 -0
  9. data/app/components/application_component.rb +19 -0
  10. data/app/components/material/button_component.html.erb +10 -0
  11. data/app/components/material/button_component.rb +190 -0
  12. data/app/components/material/button_component_controller.js +8 -0
  13. data/app/components/material/fab_component.html.erb +8 -0
  14. data/app/components/material/fab_component.rb +41 -0
  15. data/app/controllers/material_view_components/application_controller.rb +4 -0
  16. data/app/helpers/material_view_components/application_helper.rb +4 -0
  17. data/app/javascript/application.js +2 -0
  18. data/app/javascript/controllers/application.js +15 -0
  19. data/app/javascript/controllers/hello_controller.js +7 -0
  20. data/app/javascript/controllers/helpers.js +30 -0
  21. data/app/javascript/controllers/index.js +7 -0
  22. data/app/jobs/material_view_components/application_job.rb +4 -0
  23. data/app/mailers/material_view_components/application_mailer.rb +6 -0
  24. data/app/models/material_view_components/application_record.rb +5 -0
  25. data/app/views/layouts/material_view_components/application.html.erb +19 -0
  26. data/config/initializers/assets.rb +3 -0
  27. data/config/routes.rb +2 -0
  28. data/lib/material_view_components/engine.rb +7 -0
  29. data/lib/material_view_components/version.rb +3 -0
  30. data/lib/material_view_components.rb +6 -0
  31. data/lib/tasks/material_view_components_tasks.rake +4 -0
  32. metadata +146 -0
@@ -0,0 +1,1958 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ __markAsModule(target);
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+
13
+ // node_modules/@hotwired/stimulus/dist/stimulus.js
14
+ function extendEvent(event) {
15
+ if ("immediatePropagationStopped" in event) {
16
+ return event;
17
+ } else {
18
+ const { stopImmediatePropagation } = event;
19
+ return Object.assign(event, {
20
+ immediatePropagationStopped: false,
21
+ stopImmediatePropagation() {
22
+ this.immediatePropagationStopped = true;
23
+ stopImmediatePropagation.call(this);
24
+ }
25
+ });
26
+ }
27
+ }
28
+ function parseActionDescriptorString(descriptorString) {
29
+ const source = descriptorString.trim();
30
+ const matches = source.match(descriptorPattern) || [];
31
+ return {
32
+ eventTarget: parseEventTarget(matches[4]),
33
+ eventName: matches[2],
34
+ eventOptions: matches[9] ? parseEventOptions(matches[9]) : {},
35
+ identifier: matches[5],
36
+ methodName: matches[7]
37
+ };
38
+ }
39
+ function parseEventTarget(eventTargetName) {
40
+ if (eventTargetName == "window") {
41
+ return window;
42
+ } else if (eventTargetName == "document") {
43
+ return document;
44
+ }
45
+ }
46
+ function parseEventOptions(eventOptions) {
47
+ return eventOptions.split(":").reduce((options, token) => Object.assign(options, { [token.replace(/^!/, "")]: !/^!/.test(token) }), {});
48
+ }
49
+ function stringifyEventTarget(eventTarget) {
50
+ if (eventTarget == window) {
51
+ return "window";
52
+ } else if (eventTarget == document) {
53
+ return "document";
54
+ }
55
+ }
56
+ function camelize(value) {
57
+ return value.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase());
58
+ }
59
+ function capitalize(value) {
60
+ return value.charAt(0).toUpperCase() + value.slice(1);
61
+ }
62
+ function dasherize(value) {
63
+ return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
64
+ }
65
+ function tokenize(value) {
66
+ return value.match(/[^\s]+/g) || [];
67
+ }
68
+ function getDefaultEventNameForElement(element) {
69
+ const tagName = element.tagName.toLowerCase();
70
+ if (tagName in defaultEventNames) {
71
+ return defaultEventNames[tagName](element);
72
+ }
73
+ }
74
+ function error(message) {
75
+ throw new Error(message);
76
+ }
77
+ function typecast(value) {
78
+ try {
79
+ return JSON.parse(value);
80
+ } catch (o_O) {
81
+ return value;
82
+ }
83
+ }
84
+ function add(map, key, value) {
85
+ fetch(map, key).add(value);
86
+ }
87
+ function del(map, key, value) {
88
+ fetch(map, key).delete(value);
89
+ prune(map, key);
90
+ }
91
+ function fetch(map, key) {
92
+ let values = map.get(key);
93
+ if (!values) {
94
+ values = new Set();
95
+ map.set(key, values);
96
+ }
97
+ return values;
98
+ }
99
+ function prune(map, key) {
100
+ const values = map.get(key);
101
+ if (values != null && values.size == 0) {
102
+ map.delete(key);
103
+ }
104
+ }
105
+ function parseTokenString(tokenString, element, attributeName) {
106
+ return tokenString.trim().split(/\s+/).filter((content) => content.length).map((content, index) => ({ element, attributeName, content, index }));
107
+ }
108
+ function zip(left, right) {
109
+ const length = Math.max(left.length, right.length);
110
+ return Array.from({ length }, (_, index) => [left[index], right[index]]);
111
+ }
112
+ function tokensAreEqual(left, right) {
113
+ return left && right && left.index == right.index && left.content == right.content;
114
+ }
115
+ function readInheritableStaticArrayValues(constructor, propertyName) {
116
+ const ancestors = getAncestorsForConstructor(constructor);
117
+ return Array.from(ancestors.reduce((values, constructor2) => {
118
+ getOwnStaticArrayValues(constructor2, propertyName).forEach((name) => values.add(name));
119
+ return values;
120
+ }, new Set()));
121
+ }
122
+ function readInheritableStaticObjectPairs(constructor, propertyName) {
123
+ const ancestors = getAncestorsForConstructor(constructor);
124
+ return ancestors.reduce((pairs, constructor2) => {
125
+ pairs.push(...getOwnStaticObjectPairs(constructor2, propertyName));
126
+ return pairs;
127
+ }, []);
128
+ }
129
+ function getAncestorsForConstructor(constructor) {
130
+ const ancestors = [];
131
+ while (constructor) {
132
+ ancestors.push(constructor);
133
+ constructor = Object.getPrototypeOf(constructor);
134
+ }
135
+ return ancestors.reverse();
136
+ }
137
+ function getOwnStaticArrayValues(constructor, propertyName) {
138
+ const definition = constructor[propertyName];
139
+ return Array.isArray(definition) ? definition : [];
140
+ }
141
+ function getOwnStaticObjectPairs(constructor, propertyName) {
142
+ const definition = constructor[propertyName];
143
+ return definition ? Object.keys(definition).map((key) => [key, definition[key]]) : [];
144
+ }
145
+ function bless(constructor) {
146
+ return shadow(constructor, getBlessedProperties(constructor));
147
+ }
148
+ function shadow(constructor, properties) {
149
+ const shadowConstructor = extend(constructor);
150
+ const shadowProperties = getShadowProperties(constructor.prototype, properties);
151
+ Object.defineProperties(shadowConstructor.prototype, shadowProperties);
152
+ return shadowConstructor;
153
+ }
154
+ function getBlessedProperties(constructor) {
155
+ const blessings = readInheritableStaticArrayValues(constructor, "blessings");
156
+ return blessings.reduce((blessedProperties, blessing) => {
157
+ const properties = blessing(constructor);
158
+ for (const key in properties) {
159
+ const descriptor = blessedProperties[key] || {};
160
+ blessedProperties[key] = Object.assign(descriptor, properties[key]);
161
+ }
162
+ return blessedProperties;
163
+ }, {});
164
+ }
165
+ function getShadowProperties(prototype, properties) {
166
+ return getOwnKeys(properties).reduce((shadowProperties, key) => {
167
+ const descriptor = getShadowedDescriptor(prototype, properties, key);
168
+ if (descriptor) {
169
+ Object.assign(shadowProperties, { [key]: descriptor });
170
+ }
171
+ return shadowProperties;
172
+ }, {});
173
+ }
174
+ function getShadowedDescriptor(prototype, properties, key) {
175
+ const shadowingDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
176
+ const shadowedByValue = shadowingDescriptor && "value" in shadowingDescriptor;
177
+ if (!shadowedByValue) {
178
+ const descriptor = Object.getOwnPropertyDescriptor(properties, key).value;
179
+ if (shadowingDescriptor) {
180
+ descriptor.get = shadowingDescriptor.get || descriptor.get;
181
+ descriptor.set = shadowingDescriptor.set || descriptor.set;
182
+ }
183
+ return descriptor;
184
+ }
185
+ }
186
+ function blessDefinition(definition) {
187
+ return {
188
+ identifier: definition.identifier,
189
+ controllerConstructor: bless(definition.controllerConstructor)
190
+ };
191
+ }
192
+ function attributeValueContainsToken(attributeName, token) {
193
+ return `[${attributeName}~="${token}"]`;
194
+ }
195
+ function domReady() {
196
+ return new Promise((resolve) => {
197
+ if (document.readyState == "loading") {
198
+ document.addEventListener("DOMContentLoaded", () => resolve());
199
+ } else {
200
+ resolve();
201
+ }
202
+ });
203
+ }
204
+ function ClassPropertiesBlessing(constructor) {
205
+ const classes = readInheritableStaticArrayValues(constructor, "classes");
206
+ return classes.reduce((properties, classDefinition) => {
207
+ return Object.assign(properties, propertiesForClassDefinition(classDefinition));
208
+ }, {});
209
+ }
210
+ function propertiesForClassDefinition(key) {
211
+ return {
212
+ [`${key}Class`]: {
213
+ get() {
214
+ const { classes } = this;
215
+ if (classes.has(key)) {
216
+ return classes.get(key);
217
+ } else {
218
+ const attribute = classes.getAttributeName(key);
219
+ throw new Error(`Missing attribute "${attribute}"`);
220
+ }
221
+ }
222
+ },
223
+ [`${key}Classes`]: {
224
+ get() {
225
+ return this.classes.getAll(key);
226
+ }
227
+ },
228
+ [`has${capitalize(key)}Class`]: {
229
+ get() {
230
+ return this.classes.has(key);
231
+ }
232
+ }
233
+ };
234
+ }
235
+ function TargetPropertiesBlessing(constructor) {
236
+ const targets = readInheritableStaticArrayValues(constructor, "targets");
237
+ return targets.reduce((properties, targetDefinition) => {
238
+ return Object.assign(properties, propertiesForTargetDefinition(targetDefinition));
239
+ }, {});
240
+ }
241
+ function propertiesForTargetDefinition(name) {
242
+ return {
243
+ [`${name}Target`]: {
244
+ get() {
245
+ const target = this.targets.find(name);
246
+ if (target) {
247
+ return target;
248
+ } else {
249
+ throw new Error(`Missing target element "${name}" for "${this.identifier}" controller`);
250
+ }
251
+ }
252
+ },
253
+ [`${name}Targets`]: {
254
+ get() {
255
+ return this.targets.findAll(name);
256
+ }
257
+ },
258
+ [`has${capitalize(name)}Target`]: {
259
+ get() {
260
+ return this.targets.has(name);
261
+ }
262
+ }
263
+ };
264
+ }
265
+ function ValuePropertiesBlessing(constructor) {
266
+ const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values");
267
+ const propertyDescriptorMap = {
268
+ valueDescriptorMap: {
269
+ get() {
270
+ return valueDefinitionPairs.reduce((result, valueDefinitionPair) => {
271
+ const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair);
272
+ const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);
273
+ return Object.assign(result, { [attributeName]: valueDescriptor });
274
+ }, {});
275
+ }
276
+ }
277
+ };
278
+ return valueDefinitionPairs.reduce((properties, valueDefinitionPair) => {
279
+ return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair));
280
+ }, propertyDescriptorMap);
281
+ }
282
+ function propertiesForValueDefinitionPair(valueDefinitionPair) {
283
+ const definition = parseValueDefinitionPair(valueDefinitionPair);
284
+ const { key, name, reader: read, writer: write } = definition;
285
+ return {
286
+ [name]: {
287
+ get() {
288
+ const value = this.data.get(key);
289
+ if (value !== null) {
290
+ return read(value);
291
+ } else {
292
+ return definition.defaultValue;
293
+ }
294
+ },
295
+ set(value) {
296
+ if (value === void 0) {
297
+ this.data.delete(key);
298
+ } else {
299
+ this.data.set(key, write(value));
300
+ }
301
+ }
302
+ },
303
+ [`has${capitalize(name)}`]: {
304
+ get() {
305
+ return this.data.has(key) || definition.hasCustomDefaultValue;
306
+ }
307
+ }
308
+ };
309
+ }
310
+ function parseValueDefinitionPair([token, typeDefinition]) {
311
+ return valueDescriptorForTokenAndTypeDefinition(token, typeDefinition);
312
+ }
313
+ function parseValueTypeConstant(constant) {
314
+ switch (constant) {
315
+ case Array:
316
+ return "array";
317
+ case Boolean:
318
+ return "boolean";
319
+ case Number:
320
+ return "number";
321
+ case Object:
322
+ return "object";
323
+ case String:
324
+ return "string";
325
+ }
326
+ }
327
+ function parseValueTypeDefault(defaultValue) {
328
+ switch (typeof defaultValue) {
329
+ case "boolean":
330
+ return "boolean";
331
+ case "number":
332
+ return "number";
333
+ case "string":
334
+ return "string";
335
+ }
336
+ if (Array.isArray(defaultValue))
337
+ return "array";
338
+ if (Object.prototype.toString.call(defaultValue) === "[object Object]")
339
+ return "object";
340
+ }
341
+ function parseValueTypeObject(typeObject) {
342
+ const typeFromObject = parseValueTypeConstant(typeObject.type);
343
+ if (typeFromObject) {
344
+ const defaultValueType = parseValueTypeDefault(typeObject.default);
345
+ if (typeFromObject !== defaultValueType) {
346
+ throw new Error(`Type "${typeFromObject}" must match the type of the default value. Given default value: "${typeObject.default}" as "${defaultValueType}"`);
347
+ }
348
+ return typeFromObject;
349
+ }
350
+ }
351
+ function parseValueTypeDefinition(typeDefinition) {
352
+ const typeFromObject = parseValueTypeObject(typeDefinition);
353
+ const typeFromDefaultValue = parseValueTypeDefault(typeDefinition);
354
+ const typeFromConstant = parseValueTypeConstant(typeDefinition);
355
+ const type = typeFromObject || typeFromDefaultValue || typeFromConstant;
356
+ if (type)
357
+ return type;
358
+ throw new Error(`Unknown value type "${typeDefinition}"`);
359
+ }
360
+ function defaultValueForDefinition(typeDefinition) {
361
+ const constant = parseValueTypeConstant(typeDefinition);
362
+ if (constant)
363
+ return defaultValuesByType[constant];
364
+ const defaultValue = typeDefinition.default;
365
+ if (defaultValue !== void 0)
366
+ return defaultValue;
367
+ return typeDefinition;
368
+ }
369
+ function valueDescriptorForTokenAndTypeDefinition(token, typeDefinition) {
370
+ const key = `${dasherize(token)}-value`;
371
+ const type = parseValueTypeDefinition(typeDefinition);
372
+ return {
373
+ type,
374
+ key,
375
+ name: camelize(key),
376
+ get defaultValue() {
377
+ return defaultValueForDefinition(typeDefinition);
378
+ },
379
+ get hasCustomDefaultValue() {
380
+ return parseValueTypeDefault(typeDefinition) !== void 0;
381
+ },
382
+ reader: readers[type],
383
+ writer: writers[type] || writers.default
384
+ };
385
+ }
386
+ function writeJSON(value) {
387
+ return JSON.stringify(value);
388
+ }
389
+ function writeString(value) {
390
+ return `${value}`;
391
+ }
392
+ var EventListener, Dispatcher, descriptorPattern, Action, defaultEventNames, Binding, ElementObserver, AttributeObserver, StringMapObserver, Multimap, TokenListObserver, ValueListObserver, BindingObserver, ValueObserver, TargetObserver, Context, getOwnKeys, extend, Module, ClassMap, DataMap, Guide, TargetSet, Scope, ScopeObserver, Router, defaultSchema, Application, defaultValuesByType, readers, writers, Controller;
393
+ var init_stimulus = __esm({
394
+ "node_modules/@hotwired/stimulus/dist/stimulus.js"() {
395
+ EventListener = class {
396
+ constructor(eventTarget, eventName, eventOptions) {
397
+ this.eventTarget = eventTarget;
398
+ this.eventName = eventName;
399
+ this.eventOptions = eventOptions;
400
+ this.unorderedBindings = new Set();
401
+ }
402
+ connect() {
403
+ this.eventTarget.addEventListener(this.eventName, this, this.eventOptions);
404
+ }
405
+ disconnect() {
406
+ this.eventTarget.removeEventListener(this.eventName, this, this.eventOptions);
407
+ }
408
+ bindingConnected(binding) {
409
+ this.unorderedBindings.add(binding);
410
+ }
411
+ bindingDisconnected(binding) {
412
+ this.unorderedBindings.delete(binding);
413
+ }
414
+ handleEvent(event) {
415
+ const extendedEvent = extendEvent(event);
416
+ for (const binding of this.bindings) {
417
+ if (extendedEvent.immediatePropagationStopped) {
418
+ break;
419
+ } else {
420
+ binding.handleEvent(extendedEvent);
421
+ }
422
+ }
423
+ }
424
+ get bindings() {
425
+ return Array.from(this.unorderedBindings).sort((left, right) => {
426
+ const leftIndex = left.index, rightIndex = right.index;
427
+ return leftIndex < rightIndex ? -1 : leftIndex > rightIndex ? 1 : 0;
428
+ });
429
+ }
430
+ };
431
+ Dispatcher = class {
432
+ constructor(application2) {
433
+ this.application = application2;
434
+ this.eventListenerMaps = new Map();
435
+ this.started = false;
436
+ }
437
+ start() {
438
+ if (!this.started) {
439
+ this.started = true;
440
+ this.eventListeners.forEach((eventListener) => eventListener.connect());
441
+ }
442
+ }
443
+ stop() {
444
+ if (this.started) {
445
+ this.started = false;
446
+ this.eventListeners.forEach((eventListener) => eventListener.disconnect());
447
+ }
448
+ }
449
+ get eventListeners() {
450
+ return Array.from(this.eventListenerMaps.values()).reduce((listeners, map) => listeners.concat(Array.from(map.values())), []);
451
+ }
452
+ bindingConnected(binding) {
453
+ this.fetchEventListenerForBinding(binding).bindingConnected(binding);
454
+ }
455
+ bindingDisconnected(binding) {
456
+ this.fetchEventListenerForBinding(binding).bindingDisconnected(binding);
457
+ }
458
+ handleError(error2, message, detail = {}) {
459
+ this.application.handleError(error2, `Error ${message}`, detail);
460
+ }
461
+ fetchEventListenerForBinding(binding) {
462
+ const { eventTarget, eventName, eventOptions } = binding;
463
+ return this.fetchEventListener(eventTarget, eventName, eventOptions);
464
+ }
465
+ fetchEventListener(eventTarget, eventName, eventOptions) {
466
+ const eventListenerMap = this.fetchEventListenerMapForEventTarget(eventTarget);
467
+ const cacheKey = this.cacheKey(eventName, eventOptions);
468
+ let eventListener = eventListenerMap.get(cacheKey);
469
+ if (!eventListener) {
470
+ eventListener = this.createEventListener(eventTarget, eventName, eventOptions);
471
+ eventListenerMap.set(cacheKey, eventListener);
472
+ }
473
+ return eventListener;
474
+ }
475
+ createEventListener(eventTarget, eventName, eventOptions) {
476
+ const eventListener = new EventListener(eventTarget, eventName, eventOptions);
477
+ if (this.started) {
478
+ eventListener.connect();
479
+ }
480
+ return eventListener;
481
+ }
482
+ fetchEventListenerMapForEventTarget(eventTarget) {
483
+ let eventListenerMap = this.eventListenerMaps.get(eventTarget);
484
+ if (!eventListenerMap) {
485
+ eventListenerMap = new Map();
486
+ this.eventListenerMaps.set(eventTarget, eventListenerMap);
487
+ }
488
+ return eventListenerMap;
489
+ }
490
+ cacheKey(eventName, eventOptions) {
491
+ const parts = [eventName];
492
+ Object.keys(eventOptions).sort().forEach((key) => {
493
+ parts.push(`${eventOptions[key] ? "" : "!"}${key}`);
494
+ });
495
+ return parts.join(":");
496
+ }
497
+ };
498
+ descriptorPattern = /^((.+?)(@(window|document))?->)?(.+?)(#([^:]+?))(:(.+))?$/;
499
+ Action = class {
500
+ constructor(element, index, descriptor) {
501
+ this.element = element;
502
+ this.index = index;
503
+ this.eventTarget = descriptor.eventTarget || element;
504
+ this.eventName = descriptor.eventName || getDefaultEventNameForElement(element) || error("missing event name");
505
+ this.eventOptions = descriptor.eventOptions || {};
506
+ this.identifier = descriptor.identifier || error("missing identifier");
507
+ this.methodName = descriptor.methodName || error("missing method name");
508
+ }
509
+ static forToken(token) {
510
+ return new this(token.element, token.index, parseActionDescriptorString(token.content));
511
+ }
512
+ toString() {
513
+ const eventNameSuffix = this.eventTargetName ? `@${this.eventTargetName}` : "";
514
+ return `${this.eventName}${eventNameSuffix}->${this.identifier}#${this.methodName}`;
515
+ }
516
+ get params() {
517
+ if (this.eventTarget instanceof Element) {
518
+ return this.getParamsFromEventTargetAttributes(this.eventTarget);
519
+ } else {
520
+ return {};
521
+ }
522
+ }
523
+ getParamsFromEventTargetAttributes(eventTarget) {
524
+ const params = {};
525
+ const pattern = new RegExp(`^data-${this.identifier}-(.+)-param$`);
526
+ const attributes = Array.from(eventTarget.attributes);
527
+ attributes.forEach(({ name, value }) => {
528
+ const match = name.match(pattern);
529
+ const key = match && match[1];
530
+ if (key) {
531
+ Object.assign(params, { [camelize(key)]: typecast(value) });
532
+ }
533
+ });
534
+ return params;
535
+ }
536
+ get eventTargetName() {
537
+ return stringifyEventTarget(this.eventTarget);
538
+ }
539
+ };
540
+ defaultEventNames = {
541
+ "a": (e) => "click",
542
+ "button": (e) => "click",
543
+ "form": (e) => "submit",
544
+ "details": (e) => "toggle",
545
+ "input": (e) => e.getAttribute("type") == "submit" ? "click" : "input",
546
+ "select": (e) => "change",
547
+ "textarea": (e) => "input"
548
+ };
549
+ Binding = class {
550
+ constructor(context, action) {
551
+ this.context = context;
552
+ this.action = action;
553
+ }
554
+ get index() {
555
+ return this.action.index;
556
+ }
557
+ get eventTarget() {
558
+ return this.action.eventTarget;
559
+ }
560
+ get eventOptions() {
561
+ return this.action.eventOptions;
562
+ }
563
+ get identifier() {
564
+ return this.context.identifier;
565
+ }
566
+ handleEvent(event) {
567
+ if (this.willBeInvokedByEvent(event)) {
568
+ this.invokeWithEvent(event);
569
+ }
570
+ }
571
+ get eventName() {
572
+ return this.action.eventName;
573
+ }
574
+ get method() {
575
+ const method = this.controller[this.methodName];
576
+ if (typeof method == "function") {
577
+ return method;
578
+ }
579
+ throw new Error(`Action "${this.action}" references undefined method "${this.methodName}"`);
580
+ }
581
+ invokeWithEvent(event) {
582
+ const { target, currentTarget } = event;
583
+ try {
584
+ const { params } = this.action;
585
+ const actionEvent = Object.assign(event, { params });
586
+ this.method.call(this.controller, actionEvent);
587
+ this.context.logDebugActivity(this.methodName, { event, target, currentTarget, action: this.methodName });
588
+ } catch (error2) {
589
+ const { identifier, controller, element, index } = this;
590
+ const detail = { identifier, controller, element, index, event };
591
+ this.context.handleError(error2, `invoking action "${this.action}"`, detail);
592
+ }
593
+ }
594
+ willBeInvokedByEvent(event) {
595
+ const eventTarget = event.target;
596
+ if (this.element === eventTarget) {
597
+ return true;
598
+ } else if (eventTarget instanceof Element && this.element.contains(eventTarget)) {
599
+ return this.scope.containsElement(eventTarget);
600
+ } else {
601
+ return this.scope.containsElement(this.action.element);
602
+ }
603
+ }
604
+ get controller() {
605
+ return this.context.controller;
606
+ }
607
+ get methodName() {
608
+ return this.action.methodName;
609
+ }
610
+ get element() {
611
+ return this.scope.element;
612
+ }
613
+ get scope() {
614
+ return this.context.scope;
615
+ }
616
+ };
617
+ ElementObserver = class {
618
+ constructor(element, delegate) {
619
+ this.mutationObserverInit = { attributes: true, childList: true, subtree: true };
620
+ this.element = element;
621
+ this.started = false;
622
+ this.delegate = delegate;
623
+ this.elements = new Set();
624
+ this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
625
+ }
626
+ start() {
627
+ if (!this.started) {
628
+ this.started = true;
629
+ this.mutationObserver.observe(this.element, this.mutationObserverInit);
630
+ this.refresh();
631
+ }
632
+ }
633
+ pause(callback) {
634
+ if (this.started) {
635
+ this.mutationObserver.disconnect();
636
+ this.started = false;
637
+ }
638
+ callback();
639
+ if (!this.started) {
640
+ this.mutationObserver.observe(this.element, this.mutationObserverInit);
641
+ this.started = true;
642
+ }
643
+ }
644
+ stop() {
645
+ if (this.started) {
646
+ this.mutationObserver.takeRecords();
647
+ this.mutationObserver.disconnect();
648
+ this.started = false;
649
+ }
650
+ }
651
+ refresh() {
652
+ if (this.started) {
653
+ const matches = new Set(this.matchElementsInTree());
654
+ for (const element of Array.from(this.elements)) {
655
+ if (!matches.has(element)) {
656
+ this.removeElement(element);
657
+ }
658
+ }
659
+ for (const element of Array.from(matches)) {
660
+ this.addElement(element);
661
+ }
662
+ }
663
+ }
664
+ processMutations(mutations) {
665
+ if (this.started) {
666
+ for (const mutation of mutations) {
667
+ this.processMutation(mutation);
668
+ }
669
+ }
670
+ }
671
+ processMutation(mutation) {
672
+ if (mutation.type == "attributes") {
673
+ this.processAttributeChange(mutation.target, mutation.attributeName);
674
+ } else if (mutation.type == "childList") {
675
+ this.processRemovedNodes(mutation.removedNodes);
676
+ this.processAddedNodes(mutation.addedNodes);
677
+ }
678
+ }
679
+ processAttributeChange(node, attributeName) {
680
+ const element = node;
681
+ if (this.elements.has(element)) {
682
+ if (this.delegate.elementAttributeChanged && this.matchElement(element)) {
683
+ this.delegate.elementAttributeChanged(element, attributeName);
684
+ } else {
685
+ this.removeElement(element);
686
+ }
687
+ } else if (this.matchElement(element)) {
688
+ this.addElement(element);
689
+ }
690
+ }
691
+ processRemovedNodes(nodes) {
692
+ for (const node of Array.from(nodes)) {
693
+ const element = this.elementFromNode(node);
694
+ if (element) {
695
+ this.processTree(element, this.removeElement);
696
+ }
697
+ }
698
+ }
699
+ processAddedNodes(nodes) {
700
+ for (const node of Array.from(nodes)) {
701
+ const element = this.elementFromNode(node);
702
+ if (element && this.elementIsActive(element)) {
703
+ this.processTree(element, this.addElement);
704
+ }
705
+ }
706
+ }
707
+ matchElement(element) {
708
+ return this.delegate.matchElement(element);
709
+ }
710
+ matchElementsInTree(tree = this.element) {
711
+ return this.delegate.matchElementsInTree(tree);
712
+ }
713
+ processTree(tree, processor) {
714
+ for (const element of this.matchElementsInTree(tree)) {
715
+ processor.call(this, element);
716
+ }
717
+ }
718
+ elementFromNode(node) {
719
+ if (node.nodeType == Node.ELEMENT_NODE) {
720
+ return node;
721
+ }
722
+ }
723
+ elementIsActive(element) {
724
+ if (element.isConnected != this.element.isConnected) {
725
+ return false;
726
+ } else {
727
+ return this.element.contains(element);
728
+ }
729
+ }
730
+ addElement(element) {
731
+ if (!this.elements.has(element)) {
732
+ if (this.elementIsActive(element)) {
733
+ this.elements.add(element);
734
+ if (this.delegate.elementMatched) {
735
+ this.delegate.elementMatched(element);
736
+ }
737
+ }
738
+ }
739
+ }
740
+ removeElement(element) {
741
+ if (this.elements.has(element)) {
742
+ this.elements.delete(element);
743
+ if (this.delegate.elementUnmatched) {
744
+ this.delegate.elementUnmatched(element);
745
+ }
746
+ }
747
+ }
748
+ };
749
+ AttributeObserver = class {
750
+ constructor(element, attributeName, delegate) {
751
+ this.attributeName = attributeName;
752
+ this.delegate = delegate;
753
+ this.elementObserver = new ElementObserver(element, this);
754
+ }
755
+ get element() {
756
+ return this.elementObserver.element;
757
+ }
758
+ get selector() {
759
+ return `[${this.attributeName}]`;
760
+ }
761
+ start() {
762
+ this.elementObserver.start();
763
+ }
764
+ pause(callback) {
765
+ this.elementObserver.pause(callback);
766
+ }
767
+ stop() {
768
+ this.elementObserver.stop();
769
+ }
770
+ refresh() {
771
+ this.elementObserver.refresh();
772
+ }
773
+ get started() {
774
+ return this.elementObserver.started;
775
+ }
776
+ matchElement(element) {
777
+ return element.hasAttribute(this.attributeName);
778
+ }
779
+ matchElementsInTree(tree) {
780
+ const match = this.matchElement(tree) ? [tree] : [];
781
+ const matches = Array.from(tree.querySelectorAll(this.selector));
782
+ return match.concat(matches);
783
+ }
784
+ elementMatched(element) {
785
+ if (this.delegate.elementMatchedAttribute) {
786
+ this.delegate.elementMatchedAttribute(element, this.attributeName);
787
+ }
788
+ }
789
+ elementUnmatched(element) {
790
+ if (this.delegate.elementUnmatchedAttribute) {
791
+ this.delegate.elementUnmatchedAttribute(element, this.attributeName);
792
+ }
793
+ }
794
+ elementAttributeChanged(element, attributeName) {
795
+ if (this.delegate.elementAttributeValueChanged && this.attributeName == attributeName) {
796
+ this.delegate.elementAttributeValueChanged(element, attributeName);
797
+ }
798
+ }
799
+ };
800
+ StringMapObserver = class {
801
+ constructor(element, delegate) {
802
+ this.element = element;
803
+ this.delegate = delegate;
804
+ this.started = false;
805
+ this.stringMap = new Map();
806
+ this.mutationObserver = new MutationObserver((mutations) => this.processMutations(mutations));
807
+ }
808
+ start() {
809
+ if (!this.started) {
810
+ this.started = true;
811
+ this.mutationObserver.observe(this.element, { attributes: true, attributeOldValue: true });
812
+ this.refresh();
813
+ }
814
+ }
815
+ stop() {
816
+ if (this.started) {
817
+ this.mutationObserver.takeRecords();
818
+ this.mutationObserver.disconnect();
819
+ this.started = false;
820
+ }
821
+ }
822
+ refresh() {
823
+ if (this.started) {
824
+ for (const attributeName of this.knownAttributeNames) {
825
+ this.refreshAttribute(attributeName, null);
826
+ }
827
+ }
828
+ }
829
+ processMutations(mutations) {
830
+ if (this.started) {
831
+ for (const mutation of mutations) {
832
+ this.processMutation(mutation);
833
+ }
834
+ }
835
+ }
836
+ processMutation(mutation) {
837
+ const attributeName = mutation.attributeName;
838
+ if (attributeName) {
839
+ this.refreshAttribute(attributeName, mutation.oldValue);
840
+ }
841
+ }
842
+ refreshAttribute(attributeName, oldValue) {
843
+ const key = this.delegate.getStringMapKeyForAttribute(attributeName);
844
+ if (key != null) {
845
+ if (!this.stringMap.has(attributeName)) {
846
+ this.stringMapKeyAdded(key, attributeName);
847
+ }
848
+ const value = this.element.getAttribute(attributeName);
849
+ if (this.stringMap.get(attributeName) != value) {
850
+ this.stringMapValueChanged(value, key, oldValue);
851
+ }
852
+ if (value == null) {
853
+ const oldValue2 = this.stringMap.get(attributeName);
854
+ this.stringMap.delete(attributeName);
855
+ if (oldValue2)
856
+ this.stringMapKeyRemoved(key, attributeName, oldValue2);
857
+ } else {
858
+ this.stringMap.set(attributeName, value);
859
+ }
860
+ }
861
+ }
862
+ stringMapKeyAdded(key, attributeName) {
863
+ if (this.delegate.stringMapKeyAdded) {
864
+ this.delegate.stringMapKeyAdded(key, attributeName);
865
+ }
866
+ }
867
+ stringMapValueChanged(value, key, oldValue) {
868
+ if (this.delegate.stringMapValueChanged) {
869
+ this.delegate.stringMapValueChanged(value, key, oldValue);
870
+ }
871
+ }
872
+ stringMapKeyRemoved(key, attributeName, oldValue) {
873
+ if (this.delegate.stringMapKeyRemoved) {
874
+ this.delegate.stringMapKeyRemoved(key, attributeName, oldValue);
875
+ }
876
+ }
877
+ get knownAttributeNames() {
878
+ return Array.from(new Set(this.currentAttributeNames.concat(this.recordedAttributeNames)));
879
+ }
880
+ get currentAttributeNames() {
881
+ return Array.from(this.element.attributes).map((attribute) => attribute.name);
882
+ }
883
+ get recordedAttributeNames() {
884
+ return Array.from(this.stringMap.keys());
885
+ }
886
+ };
887
+ Multimap = class {
888
+ constructor() {
889
+ this.valuesByKey = new Map();
890
+ }
891
+ get keys() {
892
+ return Array.from(this.valuesByKey.keys());
893
+ }
894
+ get values() {
895
+ const sets = Array.from(this.valuesByKey.values());
896
+ return sets.reduce((values, set) => values.concat(Array.from(set)), []);
897
+ }
898
+ get size() {
899
+ const sets = Array.from(this.valuesByKey.values());
900
+ return sets.reduce((size, set) => size + set.size, 0);
901
+ }
902
+ add(key, value) {
903
+ add(this.valuesByKey, key, value);
904
+ }
905
+ delete(key, value) {
906
+ del(this.valuesByKey, key, value);
907
+ }
908
+ has(key, value) {
909
+ const values = this.valuesByKey.get(key);
910
+ return values != null && values.has(value);
911
+ }
912
+ hasKey(key) {
913
+ return this.valuesByKey.has(key);
914
+ }
915
+ hasValue(value) {
916
+ const sets = Array.from(this.valuesByKey.values());
917
+ return sets.some((set) => set.has(value));
918
+ }
919
+ getValuesForKey(key) {
920
+ const values = this.valuesByKey.get(key);
921
+ return values ? Array.from(values) : [];
922
+ }
923
+ getKeysForValue(value) {
924
+ return Array.from(this.valuesByKey).filter(([key, values]) => values.has(value)).map(([key, values]) => key);
925
+ }
926
+ };
927
+ TokenListObserver = class {
928
+ constructor(element, attributeName, delegate) {
929
+ this.attributeObserver = new AttributeObserver(element, attributeName, this);
930
+ this.delegate = delegate;
931
+ this.tokensByElement = new Multimap();
932
+ }
933
+ get started() {
934
+ return this.attributeObserver.started;
935
+ }
936
+ start() {
937
+ this.attributeObserver.start();
938
+ }
939
+ pause(callback) {
940
+ this.attributeObserver.pause(callback);
941
+ }
942
+ stop() {
943
+ this.attributeObserver.stop();
944
+ }
945
+ refresh() {
946
+ this.attributeObserver.refresh();
947
+ }
948
+ get element() {
949
+ return this.attributeObserver.element;
950
+ }
951
+ get attributeName() {
952
+ return this.attributeObserver.attributeName;
953
+ }
954
+ elementMatchedAttribute(element) {
955
+ this.tokensMatched(this.readTokensForElement(element));
956
+ }
957
+ elementAttributeValueChanged(element) {
958
+ const [unmatchedTokens, matchedTokens] = this.refreshTokensForElement(element);
959
+ this.tokensUnmatched(unmatchedTokens);
960
+ this.tokensMatched(matchedTokens);
961
+ }
962
+ elementUnmatchedAttribute(element) {
963
+ this.tokensUnmatched(this.tokensByElement.getValuesForKey(element));
964
+ }
965
+ tokensMatched(tokens) {
966
+ tokens.forEach((token) => this.tokenMatched(token));
967
+ }
968
+ tokensUnmatched(tokens) {
969
+ tokens.forEach((token) => this.tokenUnmatched(token));
970
+ }
971
+ tokenMatched(token) {
972
+ this.delegate.tokenMatched(token);
973
+ this.tokensByElement.add(token.element, token);
974
+ }
975
+ tokenUnmatched(token) {
976
+ this.delegate.tokenUnmatched(token);
977
+ this.tokensByElement.delete(token.element, token);
978
+ }
979
+ refreshTokensForElement(element) {
980
+ const previousTokens = this.tokensByElement.getValuesForKey(element);
981
+ const currentTokens = this.readTokensForElement(element);
982
+ const firstDifferingIndex = zip(previousTokens, currentTokens).findIndex(([previousToken, currentToken]) => !tokensAreEqual(previousToken, currentToken));
983
+ if (firstDifferingIndex == -1) {
984
+ return [[], []];
985
+ } else {
986
+ return [previousTokens.slice(firstDifferingIndex), currentTokens.slice(firstDifferingIndex)];
987
+ }
988
+ }
989
+ readTokensForElement(element) {
990
+ const attributeName = this.attributeName;
991
+ const tokenString = element.getAttribute(attributeName) || "";
992
+ return parseTokenString(tokenString, element, attributeName);
993
+ }
994
+ };
995
+ ValueListObserver = class {
996
+ constructor(element, attributeName, delegate) {
997
+ this.tokenListObserver = new TokenListObserver(element, attributeName, this);
998
+ this.delegate = delegate;
999
+ this.parseResultsByToken = new WeakMap();
1000
+ this.valuesByTokenByElement = new WeakMap();
1001
+ }
1002
+ get started() {
1003
+ return this.tokenListObserver.started;
1004
+ }
1005
+ start() {
1006
+ this.tokenListObserver.start();
1007
+ }
1008
+ stop() {
1009
+ this.tokenListObserver.stop();
1010
+ }
1011
+ refresh() {
1012
+ this.tokenListObserver.refresh();
1013
+ }
1014
+ get element() {
1015
+ return this.tokenListObserver.element;
1016
+ }
1017
+ get attributeName() {
1018
+ return this.tokenListObserver.attributeName;
1019
+ }
1020
+ tokenMatched(token) {
1021
+ const { element } = token;
1022
+ const { value } = this.fetchParseResultForToken(token);
1023
+ if (value) {
1024
+ this.fetchValuesByTokenForElement(element).set(token, value);
1025
+ this.delegate.elementMatchedValue(element, value);
1026
+ }
1027
+ }
1028
+ tokenUnmatched(token) {
1029
+ const { element } = token;
1030
+ const { value } = this.fetchParseResultForToken(token);
1031
+ if (value) {
1032
+ this.fetchValuesByTokenForElement(element).delete(token);
1033
+ this.delegate.elementUnmatchedValue(element, value);
1034
+ }
1035
+ }
1036
+ fetchParseResultForToken(token) {
1037
+ let parseResult = this.parseResultsByToken.get(token);
1038
+ if (!parseResult) {
1039
+ parseResult = this.parseToken(token);
1040
+ this.parseResultsByToken.set(token, parseResult);
1041
+ }
1042
+ return parseResult;
1043
+ }
1044
+ fetchValuesByTokenForElement(element) {
1045
+ let valuesByToken = this.valuesByTokenByElement.get(element);
1046
+ if (!valuesByToken) {
1047
+ valuesByToken = new Map();
1048
+ this.valuesByTokenByElement.set(element, valuesByToken);
1049
+ }
1050
+ return valuesByToken;
1051
+ }
1052
+ parseToken(token) {
1053
+ try {
1054
+ const value = this.delegate.parseValueForToken(token);
1055
+ return { value };
1056
+ } catch (error2) {
1057
+ return { error: error2 };
1058
+ }
1059
+ }
1060
+ };
1061
+ BindingObserver = class {
1062
+ constructor(context, delegate) {
1063
+ this.context = context;
1064
+ this.delegate = delegate;
1065
+ this.bindingsByAction = new Map();
1066
+ }
1067
+ start() {
1068
+ if (!this.valueListObserver) {
1069
+ this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this);
1070
+ this.valueListObserver.start();
1071
+ }
1072
+ }
1073
+ stop() {
1074
+ if (this.valueListObserver) {
1075
+ this.valueListObserver.stop();
1076
+ delete this.valueListObserver;
1077
+ this.disconnectAllActions();
1078
+ }
1079
+ }
1080
+ get element() {
1081
+ return this.context.element;
1082
+ }
1083
+ get identifier() {
1084
+ return this.context.identifier;
1085
+ }
1086
+ get actionAttribute() {
1087
+ return this.schema.actionAttribute;
1088
+ }
1089
+ get schema() {
1090
+ return this.context.schema;
1091
+ }
1092
+ get bindings() {
1093
+ return Array.from(this.bindingsByAction.values());
1094
+ }
1095
+ connectAction(action) {
1096
+ const binding = new Binding(this.context, action);
1097
+ this.bindingsByAction.set(action, binding);
1098
+ this.delegate.bindingConnected(binding);
1099
+ }
1100
+ disconnectAction(action) {
1101
+ const binding = this.bindingsByAction.get(action);
1102
+ if (binding) {
1103
+ this.bindingsByAction.delete(action);
1104
+ this.delegate.bindingDisconnected(binding);
1105
+ }
1106
+ }
1107
+ disconnectAllActions() {
1108
+ this.bindings.forEach((binding) => this.delegate.bindingDisconnected(binding));
1109
+ this.bindingsByAction.clear();
1110
+ }
1111
+ parseValueForToken(token) {
1112
+ const action = Action.forToken(token);
1113
+ if (action.identifier == this.identifier) {
1114
+ return action;
1115
+ }
1116
+ }
1117
+ elementMatchedValue(element, action) {
1118
+ this.connectAction(action);
1119
+ }
1120
+ elementUnmatchedValue(element, action) {
1121
+ this.disconnectAction(action);
1122
+ }
1123
+ };
1124
+ ValueObserver = class {
1125
+ constructor(context, receiver) {
1126
+ this.context = context;
1127
+ this.receiver = receiver;
1128
+ this.stringMapObserver = new StringMapObserver(this.element, this);
1129
+ this.valueDescriptorMap = this.controller.valueDescriptorMap;
1130
+ this.invokeChangedCallbacksForDefaultValues();
1131
+ }
1132
+ start() {
1133
+ this.stringMapObserver.start();
1134
+ }
1135
+ stop() {
1136
+ this.stringMapObserver.stop();
1137
+ }
1138
+ get element() {
1139
+ return this.context.element;
1140
+ }
1141
+ get controller() {
1142
+ return this.context.controller;
1143
+ }
1144
+ getStringMapKeyForAttribute(attributeName) {
1145
+ if (attributeName in this.valueDescriptorMap) {
1146
+ return this.valueDescriptorMap[attributeName].name;
1147
+ }
1148
+ }
1149
+ stringMapKeyAdded(key, attributeName) {
1150
+ const descriptor = this.valueDescriptorMap[attributeName];
1151
+ if (!this.hasValue(key)) {
1152
+ this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue));
1153
+ }
1154
+ }
1155
+ stringMapValueChanged(value, name, oldValue) {
1156
+ const descriptor = this.valueDescriptorNameMap[name];
1157
+ if (value === null)
1158
+ return;
1159
+ if (oldValue === null) {
1160
+ oldValue = descriptor.writer(descriptor.defaultValue);
1161
+ }
1162
+ this.invokeChangedCallback(name, value, oldValue);
1163
+ }
1164
+ stringMapKeyRemoved(key, attributeName, oldValue) {
1165
+ const descriptor = this.valueDescriptorNameMap[key];
1166
+ if (this.hasValue(key)) {
1167
+ this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), oldValue);
1168
+ } else {
1169
+ this.invokeChangedCallback(key, descriptor.writer(descriptor.defaultValue), oldValue);
1170
+ }
1171
+ }
1172
+ invokeChangedCallbacksForDefaultValues() {
1173
+ for (const { key, name, defaultValue, writer } of this.valueDescriptors) {
1174
+ if (defaultValue != void 0 && !this.controller.data.has(key)) {
1175
+ this.invokeChangedCallback(name, writer(defaultValue), void 0);
1176
+ }
1177
+ }
1178
+ }
1179
+ invokeChangedCallback(name, rawValue, rawOldValue) {
1180
+ const changedMethodName = `${name}Changed`;
1181
+ const changedMethod = this.receiver[changedMethodName];
1182
+ if (typeof changedMethod == "function") {
1183
+ const descriptor = this.valueDescriptorNameMap[name];
1184
+ const value = descriptor.reader(rawValue);
1185
+ let oldValue = rawOldValue;
1186
+ if (rawOldValue) {
1187
+ oldValue = descriptor.reader(rawOldValue);
1188
+ }
1189
+ changedMethod.call(this.receiver, value, oldValue);
1190
+ }
1191
+ }
1192
+ get valueDescriptors() {
1193
+ const { valueDescriptorMap } = this;
1194
+ return Object.keys(valueDescriptorMap).map((key) => valueDescriptorMap[key]);
1195
+ }
1196
+ get valueDescriptorNameMap() {
1197
+ const descriptors = {};
1198
+ Object.keys(this.valueDescriptorMap).forEach((key) => {
1199
+ const descriptor = this.valueDescriptorMap[key];
1200
+ descriptors[descriptor.name] = descriptor;
1201
+ });
1202
+ return descriptors;
1203
+ }
1204
+ hasValue(attributeName) {
1205
+ const descriptor = this.valueDescriptorNameMap[attributeName];
1206
+ const hasMethodName = `has${capitalize(descriptor.name)}`;
1207
+ return this.receiver[hasMethodName];
1208
+ }
1209
+ };
1210
+ TargetObserver = class {
1211
+ constructor(context, delegate) {
1212
+ this.context = context;
1213
+ this.delegate = delegate;
1214
+ this.targetsByName = new Multimap();
1215
+ }
1216
+ start() {
1217
+ if (!this.tokenListObserver) {
1218
+ this.tokenListObserver = new TokenListObserver(this.element, this.attributeName, this);
1219
+ this.tokenListObserver.start();
1220
+ }
1221
+ }
1222
+ stop() {
1223
+ if (this.tokenListObserver) {
1224
+ this.disconnectAllTargets();
1225
+ this.tokenListObserver.stop();
1226
+ delete this.tokenListObserver;
1227
+ }
1228
+ }
1229
+ tokenMatched({ element, content: name }) {
1230
+ if (this.scope.containsElement(element)) {
1231
+ this.connectTarget(element, name);
1232
+ }
1233
+ }
1234
+ tokenUnmatched({ element, content: name }) {
1235
+ this.disconnectTarget(element, name);
1236
+ }
1237
+ connectTarget(element, name) {
1238
+ var _a;
1239
+ if (!this.targetsByName.has(name, element)) {
1240
+ this.targetsByName.add(name, element);
1241
+ (_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetConnected(element, name));
1242
+ }
1243
+ }
1244
+ disconnectTarget(element, name) {
1245
+ var _a;
1246
+ if (this.targetsByName.has(name, element)) {
1247
+ this.targetsByName.delete(name, element);
1248
+ (_a = this.tokenListObserver) === null || _a === void 0 ? void 0 : _a.pause(() => this.delegate.targetDisconnected(element, name));
1249
+ }
1250
+ }
1251
+ disconnectAllTargets() {
1252
+ for (const name of this.targetsByName.keys) {
1253
+ for (const element of this.targetsByName.getValuesForKey(name)) {
1254
+ this.disconnectTarget(element, name);
1255
+ }
1256
+ }
1257
+ }
1258
+ get attributeName() {
1259
+ return `data-${this.context.identifier}-target`;
1260
+ }
1261
+ get element() {
1262
+ return this.context.element;
1263
+ }
1264
+ get scope() {
1265
+ return this.context.scope;
1266
+ }
1267
+ };
1268
+ Context = class {
1269
+ constructor(module, scope) {
1270
+ this.logDebugActivity = (functionName, detail = {}) => {
1271
+ const { identifier, controller, element } = this;
1272
+ detail = Object.assign({ identifier, controller, element }, detail);
1273
+ this.application.logDebugActivity(this.identifier, functionName, detail);
1274
+ };
1275
+ this.module = module;
1276
+ this.scope = scope;
1277
+ this.controller = new module.controllerConstructor(this);
1278
+ this.bindingObserver = new BindingObserver(this, this.dispatcher);
1279
+ this.valueObserver = new ValueObserver(this, this.controller);
1280
+ this.targetObserver = new TargetObserver(this, this);
1281
+ try {
1282
+ this.controller.initialize();
1283
+ this.logDebugActivity("initialize");
1284
+ } catch (error2) {
1285
+ this.handleError(error2, "initializing controller");
1286
+ }
1287
+ }
1288
+ connect() {
1289
+ this.bindingObserver.start();
1290
+ this.valueObserver.start();
1291
+ this.targetObserver.start();
1292
+ try {
1293
+ this.controller.connect();
1294
+ this.logDebugActivity("connect");
1295
+ } catch (error2) {
1296
+ this.handleError(error2, "connecting controller");
1297
+ }
1298
+ }
1299
+ disconnect() {
1300
+ try {
1301
+ this.controller.disconnect();
1302
+ this.logDebugActivity("disconnect");
1303
+ } catch (error2) {
1304
+ this.handleError(error2, "disconnecting controller");
1305
+ }
1306
+ this.targetObserver.stop();
1307
+ this.valueObserver.stop();
1308
+ this.bindingObserver.stop();
1309
+ }
1310
+ get application() {
1311
+ return this.module.application;
1312
+ }
1313
+ get identifier() {
1314
+ return this.module.identifier;
1315
+ }
1316
+ get schema() {
1317
+ return this.application.schema;
1318
+ }
1319
+ get dispatcher() {
1320
+ return this.application.dispatcher;
1321
+ }
1322
+ get element() {
1323
+ return this.scope.element;
1324
+ }
1325
+ get parentElement() {
1326
+ return this.element.parentElement;
1327
+ }
1328
+ handleError(error2, message, detail = {}) {
1329
+ const { identifier, controller, element } = this;
1330
+ detail = Object.assign({ identifier, controller, element }, detail);
1331
+ this.application.handleError(error2, `Error ${message}`, detail);
1332
+ }
1333
+ targetConnected(element, name) {
1334
+ this.invokeControllerMethod(`${name}TargetConnected`, element);
1335
+ }
1336
+ targetDisconnected(element, name) {
1337
+ this.invokeControllerMethod(`${name}TargetDisconnected`, element);
1338
+ }
1339
+ invokeControllerMethod(methodName, ...args) {
1340
+ const controller = this.controller;
1341
+ if (typeof controller[methodName] == "function") {
1342
+ controller[methodName](...args);
1343
+ }
1344
+ }
1345
+ };
1346
+ getOwnKeys = (() => {
1347
+ if (typeof Object.getOwnPropertySymbols == "function") {
1348
+ return (object) => [
1349
+ ...Object.getOwnPropertyNames(object),
1350
+ ...Object.getOwnPropertySymbols(object)
1351
+ ];
1352
+ } else {
1353
+ return Object.getOwnPropertyNames;
1354
+ }
1355
+ })();
1356
+ extend = (() => {
1357
+ function extendWithReflect(constructor) {
1358
+ function extended() {
1359
+ return Reflect.construct(constructor, arguments, new.target);
1360
+ }
1361
+ extended.prototype = Object.create(constructor.prototype, {
1362
+ constructor: { value: extended }
1363
+ });
1364
+ Reflect.setPrototypeOf(extended, constructor);
1365
+ return extended;
1366
+ }
1367
+ function testReflectExtension() {
1368
+ const a = function() {
1369
+ this.a.call(this);
1370
+ };
1371
+ const b = extendWithReflect(a);
1372
+ b.prototype.a = function() {
1373
+ };
1374
+ return new b();
1375
+ }
1376
+ try {
1377
+ testReflectExtension();
1378
+ return extendWithReflect;
1379
+ } catch (error2) {
1380
+ return (constructor) => class extended extends constructor {
1381
+ };
1382
+ }
1383
+ })();
1384
+ Module = class {
1385
+ constructor(application2, definition) {
1386
+ this.application = application2;
1387
+ this.definition = blessDefinition(definition);
1388
+ this.contextsByScope = new WeakMap();
1389
+ this.connectedContexts = new Set();
1390
+ }
1391
+ get identifier() {
1392
+ return this.definition.identifier;
1393
+ }
1394
+ get controllerConstructor() {
1395
+ return this.definition.controllerConstructor;
1396
+ }
1397
+ get contexts() {
1398
+ return Array.from(this.connectedContexts);
1399
+ }
1400
+ connectContextForScope(scope) {
1401
+ const context = this.fetchContextForScope(scope);
1402
+ this.connectedContexts.add(context);
1403
+ context.connect();
1404
+ }
1405
+ disconnectContextForScope(scope) {
1406
+ const context = this.contextsByScope.get(scope);
1407
+ if (context) {
1408
+ this.connectedContexts.delete(context);
1409
+ context.disconnect();
1410
+ }
1411
+ }
1412
+ fetchContextForScope(scope) {
1413
+ let context = this.contextsByScope.get(scope);
1414
+ if (!context) {
1415
+ context = new Context(this, scope);
1416
+ this.contextsByScope.set(scope, context);
1417
+ }
1418
+ return context;
1419
+ }
1420
+ };
1421
+ ClassMap = class {
1422
+ constructor(scope) {
1423
+ this.scope = scope;
1424
+ }
1425
+ has(name) {
1426
+ return this.data.has(this.getDataKey(name));
1427
+ }
1428
+ get(name) {
1429
+ return this.getAll(name)[0];
1430
+ }
1431
+ getAll(name) {
1432
+ const tokenString = this.data.get(this.getDataKey(name)) || "";
1433
+ return tokenize(tokenString);
1434
+ }
1435
+ getAttributeName(name) {
1436
+ return this.data.getAttributeNameForKey(this.getDataKey(name));
1437
+ }
1438
+ getDataKey(name) {
1439
+ return `${name}-class`;
1440
+ }
1441
+ get data() {
1442
+ return this.scope.data;
1443
+ }
1444
+ };
1445
+ DataMap = class {
1446
+ constructor(scope) {
1447
+ this.scope = scope;
1448
+ }
1449
+ get element() {
1450
+ return this.scope.element;
1451
+ }
1452
+ get identifier() {
1453
+ return this.scope.identifier;
1454
+ }
1455
+ get(key) {
1456
+ const name = this.getAttributeNameForKey(key);
1457
+ return this.element.getAttribute(name);
1458
+ }
1459
+ set(key, value) {
1460
+ const name = this.getAttributeNameForKey(key);
1461
+ this.element.setAttribute(name, value);
1462
+ return this.get(key);
1463
+ }
1464
+ has(key) {
1465
+ const name = this.getAttributeNameForKey(key);
1466
+ return this.element.hasAttribute(name);
1467
+ }
1468
+ delete(key) {
1469
+ if (this.has(key)) {
1470
+ const name = this.getAttributeNameForKey(key);
1471
+ this.element.removeAttribute(name);
1472
+ return true;
1473
+ } else {
1474
+ return false;
1475
+ }
1476
+ }
1477
+ getAttributeNameForKey(key) {
1478
+ return `data-${this.identifier}-${dasherize(key)}`;
1479
+ }
1480
+ };
1481
+ Guide = class {
1482
+ constructor(logger) {
1483
+ this.warnedKeysByObject = new WeakMap();
1484
+ this.logger = logger;
1485
+ }
1486
+ warn(object, key, message) {
1487
+ let warnedKeys = this.warnedKeysByObject.get(object);
1488
+ if (!warnedKeys) {
1489
+ warnedKeys = new Set();
1490
+ this.warnedKeysByObject.set(object, warnedKeys);
1491
+ }
1492
+ if (!warnedKeys.has(key)) {
1493
+ warnedKeys.add(key);
1494
+ this.logger.warn(message, object);
1495
+ }
1496
+ }
1497
+ };
1498
+ TargetSet = class {
1499
+ constructor(scope) {
1500
+ this.scope = scope;
1501
+ }
1502
+ get element() {
1503
+ return this.scope.element;
1504
+ }
1505
+ get identifier() {
1506
+ return this.scope.identifier;
1507
+ }
1508
+ get schema() {
1509
+ return this.scope.schema;
1510
+ }
1511
+ has(targetName) {
1512
+ return this.find(targetName) != null;
1513
+ }
1514
+ find(...targetNames) {
1515
+ return targetNames.reduce((target, targetName) => target || this.findTarget(targetName) || this.findLegacyTarget(targetName), void 0);
1516
+ }
1517
+ findAll(...targetNames) {
1518
+ return targetNames.reduce((targets, targetName) => [
1519
+ ...targets,
1520
+ ...this.findAllTargets(targetName),
1521
+ ...this.findAllLegacyTargets(targetName)
1522
+ ], []);
1523
+ }
1524
+ findTarget(targetName) {
1525
+ const selector = this.getSelectorForTargetName(targetName);
1526
+ return this.scope.findElement(selector);
1527
+ }
1528
+ findAllTargets(targetName) {
1529
+ const selector = this.getSelectorForTargetName(targetName);
1530
+ return this.scope.findAllElements(selector);
1531
+ }
1532
+ getSelectorForTargetName(targetName) {
1533
+ const attributeName = this.schema.targetAttributeForScope(this.identifier);
1534
+ return attributeValueContainsToken(attributeName, targetName);
1535
+ }
1536
+ findLegacyTarget(targetName) {
1537
+ const selector = this.getLegacySelectorForTargetName(targetName);
1538
+ return this.deprecate(this.scope.findElement(selector), targetName);
1539
+ }
1540
+ findAllLegacyTargets(targetName) {
1541
+ const selector = this.getLegacySelectorForTargetName(targetName);
1542
+ return this.scope.findAllElements(selector).map((element) => this.deprecate(element, targetName));
1543
+ }
1544
+ getLegacySelectorForTargetName(targetName) {
1545
+ const targetDescriptor = `${this.identifier}.${targetName}`;
1546
+ return attributeValueContainsToken(this.schema.targetAttribute, targetDescriptor);
1547
+ }
1548
+ deprecate(element, targetName) {
1549
+ if (element) {
1550
+ const { identifier } = this;
1551
+ const attributeName = this.schema.targetAttribute;
1552
+ const revisedAttributeName = this.schema.targetAttributeForScope(identifier);
1553
+ 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.`);
1554
+ }
1555
+ return element;
1556
+ }
1557
+ get guide() {
1558
+ return this.scope.guide;
1559
+ }
1560
+ };
1561
+ Scope = class {
1562
+ constructor(schema, element, identifier, logger) {
1563
+ this.targets = new TargetSet(this);
1564
+ this.classes = new ClassMap(this);
1565
+ this.data = new DataMap(this);
1566
+ this.containsElement = (element2) => {
1567
+ return element2.closest(this.controllerSelector) === this.element;
1568
+ };
1569
+ this.schema = schema;
1570
+ this.element = element;
1571
+ this.identifier = identifier;
1572
+ this.guide = new Guide(logger);
1573
+ }
1574
+ findElement(selector) {
1575
+ return this.element.matches(selector) ? this.element : this.queryElements(selector).find(this.containsElement);
1576
+ }
1577
+ findAllElements(selector) {
1578
+ return [
1579
+ ...this.element.matches(selector) ? [this.element] : [],
1580
+ ...this.queryElements(selector).filter(this.containsElement)
1581
+ ];
1582
+ }
1583
+ queryElements(selector) {
1584
+ return Array.from(this.element.querySelectorAll(selector));
1585
+ }
1586
+ get controllerSelector() {
1587
+ return attributeValueContainsToken(this.schema.controllerAttribute, this.identifier);
1588
+ }
1589
+ };
1590
+ ScopeObserver = class {
1591
+ constructor(element, schema, delegate) {
1592
+ this.element = element;
1593
+ this.schema = schema;
1594
+ this.delegate = delegate;
1595
+ this.valueListObserver = new ValueListObserver(this.element, this.controllerAttribute, this);
1596
+ this.scopesByIdentifierByElement = new WeakMap();
1597
+ this.scopeReferenceCounts = new WeakMap();
1598
+ }
1599
+ start() {
1600
+ this.valueListObserver.start();
1601
+ }
1602
+ stop() {
1603
+ this.valueListObserver.stop();
1604
+ }
1605
+ get controllerAttribute() {
1606
+ return this.schema.controllerAttribute;
1607
+ }
1608
+ parseValueForToken(token) {
1609
+ const { element, content: identifier } = token;
1610
+ const scopesByIdentifier = this.fetchScopesByIdentifierForElement(element);
1611
+ let scope = scopesByIdentifier.get(identifier);
1612
+ if (!scope) {
1613
+ scope = this.delegate.createScopeForElementAndIdentifier(element, identifier);
1614
+ scopesByIdentifier.set(identifier, scope);
1615
+ }
1616
+ return scope;
1617
+ }
1618
+ elementMatchedValue(element, value) {
1619
+ const referenceCount = (this.scopeReferenceCounts.get(value) || 0) + 1;
1620
+ this.scopeReferenceCounts.set(value, referenceCount);
1621
+ if (referenceCount == 1) {
1622
+ this.delegate.scopeConnected(value);
1623
+ }
1624
+ }
1625
+ elementUnmatchedValue(element, value) {
1626
+ const referenceCount = this.scopeReferenceCounts.get(value);
1627
+ if (referenceCount) {
1628
+ this.scopeReferenceCounts.set(value, referenceCount - 1);
1629
+ if (referenceCount == 1) {
1630
+ this.delegate.scopeDisconnected(value);
1631
+ }
1632
+ }
1633
+ }
1634
+ fetchScopesByIdentifierForElement(element) {
1635
+ let scopesByIdentifier = this.scopesByIdentifierByElement.get(element);
1636
+ if (!scopesByIdentifier) {
1637
+ scopesByIdentifier = new Map();
1638
+ this.scopesByIdentifierByElement.set(element, scopesByIdentifier);
1639
+ }
1640
+ return scopesByIdentifier;
1641
+ }
1642
+ };
1643
+ Router = class {
1644
+ constructor(application2) {
1645
+ this.application = application2;
1646
+ this.scopeObserver = new ScopeObserver(this.element, this.schema, this);
1647
+ this.scopesByIdentifier = new Multimap();
1648
+ this.modulesByIdentifier = new Map();
1649
+ }
1650
+ get element() {
1651
+ return this.application.element;
1652
+ }
1653
+ get schema() {
1654
+ return this.application.schema;
1655
+ }
1656
+ get logger() {
1657
+ return this.application.logger;
1658
+ }
1659
+ get controllerAttribute() {
1660
+ return this.schema.controllerAttribute;
1661
+ }
1662
+ get modules() {
1663
+ return Array.from(this.modulesByIdentifier.values());
1664
+ }
1665
+ get contexts() {
1666
+ return this.modules.reduce((contexts, module) => contexts.concat(module.contexts), []);
1667
+ }
1668
+ start() {
1669
+ this.scopeObserver.start();
1670
+ }
1671
+ stop() {
1672
+ this.scopeObserver.stop();
1673
+ }
1674
+ loadDefinition(definition) {
1675
+ this.unloadIdentifier(definition.identifier);
1676
+ const module = new Module(this.application, definition);
1677
+ this.connectModule(module);
1678
+ }
1679
+ unloadIdentifier(identifier) {
1680
+ const module = this.modulesByIdentifier.get(identifier);
1681
+ if (module) {
1682
+ this.disconnectModule(module);
1683
+ }
1684
+ }
1685
+ getContextForElementAndIdentifier(element, identifier) {
1686
+ const module = this.modulesByIdentifier.get(identifier);
1687
+ if (module) {
1688
+ return module.contexts.find((context) => context.element == element);
1689
+ }
1690
+ }
1691
+ handleError(error2, message, detail) {
1692
+ this.application.handleError(error2, message, detail);
1693
+ }
1694
+ createScopeForElementAndIdentifier(element, identifier) {
1695
+ return new Scope(this.schema, element, identifier, this.logger);
1696
+ }
1697
+ scopeConnected(scope) {
1698
+ this.scopesByIdentifier.add(scope.identifier, scope);
1699
+ const module = this.modulesByIdentifier.get(scope.identifier);
1700
+ if (module) {
1701
+ module.connectContextForScope(scope);
1702
+ }
1703
+ }
1704
+ scopeDisconnected(scope) {
1705
+ this.scopesByIdentifier.delete(scope.identifier, scope);
1706
+ const module = this.modulesByIdentifier.get(scope.identifier);
1707
+ if (module) {
1708
+ module.disconnectContextForScope(scope);
1709
+ }
1710
+ }
1711
+ connectModule(module) {
1712
+ this.modulesByIdentifier.set(module.identifier, module);
1713
+ const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
1714
+ scopes.forEach((scope) => module.connectContextForScope(scope));
1715
+ }
1716
+ disconnectModule(module) {
1717
+ this.modulesByIdentifier.delete(module.identifier);
1718
+ const scopes = this.scopesByIdentifier.getValuesForKey(module.identifier);
1719
+ scopes.forEach((scope) => module.disconnectContextForScope(scope));
1720
+ }
1721
+ };
1722
+ defaultSchema = {
1723
+ controllerAttribute: "data-controller",
1724
+ actionAttribute: "data-action",
1725
+ targetAttribute: "data-target",
1726
+ targetAttributeForScope: (identifier) => `data-${identifier}-target`
1727
+ };
1728
+ Application = class {
1729
+ constructor(element = document.documentElement, schema = defaultSchema) {
1730
+ this.logger = console;
1731
+ this.debug = false;
1732
+ this.logDebugActivity = (identifier, functionName, detail = {}) => {
1733
+ if (this.debug) {
1734
+ this.logFormattedMessage(identifier, functionName, detail);
1735
+ }
1736
+ };
1737
+ this.element = element;
1738
+ this.schema = schema;
1739
+ this.dispatcher = new Dispatcher(this);
1740
+ this.router = new Router(this);
1741
+ }
1742
+ static start(element, schema) {
1743
+ const application2 = new Application(element, schema);
1744
+ application2.start();
1745
+ return application2;
1746
+ }
1747
+ async start() {
1748
+ await domReady();
1749
+ this.logDebugActivity("application", "starting");
1750
+ this.dispatcher.start();
1751
+ this.router.start();
1752
+ this.logDebugActivity("application", "start");
1753
+ }
1754
+ stop() {
1755
+ this.logDebugActivity("application", "stopping");
1756
+ this.dispatcher.stop();
1757
+ this.router.stop();
1758
+ this.logDebugActivity("application", "stop");
1759
+ }
1760
+ register(identifier, controllerConstructor) {
1761
+ if (controllerConstructor.shouldLoad) {
1762
+ this.load({ identifier, controllerConstructor });
1763
+ }
1764
+ }
1765
+ load(head, ...rest) {
1766
+ const definitions = Array.isArray(head) ? head : [head, ...rest];
1767
+ definitions.forEach((definition) => this.router.loadDefinition(definition));
1768
+ }
1769
+ unload(head, ...rest) {
1770
+ const identifiers = Array.isArray(head) ? head : [head, ...rest];
1771
+ identifiers.forEach((identifier) => this.router.unloadIdentifier(identifier));
1772
+ }
1773
+ get controllers() {
1774
+ return this.router.contexts.map((context) => context.controller);
1775
+ }
1776
+ getControllerForElementAndIdentifier(element, identifier) {
1777
+ const context = this.router.getContextForElementAndIdentifier(element, identifier);
1778
+ return context ? context.controller : null;
1779
+ }
1780
+ handleError(error2, message, detail) {
1781
+ var _a;
1782
+ this.logger.error(`%s
1783
+
1784
+ %o
1785
+
1786
+ %o`, message, error2, detail);
1787
+ (_a = window.onerror) === null || _a === void 0 ? void 0 : _a.call(window, message, "", 0, 0, error2);
1788
+ }
1789
+ logFormattedMessage(identifier, functionName, detail = {}) {
1790
+ detail = Object.assign({ application: this }, detail);
1791
+ this.logger.groupCollapsed(`${identifier} #${functionName}`);
1792
+ this.logger.log("details:", Object.assign({}, detail));
1793
+ this.logger.groupEnd();
1794
+ }
1795
+ };
1796
+ defaultValuesByType = {
1797
+ get array() {
1798
+ return [];
1799
+ },
1800
+ boolean: false,
1801
+ number: 0,
1802
+ get object() {
1803
+ return {};
1804
+ },
1805
+ string: ""
1806
+ };
1807
+ readers = {
1808
+ array(value) {
1809
+ const array = JSON.parse(value);
1810
+ if (!Array.isArray(array)) {
1811
+ throw new TypeError("Expected array");
1812
+ }
1813
+ return array;
1814
+ },
1815
+ boolean(value) {
1816
+ return !(value == "0" || value == "false");
1817
+ },
1818
+ number(value) {
1819
+ return Number(value);
1820
+ },
1821
+ object(value) {
1822
+ const object = JSON.parse(value);
1823
+ if (object === null || typeof object != "object" || Array.isArray(object)) {
1824
+ throw new TypeError("Expected object");
1825
+ }
1826
+ return object;
1827
+ },
1828
+ string(value) {
1829
+ return value;
1830
+ }
1831
+ };
1832
+ writers = {
1833
+ default: writeString,
1834
+ array: writeJSON,
1835
+ object: writeJSON
1836
+ };
1837
+ Controller = class {
1838
+ constructor(context) {
1839
+ this.context = context;
1840
+ }
1841
+ static get shouldLoad() {
1842
+ return true;
1843
+ }
1844
+ get application() {
1845
+ return this.context.application;
1846
+ }
1847
+ get scope() {
1848
+ return this.context.scope;
1849
+ }
1850
+ get element() {
1851
+ return this.scope.element;
1852
+ }
1853
+ get identifier() {
1854
+ return this.scope.identifier;
1855
+ }
1856
+ get targets() {
1857
+ return this.scope.targets;
1858
+ }
1859
+ get classes() {
1860
+ return this.scope.classes;
1861
+ }
1862
+ get data() {
1863
+ return this.scope.data;
1864
+ }
1865
+ initialize() {
1866
+ }
1867
+ connect() {
1868
+ }
1869
+ disconnect() {
1870
+ }
1871
+ dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
1872
+ const type = prefix ? `${prefix}:${eventName}` : eventName;
1873
+ const event = new CustomEvent(type, { detail, bubbles, cancelable });
1874
+ target.dispatchEvent(event);
1875
+ return event;
1876
+ }
1877
+ };
1878
+ Controller.blessings = [ClassPropertiesBlessing, TargetPropertiesBlessing, ValuePropertiesBlessing];
1879
+ Controller.targets = [];
1880
+ Controller.values = {};
1881
+ }
1882
+ });
1883
+
1884
+ // app/components/material/button_component_controller.js
1885
+ var button_component_controller_exports = {};
1886
+ __export(button_component_controller_exports, {
1887
+ default: () => button_component_controller_default
1888
+ });
1889
+ var button_component_controller_default;
1890
+ var init_button_component_controller = __esm({
1891
+ "app/components/material/button_component_controller.js"() {
1892
+ init_stimulus();
1893
+ button_component_controller_default = class extends Controller {
1894
+ connect() {
1895
+ console.log("Hello, Stimulus!", this.element);
1896
+ }
1897
+ };
1898
+ }
1899
+ });
1900
+
1901
+ // import-glob:../../components/**/*_controller.js
1902
+ var controller_exports = {};
1903
+ __export(controller_exports, {
1904
+ default: () => controller_default,
1905
+ filenames: () => filenames
1906
+ });
1907
+ var modules, controller_default, filenames;
1908
+ var init_controller = __esm({
1909
+ "import-glob:../../components/**/*_controller.js"() {
1910
+ init_button_component_controller();
1911
+ modules = [button_component_controller_exports];
1912
+ controller_default = modules;
1913
+ filenames = ["../../components/material/button_component_controller.js"];
1914
+ }
1915
+ });
1916
+
1917
+ // app/javascript/controllers/application.js
1918
+ init_stimulus();
1919
+
1920
+ // app/javascript/controllers/helpers.js
1921
+ var controllerNameFrom = (filename) => {
1922
+ const pattern = /.*\/components\/((?:\w+\/)*)(\w+)_controller.js$/;
1923
+ const controllerName = filename.replace(pattern, (_match, $1, $2) => {
1924
+ const scope = $1.replaceAll("/", "--").replaceAll("_", "-");
1925
+ const name = $2.replaceAll("_", "-");
1926
+ return scope + name;
1927
+ });
1928
+ return controllerName;
1929
+ };
1930
+ var helpers_default = registerControllersFrom = (context) => {
1931
+ const { default: componentControllers, filenames: filenames2 } = context;
1932
+ for (let i = 0, len = componentControllers.length; i < len; i++) {
1933
+ let componentController = componentControllers[i].default;
1934
+ let filename = filenames2[i];
1935
+ let name = controllerNameFrom(filename);
1936
+ Stimulus.register(name, componentController);
1937
+ console.log(name);
1938
+ }
1939
+ };
1940
+
1941
+ // app/javascript/controllers/application.js
1942
+ var application = Application.start();
1943
+ application.warnings = true;
1944
+ application.debug = false;
1945
+ window.Stimulus = application;
1946
+ helpers_default((init_controller(), controller_exports));
1947
+
1948
+ // app/javascript/controllers/hello_controller.js
1949
+ init_stimulus();
1950
+ var hello_controller_default = class extends Controller {
1951
+ connect() {
1952
+ this.element.textContent = "Hello World!";
1953
+ }
1954
+ };
1955
+
1956
+ // app/javascript/controllers/index.js
1957
+ application.register("hello", hello_controller_default);
1958
+ })();