@adobe/cq-angular-editable-components
Version:
* [API](#api) * [Documentation](#documentation) * [Changelog](#changelog)
2 lines • 7.95 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@adobe/cq-spa-component-mapping"),require("@adobe/cq-spa-page-model-manager"),require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("@adobe/cq-angular-editable-components",["exports","@adobe/cq-spa-component-mapping","@adobe/cq-spa-page-model-manager","@angular/core","@angular/common"],t):t((e.adobe=e.adobe||{},e.adobe["cq-angular-editable-components"]={}),null,null,e.ng.core,e.ng.common)}(this,function(e,t,o,n,a){"use strict";var r=function(){function e(e){this.spaMapping=e,this.editConfigMap=new WeakMap}return e.prototype.map=function(e,t,n){void 0===n&&(n=null);var o=t;n&&this.editConfigMap.set(t,n),this.spaMapping.map(e,o)},e.prototype.get=function(e){return this.spaMapping.get(e)},e.prototype.getEditConfig=function(e){return this.editConfigMap.get(e)},e}(),i=new r(t.ComponentMapping);var p={NEW_SECTION_CLASS_NAMES:"new section",TYPE_PROP:o.Constants.TYPE_PROP,ITEMS_PROP:o.Constants.ITEMS_PROP,ITEMS_ORDER_PROP:o.Constants.ITEMS_ORDER_PROP,PATH_PROP:o.Constants.PATH_PROP,CHILDREN_PROP:o.Constants.CHILDREN_PROP,DATA_PATH_PROP:":dataPath",HIERARCHY_TYPE_PROP:":hierarchyType"};var s={isInEditor:function(){var e,t=(e=document.head.querySelector('meta[property="cq:wcmmode"]'))&&e.content;return t&&("edit"===t||"preview"===t)}},c="cq-placeholder",l="cq-dd-",d=function(){function e(e,t,n,o){this.renderer=e,this.viewContainer=t,this.factoryResolver=n,this.ngZone=o}return e.prototype.ngOnInit=function(){this.renderComponent(i.get(this.type))},Object.defineProperty(e.prototype,"type",{get:function(){return this.cqModel&&this.cqModel[":type"]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"columnClasses",{get:function(){return this.cqModel&&(this.cqModel.columnClassNames||"")},enumerable:!0,configurable:!0}),e.prototype.updateCqModel=function(){var n=this;this.getCqModel().then(function(t){n.ngZone.run(function(){t[p.DATA_PATH_PROP]=n.path,n.cqModel=t,n.updateComponentData(),n.setupElement();var e=i.getEditConfig(i.get(n.type));e&&n.setupPlaceholder(e)})})},e.prototype.getCqModel=function(){return o.PageModelManager.getData({pagePath:this.pagePath,dataPath:this.path})},e.prototype.renderComponent=function(e){if(e){var t=this.factoryResolver.resolveComponentFactory(e);this.viewContainer.clear(),this._component=this.viewContainer.createComponent(t),this.updateComponentData(),this.setupElement();var n=i.getEditConfig(e);n&&s.isInEditor&&this.setupPlaceholder(n),o.PageModelManager.removeListener({pagePath:this.pagePath,dataPath:this.path,callback:this.updateCqModel.bind(this)}),o.PageModelManager.addListener({pagePath:this.pagePath,dataPath:this.path,callback:this.updateCqModel.bind(this)})}},e.prototype.updateComponentData=function(){this._component.instance.cqModel=this.cqModel,this._component.instance.path=this.path,this._component.instance.pagePath=this.pagePath,this._component.instance.modelName=this.modelName},e.prototype.setupElement=function(){var t=this;this._oldClasses&&this._oldClasses.split(" ").forEach(function(e){t.renderer.removeClass(t._component.location.nativeElement,e)});(this._oldClasses=this.columnClasses,this.columnClasses)&&this.columnClasses.split(" ").forEach(function(e){t.renderer.addClass(t._component.location.nativeElement,e)});this.path&&this.renderer.setAttribute(this._component.location.nativeElement,"data-cq-data-path",this.path)},e.prototype.setupPlaceholder=function(e){this.renderer.removeClass(this._component.location.nativeElement,l+e.dragDropName),e.dragDropName&&0<e.dragDropName.trim().length&&this.renderer.addClass(this._component.location.nativeElement,l+e.dragDropName),this.usePlaceholder(e)?(this.renderer.addClass(this._component.location.nativeElement,c),this._component.location.nativeElement.dataset.emptytext=e.emptyLabel):(this.renderer.removeClass(this._component.location.nativeElement,c),delete this._component.location.nativeElement.dataset.emptytext)},e.prototype.usePlaceholder=function(e){return e.isEmpty&&"function"==typeof e.isEmpty&&e.isEmpty(this.cqModel)},e.prototype.ngOnDestroy=function(){o.PageModelManager.removeListener({pagePath:this.pagePath,dataPath:this.path,callback:this.updateCqModel.bind(this)}),this._component&&this._component.destroy()},e.decorators=[{type:n.Directive,args:[{selector:"[aemComponent]"}]}],e.ctorParameters=function(){return[{type:n.Renderer2},{type:n.ViewContainerRef},{type:n.ComponentFactoryResolver},{type:n.NgZone}]},e.propDecorators={cqModel:[{type:n.Input}],path:[{type:n.Input}],pagePath:[{type:n.Input}],modelName:[{type:n.Input}],aemComponent:[{type:n.Input}]},e}(),h=function(){function e(){this.path="",this.pagePath="",this.modelName=""}return e.prototype.getDataPath=function(e){return this.path?this.path+"/"+e:e},e.prototype.getPagePath=function(){return this.cqModel[p.PATH_PROP]||this.pagePath},e.prototype.getItem=function(e){return this.cqModel[p.ITEMS_PROP][e]},Object.defineProperty(e.prototype,"itemsOrder",{get:function(){return this.cqModel&&this.cqModel[p.ITEMS_ORDER_PROP]},enumerable:!0,configurable:!0}),e.decorators=[{type:n.Component,args:[{selector:"aem-container",host:{"[attr.data-cq-data-path]":"path"},template:"<ng-container *ngFor=\"let itemKey of itemsOrder\">\n <ng-container [aemComponent] [cqModel]='getItem(itemKey)' [pagePath]='getPagePath()' [path]='getDataPath(itemKey)' [modelName]='itemKey'></ng-container>\n</ng-container>\n"}]}],e.ctorParameters=function(){return[]},e.propDecorators={cqModel:[{type:n.Input}],path:[{type:n.Input}],pagePath:[{type:n.Input}],modelName:[{type:n.Input}]},e}(),m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};var u=p.NEW_SECTION_CLASS_NAMES+" aem-Grid-newComponent",g=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function(e,t){function n(){this.constructor=e}m(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),Object.defineProperty(t.prototype,"isInEditMode",{get:function(){return s.isInEditor()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"placeholderClass",{get:function(){return u},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"placeholdePath",{get:function(){return this.path&&this.path+"/*"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"gridClasses",{get:function(){return this.cqModel&&(this.cqModel.gridClassNames||"")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"classNames",{get:function(){if(!this.cqModel)return"";var e="aem-container";return this.cqModel.classNames&&(e+=" "+(this.cqModel.classNames||"")),this.cqModel.columnClassNames&&(e+=" "+(this.cqModel.columnClassNames||"")),e},enumerable:!0,configurable:!0}),t.decorators=[{type:n.Component,args:[{selector:"aem-responsivegrid",host:{"[class]":"classNames","[attr.data-cq-data-path]":"path"},template:'<div [class]="gridClasses">\n <ng-container *ngFor="let itemKey of itemsOrder">\n <ng-container [aemComponent] [cqModel]=\'getItem(itemKey)\' [pagePath]=\'getPagePath()\' [path]=\'getDataPath(itemKey)\' [modelName]=\'itemKey\'></ng-container>\n </ng-container>\n <div *ngIf="isInEditMode" [attr.data-cq-data-path]="placeholdePath" [class]="placeholderClass"></div>\n</div>\n'}]}],t}(h),f=function(){function e(){}return e.decorators=[{type:n.NgModule,args:[{imports:[a.CommonModule],declarations:[h,g,d],exports:[h,g,d]}]}],e}();e.AEMComponentDirective=d,e.AEMContainerComponent=h,e.AEMResponsiveGridComponent=g,e.ComponentMappingWithConfig=r,e.ComponentMapping=i,e.MapTo=function(n){return function(e,t){return void 0===t&&(t=null),i.map(n,e,t)}},e.Constants=p,e.Utils=s,e.SpaAngularEditableComponentsModule=f,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=adobe-cq-angular-editable-components.umd.min.js.map