@kubik-cms/wysiwyg 0.1.8
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/LICENSE.txt +21 -0
- package/README.md +0 -0
- package/dist/wysiwyg.es.js +1277 -0
- package/dist/wysiwyg.umd.js +1 -0
- package/package.json +49 -0
- package/yarn-error.log +5752 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(f,c){typeof exports=="object"&&typeof module!="undefined"?module.exports=c():typeof define=="function"&&define.amd?define(c):(f=typeof globalThis!="undefined"?globalThis:f||self,f.wysiwyg=c())})(this,function(){"use strict";function f(t){return t.replace(/(?:[_-])([a-z0-9])/g,(e,r)=>r.toUpperCase())}function c(t){return t.charAt(0).toUpperCase()+t.slice(1)}function ut(t){return t.replace(/([A-Z])/g,(e,r)=>`-${r.toLowerCase()}`)}function L(t,e){const r=R(t);return Array.from(r.reduce((a,s)=>(lt(s,e).forEach(n=>a.add(n)),a),new Set))}function ct(t,e){return R(t).reduce((a,s)=>(a.push(...ht(s,e)),a),[])}function R(t){const e=[];for(;t;)e.push(t),t=Object.getPrototypeOf(t);return e.reverse()}function lt(t,e){const r=t[e];return Array.isArray(r)?r:[]}function ht(t,e){const r=t[e];return r?Object.keys(r).map(a=>[a,r[a]]):[]}(()=>{function t(r){function a(){return Reflect.construct(r,arguments,new.target)}return a.prototype=Object.create(r.prototype,{constructor:{value:a}}),Reflect.setPrototypeOf(a,r),a}function e(){const a=t(function(){this.a.call(this)});return a.prototype.a=function(){},new a}try{return e(),t}catch{return a=>class extends a{}}})();function dt(t){return L(t,"classes").reduce((r,a)=>Object.assign(r,ft(a)),{})}function ft(t){return{[`${t}Class`]:{get(){const{classes:e}=this;if(e.has(t))return e.get(t);{const r=e.getAttributeName(t);throw new Error(`Missing attribute "${r}"`)}}},[`${t}Classes`]:{get(){return this.classes.getAll(t)}},[`has${c(t)}Class`]:{get(){return this.classes.has(t)}}}}function pt(t){return L(t,"targets").reduce((r,a)=>Object.assign(r,gt(a)),{})}function gt(t){return{[`${t}Target`]:{get(){const e=this.targets.find(t);if(e)return e;throw new Error(`Missing target element "${t}" for "${this.identifier}" controller`)}},[`${t}Targets`]:{get(){return this.targets.findAll(t)}},[`has${c(t)}Target`]:{get(){return this.targets.has(t)}}}}function vt(t){const e=ct(t,"values"),r={valueDescriptorMap:{get(){return e.reduce((a,s)=>{const n=M(s,this.identifier),o=this.data.getAttributeNameForKey(n.key);return Object.assign(a,{[o]:n})},{})}}};return e.reduce((a,s)=>Object.assign(a,mt(s)),r)}function mt(t,e){const r=M(t,e),{key:a,name:s,reader:n,writer:o}=r;return{[s]:{get(){const i=this.data.get(a);return i!==null?n(i):r.defaultValue},set(i){i===void 0?this.data.delete(a):this.data.set(a,o(i))}},[`has${c(s)}`]:{get(){return this.data.has(a)||r.hasCustomDefaultValue}}}}function M([t,e],r){return $t({controller:r,token:t,typeDefinition:e})}function T(t){switch(t){case Array:return"array";case Boolean:return"boolean";case Number:return"number";case Object:return"object";case String:return"string"}}function p(t){switch(typeof t){case"boolean":return"boolean";case"number":return"number";case"string":return"string"}if(Array.isArray(t))return"array";if(Object.prototype.toString.call(t)==="[object Object]")return"object"}function bt(t){const e=T(t.typeObject.type);if(!e)return;const r=p(t.typeObject.default);if(e!==r){const a=t.controller?`${t.controller}.${t.token}`:t.token;throw new Error(`The specified default value for the Stimulus Value "${a}" must match the defined type "${e}". The provided default value of "${t.typeObject.default}" is of type "${r}".`)}return e}function _t(t){const e=bt({controller:t.controller,token:t.token,typeObject:t.typeDefinition}),r=p(t.typeDefinition),a=T(t.typeDefinition),s=e||r||a;if(s)return s;const n=t.controller?`${t.controller}.${t.typeDefinition}`:t.token;throw new Error(`Unknown value type "${n}" for "${t.token}" value`)}function yt(t){const e=T(t);if(e)return wt[e];const r=t.default;return r!==void 0?r:t}function $t(t){const e=`${ut(t.token)}-value`,r=_t(t);return{type:r,key:e,name:f(e),get defaultValue(){return yt(t.typeDefinition)},get hasCustomDefaultValue(){return p(t.typeDefinition)!==void 0},reader:Ot[r],writer:F[r]||F.default}}const wt={get array(){return[]},boolean:!1,number:0,get object(){return{}},string:""},Ot={array(t){const e=JSON.parse(t);if(!Array.isArray(e))throw new TypeError(`expected value of type "array" but instead got value "${t}" of type "${p(e)}"`);return e},boolean(t){return!(t=="0"||String(t).toLowerCase()=="false")},number(t){return Number(t)},object(t){const e=JSON.parse(t);if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`expected value of type "object" but instead got value "${t}" of type "${p(e)}"`);return e},string(t){return t}},F={default:Tt,array:H,object:H};function H(t){return JSON.stringify(t)}function Tt(t){return`${t}`}class g{constructor(e){this.context=e}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(e,{target:r=this.element,detail:a={},prefix:s=this.identifier,bubbles:n=!0,cancelable:o=!0}={}){const i=s?`${s}:${e}`:e,u=new CustomEvent(i,{detail:a,bubbles:n,cancelable:o});return r.dispatchEvent(u),u}}g.blessings=[dt,pt,vt],g.targets=[],g.values={};var m=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},Ct=typeof m=="object"&&m&&m.Object===Object&&m,jt=Ct,St=jt,Vt=typeof self=="object"&&self&&self.Object===Object&&self,At=St||Vt||Function("return this")(),C=At,Dt=C,Pt=Dt.Symbol,j=Pt,z=j,G=Object.prototype,Nt=G.hasOwnProperty,It=G.toString,v=z?z.toStringTag:void 0;function xt(t){var e=Nt.call(t,v),r=t[v];try{t[v]=void 0;var a=!0}catch{}var s=It.call(t);return a&&(e?t[v]=r:delete t[v]),s}var Et=xt,kt=Object.prototype,Lt=kt.toString;function Rt(t){return Lt.call(t)}var Mt=Rt,K=j,Ft=Et,Ht=Mt,zt="[object Null]",Gt="[object Undefined]",U=K?K.toStringTag:void 0;function Kt(t){return t==null?t===void 0?Gt:zt:U&&U in Object(t)?Ft(t):Ht(t)}var J=Kt;function Ut(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var S=Ut,Jt=J,Wt=S,qt="[object AsyncFunction]",Bt="[object Function]",Xt="[object GeneratorFunction]",Zt="[object Proxy]";function Yt(t){if(!Wt(t))return!1;var e=Jt(t);return e==Bt||e==Xt||e==qt||e==Zt}var Qt=Yt,te=C,ee=te["__core-js_shared__"],re=ee,V=re,W=function(){var t=/[^.]+$/.exec(V&&V.keys&&V.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function ae(t){return!!W&&W in t}var se=ae,ne=Function.prototype,ie=ne.toString;function oe(t){if(t!=null){try{return ie.call(t)}catch{}try{return t+""}catch{}}return""}var ue=oe,ce=Qt,le=se,he=S,de=ue,fe=/[\\^$.*+?()[\]{}|]/g,pe=/^\[object .+?Constructor\]$/,ge=Function.prototype,ve=Object.prototype,me=ge.toString,be=ve.hasOwnProperty,_e=RegExp("^"+me.call(be).replace(fe,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ye(t){if(!he(t)||le(t))return!1;var e=ce(t)?_e:pe;return e.test(de(t))}var $e=ye;function we(t,e){return t==null?void 0:t[e]}var Oe=we,Te=$e,Ce=Oe;function je(t,e){var r=Ce(t,e);return Te(r)?r:void 0}var A=je,Se=A,Ve=function(){try{var t=Se(Object,"defineProperty");return t({},"",{}),t}catch{}}(),Ae=Ve,q=Ae;function De(t,e,r){e=="__proto__"&&q?q(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var Pe=De;function Ne(t,e){return t===e||t!==t&&e!==e}var B=Ne,Ie=Pe,xe=B,Ee=Object.prototype,ke=Ee.hasOwnProperty;function Le(t,e,r){var a=t[e];(!(ke.call(t,e)&&xe(a,r))||r===void 0&&!(e in t))&&Ie(t,e,r)}var Re=Le,Me=Array.isArray,D=Me;function Fe(t){return t!=null&&typeof t=="object"}var He=Fe,ze=J,Ge=He,Ke="[object Symbol]";function Ue(t){return typeof t=="symbol"||Ge(t)&&ze(t)==Ke}var P=Ue,Je=D,We=P,qe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Be=/^\w*$/;function Xe(t,e){if(Je(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||We(t)?!0:Be.test(t)||!qe.test(t)||e!=null&&t in Object(e)}var Ze=Xe,Ye=A,Qe=Ye(Object,"create"),b=Qe,X=b;function tr(){this.__data__=X?X(null):{},this.size=0}var er=tr;function rr(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var ar=rr,sr=b,nr="__lodash_hash_undefined__",ir=Object.prototype,or=ir.hasOwnProperty;function ur(t){var e=this.__data__;if(sr){var r=e[t];return r===nr?void 0:r}return or.call(e,t)?e[t]:void 0}var cr=ur,lr=b,hr=Object.prototype,dr=hr.hasOwnProperty;function fr(t){var e=this.__data__;return lr?e[t]!==void 0:dr.call(e,t)}var pr=fr,gr=b,vr="__lodash_hash_undefined__";function mr(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=gr&&e===void 0?vr:e,this}var br=mr,_r=er,yr=ar,$r=cr,wr=pr,Or=br;function l(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}l.prototype.clear=_r,l.prototype.delete=yr,l.prototype.get=$r,l.prototype.has=wr,l.prototype.set=Or;var Tr=l;function Cr(){this.__data__=[],this.size=0}var jr=Cr,Sr=B;function Vr(t,e){for(var r=t.length;r--;)if(Sr(t[r][0],e))return r;return-1}var _=Vr,Ar=_,Dr=Array.prototype,Pr=Dr.splice;function Nr(t){var e=this.__data__,r=Ar(e,t);if(r<0)return!1;var a=e.length-1;return r==a?e.pop():Pr.call(e,r,1),--this.size,!0}var Ir=Nr,xr=_;function Er(t){var e=this.__data__,r=xr(e,t);return r<0?void 0:e[r][1]}var kr=Er,Lr=_;function Rr(t){return Lr(this.__data__,t)>-1}var Mr=Rr,Fr=_;function Hr(t,e){var r=this.__data__,a=Fr(r,t);return a<0?(++this.size,r.push([t,e])):r[a][1]=e,this}var zr=Hr,Gr=jr,Kr=Ir,Ur=kr,Jr=Mr,Wr=zr;function h(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}h.prototype.clear=Gr,h.prototype.delete=Kr,h.prototype.get=Ur,h.prototype.has=Jr,h.prototype.set=Wr;var qr=h,Br=A,Xr=C,Zr=Br(Xr,"Map"),Yr=Zr,Z=Tr,Qr=qr,ta=Yr;function ea(){this.size=0,this.__data__={hash:new Z,map:new(ta||Qr),string:new Z}}var ra=ea;function aa(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var sa=aa,na=sa;function ia(t,e){var r=t.__data__;return na(e)?r[typeof e=="string"?"string":"hash"]:r.map}var y=ia,oa=y;function ua(t){var e=oa(this,t).delete(t);return this.size-=e?1:0,e}var ca=ua,la=y;function ha(t){return la(this,t).get(t)}var da=ha,fa=y;function pa(t){return fa(this,t).has(t)}var ga=pa,va=y;function ma(t,e){var r=va(this,t),a=r.size;return r.set(t,e),this.size+=r.size==a?0:1,this}var ba=ma,_a=ra,ya=ca,$a=da,wa=ga,Oa=ba;function d(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}d.prototype.clear=_a,d.prototype.delete=ya,d.prototype.get=$a,d.prototype.has=wa,d.prototype.set=Oa;var Ta=d,Y=Ta,Ca="Expected a function";function N(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(Ca);var r=function(){var a=arguments,s=e?e.apply(this,a):a[0],n=r.cache;if(n.has(s))return n.get(s);var o=t.apply(this,a);return r.cache=n.set(s,o)||n,o};return r.cache=new(N.Cache||Y),r}N.Cache=Y;var ja=N,Sa=ja,Va=500;function Aa(t){var e=Sa(t,function(a){return r.size===Va&&r.clear(),a}),r=e.cache;return e}var Da=Aa,Pa=Da,Na=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ia=/\\(\\)?/g,xa=Pa(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Na,function(r,a,s,n){e.push(s?n.replace(Ia,"$1"):a||r)}),e}),Ea=xa;function ka(t,e){for(var r=-1,a=t==null?0:t.length,s=Array(a);++r<a;)s[r]=e(t[r],r,t);return s}var La=ka,Q=j,Ra=La,Ma=D,Fa=P,Ha=1/0,tt=Q?Q.prototype:void 0,et=tt?tt.toString:void 0;function rt(t){if(typeof t=="string")return t;if(Ma(t))return Ra(t,rt)+"";if(Fa(t))return et?et.call(t):"";var e=t+"";return e=="0"&&1/t==-Ha?"-0":e}var za=rt,Ga=za;function Ka(t){return t==null?"":Ga(t)}var Ua=Ka,Ja=D,Wa=Ze,qa=Ea,Ba=Ua;function Xa(t,e){return Ja(t)?t:Wa(t,e)?[t]:qa(Ba(t))}var Za=Xa,Ya=9007199254740991,Qa=/^(?:0|[1-9]\d*)$/;function ts(t,e){var r=typeof t;return e=e==null?Ya:e,!!e&&(r=="number"||r!="symbol"&&Qa.test(t))&&t>-1&&t%1==0&&t<e}var es=ts,rs=P,as=1/0;function ss(t){if(typeof t=="string"||rs(t))return t;var e=t+"";return e=="0"&&1/t==-as?"-0":e}var ns=ss,is=Re,os=Za,us=es,at=S,cs=ns;function ls(t,e,r,a){if(!at(t))return t;e=os(e,t);for(var s=-1,n=e.length,o=n-1,i=t;i!=null&&++s<n;){var u=cs(e[s]),O=r;if(u==="__proto__"||u==="constructor"||u==="prototype")return t;if(s!=o){var k=i[u];O=a?a(k,u,i):void 0,O===void 0&&(O=at(k)?k:us(e[s+1])?[]:{})}is(i,u,O),i=i[u]}return t}var hs=ls,ds=hs;function fs(t,e,r){return t==null?t:ds(t,e,r)}var $=fs;const I=t=>t instanceof Date,ps=t=>Object.keys(t).length===0,x=t=>t!=null&&typeof t=="object",gs=(t,...e)=>Object.prototype.hasOwnProperty.call(t,...e),E=t=>x(t)&&ps(t),vs=()=>Object.create(null),st=(t,e)=>t===e?{}:!x(t)||!x(e)?e:I(t)||I(e)?t.valueOf()==e.valueOf()?{}:e:Object.keys(e).reduce((r,a)=>{if(gs(t,a)){const s=st(t[a],e[a]);return E(s)&&!I(s)&&(E(t[a])||!E(e[a]))||(r[a]=s),r}return r},vs());function ms(t){return t!==null&&typeof t=="object"&&!(t instanceof Date)}var bs=Array.isArray;function nt(t,e,r,a){return Object.keys(t).forEach(function(s){var n=s.replace(/\./g,"\\.");if(ms(t[s])&&!bs(t[s])){var o=r&&r+"."+n;a&&e.push(r?o:n),nt(t[s],e,o||n,a)}else{var i=r?r+"."+n:n;e.push(i)}}),e}var _s=function(t,e){return nt(t,[],null,e)};function ys(t){return document.head.querySelector(`meta[name="${t}"]`).getAttribute("content")}function $s(t,e,r){if(r>=t.length)for(var a=r-t.length+1;a--;)t.push(void 0);return t.splice(r,0,t.splice(e,1)[0]),t}class it extends g{connect(){this.getNewWidget()}moveItemUp(e){const r=e.currentTarget;this.moveItemToPosition(r,-1)}moveItemDown(e){const r=e.currentTarget;this.moveItemToPosition(r,1)}moveItemToPosition(e,r){const a=parseInt(e.dataset.itemIndex),s=e.dataset.targetList,n=this.dataValue[s].repeated_items,o=$s(n,a,a+r),i=Object.assign({},this.dataValue);i[s].repeated_items=o,this.dataValue=i}removeItem(e){const r=e.currentTarget,a=r.dataset.itemIndex,s=r.dataset.targetList,n=Object.assign({},this.dataValue);n[s].repeated_items.splice(a,1),this.dataValue=n,this.getNewWidget()}addItem(e){const a=e.currentTarget.dataset.targetList;typeof this.dataValue[a]=="undefined"&&(this.dataValue=Object.assign({},this.dataValue,{[a]:{repeated_items:[]}})),this.dataValue=Object.assign({},this.dataValue,{[a]:{repeated_items:[...this.dataValue[a].repeated_items,{}]}}),this.getNewWidget()}dataValueChanged(e,r){const a=st(e,r),s=_s(a);(a.items&&a.items.repeated_items&&JSON.stringify(Object.values(a.items.repeated_items)[0])===JSON.stringify({})||s.filter(o=>o.match(/^id$|\.id$/g)).length>0)&&this.getNewWidget()}updateField(e){const r=e.currentTarget.name,a=$(this.dataValue,r,e.currentTarget.value);this.dataValue=a}selectResult(e){const r=e.currentTarget,a=JSON.parse(r.dataset.returnObject),s=$(this.dataValue,r.dataset.fieldName,a.id);this.dataValue=s,this.getNewWidget()}removeResource(e){const r=e.currentTarget,a=$(this.dataValue,r.dataset.fieldName,null);this.dataValue=a,this.getNewWidget()}receiveModalReturn(e){const r=e,a=$(this.dataValue,r.return_payload.field_name,r.payload.id);this.dataValue=a,this.getNewWidget()}getNewWidget(){fetch(`${this.setupValue.src}.json`,{method:"POST",headers:{"Content-Type":"application/json","X-CSRF-Token":ys("csrf-token")},body:JSON.stringify({widget_id:this.widgetIdValue,data:this.dataValue,setup:this.setupValue,max_items:this.maxItemsValue})}).then(e=>e.json()).then(e=>{this.element.innerHTML=e.html_data})}}it.values={widgetId:String,setup:Object,data:Object,maxItems:{type:Number,default:0}};function ot(t,e=[],r={},a=""){const s=document.createElement(t);s.classList.add(...e);for(const n in r)s.setAttribute(n,r[n]);return typeof a=="string"&&(s.innerText=a),s}class w extends g{connect(){this._loadDefaultResults()}showForm(){this.element.classList.add(this.activeListClass)}cancel(e){e.preventDefault(),this.element.classList.remove(this.activeListClass)}errorValueChanged(){this.errorValue==""?this.element.classList.remove(this.fetchErrorClass):this.element.classList.add(this.fetchErrorClass)}resultActiveValueChanged(){if(this.resultTargets.forEach(e=>{e.classList.remove(this.activeResultClass)}),!isNaN(this.resultActiveValue)){const e=this.resultActiveValue;this.resultTargets[e].classList.add(this.activeResultClass)}}mouseOver(e){const r=e.currentTarget;this.resultActiveValue=parseInt(r.dataset.index)}mouseOut(e){this.resultActiveValue=null}resultsValueChanged(){const e=this.fieldNameValue;this.resultTargets.forEach(r=>r.remove()),this.resultActiveValue=null,this.resultsValue.forEach((r,a)=>{const s=Object.assign({receive_index:this.inputTarget.dataset.itemIndex},r),n=ot("li",["kubik-wysiwyg-component--item-autocomplete-results-list-item"],{"data-kubik-autocomplete-target":"result","data-index":a,"data-return-id":s.id,"data-return-object":JSON.stringify(s),"data-field-name":e,"data-action":"mouseout->kubik-autocomplete#mouseOut mouseover->kubik-autocomplete#mouseOver mousedown->kubik-widget#selectResult mousedown->kubik-autocomplete#blur"},r.return_object.display_name);this.resultsListTarget.insertBefore(n,this.feedbackTarget)}),this.resultActiveValue>this.resultsValue.length&&(this.resultActiveValue=this.resultsValue.length-1)}load(){this._fetchResults()}focus(){this.element.classList.add(this.activeClass)}blur(){this.errorValue="",this.inputTarget.blur(),this.connectionController.abort(),this.element.classList.remove(this.fetchErrorClass),this.element.classList.remove(this.loadingClass),this.element.classList.remove(this.activeClass)}_sourceURL(){const e=[window.location.protocol,window.location.host].join("//"),r=new URLSearchParams({kubik_search:"1",q:this.inputTarget.value});return new URL([this.srcValue,".json?",r.toString()].join(""),e)}_loadDefaultResults(){this._fetchResults()}keyCheck(e){switch(e.key){case"Down":case"ArrowDown":this._nextResult(),e.preventDefault(),e.stopImmediatePropagation();return;case"Up":case"ArrowUp":this._previousResult(),e.preventDefault(),e.stopImmediatePropagation();return;case"Enter":const r=this.resultTargets[this.resultActiveValue];r&&r.dispatchEvent(new Event("mousedown")),e.preventDefault(),e.stopImmediatePropagation();return;case"Backspace":e.stopImmediatePropagation();return}}_previousResult(){isNaN(this.resultActiveValue)?this.resultActiveValue=this.resultTargets.length>1?this.resultTargets.length-1:0:this.resultActiveValue=this.resultActiveValue==0?this.resultTargets.length-1:this.resultActiveValue-1}_nextResult(){isNaN(this.resultActiveValue)?this.resultActiveValue=0:this.resultActiveValue=this.resultActiveValue+1==this.resultTargets.length?0:this.resultActiveValue+1}_fetchResults(){this.errorValue="",this.feedbackTarget.innerHTML="Loading...",this.connectionController=new AbortController,fetch(this._sourceURL(),{headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{this.errorValue="",e.length>0&&(this.resultsValue=e,this.queryValue=this.inputTarget.value),this.inputTarget.value==""?(this.queryValue="",this.feedbackTarget.innerHTML="",this.feedbackTarget.insertAdjacentHTML("beforeend",`Showing latest <span>${e.length}</span> results`)):(this.feedbackTarget.innerHTML="",this.queryValue==""?this.feedbackTarget.insertAdjacentHTML("beforeend",`Showing latest <span>${e.length}</span> results`):this.feedbackTarget.insertAdjacentHTML("beforeend",`Showing results for <span>${this.queryValue}</span>`)),this.queryValue==this.inputTarget.value?this.element.classList.remove(this.noResultsClass):this.element.classList.add(this.noResultsClass)}).catch(e=>{this.feedbackTarget.innerHTML="",this.errorValue="Error loading the results"})}}w.classes=["fetchError","loading","active","activeResult","noResults","activeList"],w.targets=["feedback","input","resultsList","result"],w.values={returnController:String,src:String,fieldName:String,query:{type:String,default:""},error:{type:String,default:""},results:{type:Array,default:[]},resultActive:Number};const ws=function(e={},r){let a={"data-controller":"kubik-widget","data-kubik-widget-setup-value":JSON.stringify(e.setup),"data-kubik-widget-data-value":JSON.stringify(r),"data-kubik-widget-widget-id-value":e.setup.widget_id,id:e.setup.widget_id};return e.items_limit&&(a["data-kubik-widget-items-max-items-value"]=e.items_limit),ot("div",["kubik_media_wrapper","kubik-wysiwyg-component"],a)};class Os{static get defaultWidgetConfig(){return{data_src:"/admin/kubik_wysiwyg_widget/show"}}constructor({data:e,api:r}){this.data=e,this.api=r,this.randomString=Math.random().toString(36).substring(2,7),this.label=this.constructor.toolbox.title;const a=this.constructor.defaultWidgetConfig,s=this.constructor.widgetConfig;this.config=Object.assign(a,s)}render(){const e=[this.config.widget_name,this.randomString].join("-");return ws({setup:{label:this.label,widget_model:this.config.widget_model,src:this.config.data_src,widget_id:e,widget_type:this.config.widget_name,config:this.config}},this.data)}save(e){const r=JSON.parse(e.attributes["data-kubik-widget-data-value"].value);let a={};return this.config.tabs.forEach(s=>{a[s.name]=r[s.name]}),a}validate(e){return!0}}var Ts={KubikWidgetController:it,PluginFactory:Os,KubikAutocompleteController:w};return Ts});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubik-cms/wysiwyg",
|
|
3
|
+
"version": "0.1.8",
|
|
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/wysiwyg/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/kubik-cms/wysiwyg",
|
|
13
|
+
"private": false,
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git://github.com/kubik-cms/wysiwyg.git"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"main": "dist/wysiwyg.umd.js",
|
|
22
|
+
"module": "dist/wysiwyg.es.js",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"format": "prettier-standard '**/*.{ts,css,html}' --format",
|
|
25
|
+
"lint": "prettier-standard '**/*.{ts,css,html}' --lint",
|
|
26
|
+
"dev": "watch 'npm run build' src",
|
|
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
|
+
"jest": "^29.0.1",
|
|
34
|
+
"np": "^7.6.2",
|
|
35
|
+
"prettier-standard": "^16.4.1",
|
|
36
|
+
"typescript": "^4.8.2",
|
|
37
|
+
"vite": "^2.7.13",
|
|
38
|
+
"watch": "^1.0.2"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@hotwired/stimulus": "^3.0.1"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"deep-keys": "^0.5.0",
|
|
45
|
+
"deep-object-diff": "^1.1.9",
|
|
46
|
+
"lodash.set": "^4.3.2"
|
|
47
|
+
},
|
|
48
|
+
"description": "Wysiwyg for Kubik CMS"
|
|
49
|
+
}
|