@claspo/renderer 18.9.1 → 18.9.3
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/action/ActionFactory.js +1 -1
- package/action/InAppActionFactory.js +1 -1
- package/action/actions/DispatchEventAction.d.ts +4 -1
- package/action/actions/DispatchEventAction.js +1 -1
- package/common/ConfigService.js +1 -1
- package/package.json +2 -2
- package/wc-renderer/decorators/wcUpdatingDecorator.d.ts +0 -3
- package/wc-renderer/decorators/wcUpdatingDecorator.js +1 -1
package/action/ActionFactory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,n,c,s){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=c,this.getServices=s}get(t){switch(t.type){case SysActionTypes.SUBSCRIBE_CONTACT:return new SubscribeContactAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.REQUEST:return new RequestAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t);case SysActionTypes.GO_TO_VIEW:return new GoToViewAction(this.eventEmitter,t,this.configService,this.form,this.getServices().viewRouter,this.getServices().documentModel,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_PREVIOUS_VIEW:return new GoToPreviousViewAction(this.eventEmitter,t,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_NEXT_VIEW:return new GoToNextViewAction(this.eventEmitter,this.form,t,this.tracking);case SysActionTypes.SHOW_WIDGET:return new ShowWidgetAction(this.eventEmitter,t,this.tracking);case SysActionTypes.OPEN_LINK:return new OpenLinkAction(t,this.configService,this.tracking);case SysActionTypes.CLOSE_WIDGET:return new CloseWidgetAction(this.eventEmitter,t,this.configService,this.tracking);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
1
|
+
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,n,c,s){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=c,this.getServices=s}get(t){switch(t.type){case SysActionTypes.SUBSCRIBE_CONTACT:return new SubscribeContactAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.REQUEST:return new RequestAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t,this.form,this.configService,this.context);case SysActionTypes.GO_TO_VIEW:return new GoToViewAction(this.eventEmitter,t,this.configService,this.form,this.getServices().viewRouter,this.getServices().documentModel,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_PREVIOUS_VIEW:return new GoToPreviousViewAction(this.eventEmitter,t,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_NEXT_VIEW:return new GoToNextViewAction(this.eventEmitter,this.form,t,this.tracking);case SysActionTypes.SHOW_WIDGET:return new ShowWidgetAction(this.eventEmitter,t,this.tracking);case SysActionTypes.OPEN_LINK:return new OpenLinkAction(t,this.configService,this.tracking);case SysActionTypes.CLOSE_WIDGET:return new CloseWidgetAction(this.eventEmitter,t,this.configService,this.tracking);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"./SysActionTypes";import DispatchEventAction from"./actions/DispatchEventAction";import InAppOpenLinkAction from"./actions/InAppOpenLinkAction";import ActionFactory from"./ActionFactory";export default class InAppActionFactory extends ActionFactory{executeAction(t,{params:e}={}){return{execute:(n,i)=>{var s;return this.eventEmitter.emit(t,Object.assign(Object.assign({},e),{targetComponentId:null===(s=null==i?void 0:i.target)||void 0===s?void 0:s.getAttribute("cl-id")})),Promise.resolve(!0)}}}get(t){switch(t.type){case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t);case SysActionTypes.OPEN_LINK:return new InAppOpenLinkAction(this.eventEmitter,t);case SysActionTypes.CLOSE_WIDGET:return this.executeAction(SysActionTypes.CLOSE_WIDGET,t);case SysActionTypes.CLICK:return this.executeAction(SysActionTypes.CLICK,t);case SysActionTypes.GO_TO_VIEW:case SysActionTypes.GO_TO_NEXT_VIEW:case SysActionTypes.GO_TO_PREVIOUS_VIEW:return super.get(t);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
1
|
+
import SysActionTypes from"./SysActionTypes";import DispatchEventAction from"./actions/DispatchEventAction";import InAppOpenLinkAction from"./actions/InAppOpenLinkAction";import ActionFactory from"./ActionFactory";export default class InAppActionFactory extends ActionFactory{executeAction(t,{params:e}={}){return{execute:(n,i)=>{var s;return this.eventEmitter.emit(t,Object.assign(Object.assign({},e),{targetComponentId:null===(s=null==i?void 0:i.target)||void 0===s?void 0:s.getAttribute("cl-id")})),Promise.resolve(!0)}}}get(t){switch(t.type){case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t,this.form,this.configService,this.context);case SysActionTypes.OPEN_LINK:return new InAppOpenLinkAction(this.eventEmitter,t);case SysActionTypes.CLOSE_WIDGET:return this.executeAction(SysActionTypes.CLOSE_WIDGET,t);case SysActionTypes.CLICK:return this.executeAction(SysActionTypes.CLICK,t);case SysActionTypes.GO_TO_VIEW:case SysActionTypes.GO_TO_NEXT_VIEW:case SysActionTypes.GO_TO_PREVIOUS_VIEW:return super.get(t);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
@@ -2,7 +2,10 @@ import SysActionTypes from "../SysActionTypes";
|
|
|
2
2
|
export default class DispatchEventAction {
|
|
3
3
|
eventEmitter: any;
|
|
4
4
|
config: any;
|
|
5
|
+
form: any;
|
|
6
|
+
configService: any;
|
|
7
|
+
context: any;
|
|
5
8
|
type: SysActionTypes;
|
|
6
|
-
constructor(eventEmitter: any, config: any);
|
|
9
|
+
constructor(eventEmitter: any, config: any, form: any, configService: any, context: any);
|
|
7
10
|
execute(payload: any): Promise<boolean>;
|
|
8
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";export default class DispatchEventAction{constructor(t,e){this.type=SysActionTypes.DISPATCH_EVENT,this.eventEmitter=t,this.config=e}execute(t){return this.eventEmitter.emit(this.config.params.eventName,
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";import UTMParamsExtractor from"../UTMParamsExtractor";import{constructRequestPayload,extractContextValue}from"../RequestPayloadBuilder";export default class DispatchEventAction{constructor(t,e,o,i,r){this.type=SysActionTypes.DISPATCH_EVENT,this.eventEmitter=t,this.config=e,this.form=o,this.configService=i,this.context=r}execute(t){var e,o,i,r,s,a,c;const n=constructRequestPayload({contextValue:this.context?extractContextValue(this.context):{},formValue:null!==(i=null===(o=null===(e=this.form)||void 0===e?void 0:e.getControlsMap)||void 0===o?void 0:o.call(e))&&void 0!==i?i:{},utmParams:this.context?UTMParamsExtractor.extractTrackingParams(this.context):{},referrer:window.location.href,triggeredBy:null===(s=null===(r=this.configService)||void 0===r?void 0:r.getConfig)||void 0===s?void 0:s.call(r,"triggeredBy"),widgetDebugMode:null===(c=null===(a=this.configService)||void 0===a?void 0:a.getConfig)||void 0===c?void 0:c.call(a,"widgetDebugMode")});return this.eventEmitter.emit(this.config.params.eventName,n),Promise.resolve(!0)}}
|
package/common/ConfigService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default class ConfigService{constructor(
|
|
1
|
+
export default class ConfigService{constructor(i){this.config=Object.assign(Object.assign({},{subscribeContactUrl:"",submitOnClose:{enabled:!1,skipValidation:!0}}),i)}getConfig(i){return i?this.config[i]:this.config}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/renderer",
|
|
3
|
-
"version": "18.9.
|
|
3
|
+
"version": "18.9.3",
|
|
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.
|
|
18
|
+
"@claspo/common": "7.5.2",
|
|
19
19
|
"@testing-library/dom": "^10.4.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -21,9 +21,6 @@ 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;
|
|
27
24
|
_elementDragEndListener(event: any): void;
|
|
28
25
|
_elementDragOverListener(event: any): void;
|
|
29
26
|
_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();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")))}}}
|
|
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")))}}}
|