katalyst-kpop 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd02fdc721febf6d11b4080487d121731b29341deda1b91e9b381cb7fb5719cb
|
4
|
+
data.tar.gz: 8c721692d22bddfc09d0bd77782c6c6c440803cdc46f57c1634ee986c9c0238d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58dad52030790bff9def0411edd0df0de10915889d887c6e553409d3d2f502f253ffe7120fadd65749a8847f68a4eb0daaf89b8240241d9d8f735878b0ed5557
|
7
|
+
data.tar.gz: a04b5c53da4ee4afe9dddb7642e88692e8822aab496b12d3b63cc257ecfd09c45bd22644caf60f6b7e389f27a43e10f7cd29e33a045d03bc7f8aeb3e00964092
|
@@ -0,0 +1,634 @@
|
|
1
|
+
function camelize(value) {
|
2
|
+
return value.replace(/(?:[_-])([a-z0-9])/g, ((_, char) => char.toUpperCase()));
|
3
|
+
}
|
4
|
+
|
5
|
+
function namespaceCamelize(value) {
|
6
|
+
return camelize(value.replace(/--/g, "-").replace(/__/g, "_"));
|
7
|
+
}
|
8
|
+
|
9
|
+
function capitalize(value) {
|
10
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
11
|
+
}
|
12
|
+
|
13
|
+
function dasherize(value) {
|
14
|
+
return value.replace(/([A-Z])/g, ((_, char) => `-${char.toLowerCase()}`));
|
15
|
+
}
|
16
|
+
|
17
|
+
function readInheritableStaticArrayValues(constructor, propertyName) {
|
18
|
+
const ancestors = getAncestorsForConstructor(constructor);
|
19
|
+
return Array.from(ancestors.reduce(((values, constructor) => {
|
20
|
+
getOwnStaticArrayValues(constructor, propertyName).forEach((name => values.add(name)));
|
21
|
+
return values;
|
22
|
+
}), new Set));
|
23
|
+
}
|
24
|
+
|
25
|
+
function readInheritableStaticObjectPairs(constructor, propertyName) {
|
26
|
+
const ancestors = getAncestorsForConstructor(constructor);
|
27
|
+
return ancestors.reduce(((pairs, constructor) => {
|
28
|
+
pairs.push(...getOwnStaticObjectPairs(constructor, propertyName));
|
29
|
+
return pairs;
|
30
|
+
}), []);
|
31
|
+
}
|
32
|
+
|
33
|
+
function getAncestorsForConstructor(constructor) {
|
34
|
+
const ancestors = [];
|
35
|
+
while (constructor) {
|
36
|
+
ancestors.push(constructor);
|
37
|
+
constructor = Object.getPrototypeOf(constructor);
|
38
|
+
}
|
39
|
+
return ancestors.reverse();
|
40
|
+
}
|
41
|
+
|
42
|
+
function getOwnStaticArrayValues(constructor, propertyName) {
|
43
|
+
const definition = constructor[propertyName];
|
44
|
+
return Array.isArray(definition) ? definition : [];
|
45
|
+
}
|
46
|
+
|
47
|
+
function getOwnStaticObjectPairs(constructor, propertyName) {
|
48
|
+
const definition = constructor[propertyName];
|
49
|
+
return definition ? Object.keys(definition).map((key => [ key, definition[key] ])) : [];
|
50
|
+
}
|
51
|
+
|
52
|
+
(() => {
|
53
|
+
function extendWithReflect(constructor) {
|
54
|
+
function extended() {
|
55
|
+
return Reflect.construct(constructor, arguments, new.target);
|
56
|
+
}
|
57
|
+
extended.prototype = Object.create(constructor.prototype, {
|
58
|
+
constructor: {
|
59
|
+
value: extended
|
60
|
+
}
|
61
|
+
});
|
62
|
+
Reflect.setPrototypeOf(extended, constructor);
|
63
|
+
return extended;
|
64
|
+
}
|
65
|
+
function testReflectExtension() {
|
66
|
+
const a = function() {
|
67
|
+
this.a.call(this);
|
68
|
+
};
|
69
|
+
const b = extendWithReflect(a);
|
70
|
+
b.prototype.a = function() {};
|
71
|
+
return new b;
|
72
|
+
}
|
73
|
+
try {
|
74
|
+
testReflectExtension();
|
75
|
+
return extendWithReflect;
|
76
|
+
} catch (error) {
|
77
|
+
return constructor => class extended extends constructor {};
|
78
|
+
}
|
79
|
+
})();
|
80
|
+
|
81
|
+
({
|
82
|
+
controllerAttribute: "data-controller",
|
83
|
+
actionAttribute: "data-action",
|
84
|
+
targetAttribute: "data-target",
|
85
|
+
targetAttributeForScope: identifier => `data-${identifier}-target`,
|
86
|
+
outletAttributeForScope: (identifier, outlet) => `data-${identifier}-${outlet}-outlet`,
|
87
|
+
keyMappings: Object.assign(Object.assign({
|
88
|
+
enter: "Enter",
|
89
|
+
tab: "Tab",
|
90
|
+
esc: "Escape",
|
91
|
+
space: " ",
|
92
|
+
up: "ArrowUp",
|
93
|
+
down: "ArrowDown",
|
94
|
+
left: "ArrowLeft",
|
95
|
+
right: "ArrowRight",
|
96
|
+
home: "Home",
|
97
|
+
end: "End"
|
98
|
+
}, objectFromEntries("abcdefghijklmnopqrstuvwxyz".split("").map((c => [ c, c ])))), objectFromEntries("0123456789".split("").map((n => [ n, n ]))))
|
99
|
+
});
|
100
|
+
|
101
|
+
function objectFromEntries(array) {
|
102
|
+
return array.reduce(((memo, [k, v]) => Object.assign(Object.assign({}, memo), {
|
103
|
+
[k]: v
|
104
|
+
})), {});
|
105
|
+
}
|
106
|
+
|
107
|
+
function ClassPropertiesBlessing(constructor) {
|
108
|
+
const classes = readInheritableStaticArrayValues(constructor, "classes");
|
109
|
+
return classes.reduce(((properties, classDefinition) => Object.assign(properties, propertiesForClassDefinition(classDefinition))), {});
|
110
|
+
}
|
111
|
+
|
112
|
+
function propertiesForClassDefinition(key) {
|
113
|
+
return {
|
114
|
+
[`${key}Class`]: {
|
115
|
+
get() {
|
116
|
+
const {classes: classes} = this;
|
117
|
+
if (classes.has(key)) {
|
118
|
+
return classes.get(key);
|
119
|
+
} else {
|
120
|
+
const attribute = classes.getAttributeName(key);
|
121
|
+
throw new Error(`Missing attribute "${attribute}"`);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
},
|
125
|
+
[`${key}Classes`]: {
|
126
|
+
get() {
|
127
|
+
return this.classes.getAll(key);
|
128
|
+
}
|
129
|
+
},
|
130
|
+
[`has${capitalize(key)}Class`]: {
|
131
|
+
get() {
|
132
|
+
return this.classes.has(key);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
};
|
136
|
+
}
|
137
|
+
|
138
|
+
function OutletPropertiesBlessing(constructor) {
|
139
|
+
const outlets = readInheritableStaticArrayValues(constructor, "outlets");
|
140
|
+
return outlets.reduce(((properties, outletDefinition) => Object.assign(properties, propertiesForOutletDefinition(outletDefinition))), {});
|
141
|
+
}
|
142
|
+
|
143
|
+
function propertiesForOutletDefinition(name) {
|
144
|
+
const camelizedName = namespaceCamelize(name);
|
145
|
+
return {
|
146
|
+
[`${camelizedName}Outlet`]: {
|
147
|
+
get() {
|
148
|
+
const outlet = this.outlets.find(name);
|
149
|
+
if (outlet) {
|
150
|
+
const outletController = this.application.getControllerForElementAndIdentifier(outlet, name);
|
151
|
+
if (outletController) {
|
152
|
+
return outletController;
|
153
|
+
} else {
|
154
|
+
throw new Error(`Missing "data-controller=${name}" attribute on outlet element for "${this.identifier}" controller`);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
throw new Error(`Missing outlet element "${name}" for "${this.identifier}" controller`);
|
158
|
+
}
|
159
|
+
},
|
160
|
+
[`${camelizedName}Outlets`]: {
|
161
|
+
get() {
|
162
|
+
const outlets = this.outlets.findAll(name);
|
163
|
+
if (outlets.length > 0) {
|
164
|
+
return outlets.map((outlet => {
|
165
|
+
const controller = this.application.getControllerForElementAndIdentifier(outlet, name);
|
166
|
+
if (controller) {
|
167
|
+
return controller;
|
168
|
+
} else {
|
169
|
+
console.warn(`The provided outlet element is missing the outlet controller "${name}" for "${this.identifier}"`, outlet);
|
170
|
+
}
|
171
|
+
})).filter((controller => controller));
|
172
|
+
}
|
173
|
+
return [];
|
174
|
+
}
|
175
|
+
},
|
176
|
+
[`${camelizedName}OutletElement`]: {
|
177
|
+
get() {
|
178
|
+
const outlet = this.outlets.find(name);
|
179
|
+
if (outlet) {
|
180
|
+
return outlet;
|
181
|
+
} else {
|
182
|
+
throw new Error(`Missing outlet element "${name}" for "${this.identifier}" controller`);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
},
|
186
|
+
[`${camelizedName}OutletElements`]: {
|
187
|
+
get() {
|
188
|
+
return this.outlets.findAll(name);
|
189
|
+
}
|
190
|
+
},
|
191
|
+
[`has${capitalize(camelizedName)}Outlet`]: {
|
192
|
+
get() {
|
193
|
+
return this.outlets.has(name);
|
194
|
+
}
|
195
|
+
}
|
196
|
+
};
|
197
|
+
}
|
198
|
+
|
199
|
+
function TargetPropertiesBlessing(constructor) {
|
200
|
+
const targets = readInheritableStaticArrayValues(constructor, "targets");
|
201
|
+
return targets.reduce(((properties, targetDefinition) => Object.assign(properties, propertiesForTargetDefinition(targetDefinition))), {});
|
202
|
+
}
|
203
|
+
|
204
|
+
function propertiesForTargetDefinition(name) {
|
205
|
+
return {
|
206
|
+
[`${name}Target`]: {
|
207
|
+
get() {
|
208
|
+
const target = this.targets.find(name);
|
209
|
+
if (target) {
|
210
|
+
return target;
|
211
|
+
} else {
|
212
|
+
throw new Error(`Missing target element "${name}" for "${this.identifier}" controller`);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
},
|
216
|
+
[`${name}Targets`]: {
|
217
|
+
get() {
|
218
|
+
return this.targets.findAll(name);
|
219
|
+
}
|
220
|
+
},
|
221
|
+
[`has${capitalize(name)}Target`]: {
|
222
|
+
get() {
|
223
|
+
return this.targets.has(name);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
};
|
227
|
+
}
|
228
|
+
|
229
|
+
function ValuePropertiesBlessing(constructor) {
|
230
|
+
const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values");
|
231
|
+
const propertyDescriptorMap = {
|
232
|
+
valueDescriptorMap: {
|
233
|
+
get() {
|
234
|
+
return valueDefinitionPairs.reduce(((result, valueDefinitionPair) => {
|
235
|
+
const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair, this.identifier);
|
236
|
+
const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);
|
237
|
+
return Object.assign(result, {
|
238
|
+
[attributeName]: valueDescriptor
|
239
|
+
});
|
240
|
+
}), {});
|
241
|
+
}
|
242
|
+
}
|
243
|
+
};
|
244
|
+
return valueDefinitionPairs.reduce(((properties, valueDefinitionPair) => Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair))), propertyDescriptorMap);
|
245
|
+
}
|
246
|
+
|
247
|
+
function propertiesForValueDefinitionPair(valueDefinitionPair, controller) {
|
248
|
+
const definition = parseValueDefinitionPair(valueDefinitionPair, controller);
|
249
|
+
const {key: key, name: name, reader: read, writer: write} = definition;
|
250
|
+
return {
|
251
|
+
[name]: {
|
252
|
+
get() {
|
253
|
+
const value = this.data.get(key);
|
254
|
+
if (value !== null) {
|
255
|
+
return read(value);
|
256
|
+
} else {
|
257
|
+
return definition.defaultValue;
|
258
|
+
}
|
259
|
+
},
|
260
|
+
set(value) {
|
261
|
+
if (value === undefined) {
|
262
|
+
this.data.delete(key);
|
263
|
+
} else {
|
264
|
+
this.data.set(key, write(value));
|
265
|
+
}
|
266
|
+
}
|
267
|
+
},
|
268
|
+
[`has${capitalize(name)}`]: {
|
269
|
+
get() {
|
270
|
+
return this.data.has(key) || definition.hasCustomDefaultValue;
|
271
|
+
}
|
272
|
+
}
|
273
|
+
};
|
274
|
+
}
|
275
|
+
|
276
|
+
function parseValueDefinitionPair([token, typeDefinition], controller) {
|
277
|
+
return valueDescriptorForTokenAndTypeDefinition({
|
278
|
+
controller: controller,
|
279
|
+
token: token,
|
280
|
+
typeDefinition: typeDefinition
|
281
|
+
});
|
282
|
+
}
|
283
|
+
|
284
|
+
function parseValueTypeConstant(constant) {
|
285
|
+
switch (constant) {
|
286
|
+
case Array:
|
287
|
+
return "array";
|
288
|
+
|
289
|
+
case Boolean:
|
290
|
+
return "boolean";
|
291
|
+
|
292
|
+
case Number:
|
293
|
+
return "number";
|
294
|
+
|
295
|
+
case Object:
|
296
|
+
return "object";
|
297
|
+
|
298
|
+
case String:
|
299
|
+
return "string";
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
function parseValueTypeDefault(defaultValue) {
|
304
|
+
switch (typeof defaultValue) {
|
305
|
+
case "boolean":
|
306
|
+
return "boolean";
|
307
|
+
|
308
|
+
case "number":
|
309
|
+
return "number";
|
310
|
+
|
311
|
+
case "string":
|
312
|
+
return "string";
|
313
|
+
}
|
314
|
+
if (Array.isArray(defaultValue)) return "array";
|
315
|
+
if (Object.prototype.toString.call(defaultValue) === "[object Object]") return "object";
|
316
|
+
}
|
317
|
+
|
318
|
+
function parseValueTypeObject(payload) {
|
319
|
+
const typeFromObject = parseValueTypeConstant(payload.typeObject.type);
|
320
|
+
if (!typeFromObject) return;
|
321
|
+
const defaultValueType = parseValueTypeDefault(payload.typeObject.default);
|
322
|
+
if (typeFromObject !== defaultValueType) {
|
323
|
+
const propertyPath = payload.controller ? `${payload.controller}.${payload.token}` : payload.token;
|
324
|
+
throw new Error(`The specified default value for the Stimulus Value "${propertyPath}" must match the defined type "${typeFromObject}". The provided default value of "${payload.typeObject.default}" is of type "${defaultValueType}".`);
|
325
|
+
}
|
326
|
+
return typeFromObject;
|
327
|
+
}
|
328
|
+
|
329
|
+
function parseValueTypeDefinition(payload) {
|
330
|
+
const typeFromObject = parseValueTypeObject({
|
331
|
+
controller: payload.controller,
|
332
|
+
token: payload.token,
|
333
|
+
typeObject: payload.typeDefinition
|
334
|
+
});
|
335
|
+
const typeFromDefaultValue = parseValueTypeDefault(payload.typeDefinition);
|
336
|
+
const typeFromConstant = parseValueTypeConstant(payload.typeDefinition);
|
337
|
+
const type = typeFromObject || typeFromDefaultValue || typeFromConstant;
|
338
|
+
if (type) return type;
|
339
|
+
const propertyPath = payload.controller ? `${payload.controller}.${payload.typeDefinition}` : payload.token;
|
340
|
+
throw new Error(`Unknown value type "${propertyPath}" for "${payload.token}" value`);
|
341
|
+
}
|
342
|
+
|
343
|
+
function defaultValueForDefinition(typeDefinition) {
|
344
|
+
const constant = parseValueTypeConstant(typeDefinition);
|
345
|
+
if (constant) return defaultValuesByType[constant];
|
346
|
+
const defaultValue = typeDefinition.default;
|
347
|
+
if (defaultValue !== undefined) return defaultValue;
|
348
|
+
return typeDefinition;
|
349
|
+
}
|
350
|
+
|
351
|
+
function valueDescriptorForTokenAndTypeDefinition(payload) {
|
352
|
+
const key = `${dasherize(payload.token)}-value`;
|
353
|
+
const type = parseValueTypeDefinition(payload);
|
354
|
+
return {
|
355
|
+
type: type,
|
356
|
+
key: key,
|
357
|
+
name: camelize(key),
|
358
|
+
get defaultValue() {
|
359
|
+
return defaultValueForDefinition(payload.typeDefinition);
|
360
|
+
},
|
361
|
+
get hasCustomDefaultValue() {
|
362
|
+
return parseValueTypeDefault(payload.typeDefinition) !== undefined;
|
363
|
+
},
|
364
|
+
reader: readers[type],
|
365
|
+
writer: writers[type] || writers.default
|
366
|
+
};
|
367
|
+
}
|
368
|
+
|
369
|
+
const defaultValuesByType = {
|
370
|
+
get array() {
|
371
|
+
return [];
|
372
|
+
},
|
373
|
+
boolean: false,
|
374
|
+
number: 0,
|
375
|
+
get object() {
|
376
|
+
return {};
|
377
|
+
},
|
378
|
+
string: ""
|
379
|
+
};
|
380
|
+
|
381
|
+
const readers = {
|
382
|
+
array(value) {
|
383
|
+
const array = JSON.parse(value);
|
384
|
+
if (!Array.isArray(array)) {
|
385
|
+
throw new TypeError(`expected value of type "array" but instead got value "${value}" of type "${parseValueTypeDefault(array)}"`);
|
386
|
+
}
|
387
|
+
return array;
|
388
|
+
},
|
389
|
+
boolean(value) {
|
390
|
+
return !(value == "0" || String(value).toLowerCase() == "false");
|
391
|
+
},
|
392
|
+
number(value) {
|
393
|
+
return Number(value);
|
394
|
+
},
|
395
|
+
object(value) {
|
396
|
+
const object = JSON.parse(value);
|
397
|
+
if (object === null || typeof object != "object" || Array.isArray(object)) {
|
398
|
+
throw new TypeError(`expected value of type "object" but instead got value "${value}" of type "${parseValueTypeDefault(object)}"`);
|
399
|
+
}
|
400
|
+
return object;
|
401
|
+
},
|
402
|
+
string(value) {
|
403
|
+
return value;
|
404
|
+
}
|
405
|
+
};
|
406
|
+
|
407
|
+
const writers = {
|
408
|
+
default: writeString,
|
409
|
+
array: writeJSON,
|
410
|
+
object: writeJSON
|
411
|
+
};
|
412
|
+
|
413
|
+
function writeJSON(value) {
|
414
|
+
return JSON.stringify(value);
|
415
|
+
}
|
416
|
+
|
417
|
+
function writeString(value) {
|
418
|
+
return `${value}`;
|
419
|
+
}
|
420
|
+
|
421
|
+
class Controller {
|
422
|
+
constructor(context) {
|
423
|
+
this.context = context;
|
424
|
+
}
|
425
|
+
static get shouldLoad() {
|
426
|
+
return true;
|
427
|
+
}
|
428
|
+
static afterLoad(_identifier, _application) {
|
429
|
+
return;
|
430
|
+
}
|
431
|
+
get application() {
|
432
|
+
return this.context.application;
|
433
|
+
}
|
434
|
+
get scope() {
|
435
|
+
return this.context.scope;
|
436
|
+
}
|
437
|
+
get element() {
|
438
|
+
return this.scope.element;
|
439
|
+
}
|
440
|
+
get identifier() {
|
441
|
+
return this.scope.identifier;
|
442
|
+
}
|
443
|
+
get targets() {
|
444
|
+
return this.scope.targets;
|
445
|
+
}
|
446
|
+
get outlets() {
|
447
|
+
return this.scope.outlets;
|
448
|
+
}
|
449
|
+
get classes() {
|
450
|
+
return this.scope.classes;
|
451
|
+
}
|
452
|
+
get data() {
|
453
|
+
return this.scope.data;
|
454
|
+
}
|
455
|
+
initialize() {}
|
456
|
+
connect() {}
|
457
|
+
disconnect() {}
|
458
|
+
dispatch(eventName, {target: target = this.element, detail: detail = {}, prefix: prefix = this.identifier, bubbles: bubbles = true, cancelable: cancelable = true} = {}) {
|
459
|
+
const type = prefix ? `${prefix}:${eventName}` : eventName;
|
460
|
+
const event = new CustomEvent(type, {
|
461
|
+
detail: detail,
|
462
|
+
bubbles: bubbles,
|
463
|
+
cancelable: cancelable
|
464
|
+
});
|
465
|
+
target.dispatchEvent(event);
|
466
|
+
return event;
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
Controller.blessings = [ ClassPropertiesBlessing, TargetPropertiesBlessing, ValuePropertiesBlessing, OutletPropertiesBlessing ];
|
471
|
+
|
472
|
+
Controller.targets = [];
|
473
|
+
|
474
|
+
Controller.outlets = [];
|
475
|
+
|
476
|
+
Controller.values = {};
|
477
|
+
|
478
|
+
class ScrimController extends Controller {
|
479
|
+
static values={
|
480
|
+
open: Boolean,
|
481
|
+
captive: Boolean,
|
482
|
+
zIndex: Number
|
483
|
+
};
|
484
|
+
static showScrim({dismiss: dismiss = true, zIndex: zIndex = undefined, top: top = undefined} = {}) {
|
485
|
+
return window.dispatchEvent(new CustomEvent("scrim:request:show", {
|
486
|
+
cancelable: true,
|
487
|
+
detail: {
|
488
|
+
captive: !dismiss,
|
489
|
+
zIndex: zIndex,
|
490
|
+
top: top
|
491
|
+
}
|
492
|
+
}));
|
493
|
+
}
|
494
|
+
static hideScrim() {
|
495
|
+
return window.dispatchEvent(new CustomEvent("scrim:request:hide", {
|
496
|
+
cancelable: true
|
497
|
+
}));
|
498
|
+
}
|
499
|
+
connect() {
|
500
|
+
this.defaultZIndexValue = this.zIndexValue;
|
501
|
+
this.defaultCaptiveValue = this.captiveValue;
|
502
|
+
}
|
503
|
+
show(request) {
|
504
|
+
if (this.openValue) this.hide(request);
|
505
|
+
if (this.openValue) return;
|
506
|
+
this.openValue = true;
|
507
|
+
const event = this.dispatch("show", {
|
508
|
+
bubbles: true,
|
509
|
+
cancelable: true
|
510
|
+
});
|
511
|
+
if (event.defaultPrevented) {
|
512
|
+
this.openValue = false;
|
513
|
+
request.preventDefault();
|
514
|
+
return;
|
515
|
+
}
|
516
|
+
this.#show(request.detail);
|
517
|
+
}
|
518
|
+
hide(request) {
|
519
|
+
if (!this.openValue) return;
|
520
|
+
this.openValue = false;
|
521
|
+
const event = this.dispatch("hide", {
|
522
|
+
bubbles: true,
|
523
|
+
cancelable: true
|
524
|
+
});
|
525
|
+
if (event.defaultPrevented) {
|
526
|
+
this.openValue = true;
|
527
|
+
request.preventDefault();
|
528
|
+
return;
|
529
|
+
}
|
530
|
+
this.#hide();
|
531
|
+
}
|
532
|
+
dismiss(event) {
|
533
|
+
if (!this.captiveValue) this.hide(event);
|
534
|
+
}
|
535
|
+
escape(event) {
|
536
|
+
if (event.key === "Escape" && !this.captiveValue && !event.defaultPrevented) this.hide(event);
|
537
|
+
}
|
538
|
+
disconnect() {
|
539
|
+
super.disconnect();
|
540
|
+
}
|
541
|
+
#show({captive: captive = this.defaultCaptiveValue, zIndex: zIndex = this.defaultZIndexValue, top: top = window.scrollY}) {
|
542
|
+
this.captiveValue = captive;
|
543
|
+
this.zIndexValue = zIndex;
|
544
|
+
this.scrollY = top;
|
545
|
+
this.previousPosition = document.body.style.position;
|
546
|
+
this.previousTop = document.body.style.top;
|
547
|
+
this.element.style.zIndex = this.zIndexValue;
|
548
|
+
document.body.style.top = `-${top}px`;
|
549
|
+
document.body.style.position = "fixed";
|
550
|
+
}
|
551
|
+
#hide() {
|
552
|
+
this.captiveValue = this.defaultCaptiveValue;
|
553
|
+
this.zIndexValue = this.defaultZIndexValue;
|
554
|
+
resetStyle(this.element, "z-index", null);
|
555
|
+
resetStyle(document.body, "position", null);
|
556
|
+
resetStyle(document.body, "top", null);
|
557
|
+
window.scrollTo(0, this.scrollY);
|
558
|
+
delete this.scrollY;
|
559
|
+
delete this.previousPosition;
|
560
|
+
delete this.previousTop;
|
561
|
+
}
|
562
|
+
}
|
563
|
+
|
564
|
+
function resetStyle(element, property, previousValue) {
|
565
|
+
if (previousValue) {
|
566
|
+
element.style.setProperty(property, previousValue);
|
567
|
+
} else {
|
568
|
+
element.style.removeProperty(property);
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
class KpopController extends Controller {
|
573
|
+
static targets=[ "content", "closeButton" ];
|
574
|
+
static values={
|
575
|
+
open: Boolean
|
576
|
+
};
|
577
|
+
contentTargetConnected() {
|
578
|
+
if (this.openValue) return;
|
579
|
+
if (ScrimController.showScrim({
|
580
|
+
dismiss: this.hasCloseButtonTarget
|
581
|
+
})) {
|
582
|
+
this.openValue = true;
|
583
|
+
} else {
|
584
|
+
this.#clear();
|
585
|
+
}
|
586
|
+
}
|
587
|
+
contentTargetDisconnected() {
|
588
|
+
if (this.hasContentTarget) return;
|
589
|
+
this.openValue = false;
|
590
|
+
ScrimController.hideScrim();
|
591
|
+
}
|
592
|
+
openValueChanged(open) {
|
593
|
+
this.element.style.display = open ? "flex" : "none";
|
594
|
+
}
|
595
|
+
dismiss() {
|
596
|
+
if (!this.hasContentTarget || !this.openValue) return;
|
597
|
+
const dismissUrl = this.contentTarget.dataset.dismissUrl;
|
598
|
+
const dismissAction = this.contentTarget.dataset.dismissAction;
|
599
|
+
if (dismissUrl) {
|
600
|
+
if (dismissAction === "replace") {
|
601
|
+
if (isSameUrl(document.referrer, dismissUrl)) {
|
602
|
+
history.back();
|
603
|
+
} else {
|
604
|
+
history.replaceState({}, "", dismissUrl);
|
605
|
+
}
|
606
|
+
} else {
|
607
|
+
window.location.href = dismissUrl;
|
608
|
+
}
|
609
|
+
}
|
610
|
+
this.#clear();
|
611
|
+
}
|
612
|
+
#clear() {
|
613
|
+
this.element.removeAttribute("src");
|
614
|
+
this.element.innerHTML = "";
|
615
|
+
}
|
616
|
+
}
|
617
|
+
|
618
|
+
function isSameUrl(previous, next) {
|
619
|
+
try {
|
620
|
+
return `${new URL(previous)}` === `${new URL(next, location.href)}`;
|
621
|
+
} catch {
|
622
|
+
return false;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
|
626
|
+
const Definitions = [ {
|
627
|
+
identifier: "kpop",
|
628
|
+
controllerConstructor: KpopController
|
629
|
+
}, {
|
630
|
+
identifier: "scrim",
|
631
|
+
controllerConstructor: ScrimController
|
632
|
+
} ];
|
633
|
+
|
634
|
+
export { KpopController, ScrimController, Definitions as default };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
2
|
-
import ScrimController from "
|
2
|
+
import ScrimController from "controllers/scrim_controller";
|
3
3
|
|
4
4
|
export default class KpopController extends Controller {
|
5
5
|
static targets = ["content", "closeButton"];
|
data/app/helpers/kpop_helper.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module KpopHelper
|
4
|
+
# Render a modal dialog. Intended for use inside a kpop turbo frame tag.
|
5
|
+
# See builder for options.
|
4
6
|
def render_kpop(options = {}, &block)
|
5
7
|
Kpop::Modal.new(self).render(options, &block)
|
6
8
|
end
|
7
9
|
|
10
|
+
# Render a turbo stream action that will dismiss any open kpop modals.
|
11
|
+
def dismiss_kpop
|
12
|
+
turbo_stream.update("kpop", "")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Render a turbo frame tag that can be targeted for rendering kpop modals.
|
8
16
|
def kpop_frame_tag(&block)
|
9
17
|
turbo_frame_tag "kpop",
|
10
18
|
class: "kpop-container",
|
@@ -13,6 +21,8 @@ module KpopHelper
|
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
24
|
+
# Renders a link that will navigate the kpop turbo frame to the given URL.
|
25
|
+
# The URL should render a modal response inside a kpop frame tag.
|
16
26
|
def kpop_link_to(name = nil, options = nil, html_options = nil, &block)
|
17
27
|
default_html_options = {
|
18
28
|
data: { turbo: true, turbo_frame: "kpop" },
|
@@ -25,6 +35,8 @@ module KpopHelper
|
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
38
|
+
# Renders a button that will navigate the kpop turbo frame to the given URL.
|
39
|
+
# The URL should render a modal response inside a kpop frame tag.
|
28
40
|
def kpop_button_to(name = nil, options = nil, html_options = nil, &block)
|
29
41
|
default_html_options = {
|
30
42
|
form: { data: { turbo: true, turbo_frame: "kpop" } },
|
@@ -32,6 +44,7 @@ module KpopHelper
|
|
32
44
|
button_to(name, options, default_html_options.deep_merge(html_options || {}), &block)
|
33
45
|
end
|
34
46
|
|
47
|
+
# Renders a button that will close the current kpop modal, if any.
|
35
48
|
def kpop_button_close(content = nil, **options, &block)
|
36
49
|
content = block ? capture(yield) : content
|
37
50
|
tag.button content, data: { action: "click->kpop#dismiss:prevent" }, **options
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-kpop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- app/assets/builds/katalyst/kpop.css
|
22
|
+
- app/assets/builds/katalyst/kpop.js
|
22
23
|
- app/assets/builds/katalyst/kpop.min.js
|
23
24
|
- app/assets/config/kpop.js
|
24
25
|
- app/assets/javascripts/controllers/kpop_controller.js
|