@kubik-cms/interface_elements 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.bablerc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "presets": [
3
+ "@babel/env",
4
+ "@babel/preset-typescript"
5
+ ],
6
+ "plugins": [
7
+ "@babel/plugin-transform-typescript",
8
+ "@babel/plugin-proposal-class-properties"
9
+ ]
10
+ }
package/.eslintingonre ADDED
@@ -0,0 +1 @@
1
+ dist
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,469 @@
1
+ var modalElement = `
2
+ <template id='kubik-modal-template' data-kubik-modal-target='modalTemplate'>
3
+ <div id='kubik-modal' class='kubik-modal-element' data-kubik-modal-target='modalContainer'>
4
+ <div class='kubik-modal-background' data-action='click->kubik-modal#closeModal'>
5
+ </div>
6
+ <div class='kubik-modal-element-window'>
7
+ <div data-kubik-modal-target='modalHeader' class='h4 kubik-modal-title-bar'>Test header</div>
8
+ <turbo-frame id='media_library_frame' class='kubik-modal-element-content' data-kubik-modal-target='modalFrame'>
9
+ </turbo-frame>
10
+ </div>
11
+ </div>
12
+ </template>
13
+ `;
14
+ function camelize(value) {
15
+ return value.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase());
16
+ }
17
+ function capitalize(value) {
18
+ return value.charAt(0).toUpperCase() + value.slice(1);
19
+ }
20
+ function dasherize(value) {
21
+ return value.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`);
22
+ }
23
+ function readInheritableStaticArrayValues(constructor, propertyName) {
24
+ const ancestors = getAncestorsForConstructor(constructor);
25
+ return Array.from(ancestors.reduce((values, constructor2) => {
26
+ getOwnStaticArrayValues(constructor2, propertyName).forEach((name) => values.add(name));
27
+ return values;
28
+ }, /* @__PURE__ */ new Set()));
29
+ }
30
+ function readInheritableStaticObjectPairs(constructor, propertyName) {
31
+ const ancestors = getAncestorsForConstructor(constructor);
32
+ return ancestors.reduce((pairs, constructor2) => {
33
+ pairs.push(...getOwnStaticObjectPairs(constructor2, propertyName));
34
+ return pairs;
35
+ }, []);
36
+ }
37
+ function getAncestorsForConstructor(constructor) {
38
+ const ancestors = [];
39
+ while (constructor) {
40
+ ancestors.push(constructor);
41
+ constructor = Object.getPrototypeOf(constructor);
42
+ }
43
+ return ancestors.reverse();
44
+ }
45
+ function getOwnStaticArrayValues(constructor, propertyName) {
46
+ const definition = constructor[propertyName];
47
+ return Array.isArray(definition) ? definition : [];
48
+ }
49
+ function getOwnStaticObjectPairs(constructor, propertyName) {
50
+ const definition = constructor[propertyName];
51
+ return definition ? Object.keys(definition).map((key) => [key, definition[key]]) : [];
52
+ }
53
+ (() => {
54
+ function extendWithReflect(constructor) {
55
+ function extended() {
56
+ return Reflect.construct(constructor, arguments, new.target);
57
+ }
58
+ extended.prototype = Object.create(constructor.prototype, {
59
+ constructor: { value: extended }
60
+ });
61
+ Reflect.setPrototypeOf(extended, constructor);
62
+ return extended;
63
+ }
64
+ function testReflectExtension() {
65
+ const a = function() {
66
+ this.a.call(this);
67
+ };
68
+ const b = extendWithReflect(a);
69
+ b.prototype.a = function() {
70
+ };
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
+ function ClassPropertiesBlessing(constructor) {
82
+ const classes = readInheritableStaticArrayValues(constructor, "classes");
83
+ return classes.reduce((properties, classDefinition) => {
84
+ return Object.assign(properties, propertiesForClassDefinition(classDefinition));
85
+ }, {});
86
+ }
87
+ function propertiesForClassDefinition(key) {
88
+ return {
89
+ [`${key}Class`]: {
90
+ get() {
91
+ const { classes } = this;
92
+ if (classes.has(key)) {
93
+ return classes.get(key);
94
+ } else {
95
+ const attribute = classes.getAttributeName(key);
96
+ throw new Error(`Missing attribute "${attribute}"`);
97
+ }
98
+ }
99
+ },
100
+ [`${key}Classes`]: {
101
+ get() {
102
+ return this.classes.getAll(key);
103
+ }
104
+ },
105
+ [`has${capitalize(key)}Class`]: {
106
+ get() {
107
+ return this.classes.has(key);
108
+ }
109
+ }
110
+ };
111
+ }
112
+ function TargetPropertiesBlessing(constructor) {
113
+ const targets = readInheritableStaticArrayValues(constructor, "targets");
114
+ return targets.reduce((properties, targetDefinition) => {
115
+ return Object.assign(properties, propertiesForTargetDefinition(targetDefinition));
116
+ }, {});
117
+ }
118
+ function propertiesForTargetDefinition(name) {
119
+ return {
120
+ [`${name}Target`]: {
121
+ get() {
122
+ const target = this.targets.find(name);
123
+ if (target) {
124
+ return target;
125
+ } else {
126
+ throw new Error(`Missing target element "${name}" for "${this.identifier}" controller`);
127
+ }
128
+ }
129
+ },
130
+ [`${name}Targets`]: {
131
+ get() {
132
+ return this.targets.findAll(name);
133
+ }
134
+ },
135
+ [`has${capitalize(name)}Target`]: {
136
+ get() {
137
+ return this.targets.has(name);
138
+ }
139
+ }
140
+ };
141
+ }
142
+ function ValuePropertiesBlessing(constructor) {
143
+ const valueDefinitionPairs = readInheritableStaticObjectPairs(constructor, "values");
144
+ const propertyDescriptorMap = {
145
+ valueDescriptorMap: {
146
+ get() {
147
+ return valueDefinitionPairs.reduce((result, valueDefinitionPair) => {
148
+ const valueDescriptor = parseValueDefinitionPair(valueDefinitionPair, this.identifier);
149
+ const attributeName = this.data.getAttributeNameForKey(valueDescriptor.key);
150
+ return Object.assign(result, { [attributeName]: valueDescriptor });
151
+ }, {});
152
+ }
153
+ }
154
+ };
155
+ return valueDefinitionPairs.reduce((properties, valueDefinitionPair) => {
156
+ return Object.assign(properties, propertiesForValueDefinitionPair(valueDefinitionPair));
157
+ }, propertyDescriptorMap);
158
+ }
159
+ function propertiesForValueDefinitionPair(valueDefinitionPair, controller) {
160
+ const definition = parseValueDefinitionPair(valueDefinitionPair, controller);
161
+ const { key, name, reader: read, writer: write } = definition;
162
+ return {
163
+ [name]: {
164
+ get() {
165
+ const value = this.data.get(key);
166
+ if (value !== null) {
167
+ return read(value);
168
+ } else {
169
+ return definition.defaultValue;
170
+ }
171
+ },
172
+ set(value) {
173
+ if (value === void 0) {
174
+ this.data.delete(key);
175
+ } else {
176
+ this.data.set(key, write(value));
177
+ }
178
+ }
179
+ },
180
+ [`has${capitalize(name)}`]: {
181
+ get() {
182
+ return this.data.has(key) || definition.hasCustomDefaultValue;
183
+ }
184
+ }
185
+ };
186
+ }
187
+ function parseValueDefinitionPair([token, typeDefinition], controller) {
188
+ return valueDescriptorForTokenAndTypeDefinition({
189
+ controller,
190
+ token,
191
+ typeDefinition
192
+ });
193
+ }
194
+ function parseValueTypeConstant(constant) {
195
+ switch (constant) {
196
+ case Array:
197
+ return "array";
198
+ case Boolean:
199
+ return "boolean";
200
+ case Number:
201
+ return "number";
202
+ case Object:
203
+ return "object";
204
+ case String:
205
+ return "string";
206
+ }
207
+ }
208
+ function parseValueTypeDefault(defaultValue) {
209
+ switch (typeof defaultValue) {
210
+ case "boolean":
211
+ return "boolean";
212
+ case "number":
213
+ return "number";
214
+ case "string":
215
+ return "string";
216
+ }
217
+ if (Array.isArray(defaultValue))
218
+ return "array";
219
+ if (Object.prototype.toString.call(defaultValue) === "[object Object]")
220
+ return "object";
221
+ }
222
+ function parseValueTypeObject(payload) {
223
+ const typeFromObject = parseValueTypeConstant(payload.typeObject.type);
224
+ if (!typeFromObject)
225
+ return;
226
+ const defaultValueType = parseValueTypeDefault(payload.typeObject.default);
227
+ if (typeFromObject !== defaultValueType) {
228
+ const propertyPath = payload.controller ? `${payload.controller}.${payload.token}` : payload.token;
229
+ 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}".`);
230
+ }
231
+ return typeFromObject;
232
+ }
233
+ function parseValueTypeDefinition(payload) {
234
+ const typeFromObject = parseValueTypeObject({
235
+ controller: payload.controller,
236
+ token: payload.token,
237
+ typeObject: payload.typeDefinition
238
+ });
239
+ const typeFromDefaultValue = parseValueTypeDefault(payload.typeDefinition);
240
+ const typeFromConstant = parseValueTypeConstant(payload.typeDefinition);
241
+ const type = typeFromObject || typeFromDefaultValue || typeFromConstant;
242
+ if (type)
243
+ return type;
244
+ const propertyPath = payload.controller ? `${payload.controller}.${payload.typeDefinition}` : payload.token;
245
+ throw new Error(`Unknown value type "${propertyPath}" for "${payload.token}" value`);
246
+ }
247
+ function defaultValueForDefinition(typeDefinition) {
248
+ const constant = parseValueTypeConstant(typeDefinition);
249
+ if (constant)
250
+ return defaultValuesByType[constant];
251
+ const defaultValue = typeDefinition.default;
252
+ if (defaultValue !== void 0)
253
+ return defaultValue;
254
+ return typeDefinition;
255
+ }
256
+ function valueDescriptorForTokenAndTypeDefinition(payload) {
257
+ const key = `${dasherize(payload.token)}-value`;
258
+ const type = parseValueTypeDefinition(payload);
259
+ return {
260
+ type,
261
+ key,
262
+ name: camelize(key),
263
+ get defaultValue() {
264
+ return defaultValueForDefinition(payload.typeDefinition);
265
+ },
266
+ get hasCustomDefaultValue() {
267
+ return parseValueTypeDefault(payload.typeDefinition) !== void 0;
268
+ },
269
+ reader: readers[type],
270
+ writer: writers[type] || writers.default
271
+ };
272
+ }
273
+ const defaultValuesByType = {
274
+ get array() {
275
+ return [];
276
+ },
277
+ boolean: false,
278
+ number: 0,
279
+ get object() {
280
+ return {};
281
+ },
282
+ string: ""
283
+ };
284
+ const readers = {
285
+ array(value) {
286
+ const array = JSON.parse(value);
287
+ if (!Array.isArray(array)) {
288
+ throw new TypeError(`expected value of type "array" but instead got value "${value}" of type "${parseValueTypeDefault(array)}"`);
289
+ }
290
+ return array;
291
+ },
292
+ boolean(value) {
293
+ return !(value == "0" || String(value).toLowerCase() == "false");
294
+ },
295
+ number(value) {
296
+ return Number(value);
297
+ },
298
+ object(value) {
299
+ const object = JSON.parse(value);
300
+ if (object === null || typeof object != "object" || Array.isArray(object)) {
301
+ throw new TypeError(`expected value of type "object" but instead got value "${value}" of type "${parseValueTypeDefault(object)}"`);
302
+ }
303
+ return object;
304
+ },
305
+ string(value) {
306
+ return value;
307
+ }
308
+ };
309
+ const writers = {
310
+ default: writeString,
311
+ array: writeJSON,
312
+ object: writeJSON
313
+ };
314
+ function writeJSON(value) {
315
+ return JSON.stringify(value);
316
+ }
317
+ function writeString(value) {
318
+ return `${value}`;
319
+ }
320
+ class Controller {
321
+ constructor(context) {
322
+ this.context = context;
323
+ }
324
+ static get shouldLoad() {
325
+ return true;
326
+ }
327
+ get application() {
328
+ return this.context.application;
329
+ }
330
+ get scope() {
331
+ return this.context.scope;
332
+ }
333
+ get element() {
334
+ return this.scope.element;
335
+ }
336
+ get identifier() {
337
+ return this.scope.identifier;
338
+ }
339
+ get targets() {
340
+ return this.scope.targets;
341
+ }
342
+ get classes() {
343
+ return this.scope.classes;
344
+ }
345
+ get data() {
346
+ return this.scope.data;
347
+ }
348
+ initialize() {
349
+ }
350
+ connect() {
351
+ }
352
+ disconnect() {
353
+ }
354
+ dispatch(eventName, { target = this.element, detail = {}, prefix = this.identifier, bubbles = true, cancelable = true } = {}) {
355
+ const type = prefix ? `${prefix}:${eventName}` : eventName;
356
+ const event = new CustomEvent(type, { detail, bubbles, cancelable });
357
+ target.dispatchEvent(event);
358
+ return event;
359
+ }
360
+ }
361
+ Controller.blessings = [ClassPropertiesBlessing, TargetPropertiesBlessing, ValuePropertiesBlessing];
362
+ Controller.targets = [];
363
+ Controller.values = {};
364
+ class src_default extends Controller {
365
+ initialize() {
366
+ if (!document.getElementById("kubik-modal-template")) {
367
+ document.head.insertAdjacentHTML("beforeend", modalElement);
368
+ }
369
+ }
370
+ connect() {
371
+ this._renderDOMElements();
372
+ document.addEventListener("keydown", (event) => {
373
+ if (event.keyCode === 27) {
374
+ this.closeModal();
375
+ }
376
+ });
377
+ }
378
+ get modalTemplate() {
379
+ return this.modalTemplateTarget.innerHTML;
380
+ }
381
+ selectModal(e) {
382
+ const target = e.currentTarget;
383
+ if (this.modalActionValue === "return") {
384
+ const [
385
+ targetControllerName,
386
+ targetControllerId
387
+ ] = this.modalReturnControllerValue.split("#");
388
+ const targetController = this.application.getControllerForElementAndIdentifier(
389
+ document.getElementById(targetControllerId),
390
+ targetControllerName
391
+ );
392
+ targetController.receiveModalReturn({
393
+ payload: {
394
+ kubik_media_upload_id: parseInt(
395
+ target.dataset.selectedKubikMediaUploadId
396
+ ),
397
+ thumb: target.dataset.selectedThumb
398
+ },
399
+ return_payload: this.modalReturnPayloadValue
400
+ });
401
+ this.closeModal();
402
+ }
403
+ }
404
+ modalStatusValueChanged() {
405
+ if (this.hasModalContainerTarget) {
406
+ if (this.modalStatusValue === "opened") {
407
+ this.modalContainerTarget.classList.add("kubik-modal-element__open");
408
+ } else {
409
+ this.modalContainerTarget.classList.remove("kubik-modal-element__open");
410
+ }
411
+ }
412
+ }
413
+ modalSrcValueChanged() {
414
+ if (this.hasModalFrameTarget) {
415
+ if (this.modalSrcValue === "") {
416
+ this.modalFrameTarget.setAttribute("src", this.modalSrcValue);
417
+ this.modalFrameTarget.innerHTML = "";
418
+ } else {
419
+ this.modalFrameTarget.setAttribute("src", this.modalSrcValue);
420
+ }
421
+ }
422
+ }
423
+ modalHeaderValueChanged() {
424
+ if (this.hasModalHeaderTarget) {
425
+ this.modalHeaderTarget.innerText = this.modalHeaderValue;
426
+ }
427
+ }
428
+ openModal(e) {
429
+ const target = e.currentTarget;
430
+ this.modalSrcValue = target.getAttribute("src");
431
+ this.modalHeaderValue = target.dataset.kubikModalHeaderText;
432
+ this.modalActionValue = target.dataset.kubikModalAction;
433
+ this.modalReturnControllerValue = target.dataset.kubikModalReturnController;
434
+ if (target.dataset.kubikModalReturnPayload) {
435
+ this.modalReturnPayloadValue = JSON.parse(
436
+ target.dataset.kubikModalReturnPayload
437
+ );
438
+ }
439
+ this.modalStatusValue = "opened";
440
+ }
441
+ closeModal() {
442
+ this.modalStatusValue = "closed";
443
+ this.modalSrcValue = "";
444
+ this.modalHeaderValue = "";
445
+ this.modalActionValue = "";
446
+ this.modalReturnControllerValue = "";
447
+ this.modalReturnPayloadValue = {};
448
+ }
449
+ _renderDOMElements() {
450
+ if (!document.getElementById("kubik-modal")) {
451
+ document.body.insertAdjacentHTML("beforeend", this.modalTemplate);
452
+ }
453
+ }
454
+ }
455
+ src_default.targets = [
456
+ "modalTemplate",
457
+ "modalContainer",
458
+ "modalFrame",
459
+ "modalHeader"
460
+ ];
461
+ src_default.values = {
462
+ modalHeader: { type: String, default: "" },
463
+ modalStatus: { type: String, default: "closed" },
464
+ modalSrc: { type: String, default: "" },
465
+ modalAction: { type: String, default: "" },
466
+ modalReturnPayload: { type: Object, default: {} },
467
+ modalReturnController: { type: String, default: "" }
468
+ };
469
+ export { src_default as default };
@@ -0,0 +1,13 @@
1
+ (function(s,l){typeof exports=="object"&&typeof module!="undefined"?module.exports=l():typeof define=="function"&&define.amd?define(l):(s=typeof globalThis!="undefined"?globalThis:s||self,s["kubik-modal"]=l())})(this,function(){"use strict";var s=`
2
+ <template id='kubik-modal-template' data-kubik-modal-target='modalTemplate'>
3
+ <div id='kubik-modal' class='kubik-modal-element' data-kubik-modal-target='modalContainer'>
4
+ <div class='kubik-modal-background' data-action='click->kubik-modal#closeModal'>
5
+ </div>
6
+ <div class='kubik-modal-element-window'>
7
+ <div data-kubik-modal-target='modalHeader' class='h4 kubik-modal-title-bar'>Test header</div>
8
+ <turbo-frame id='media_library_frame' class='kubik-modal-element-content' data-kubik-modal-target='modalFrame'>
9
+ </turbo-frame>
10
+ </div>
11
+ </div>
12
+ </template>
13
+ `;function l(e){return e.replace(/(?:[_-])([a-z0-9])/g,(t,r)=>r.toUpperCase())}function f(e){return e.charAt(0).toUpperCase()+e.slice(1)}function V(e){return e.replace(/([A-Z])/g,(t,r)=>`-${r.toLowerCase()}`)}function h(e,t){const r=g(e);return Array.from(r.reduce((n,a)=>(w(a,t).forEach(o=>n.add(o)),n),new Set))}function C(e,t){return g(e).reduce((n,a)=>(n.push(...j(a,t)),n),[])}function g(e){const t=[];for(;e;)t.push(e),e=Object.getPrototypeOf(e);return t.reverse()}function w(e,t){const r=e[t];return Array.isArray(r)?r:[]}function j(e,t){const r=e[t];return r?Object.keys(r).map(n=>[n,r[n]]):[]}(()=>{function e(r){function n(){return Reflect.construct(r,arguments,new.target)}return n.prototype=Object.create(r.prototype,{constructor:{value:n}}),Reflect.setPrototypeOf(n,r),n}function t(){const n=e(function(){this.a.call(this)});return n.prototype.a=function(){},new n}try{return t(),e}catch{return n=>class extends n{}}})();function S(e){return h(e,"classes").reduce((r,n)=>Object.assign(r,A(n)),{})}function A(e){return{[`${e}Class`]:{get(){const{classes:t}=this;if(t.has(e))return t.get(e);{const r=t.getAttributeName(e);throw new Error(`Missing attribute "${r}"`)}}},[`${e}Classes`]:{get(){return this.classes.getAll(e)}},[`has${f(e)}Class`]:{get(){return this.classes.has(e)}}}}function O(e){return h(e,"targets").reduce((r,n)=>Object.assign(r,$(n)),{})}function $(e){return{[`${e}Target`]:{get(){const t=this.targets.find(e);if(t)return t;throw new Error(`Missing target element "${e}" for "${this.identifier}" controller`)}},[`${e}Targets`]:{get(){return this.targets.findAll(e)}},[`has${f(e)}Target`]:{get(){return this.targets.has(e)}}}}function v(e){const t=C(e,"values"),r={valueDescriptorMap:{get(){return t.reduce((n,a)=>{const o=b(a,this.identifier),c=this.data.getAttributeNameForKey(o.key);return Object.assign(n,{[c]:o})},{})}}};return t.reduce((n,a)=>Object.assign(n,M(a)),r)}function M(e,t){const r=b(e,t),{key:n,name:a,reader:o,writer:c}=r;return{[a]:{get(){const i=this.data.get(n);return i!==null?o(i):r.defaultValue},set(i){i===void 0?this.data.delete(n):this.data.set(n,c(i))}},[`has${f(a)}`]:{get(){return this.data.has(n)||r.hasCustomDefaultValue}}}}function b([e,t],r){return P({controller:r,token:e,typeDefinition:t})}function m(e){switch(e){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function u(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}if(Array.isArray(e))return"array";if(Object.prototype.toString.call(e)==="[object Object]")return"object"}function D(e){const t=m(e.typeObject.type);if(!t)return;const r=u(e.typeObject.default);if(t!==r){const n=e.controller?`${e.controller}.${e.token}`:e.token;throw new Error(`The specified default value for the Stimulus Value "${n}" must match the defined type "${t}". The provided default value of "${e.typeObject.default}" is of type "${r}".`)}return t}function E(e){const t=D({controller:e.controller,token:e.token,typeObject:e.typeDefinition}),r=u(e.typeDefinition),n=m(e.typeDefinition),a=t||r||n;if(a)return a;const o=e.controller?`${e.controller}.${e.typeDefinition}`:e.token;throw new Error(`Unknown value type "${o}" for "${e.token}" value`)}function F(e){const t=m(e);if(t)return R[t];const r=e.default;return r!==void 0?r:e}function P(e){const t=`${V(e.token)}-value`,r=E(e);return{type:r,key:t,name:l(t),get defaultValue(){return F(e.typeDefinition)},get hasCustomDefaultValue(){return u(e.typeDefinition)!==void 0},reader:_[r],writer:y[r]||y.default}}const R={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},_={array(e){const t=JSON.parse(e);if(!Array.isArray(t))throw new TypeError(`expected value of type "array" but instead got value "${e}" of type "${u(t)}"`);return t},boolean(e){return!(e=="0"||String(e).toLowerCase()=="false")},number(e){return Number(e)},object(e){const t=JSON.parse(e);if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`expected value of type "object" but instead got value "${e}" of type "${u(t)}"`);return t},string(e){return e}},y={default:x,array:k,object:k};function k(e){return JSON.stringify(e)}function x(e){return`${e}`}class d{constructor(t){this.context=t}static get shouldLoad(){return!0}get application(){return this.context.application}get scope(){return this.context.scope}get element(){return this.scope.element}get identifier(){return this.scope.identifier}get targets(){return this.scope.targets}get classes(){return this.scope.classes}get data(){return this.scope.data}initialize(){}connect(){}disconnect(){}dispatch(t,{target:r=this.element,detail:n={},prefix:a=this.identifier,bubbles:o=!0,cancelable:c=!0}={}){const i=a?`${a}:${t}`:t,T=new CustomEvent(i,{detail:n,bubbles:o,cancelable:c});return r.dispatchEvent(T),T}}d.blessings=[S,O,v],d.targets=[],d.values={};class p extends d{initialize(){document.getElementById("kubik-modal-template")||document.head.insertAdjacentHTML("beforeend",s)}connect(){this._renderDOMElements(),document.addEventListener("keydown",t=>{t.keyCode===27&&this.closeModal()})}get modalTemplate(){return this.modalTemplateTarget.innerHTML}selectModal(t){const r=t.currentTarget;if(this.modalActionValue==="return"){const[n,a]=this.modalReturnControllerValue.split("#");this.application.getControllerForElementAndIdentifier(document.getElementById(a),n).receiveModalReturn({payload:{kubik_media_upload_id:parseInt(r.dataset.selectedKubikMediaUploadId),thumb:r.dataset.selectedThumb},return_payload:this.modalReturnPayloadValue}),this.closeModal()}}modalStatusValueChanged(){this.hasModalContainerTarget&&(this.modalStatusValue==="opened"?this.modalContainerTarget.classList.add("kubik-modal-element__open"):this.modalContainerTarget.classList.remove("kubik-modal-element__open"))}modalSrcValueChanged(){this.hasModalFrameTarget&&(this.modalSrcValue===""?(this.modalFrameTarget.setAttribute("src",this.modalSrcValue),this.modalFrameTarget.innerHTML=""):this.modalFrameTarget.setAttribute("src",this.modalSrcValue))}modalHeaderValueChanged(){this.hasModalHeaderTarget&&(this.modalHeaderTarget.innerText=this.modalHeaderValue)}openModal(t){const r=t.currentTarget;this.modalSrcValue=r.getAttribute("src"),this.modalHeaderValue=r.dataset.kubikModalHeaderText,this.modalActionValue=r.dataset.kubikModalAction,this.modalReturnControllerValue=r.dataset.kubikModalReturnController,r.dataset.kubikModalReturnPayload&&(this.modalReturnPayloadValue=JSON.parse(r.dataset.kubikModalReturnPayload)),this.modalStatusValue="opened"}closeModal(){this.modalStatusValue="closed",this.modalSrcValue="",this.modalHeaderValue="",this.modalActionValue="",this.modalReturnControllerValue="",this.modalReturnPayloadValue={}}_renderDOMElements(){document.getElementById("kubik-modal")||document.body.insertAdjacentHTML("beforeend",this.modalTemplate)}}return p.targets=["modalTemplate","modalContainer","modalFrame","modalHeader"],p.values={modalHeader:{type:String,default:""},modalStatus:{type:String,default:"closed"},modalSrc:{type:String,default:""},modalAction:{type:String,default:""},modalReturnPayload:{type:Object,default:{}},modalReturnController:{type:String,default:""}},p});
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@kubik-cms/interface_elements",
3
+ "version": "0.1.2",
4
+ "license": "MIT",
5
+ "author": "Primate Inc.",
6
+ "contributors": [
7
+ "Bart Oleszczyk <bart@primate.co.uk>"
8
+ ],
9
+ "bugs": {
10
+ "url": "https://github.com/kubik-cms/kubik_interface_elements/issues"
11
+ },
12
+ "homepage": "https://github.com/kubik-cms/kubik_interface_elements",
13
+ "private": false,
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git://github.com/kubik-cms/kubik_interface_elements.git"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "main": "dist/kubik_interface_elements.umd.js",
22
+ "module": "dist/kubik_interface_elements.es.js",
23
+ "scripts": {
24
+ "format": "prettier-standard '**/*.{ts,css,html}' --format",
25
+ "lint": "prettier-standard '**/*.{ts,css,html}' --lint",
26
+ "dev": "vite",
27
+ "prod": "vite build",
28
+ "build": "tsc --noEmit && vite build",
29
+ "test": "BABEL_ENV=test jest",
30
+ "np": "np --no-2fa --branch master"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "7.15.8",
34
+ "@babel/plugin-syntax-class-properties": "7.12.13",
35
+ "@babel/polyfill": "^7.12.1",
36
+ "@babel/preset-env": "^7.15.8",
37
+ "@babel/preset-typescript": "^7.15.0",
38
+ "@hotwired/stimulus": "^3.0.1",
39
+ "@types/jest": "^27.0.2",
40
+ "babel-jest": "^27.3.1",
41
+ "jest": "^29.0.1",
42
+ "jest-environment-jsdom": "^29.0.3",
43
+ "np": "^7.6.2",
44
+ "prettier-standard": "^16.4.1",
45
+ "ts-jest": "^29.0.1",
46
+ "typescript": "^4.8.2",
47
+ "vite": "^2.7.13"
48
+ },
49
+ "peerDependencies": {
50
+ "@hotwired/stimulus": "^3.0.1"
51
+ },
52
+ "description": "Add the ability to preview individual model pages."
53
+ }