@claspo/renderer 18.9.2 → 18.10.0-dsp1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.9.2",
3
+ "version": "18.10.0-dsp1",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
@@ -15,7 +15,7 @@
15
15
  "node": ">=18.16.0"
16
16
  },
17
17
  "dependencies": {
18
- "@claspo/common": "7.5.1",
18
+ "@claspo/common": "7.5.1-dsp1",
19
19
  "@testing-library/dom": "^10.4.0"
20
20
  },
21
21
  "devDependencies": {
@@ -6,7 +6,8 @@ export default class PrizePool {
6
6
  randomDistributor: any;
7
7
  constructor(config: any, httpClient: any, configService: any);
8
8
  load(): Promise<void>;
9
- _fetchReward(url: any, options: any): Promise<any>;
9
+ _fetchReward(url: any, options: any, prizePoolId: any): Promise<any>;
10
+ _resolveReward(reward: any, options: any, prizePoolId: any): any;
10
11
  _mergeRewardIntoOption(reward: any, options: any): any;
11
12
  _fetchPool(url: string, prizePoolId: string): Promise<any>;
12
13
  _fetchJson(url: any, headers?: any): Promise<any>;
@@ -1 +1 @@
1
- import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";import{PrizeCodeType,PrizeOptionValueType,PrizeSourceType}from"@claspo/common/PrizePool.interface";import{PreviewMode}from"../sdk/PreviewMode";import ErrorLogger from"../error/ErrorLogger";const FETCHABLE_SOURCE_TYPES=[PrizeSourceType.MANUAL,PrizeSourceType.SHOPIFY],drawnPrizeCodePlaceholder="CLXXXXXXXX";export default class PrizePool{constructor(e,i,o){if(this.httpClient=i,this.configService=o,this.instanceModel=e||{},"FIXED"!==this.instanceModel.model){const e=this.configService.getConfig("prizePoolModels");if(e&&this.instanceModel.id){const i=e.find(e=>e.id===this.instanceModel.id);i&&(this.instanceModel=i)}}this.prizeOption=null,this.randomDistributor=new RandomDistributor}async load(){const{id:e,model:i,sourceType:o,options:t}=this.instanceModel;if(!(!t&&!!e&&"FIXED"!==i&&(!o||FETCHABLE_SOURCE_TYPES.includes(o))))return;const n=this.configService.getConfig("widgetId");try{const i=this.configService.getConfig("hostUrl"),t=`${i}forms/v2/prize/pool/${e}`,r=`${i}forms/v1/prizePool/${e}/reward?widgetId=${n}`;if(this._isPreview()){const i=await this._fetchPool(t,e);if(this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:o||i.sourceType,options:i.options}),this._mintsCodePerWinner(i.options))return;return void(this.prizeOption=await this._fetchReward(r,i.options))}const[s,a]=await Promise.all([this._fetchPool(t,e),this._fetchJson(r,{"cl-customer-id":this.configService.getConfig("clCustomerId")})]);this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:o||s.sourceType,options:s.options}),this.prizeOption=this._mergeRewardIntoOption(a,s.options)}catch(i){throw console.error(`PrizePool: failed to load pool or reward for widgetId "${n}" with poolId "${e}"`,i),i}}async _fetchReward(e,i){const o=await this._fetchJson(e,{"cl-customer-id":this.configService.getConfig("clCustomerId")});return this._mergeRewardIntoOption(o,i)}_mergeRewardIntoOption(e,i){return Object.assign(Object.assign({},i.find(i=>i.id===e.id)),e)}async _fetchPool(e,i){const o=await this._fetchJson(e);if(!1===(null==o?void 0:o.available))throw ErrorLogger.log(`PrizePool: the pool ${i} is not available and cannot be handed out with a reason "${o.unavailableReason}"`),new Error("PrizePool: the pool is not available and cannot be handed out");return o}async _fetchJson(e,i){const o=await this.httpClient.execute({url:e,headers:i});if(!o.ok)throw new Error(`PrizePool: request failed with status ${o.status} - ${e}`);return o.json()}getModel(){return this.instanceModel}async getPrize(){return this.instanceModel?"FIXED"===this.instanceModel.model?this.instanceModel.data:FETCHABLE_SOURCE_TYPES.includes(this.instanceModel.sourceType)?(this.instanceModel.options&&!this.prizeOption&&(this.prizeOption=this._calculatePrize()),this.prizeOption?this.mapPrizeOption(this.prizeOption):null):null:null}submitPrize(){}mapPrizeOption(e){const i=e.valueType===PrizeOptionValueType.PROMOCODE?e.value||"":this._mapLabelSuffix(e.value,e.valueType);return{id:e.id,label:i,value:e.code}}_calculatePrize(){const e=sum(this.instanceModel.options.map(e=>parseFloat(e.weight))),i=this.randomDistributor.calculateFromWeights(this.instanceModel.options,e);return i&&this._isCodeMintedPerWinner(i)?Object.assign(Object.assign({},i),{code:"CLXXXXXXXX"}):i}_mintsCodePerWinner(e){return(e||[]).some(e=>this._isCodeMintedPerWinner(e))}_isPreview(){return!!(this.configService.getConfig(PreviewMode.CABINET_PREVIEW)||this.configService.getConfig(PreviewMode.EDITOR_PREVIEW)||this.configService.getConfig(PreviewMode.DEMO))}_isCodeMintedPerWinner(e){var i;return(null===(i=null==e?void 0:e.config)||void 0===i?void 0:i.codeType)===PrizeCodeType.UNIQUE}_mapLabelSuffix(e,i){return i===PrizeOptionValueType.DISCOUNT_PERCENTAGE?`${e}%`:e}}
1
+ import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";import{PrizeCodeType,PrizeOptionValueType,PrizeSourceType}from"@claspo/common/PrizePool.interface";import{PreviewMode}from"../sdk/PreviewMode";import ErrorLogger from"../error/ErrorLogger";const FETCHABLE_SOURCE_TYPES=[PrizeSourceType.MANUAL,PrizeSourceType.SHOPIFY],drawnPrizeCodePlaceholder="CLXXXXXXXX";export default class PrizePool{constructor(e,o,i){if(this.httpClient=o,this.configService=i,this.instanceModel=e||{},"FIXED"!==this.instanceModel.model){const e=this.configService.getConfig("prizePoolModels");if(e&&this.instanceModel.id){const o=e.find(e=>e.id===this.instanceModel.id);o&&(this.instanceModel=o)}}this.prizeOption=null,this.randomDistributor=new RandomDistributor}async load(){const{id:e,model:o,sourceType:i,options:t}=this.instanceModel;if(!(!t&&!!e&&"FIXED"!==o&&(!i||FETCHABLE_SOURCE_TYPES.includes(i))))return;const r=this.configService.getConfig("widgetId");try{const o=this.configService.getConfig("hostUrl"),t=`${o}forms/v2/prize/pool/${e}`,n=`${o}forms/v1/prizePool/${e}/reward?widgetId=${r}`;if(this._isPreview()){const o=await this._fetchPool(t,e);if(this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:i||o.sourceType,options:o.options}),this._mintsCodePerWinner(o.options))return;return void(this.prizeOption=await this._fetchReward(n,o.options,e))}const[s,a]=await Promise.all([this._fetchPool(t,e),this._fetchJson(n,{"cl-customer-id":this.configService.getConfig("clCustomerId")})]);this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:i||s.sourceType,options:s.options}),this.prizeOption=this._resolveReward(a,s.options,e)}catch(o){throw console.error(`PrizePool: failed to load pool or reward for widgetId "${r}" with poolId "${e}"`,o),o}}async _fetchReward(e,o,i){const t=await this._fetchJson(e,{"cl-customer-id":this.configService.getConfig("clCustomerId")});return this._resolveReward(t,o,i)}_resolveReward(e,o,i){const t=this._mergeRewardIntoOption(e,o);if(null==e?void 0:e.unavailableReason)throw ErrorLogger.log(`PrizePool: the reward from pool ${i} cannot be handed out with a reason "${e.unavailableReason}"`),new Error("PrizePool: the reward cannot be handed out");if(t.valueType===PrizeOptionValueType.PROMOCODE&&!t.code)throw ErrorLogger.log(`PrizePool: the reward from pool ${i} came back without a promo code`),new Error("PrizePool: the reward cannot be handed out");return t}_mergeRewardIntoOption(e,o){return Object.assign(Object.assign({},o.find(o=>o.id===e.id)),e)}async _fetchPool(e,o){const i=await this._fetchJson(e);if(!1===(null==i?void 0:i.available))throw ErrorLogger.log(`PrizePool: the pool ${o} is not available and cannot be handed out with a reason "${i.unavailableReason}"`),new Error("PrizePool: the pool is not available and cannot be handed out");return i}async _fetchJson(e,o){const i=await this.httpClient.execute({url:e,headers:o});if(!i.ok)throw new Error(`PrizePool: request failed with status ${i.status} - ${e}`);return i.json()}getModel(){return this.instanceModel}async getPrize(){return this.instanceModel?"FIXED"===this.instanceModel.model?this.instanceModel.data:FETCHABLE_SOURCE_TYPES.includes(this.instanceModel.sourceType)?(this.instanceModel.options&&!this.prizeOption&&(this.prizeOption=this._calculatePrize()),this.prizeOption?this.mapPrizeOption(this.prizeOption):null):null:null}submitPrize(){}mapPrizeOption(e){const o=e.valueType===PrizeOptionValueType.PROMOCODE?e.value||"":this._mapLabelSuffix(e.value,e.valueType);return{id:e.id,label:o,value:e.code}}_calculatePrize(){const e=sum(this.instanceModel.options.map(e=>parseFloat(e.weight))),o=this.randomDistributor.calculateFromWeights(this.instanceModel.options,e);return o&&this._isCodeMintedPerWinner(o)?Object.assign(Object.assign({},o),{code:"CLXXXXXXXX"}):o}_mintsCodePerWinner(e){return(e||[]).some(e=>this._isCodeMintedPerWinner(e))}_isPreview(){return!!(this.configService.getConfig(PreviewMode.CABINET_PREVIEW)||this.configService.getConfig(PreviewMode.EDITOR_PREVIEW)||this.configService.getConfig(PreviewMode.DEMO))}_isCodeMintedPerWinner(e){var o;return(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.codeType)===PrizeCodeType.UNIQUE}_mapLabelSuffix(e,o){return o===PrizeOptionValueType.DISCOUNT_PERCENTAGE?`${e}%`:e}}
@@ -21,6 +21,9 @@ export default function wcUpdatingDecorator(clazz: any): {
21
21
  _elementClickListener(event: any, inlineEdit: any): void;
22
22
  _elementDoubleClickListener(event: any): void;
23
23
  _elementDragStartListener(event: any): void;
24
+ _createDragPreviewPlaceholder(hostElementCoords: any): HTMLDivElement;
25
+ _isWidgetRotated(sharedModel: any, isDesktop: any): boolean;
26
+ _getFloatingBoxParams(sharedModel: any, isDesktop: any): any;
24
27
  _elementDragEndListener(event: any): void;
25
28
  _elementDragOverListener(event: any): void;
26
29
  _documentDropListener(event: any): void;
@@ -1 +1 @@
1
- import ViewEntryType from"../../document-model/ViewEntryType";import{WidgetToEditorEventType}from"../../renderer/WidgetToEditorEventType";import ComponentType from"../../sdk/ComponentType";import{applySysAttrPrefix,applySysClassPrefix}from"../../renderer/RenderConstants";import getParentHostElement from"../../sdk/getParentHostElement";import debounce from"@claspo/common/async/debounce";import wcStaticDecorator from"./wcStaticDecorator";import{EditorToWidgetEventType}from"../../document-model/DocumentModelService";export default function wcUpdatingDecorator(e){return class extends(wcStaticDecorator(e)){constructor(){super(),this.eventListeners=[],this.lastDragOverEvent=null,this.focusedElements=[],this.observer=null,this._observeChanges()}connectedCallback(){super.connectedCallback(),this._addAllListeners()}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),this._deactivateEventListeners(),null===(e=this.removeFocusSubscription)||void 0===e||e.off(),null===(t=this.setFocusSubscription)||void 0===t||t.off(),null===(s=this.componentFocusedSubscription)||void 0===s||s.off(),this.observer.disconnect()}_addAllListeners(){this.observer.observe(this.getRootElement(),{childList:!0,subtree:!0}),this.model.type===ViewEntryType.VIEW&&(this.eventListeners.push({eventName:"mousemove",callback:this._mouseMoveEventListener.bind(this),element:this}),this.eventListeners.push({eventName:"mouseout",callback:this._mouseOutEventListener.bind(this),element:this})),this.removeFocusSubscription=this.services.eventEmitter.on(EditorToWidgetEventType.REMOVE_FOCUS,()=>{this._removeFocus()}),this.setFocusSubscription=this.services.eventEmitter.on(EditorToWidgetEventType.SET_FOCUS,e=>{this._removeFocus(),this.model.id===e&&this._setFocus("host")}),this.componentFocusedSubscription=this.services.eventEmitter.on(WidgetToEditorEventType.COMPONENT_FOCUSED,({id:e,targetElementName:t})=>{this._removeFocus(),this.model.id===e&&this._setFocus(t)}),this.manifest.preventDraggable||this.getHostElement().setAttribute("draggable","true"),this._setElementListeners(this.getHostElement()),this._setGlobalListeners(),this._setEventListeners(),this._activateEventListeners(),this._setFocusableElementsAttribute()}_observeChanges(){let e={addded:!1,removed:!1};const t=debounce(()=>{e.removed&&this._removeListenersForDisconnectedNodes(),e.addded&&(this._setEventListeners(),this._activateEventListeners(),this._setFocusableElementsAttribute(),this._updateFocusedElementClasses()),e={addded:!1,removed:!1}},500);this.observer=new MutationObserver(function(s){for(let i of s){for(let t of i.addedNodes)t instanceof HTMLElement&&"STYLE"!==t.nodeName&&!e.addded&&(e=Object.assign(Object.assign({},e),{addded:!0}));for(let t of i.removedNodes)t instanceof HTMLElement&&"STYLE"!==t.nodeName&&!e.removed&&(e=Object.assign(Object.assign({},e),{removed:!0}));t()}})}_setEventListeners(){this.getRootElement().querySelectorAll("[cl-inline-edit], [cl-inline-edit] *").forEach(e=>{this._isEventListenerPresent(e)||"STYLE"!==e.tagName&&(e.getAttribute("draggable")||e.setAttribute("draggable","true"),this._setElementListeners(e,!0))}),this.getRootElement().querySelectorAll(":not([cl-inline-edit]):not([cl-type]):not([cl-inline-edit] *)").forEach(e=>{if(!this._isEventListenerPresent(e)&&"STYLE"!==e.tagName){if(e.getAttribute("draggable")||e.setAttribute("draggable","true"),e instanceof HTMLElement){const t=e.tagName.toLowerCase();"input"!==t&&"textarea"!==t||"readonly"===!e.getAttribute("readonly")||e.setAttribute("readonly","readonly"),this.manifest.componentType===ComponentType.VIDEO&&e.classList.contains("video-overlay")&&(e.style.visibility="visible")}this._setElementListeners(e)}})}_removeListenersForDisconnectedNodes(){this.eventListeners=this.eventListeners.filter(e=>(e.element.isConnected||e.element.removeEventListener(e.eventName,e.callback),e.element.isConnected))}_setGlobalListeners(){this.eventListeners.push({eventName:"drop",callback:e=>this._documentDropListener(e),element:document})}_isEventListenerPresent(e){return!!this.eventListeners.find(t=>t.element===e)}_setElementListeners(e,t){[{eventName:"click",callback:e=>this._elementClickListener(e,t),element:e},{eventName:"dblclick",callback:this._elementDoubleClickListener.bind(this),element:e},{eventName:"dragstart",callback:this._elementDragStartListener.bind(this),element:e},{eventName:"dragend",callback:this._elementDragEndListener.bind(this),element:e},{eventName:"dragover",callback:this._elementDragOverListener.bind(this),element:e},{eventName:"blur",callback:this._blurEventListener.bind(this),element:e,useCapture:!0}].forEach(e=>this.eventListeners.push(e))}_elementClickListener(e,t){e.preventDefault(),e.stopImmediatePropagation();const s=e.composedPath()[0],i=this.getHostElement();if(t&&this.services.eventEmitter.emit(WidgetToEditorEventType.SHOW_INLINE_EDIT,{id:this.model.id,hostElement:i,targetElement:s}),this.model.focusParentOnClick){const e=getParentHostElement(i);this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_FOCUSED,{id:e.getAttribute(applySysAttrPrefix("id")),hostElement:e,targetElement:e,targetElementName:"host"})}else{const e=this.focusedElements.length>0,t=e?this._getElementNameByNode(s):"host";this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_FOCUSED,{id:this.model.id,hostElement:i,targetElement:e?s:i,targetElementName:t})}this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_CLICKED,e)}_elementDoubleClickListener(e){e.preventDefault(),e.stopImmediatePropagation(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DOUBLE_CLICKED,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0]})}_elementDragStartListener(e){e.stopPropagation();this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGSTART,{id:this.model.id,path:this.model.path,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e,checkIfAllowed:t=>{t||(e.preventDefault(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGEND))}})}_elementDragEndListener(e){e.stopPropagation(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGEND,{id:this.model.id,path:this.model.path,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e})}_elementDragOverListener(e){e.preventDefault(),e.stopPropagation();const t=this.lastDragOverEvent;this.lastDragOverEvent=e,e.pageX&&e.pageY&&(t&&t.clientY===e.clientY&&t.clientX===e.clientX||this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGOVER,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e}))}_documentDropListener(e){this.services.eventEmitter.emit(WidgetToEditorEventType.DOCUMENT_DROP,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e})}_mouseMoveEventListener(e){const t=this._findClosestHostElement(e.composedPath());if(this.preHoveredElement&&this.preHoveredElement!==t&&this.preHoveredElement.classList.remove(applySysClassPrefix("hovered")),this.preHoveredElement=t,t){t.classList.add(applySysClassPrefix("hovered"));const s={id:t.getAttribute(applySysAttrPrefix("id")),hostElement:t,targetElement:e.composedPath()[0],event:e};this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_MOUSE_MOVE,s)}}_mouseOutEventListener(e){e.stopPropagation();const t=this._findClosestHostElement(e.composedPath());t&&t.classList.remove(applySysClassPrefix("hovered"))}_blurEventListener(e){e.stopImmediatePropagation()}_removeFocus(){this.focusedElements.length&&this.focusedElements.forEach(e=>{var t;return null===(t=e.classList)||void 0===t?void 0:t.remove(applySysClassPrefix("focused"))}),this.focusedElements=[]}_setFocus(e){const t=this.getHostElement();if(this.focusedElements=[t],t.classList.add(applySysClassPrefix("focused")),"host"!==e){const t=this.getElements().filter(t=>t.getAttribute(applySysAttrPrefix("element"))===e);t.forEach(e=>e.classList.add(applySysClassPrefix("focused"))),this.focusedElements=this.focusedElements.concat(t)}}_findClosestHostElement(e){const t=e.filter(e=>e instanceof HTMLElement).filter(e=>!!e.getAttribute(applySysAttrPrefix("component")));return t.length?t[0]:null}_activateEventListeners(){this.eventListeners.forEach(e=>{e.activated||(e.element.addEventListener(e.eventName,e.callback,e.useCapture),e.activated=!0)})}_deactivateEventListeners(){this.eventListeners.forEach(e=>{e.element.removeEventListener(e.eventName,e.callback)}),this.eventListeners=[]}_getElementNameByNode(e){var t;const s="host";if(!e)return s;const i=e.closest(`[${applySysAttrPrefix("element")}]`);if(!i)return s;const n=i.getAttribute(applySysAttrPrefix("element"));return"host"===n||(null===(t=this.manifest.focusableElements)||void 0===t?void 0:t.includes(n))?n:s}_setFocusableElementsAttribute(){this.getElements().forEach(e=>{var t;(null===(t=this.manifest.focusableElements)||void 0===t?void 0:t.includes(e.getAttribute(applySysAttrPrefix("element"))))&&e.setAttribute(applySysAttrPrefix("focusable-element"),"")})}_updateFocusedElementClasses(){if(this.focusedElements.length<2)return;const e=this.focusedElements.find(e=>e.hasAttribute(applySysAttrPrefix("focusable-element")));e&&this._setFocus(e.getAttribute(applySysAttrPrefix("element")))}}}
1
+ import ViewEntryType from"../../document-model/ViewEntryType";import{WidgetToEditorEventType}from"../../renderer/WidgetToEditorEventType";import ComponentType from"../../sdk/ComponentType";import{applySysAttrPrefix,applySysClassPrefix}from"../../renderer/RenderConstants";import getParentHostElement from"../../sdk/getParentHostElement";import debounce from"@claspo/common/async/debounce";import wcStaticDecorator from"./wcStaticDecorator";import{EditorToWidgetEventType}from"../../document-model/DocumentModelService";export default function wcUpdatingDecorator(e){return class extends(wcStaticDecorator(e)){constructor(){super(),this.eventListeners=[],this.lastDragOverEvent=null,this.focusedElements=[],this.observer=null,this._observeChanges()}connectedCallback(){super.connectedCallback(),this._addAllListeners()}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),this._deactivateEventListeners(),null===(e=this.removeFocusSubscription)||void 0===e||e.off(),null===(t=this.setFocusSubscription)||void 0===t||t.off(),null===(s=this.componentFocusedSubscription)||void 0===s||s.off(),this.observer.disconnect()}_addAllListeners(){this.observer.observe(this.getRootElement(),{childList:!0,subtree:!0}),this.model.type===ViewEntryType.VIEW&&(this.eventListeners.push({eventName:"mousemove",callback:this._mouseMoveEventListener.bind(this),element:this}),this.eventListeners.push({eventName:"mouseout",callback:this._mouseOutEventListener.bind(this),element:this})),this.removeFocusSubscription=this.services.eventEmitter.on(EditorToWidgetEventType.REMOVE_FOCUS,()=>{this._removeFocus()}),this.setFocusSubscription=this.services.eventEmitter.on(EditorToWidgetEventType.SET_FOCUS,e=>{this._removeFocus(),this.model.id===e&&this._setFocus("host")}),this.componentFocusedSubscription=this.services.eventEmitter.on(WidgetToEditorEventType.COMPONENT_FOCUSED,({id:e,targetElementName:t})=>{this._removeFocus(),this.model.id===e&&this._setFocus(t)}),this.manifest.preventDraggable||this.getHostElement().setAttribute("draggable","true"),this._setElementListeners(this.getHostElement()),this._setGlobalListeners(),this._setEventListeners(),this._activateEventListeners(),this._setFocusableElementsAttribute()}_observeChanges(){let e={addded:!1,removed:!1};const t=debounce(()=>{e.removed&&this._removeListenersForDisconnectedNodes(),e.addded&&(this._setEventListeners(),this._activateEventListeners(),this._setFocusableElementsAttribute(),this._updateFocusedElementClasses()),e={addded:!1,removed:!1}},500);this.observer=new MutationObserver(function(s){for(let i of s){for(let t of i.addedNodes)t instanceof HTMLElement&&"STYLE"!==t.nodeName&&!e.addded&&(e=Object.assign(Object.assign({},e),{addded:!0}));for(let t of i.removedNodes)t instanceof HTMLElement&&"STYLE"!==t.nodeName&&!e.removed&&(e=Object.assign(Object.assign({},e),{removed:!0}));t()}})}_setEventListeners(){this.getRootElement().querySelectorAll("[cl-inline-edit], [cl-inline-edit] *").forEach(e=>{this._isEventListenerPresent(e)||"STYLE"!==e.tagName&&(e.getAttribute("draggable")||e.setAttribute("draggable","true"),this._setElementListeners(e,!0))}),this.getRootElement().querySelectorAll(":not([cl-inline-edit]):not([cl-type]):not([cl-inline-edit] *)").forEach(e=>{if(!this._isEventListenerPresent(e)&&"STYLE"!==e.tagName){if(e.getAttribute("draggable")||e.setAttribute("draggable","true"),e instanceof HTMLElement){const t=e.tagName.toLowerCase();"input"!==t&&"textarea"!==t||"readonly"===!e.getAttribute("readonly")||e.setAttribute("readonly","readonly"),this.manifest.componentType===ComponentType.VIDEO&&e.classList.contains("video-overlay")&&(e.style.visibility="visible")}this._setElementListeners(e)}})}_removeListenersForDisconnectedNodes(){this.eventListeners=this.eventListeners.filter(e=>(e.element.isConnected||e.element.removeEventListener(e.eventName,e.callback),e.element.isConnected))}_setGlobalListeners(){this.eventListeners.push({eventName:"drop",callback:e=>this._documentDropListener(e),element:document})}_isEventListenerPresent(e){return!!this.eventListeners.find(t=>t.element===e)}_setElementListeners(e,t){[{eventName:"click",callback:e=>this._elementClickListener(e,t),element:e},{eventName:"dblclick",callback:this._elementDoubleClickListener.bind(this),element:e},{eventName:"dragstart",callback:this._elementDragStartListener.bind(this),element:e},{eventName:"dragend",callback:this._elementDragEndListener.bind(this),element:e},{eventName:"dragover",callback:this._elementDragOverListener.bind(this),element:e},{eventName:"blur",callback:this._blurEventListener.bind(this),element:e,useCapture:!0}].forEach(e=>this.eventListeners.push(e))}_elementClickListener(e,t){e.preventDefault(),e.stopImmediatePropagation();const s=e.composedPath()[0],i=this.getHostElement();if(t&&this.services.eventEmitter.emit(WidgetToEditorEventType.SHOW_INLINE_EDIT,{id:this.model.id,hostElement:i,targetElement:s}),this.model.focusParentOnClick){const e=getParentHostElement(i);this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_FOCUSED,{id:e.getAttribute(applySysAttrPrefix("id")),hostElement:e,targetElement:e,targetElementName:"host"})}else{const e=this.focusedElements.length>0,t=e?this._getElementNameByNode(s):"host";this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_FOCUSED,{id:this.model.id,hostElement:i,targetElement:e?s:i,targetElementName:t})}this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_CLICKED,e)}_elementDoubleClickListener(e){e.preventDefault(),e.stopImmediatePropagation(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DOUBLE_CLICKED,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0]})}_elementDragStartListener(e){e.stopPropagation();const t=e.composedPath().find(e=>{var t;return null===(t=e.hasAttribute)||void 0===t?void 0:t.call(e,applySysAttrPrefix("type"))}),s=t.getAttribute(applySysAttrPrefix("type"));this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGSTART,{id:this.model.id,path:this.model.path,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e,checkIfAllowed:i=>{if(i){const i=t.getBoundingClientRect();if(this._isWidgetRotated(this.documentModel.getShared(),!this.resizeListener.isMobile())){const s=e.pageX-i.left-window.pageXOffset,n=e.pageY-i.top-window.pageYOffset;if(navigator.userAgent.match(/Firefox/i)){const i=t.style.transform,o=t.style.transformOrigin;t.style.transform="rotate(-90deg)",t.style.transformOrigin="left top",e.dataTransfer.setDragImage(t,s,n),requestAnimationFrame(()=>{t.style.transform=i,t.style.transformOrigin=o})}else{const t=this._createDragPreviewPlaceholder(i);document.body.appendChild(t),e.dataTransfer.setDragImage(t,s,n),setTimeout(()=>{t.remove()})}}else e.dataTransfer.setDragImage(t,e.pageX-i.left-window.pageXOffset,e.pageY-i.top-window.pageYOffset);if(s===ViewEntryType.SLIDER){const s=t.shadowRoot.querySelector(".slides-container"),n=new WebKitCSSMatrix(getComputedStyle(s).transform).m41;e.dataTransfer.setDragImage(t,e.pageX-i.left-n-window.pageXOffset,e.pageY-i.top-window.pageYOffset)}}else e.preventDefault(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGEND)}})}_createDragPreviewPlaceholder(e){const t=document.createElement("div");return t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.background="rgba(159, 41, 176, 0.3)",t.style.display="flex",t.style.justifyContent="center",t.style.alignItems="center",t.innerHTML='<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">\n<g opacity="0.6" clip-path="url(#clip0_43446_120564)">\n<path d="M26.5566 11.7573L30.7993 16L26.5566 20.2426" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M20.2422 26.5564L15.9995 30.799L11.7569 26.5564" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M5.44336 20.2426L1.20072 16L5.44336 11.7573" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M11.7569 5.4436L15.9995 1.20096L20.2422 5.4436" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M30.7994 16H20.8999" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M15.9995 30.7989L15.9995 20.8994" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M1.20064 16H11.1001" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n<path d="M15.9995 1.20113L15.9995 11.1006" stroke="#50005B" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n</g>\n<defs>\n<clipPath id="clip0_43446_120564">\n<rect width="32" height="32" fill="white"/>\n</clipPath>\n</defs>\n</svg>',t.firstChild.style.width=.4*e.width+"px",t.firstChild.style.height=.4*e.height+"px",t}_isWidgetRotated(e,t){const s=this._getFloatingBoxParams(e,t);return!!s&&"CENTER"===s.verticalPosition}_getFloatingBoxParams(e,t){return e&&e.floatingBox?t?e.floatingBox:e.floatingBox.mobile:null}_elementDragEndListener(e){e.stopPropagation(),this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGEND,{id:this.model.id,path:this.model.path,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e})}_elementDragOverListener(e){e.preventDefault(),e.stopPropagation();const t=this.lastDragOverEvent;this.lastDragOverEvent=e,e.pageX&&e.pageY&&(t&&t.clientY===e.clientY&&t.clientX===e.clientX||this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_DRAGOVER,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e}))}_documentDropListener(e){this.services.eventEmitter.emit(WidgetToEditorEventType.DOCUMENT_DROP,{id:this.model.id,hostElement:this.getHostElement(),targetElement:e.composedPath()[0],event:e})}_mouseMoveEventListener(e){const t=this._findClosestHostElement(e.composedPath());if(this.preHoveredElement&&this.preHoveredElement!==t&&this.preHoveredElement.classList.remove(applySysClassPrefix("hovered")),this.preHoveredElement=t,t){t.classList.add(applySysClassPrefix("hovered"));const s={id:t.getAttribute(applySysAttrPrefix("id")),hostElement:t,targetElement:e.composedPath()[0],event:e};this.services.eventEmitter.emit(WidgetToEditorEventType.COMPONENT_MOUSE_MOVE,s)}}_mouseOutEventListener(e){e.stopPropagation();const t=this._findClosestHostElement(e.composedPath());t&&t.classList.remove(applySysClassPrefix("hovered"))}_blurEventListener(e){e.stopImmediatePropagation()}_removeFocus(){this.focusedElements.length&&this.focusedElements.forEach(e=>{var t;return null===(t=e.classList)||void 0===t?void 0:t.remove(applySysClassPrefix("focused"))}),this.focusedElements=[]}_setFocus(e){const t=this.getHostElement();if(this.focusedElements=[t],t.classList.add(applySysClassPrefix("focused")),"host"!==e){const t=this.getElements().filter(t=>t.getAttribute(applySysAttrPrefix("element"))===e);t.forEach(e=>e.classList.add(applySysClassPrefix("focused"))),this.focusedElements=this.focusedElements.concat(t)}}_findClosestHostElement(e){const t=e.filter(e=>e instanceof HTMLElement).filter(e=>!!e.getAttribute(applySysAttrPrefix("component")));return t.length?t[0]:null}_activateEventListeners(){this.eventListeners.forEach(e=>{e.activated||(e.element.addEventListener(e.eventName,e.callback,e.useCapture),e.activated=!0)})}_deactivateEventListeners(){this.eventListeners.forEach(e=>{e.element.removeEventListener(e.eventName,e.callback)}),this.eventListeners=[]}_getElementNameByNode(e){var t;const s="host";if(!e)return s;const i=e.closest(`[${applySysAttrPrefix("element")}]`);if(!i)return s;const n=i.getAttribute(applySysAttrPrefix("element"));return"host"===n||(null===(t=this.manifest.focusableElements)||void 0===t?void 0:t.includes(n))?n:s}_setFocusableElementsAttribute(){this.getElements().forEach(e=>{var t;(null===(t=this.manifest.focusableElements)||void 0===t?void 0:t.includes(e.getAttribute(applySysAttrPrefix("element"))))&&e.setAttribute(applySysAttrPrefix("focusable-element"),"")})}_updateFocusedElementClasses(){if(this.focusedElements.length<2)return;const e=this.focusedElements.find(e=>e.hasAttribute(applySysAttrPrefix("focusable-element")));e&&this._setFocus(e.getAttribute(applySysAttrPrefix("element")))}}}