@kubik-cms/interface_elements 0.1.3 → 0.1.4
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.
|
@@ -363,9 +363,7 @@ Controller.targets = [];
|
|
|
363
363
|
Controller.values = {};
|
|
364
364
|
class src_default extends Controller {
|
|
365
365
|
initialize() {
|
|
366
|
-
|
|
367
|
-
document.head.insertAdjacentHTML("beforeend", modalElement);
|
|
368
|
-
}
|
|
366
|
+
document.head.insertAdjacentHTML("beforeend", modalElement);
|
|
369
367
|
}
|
|
370
368
|
connect() {
|
|
371
369
|
this._renderDOMElements();
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
</div>
|
|
12
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
|
|
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 E({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 F(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 P(e){const t=m(e);if(t)return R[t];const r=e.default;return r!==void 0?r:e}function E(e){const t=`${V(e.token)}-value`,r=F(e);return{type:r,key:t,name:l(t),get defaultValue(){return P(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.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});
|