@social-mail/social-mail-client 1.2.640 → 1.2.641
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/dist/admin/AdminAppIndex.pack.js +23 -0
- package/dist/admin/AdminAppIndex.pack.js.map +1 -1
- package/dist/admin/AdminAppIndex.pack.min.js +1 -1
- package/dist/admin/AdminAppIndex.pack.min.js.map +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.d.ts.map +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.js +23 -0
- package/dist/site-editor/editor/HtmlPageEditor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/web/AppIndex.pack.js +23 -0
- package/dist/web/AppIndex.pack.js.map +1 -1
- package/dist/web/AppIndex.pack.min.js +1 -1
- package/dist/web/AppIndex.pack.min.js.map +1 -1
- package/package.json +1 -1
- package/src/site-editor/editor/HtmlPageEditor.tsx +29 -0
|
@@ -4552,7 +4552,7 @@ display: grid;
|
|
|
4552
4552
|
z-index: 50;
|
|
4553
4553
|
}
|
|
4554
4554
|
}
|
|
4555
|
-
`.installGlobal("[data-html-page-editor=html-page-editor]");desktopWidth=992;tabletWidth=768;mobileWidth=480;languageSymbol=Symbol.for("language");_export("default",HtmlPageEditor=class HtmlPageEditor extends AtomControl{get modifiedDocument(){var _a;if(!this.undoRedo.changed){return null}const clone=this.htmlDocument.documentElement.cloneNode(true);const body=clone.querySelector("body");body.removeAttribute("contentEditable");body.removeAttribute("editing");body.removeAttribute("editing-lang");const all=clone.querySelectorAll("*");const clearChildren=[];const removeAll=[];for(let index=0;index<all.length;index++){const element=all[index];if(element.hasAttribute("remove-when-save")){removeAll.push(element);continue}if(element.tagName==="INJECT"){clearChildren.push(element);continue}if(element.getAttribute("data-cursor-style")==="editing"){removeAll.push(element);continue}element.removeAttribute("draggable")}for(const iterator of clearChildren){iterator.innerHTML=""}for(const iterator of removeAll){iterator.remove()}if(clone.querySelector(`[styler-layout="component"]`)){let componentScript=clone.querySelector("[styler-component-script]");if(!componentScript){componentScript=this.htmlDocument.createElement("script");const head=clone.querySelector("head");head.appendChild(componentScript)}componentScript.src=UMD.resolvePath("@social-mail/social-mail-client/component.js");componentScript.setAttribute("styler-component-script","component-script")}if(this.baseUrl){if(!this.originalBaseUrl){(_a=clone.querySelector("base"))===null||_a===void 0?void 0:_a.remove()}else{const baseUrl=clone.querySelector("base");if(baseUrl){baseUrl.setAttribute("href",this.originalBaseUrl)}}}return clone}get modifiedPage(){var _a;return(_a=this.modifiedDocument)===null||_a===void 0?void 0:_a.outerHTML}get modifiedBody(){const doc=this.modifiedDocument;if(!doc){return}const body=doc.querySelector("body");return body.innerHTML}get htmlPage(){var _a,_b;return(_b=(_a=this.htmlDocument)===null||_a===void 0?void 0:_a.documentElement)===null||_b===void 0?void 0:_b.outerHTML}set htmlPage(v){var _a;if(!this.element){return}if(!this.ready){setTimeout((()=>{this.htmlPage=v}),100);return}(_a=this.initCT)===null||_a===void 0?void 0:_a.cancel();const ct=this.initCT=new CancelToken;void this.ready.then((()=>{const prevInit=this.lastInit;this.lastInit=this.initDocument(prevInit,v,ct)}))}get language(){return this[languageSymbol]}set language(v){var _a;if(v===this[languageSymbol]){return}this[languageSymbol]=v;localStorage.setItem("editing-lang",v);if((_a=this.htmlDocument)===null||_a===void 0?void 0:_a.body){this.htmlDocument.body.setAttribute("editing-lang",v)}AtomBinder.refreshValue(this,"language")}constructor(app,e){super(app,e);this.selection=new SelectedElement(this);this.undoRedo={canUndo:false,canRedo:false,dispose(){}};this.pageVariables=[];this.languages=null;this.hover=new SelectedElement(this);this.dropTarget=new SelectedElement(this);this.maxWidth=desktopWidth;this.ready=this.init()}init(){return __awaiter(this,void 0,void 0,(function*(){this.render(XNode.create("div",{"data-html-page-editor":"html-page-editor"},XNode.create("div",{"data-element":"top"},XNode.create(EditorToolbar,{"data-element":"max-width","event-click":()=>this.deferUpdate()},XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===desktopWidth)),"event-click":()=>this.maxWidth=desktopWidth,class:"fas fa-desktop"}),XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===tabletWidth)),"event-click":()=>this.maxWidth=tabletWidth,class:"fas fa-tablet-screen"}),XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===mobileWidth)),"event-click":()=>this.maxWidth=mobileWidth,class:"fas fa-mobile-screen"})),XNode.create(UndoRedoToolbar,null),XNode.create(EditorToolbar,null,XNode.create("i",{"data-click-event":"edit-code",class:"fa-solid fa-code"}),XNode.create(LanguageDropDown,null))),XNode.create(EditorToolbar,{"data-element":"left"},XNode.create(TextBox,null),XNode.create(Image,null),XNode.create(WrapGrid,null),XNode.create(ImageBox,null),XNode.create(RightImageBox,null),XNode.create(Card,null),XNode.create(ImageCard,null),XNode.create(ColumnBox,null),XNode.create(Columns2,null),XNode.create(Columns3,null),XNode.create(List,null),XNode.create(ImageLink,null),XNode.create(LinkButton,null),XNode.create(InlinePopupButton,{icon:"fas fa-plus","data-layout":"warning-icon-button",alignment:"above",popup:()=>XNode.create(EditorToolbar,null,XNode.create(RowBox,null),XNode.create(VerticalImageBox,null),XNode.create(PriceTable,null),XNode.create(TypeWriterComponent,null),XNode.create(Billboard,null),XNode.create(PDFFlipBook,null),XNode.create(PDFViewer,null),XNode.create(OutlineText,null),XNode.create(Carousel,null),XNode.create(BlogComponent,null),XNode.create(BoxFrame,null),XNode.create(VideoPlayer,null),XNode.create(BackgroundVideo,null),XNode.create(TextMask,null),XNode.create(InjectBox,null),XNode.create(ImageGrid,null),XNode.create(ImageGallery,null),XNode.create(MarqueeText,null),XNode.create(Banner,null))})),XNode.create("div",{"data-element":"editor","style-max-width":Bind.oneWay((()=>this.maxWidth>768?"":this.maxWidth+"px"))},XNode.create("div",{"data-element":"resizer"}),XNode.create("div",{"data-element":"drop-target","style-display":Bind.oneWay((()=>this.dropTarget.element?"":"none")),"style-position":"absolute","style-left":Bind.oneWay((()=>this.dropTarget.left)),"style-top":Bind.oneWay((()=>this.dropTarget.top)),"style-width":Bind.oneWay((()=>this.dropTarget.width)),"style-height":Bind.oneWay((()=>this.dropTarget.height))}),XNode.create("div",{"data-element":"selection","style-left":Bind.oneWay((()=>this.selection.left)),"style-top":Bind.oneWay((()=>this.selection.top)),"style-width":Bind.oneWay((()=>this.selection.width)),"style-height":Bind.oneWay((()=>this.selection.height))},XNode.create("i",{class:"lt"}),XNode.create("i",{class:"rt"}),XNode.create("i",{class:"lb"}),XNode.create("i",{class:"rb"}),XNode.create("div",null,XNode.create("i",{class:"fa-regular fa-arrow-up","event-click":()=>{if(this.selection.element.parentElement!==this.htmlDocument.body){this.selection.update(this.selection.element.parentElement)}}}),XNode.create("i",{"event-click":()=>{this.selection.setDraggable()},class:"fa-solid fa-up-down-left-right","data-click-event":"start-drag"}),XNode.create("i",{"style-display":Bind.oneWay((()=>this.selection.isImage)),"data-click-event":"change-image",title:"Change Image (Double Click)",class:"fa-solid fa-arrows-rotate-reverse"}),XNode.create("i",{title:"Duplicate","data-click-event":"copy-element",class:"fas fa-copy"}),XNode.create("i",{title:"Move Up","data-click-event":"move-up-element",class:"fa-duotone fa-angles-up"}),XNode.create("i",{title:"Move Down","data-click-event":"move-down-element",class:"fa-duotone fa-angles-down"}),XNode.create("i",{title:"Extract Fragment","data-click-event":"extract-element",class:"fad fa-file-export"}),XNode.create("i",{title:"Delete","data-click-event":"delete-element",class:"fas fa-trash-can"}))),XNode.create("div",{"data-element":"hover","style-left":Bind.oneWay((()=>this.hover.left)),"style-top":Bind.oneWay((()=>this.hover.top)),"style-width":Bind.oneWay((()=>this.hover.width)),"style-height":Bind.oneWay((()=>this.hover.height))},XNode.create("label",{text:Bind.oneWay((()=>this.hover.name))})),XNode.create("div",{"data-element":"content-frame"},XNode.create("iframe",{"data-element":"content-editor",sandbox:"allow-same-origin "}))),XNode.create("div",{"data-element":"right"},XNode.create("button",{"data-click-event":"open-variables","data-layout":"icon-button"},XNode.create("i",{class:"fas fa-code"}),"Variables"),XNode.create(Properties,null)),XNode.create(BreadCrum,{selection:Bind.oneWay((()=>this.selection.element))})));this.contentEditor=this.element.querySelector(`[data-element="content-editor"]`)}))}buildXNode(node){const build=n=>{const e=this.htmlDocument.createElement(n.name);if(n.attributes){for(const key in n.attributes){if(Object.prototype.hasOwnProperty.call(n.attributes,key)){const element=n.attributes[key];e.setAttribute(key,element)}}}if(n.children){for(const iterator of n.children){if(typeof iterator==="string"){e.append(iterator);continue}e.appendChild(build(iterator))}}return e};return build(node)}deleteElement(){var _a;return __awaiter(this,void 0,void 0,(function*(){const current=this.selection.element;let previous=(_a=current.previousElementSibling)!==null&&_a!==void 0?_a:current.parentElement;current.remove();this.commit();if(!previous.textContent){previous=previous.previousElementSibling.lastElementChild}this.setSelection(previous);yield sleep(100);this.selection.update()}))}copyElement(){const current=this.selection.element;const copy=current.cloneNode(true);for(const iterator of descendentElementIterator(copy)){if(iterator.id){iterator.id=`sm-${Date.now()}`}}current.insertAdjacentElement("afterend",copy);this.commit()}moveUpElement(){const current=this.selection.element;const prevSibling=current.previousElementSibling;if(!prevSibling){return}current.remove();prevSibling.insertAdjacentElement("beforebegin",current);this.commit()}moveDownElement(){const current=this.selection.element;const nextSibling=current.nextElementSibling;if(!nextSibling){return}current.remove();nextSibling.insertAdjacentElement("afterend",current);this.commit()}changeImage(){return __awaiter(this,void 0,void 0,(function*(){return this.insertImage({src:prompt("Image Src","")})}))}changeBackgroundImage(){return __awaiter(this,void 0,void 0,(function*(){const img=prompt("Image Src","");this.selection.element.style.setProperty("--styler-background-image",`url(${JSON.stringify(img)})`);return}))}extractElement(){return __awaiter(this,void 0,void 0,(function*(){alert("Not implemented")}))}onKeyUp(d,ke){if(ke.ctrlKey){switch(ke.key){case"z":ke.preventDefault();this.undo();break;case"y":ke.preventDefault();this.redo();break}}}insertImage(...images){var _a;return __awaiter(this,void 0,void 0,(function*(){let img=((_a=this.selection)===null||_a===void 0?void 0:_a.isImage)?this.selection.element:null;const container=img?img.parentElement:this.selection.element;for(let _b of images){const{src,style}=_b,a=__rest(_b,["src","style"]);if(!img){img=this.htmlDocument.createElement("img");container.appendChild(img);container.appendChild(document.createTextNode("\n"))}img.src=src;const i=img;img.onload=()=>{this.selection.update();i.onload=null};if(style){for(const key in style){if(Object.prototype.hasOwnProperty.call(style,key)){const element=style[key];img.style[key]=element}}}if(a){for(const key in a){if(Object.prototype.hasOwnProperty.call(a,key)){const element=a[key];img.setAttribute(key,element)}}}img=null}this.commit()}))}insertElement(e,parent=this.selection.element,preferMain=false){if(preferMain){while(parent.parentElement!==this.htmlDocument.body){parent=parent.parentElement}}parent.appendChild(e);if(!e.id){e.id="sm-"+Date.now().toString()}setTimeout((()=>{this.setSelection(e);this.commit()}),100)}deferUpdate(){var _a,_b;return __awaiter(this,void 0,void 0,(function*(){yield sleep(100);(_a=this.hover)===null||_a===void 0?void 0:_a.update();(_b=this.selection)===null||_b===void 0?void 0:_b.update()}))}setSelection(element,commit=true){var _a;const old=(_a=this.selection)===null||_a===void 0?void 0:_a.element;if(old===null||old===void 0?void 0:old.draggable){old.removeAttribute("draggable")}this.selection.update(element);if(commit){this.commit()}}commit(){}undo(){var _a;(_a=this.undoRedo)===null||_a===void 0?void 0:_a.undo()}redo(){var _a;(_a=this.undoRedo)===null||_a===void 0?void 0:_a.redo()}merge(text){return __awaiter(this,void 0,void 0,(function*(){const parser=new this.htmlDocument.defaultView.DOMParser;const dom=parser.parseFromString(text,"text/html");yield DomHelper.applyChanges(this.htmlDocument,dom);yield this.updateEditable(this.htmlDocument)}))}initDocument(prev,v,ct){return __awaiter(this,void 0,void 0,(function*(){try{yield prev}catch(_a){}this.undoRedo.dispose();this.contentEditor.srcdoc="about:empty";const dom=new DOMParser;const doc=dom.parseFromString(v,"text/html");yield this.updateEditable(doc);this.htmlDocument=void 0;yield this.loadContentDocument();this.htmlDocument.open();this.htmlDocument.write(doc.documentElement.outerHTML);this.htmlDocument.close();yield sleep(1e3);yield WebComponents.run(this.contentEditor,this.htmlDocument);this.htmlDocument.addEventListener("click",(e=>{const target=e.target;const previous=this.selection.element;if(previous===null||previous===void 0?void 0:previous.isContentEditable){let start=target;while(start){if(previous===target){return}start=start.parentElement}if(previous!==this.htmlDocument.body){previous.removeAttribute("contentEditable")}this.queueCommit()}e.preventDefault();this.setSelection(target)}));this.htmlDocument.addEventListener("dblclick",(e=>{const target=e.target;e.preventDefault();const element=target.nodeType===Node.ELEMENT_NODE?target:target.parentElement;if(/^(IMG|INJECT|VIDEO|PDF)/.test(element.tagName)){this.changeImage().catch(console.error);return}if(element.getAttribute("data-editable")==="false"){return}if(element.hasAttribute("data-web-atoms-view")){return}this.setSelection(element)}));this.htmlDocument.addEventListener("scroll",(e=>{this.hover.update();this.selection.update()}),{passive:true});this.htmlDocument.addEventListener("pointerover",(e=>{let target=e.target;target=target.nodeType===Node.ELEMENT_NODE&&target.tagName?target:target.parentElement;if(this.hover.element===target){return}this.hover.update(target)}),{capture:true});this.htmlDocument.addEventListener("keydown",(e=>{if(e.ctrlKey||e.metaKey){switch(e.key){case"s":this.contentEditor.dispatchEvent(new CustomEvent("savePage",{bubbles:true}));e.preventDefault();break;case"z":this.contentEditor.dispatchEvent(new CustomEvent("undo",{bubbles:true}));e.preventDefault();break;case"y":this.contentEditor.dispatchEvent(new CustomEvent("redo",{bubbles:true}));e.preventDefault();break}}}));this.htmlDocument.addEventListener("input",(()=>this.queueCommit()));InstallDragDropHelper(this);setTimeout((()=>{this.undoRedo=new UndoRedo(this.htmlDocument,this)}),10)}))}updateEditable(doc){return __awaiter(this,void 0,void 0,(function*(){doc.body.contentEditable="true";doc.body.setAttribute("editing","true");this.updateBaseUrl(doc);yield this.setStylerSheet(doc);const lc=doc.querySelector("language-chooser");const languageStyles=[];if(lc){const languages=[{label:"Lang",value:"all"}];const list=lc.getAttribute("languages");if(list){for(const token of list.split(/[\,\;\s]+/)){const lang=token.trim();if(!lang){continue}languageStyles.push(`body[editing-lang=${lang}] *[lang]:not([lang=${lang}]) { display: none; }`);languages.push({label:lang,value:lang})}}this.languages=languages;const current=localStorage.getItem("editing-lang");if(current){doc.body.setAttribute("editing-lang",current);this[languageSymbol]=current;AtomBinder.refreshValue(this,"language")}else{this[languageSymbol]="all"}}doc.body.removeAttribute("data-lang");const cursorStyle=doc.createElement("style");cursorStyle.textContent=`* {\n caret-color: currentColor !important;\n }\n ${languageStyles.join("\n")}\n `;cursorStyle.setAttribute("data-cursor-style","editing");doc.head.append(cursorStyle)}))}queueCommit(){const id=this.lastCommitTimerID;if(id){clearTimeout(id)}this.lastCommitTimerID=setTimeout((()=>this.commit()),1e3)}setStylerSheet(doc=this.htmlDocument){return __awaiter(this,void 0,void 0,(function*(){let style=doc.querySelector(`[styler-style-sheet]`);if(!style){style=doc.createElement("style");style.setAttribute("styler-style-sheet","inline");doc.head.appendChild(style)}style.textContent=StylerSet.instance.toString()}))}updateBaseUrl(doc){var _a;let baseElement=doc.querySelector("base");if((_a=baseElement===null||baseElement===void 0?void 0:baseElement.getAttribute("href"))===null||_a===void 0?void 0:_a.startsWith("/api/site/")){baseElement.remove();baseElement=null}if(baseElement){const href=baseElement.getAttribute("href");if(href!==this.baseUrl){this.originalBaseUrl=href;baseElement.setAttribute("href",this.baseUrl)}}else{baseElement=doc.createElement("base");baseElement.setAttribute("href",this.baseUrl);doc.head.insertAdjacentElement("afterbegin",baseElement)}}loadContentDocument(){return __awaiter(this,void 0,void 0,(function*(){this.contentEditor=this.element.querySelector(`[data-element="content-editor"]`);while(!this.htmlDocument){this.htmlDocument=this.contentEditor.contentDocument;yield sleep(100)}}))}});__decorate([BindableProperty,__metadata("design:type",String)],HtmlPageEditor.prototype,"baseUrl",void 0);__decorate([Action({onEvent:"delete-element"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"deleteElement",null);__decorate([Action({onEvent:"copy-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"copyElement",null);__decorate([Action({onEvent:"move-up-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"moveUpElement",null);__decorate([Action({onEvent:"move-down-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"moveDownElement",null);__decorate([Action({onEvent:"change-image"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"changeImage",null);__decorate([Action({onEvent:"change-background-image"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"changeBackgroundImage",null);__decorate([Action({onEvent:"extract-element"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"extractElement",null);__decorate([Action({onEvent:"keyup"}),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,KeyboardEvent]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"onKeyUp",null);__decorate([Action({onEvent:"undo"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"undo",null);__decorate([Action({onEvent:"redo"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"redo",null)}}}));AmdLoader.instance.setup("@social-mail/social-mail-client/dist/site-editor/editor/HtmlPageEditor");System.register(["tslib","@web-atoms/web-controls/dist/mobile-app/MobileApp","@web-atoms/core/dist/core/XNode","../../../../common/controls/tree/FileTreeView","@web-atoms/web-controls/dist/basic/AtomRepeater","@web-atoms/core/dist/core/Bind","@web-atoms/core/dist/core/InjectProperty","../service/CloudFileService","@web-atoms/core/dist/style/styled","../../../../common/controls/drag-drop/FilesDragDrop","@web-atoms/core/dist/view-model/Action","@web-atoms/web-controls/dist/basic/UploadEvent","../../../../common/controls/buttons/IconButton","../../../../common/fileUrl"],(function(_export,_context){"use strict";var __awaiter,__decorate,__metadata,PopupWindowPage,XNode,FolderTreeView,AtomRepeater,SelectAll,SelectorCheckBox,Bind,InjectProperty,CloudFileService,styled,FilesDragDrop,Action,UploadEvent,SaveIconTextButton,fileUrl,ChooseMediaPage,css;_export("default",void 0);return{setters:[function(_tslib){__awaiter=_tslib.__awaiter;__decorate=_tslib.__decorate;__metadata=_tslib.__metadata},function(_webAtomsWebControlsDistMobileAppMobileApp){PopupWindowPage=_webAtomsWebControlsDistMobileAppMobileApp.PopupWindowPage},function(_webAtomsCoreDistCoreXNode){XNode=_webAtomsCoreDistCoreXNode.default},function(_commonControlsTreeFileTreeView){FolderTreeView=_commonControlsTreeFileTreeView.FolderTreeView},function(_webAtomsWebControlsDistBasicAtomRepeater){AtomRepeater=_webAtomsWebControlsDistBasicAtomRepeater.default;SelectAll=_webAtomsWebControlsDistBasicAtomRepeater.SelectAll;SelectorCheckBox=_webAtomsWebControlsDistBasicAtomRepeater.SelectorCheckBox},function(_webAtomsCoreDistCoreBind){Bind=_webAtomsCoreDistCoreBind.default},function(_webAtomsCoreDistCoreInjectProperty){InjectProperty=_webAtomsCoreDistCoreInjectProperty.default},function(_serviceCloudFileService){CloudFileService=_serviceCloudFileService.default},function(_webAtomsCoreDistStyleStyled){styled=_webAtomsCoreDistStyleStyled.default},function(_commonControlsDragDropFilesDragDrop){FilesDragDrop=_commonControlsDragDropFilesDragDrop.FilesDragDrop},function(_webAtomsCoreDistViewModelAction){Action=_webAtomsCoreDistViewModelAction.default},function(_webAtomsWebControlsDistBasicUploadEvent){UploadEvent=_webAtomsWebControlsDistBasicUploadEvent.default},function(_commonControlsButtonsIconButton){SaveIconTextButton=_commonControlsButtonsIconButton.SaveIconTextButton},function(_commonFileUrl){fileUrl=_commonFileUrl.fileUrl}],execute:function(){css=styled.css`
|
|
4555
|
+
`.installGlobal("[data-html-page-editor=html-page-editor]");desktopWidth=992;tabletWidth=768;mobileWidth=480;languageSymbol=Symbol.for("language");_export("default",HtmlPageEditor=class HtmlPageEditor extends AtomControl{get modifiedDocument(){var _a;if(!this.undoRedo.changed){return null}const clone=this.htmlDocument.documentElement.cloneNode(true);const body=clone.querySelector("body");body.removeAttribute("contentEditable");body.removeAttribute("editing");body.removeAttribute("editing-lang");const all=clone.querySelectorAll("*");const clearChildren=[];const removeAll=[];for(let index=0;index<all.length;index++){const element=all[index];if(element.hasAttribute("remove-when-save")){removeAll.push(element);continue}if(element.tagName==="INJECT"){clearChildren.push(element);continue}if(element.getAttribute("data-cursor-style")==="editing"){removeAll.push(element);continue}element.removeAttribute("draggable")}for(const iterator of clearChildren){iterator.innerHTML=""}for(const iterator of removeAll){iterator.remove()}if(clone.querySelector(`[styler-layout="component"]`)){let componentScript=clone.querySelector("[styler-component-script]");if(!componentScript){componentScript=this.htmlDocument.createElement("script");const head=clone.querySelector("head");head.appendChild(componentScript)}componentScript.src=UMD.resolvePath("@social-mail/social-mail-client/component.js");componentScript.setAttribute("styler-component-script","component-script")}if(this.baseUrl){if(!this.originalBaseUrl){(_a=clone.querySelector("base"))===null||_a===void 0?void 0:_a.remove()}else{const baseUrl=clone.querySelector("base");if(baseUrl){baseUrl.setAttribute("href",this.originalBaseUrl)}}}return clone}get modifiedPage(){var _a;return(_a=this.modifiedDocument)===null||_a===void 0?void 0:_a.outerHTML}get modifiedBody(){const doc=this.modifiedDocument;if(!doc){return}const body=doc.querySelector("body");return body.innerHTML}get htmlPage(){var _a,_b;return(_b=(_a=this.htmlDocument)===null||_a===void 0?void 0:_a.documentElement)===null||_b===void 0?void 0:_b.outerHTML}set htmlPage(v){var _a;if(!this.element){return}if(!this.ready){setTimeout((()=>{this.htmlPage=v}),100);return}(_a=this.initCT)===null||_a===void 0?void 0:_a.cancel();const ct=this.initCT=new CancelToken;void this.ready.then((()=>{const prevInit=this.lastInit;this.lastInit=this.initDocument(prevInit,v,ct)}))}get language(){return this[languageSymbol]}set language(v){var _a;if(v===this[languageSymbol]){return}this[languageSymbol]=v;localStorage.setItem("editing-lang",v);if((_a=this.htmlDocument)===null||_a===void 0?void 0:_a.body){this.htmlDocument.body.setAttribute("editing-lang",v)}AtomBinder.refreshValue(this,"language")}constructor(app,e){super(app,e);this.selection=new SelectedElement(this);this.undoRedo={canUndo:false,canRedo:false,dispose(){}};this.pageVariables=[];this.languages=null;this.hover=new SelectedElement(this);this.dropTarget=new SelectedElement(this);this.maxWidth=desktopWidth;this.ready=this.init()}init(){return __awaiter(this,void 0,void 0,(function*(){this.render(XNode.create("div",{"data-html-page-editor":"html-page-editor"},XNode.create("div",{"data-element":"top"},XNode.create(EditorToolbar,{"data-element":"max-width","event-click":()=>this.deferUpdate()},XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===desktopWidth)),"event-click":()=>this.maxWidth=desktopWidth,class:"fas fa-desktop"}),XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===tabletWidth)),"event-click":()=>this.maxWidth=tabletWidth,class:"fas fa-tablet-screen"}),XNode.create("i",{"data-selected":Bind.oneWay((()=>this.maxWidth===mobileWidth)),"event-click":()=>this.maxWidth=mobileWidth,class:"fas fa-mobile-screen"})),XNode.create(UndoRedoToolbar,null),XNode.create(EditorToolbar,null,XNode.create("i",{"data-click-event":"edit-code",class:"fa-solid fa-code"}),XNode.create(LanguageDropDown,null))),XNode.create(EditorToolbar,{"data-element":"left"},XNode.create(TextBox,null),XNode.create(Image,null),XNode.create(WrapGrid,null),XNode.create(ImageBox,null),XNode.create(RightImageBox,null),XNode.create(Card,null),XNode.create(ImageCard,null),XNode.create(ColumnBox,null),XNode.create(Columns2,null),XNode.create(Columns3,null),XNode.create(List,null),XNode.create(ImageLink,null),XNode.create(LinkButton,null),XNode.create(InlinePopupButton,{icon:"fas fa-plus","data-layout":"warning-icon-button",alignment:"above",popup:()=>XNode.create(EditorToolbar,null,XNode.create(RowBox,null),XNode.create(VerticalImageBox,null),XNode.create(PriceTable,null),XNode.create(TypeWriterComponent,null),XNode.create(Billboard,null),XNode.create(PDFFlipBook,null),XNode.create(PDFViewer,null),XNode.create(OutlineText,null),XNode.create(Carousel,null),XNode.create(BlogComponent,null),XNode.create(BoxFrame,null),XNode.create(VideoPlayer,null),XNode.create(BackgroundVideo,null),XNode.create(TextMask,null),XNode.create(InjectBox,null),XNode.create(ImageGrid,null),XNode.create(ImageGallery,null),XNode.create(MarqueeText,null),XNode.create(Banner,null))})),XNode.create("div",{"data-element":"editor","style-max-width":Bind.oneWay((()=>this.maxWidth>768?"":this.maxWidth+"px"))},XNode.create("div",{"data-element":"resizer"}),XNode.create("div",{"data-element":"drop-target","style-display":Bind.oneWay((()=>this.dropTarget.element?"":"none")),"style-position":"absolute","style-left":Bind.oneWay((()=>this.dropTarget.left)),"style-top":Bind.oneWay((()=>this.dropTarget.top)),"style-width":Bind.oneWay((()=>this.dropTarget.width)),"style-height":Bind.oneWay((()=>this.dropTarget.height))}),XNode.create("div",{"data-element":"selection","style-left":Bind.oneWay((()=>this.selection.left)),"style-top":Bind.oneWay((()=>this.selection.top)),"style-width":Bind.oneWay((()=>this.selection.width)),"style-height":Bind.oneWay((()=>this.selection.height))},XNode.create("i",{class:"lt"}),XNode.create("i",{class:"rt"}),XNode.create("i",{class:"lb"}),XNode.create("i",{class:"rb"}),XNode.create("div",null,XNode.create("i",{class:"fa-regular fa-arrow-up","event-click":()=>{if(this.selection.element.parentElement!==this.htmlDocument.body){this.selection.update(this.selection.element.parentElement)}}}),XNode.create("i",{"event-click":()=>{this.selection.setDraggable()},class:"fa-solid fa-up-down-left-right","data-click-event":"start-drag"}),XNode.create("i",{"style-display":Bind.oneWay((()=>this.selection.isImage)),"data-click-event":"change-image",title:"Change Image (Double Click)",class:"fa-solid fa-arrows-rotate-reverse"}),XNode.create("i",{title:"Duplicate","data-click-event":"copy-element",class:"fas fa-copy"}),XNode.create("i",{title:"Move Up","data-click-event":"move-up-element",class:"fa-duotone fa-angles-up"}),XNode.create("i",{title:"Move Down","data-click-event":"move-down-element",class:"fa-duotone fa-angles-down"}),XNode.create("i",{title:"Extract Fragment","data-click-event":"extract-element",class:"fad fa-file-export"}),XNode.create("i",{title:"Delete","data-click-event":"delete-element",class:"fas fa-trash-can"}))),XNode.create("div",{"data-element":"hover","style-left":Bind.oneWay((()=>this.hover.left)),"style-top":Bind.oneWay((()=>this.hover.top)),"style-width":Bind.oneWay((()=>this.hover.width)),"style-height":Bind.oneWay((()=>this.hover.height))},XNode.create("label",{text:Bind.oneWay((()=>this.hover.name))})),XNode.create("div",{"data-element":"content-frame"},XNode.create("iframe",{"data-element":"content-editor",sandbox:"allow-same-origin "}))),XNode.create("div",{"data-element":"right"},XNode.create("button",{"data-click-event":"open-variables","data-layout":"icon-button"},XNode.create("i",{class:"fas fa-code"}),"Variables"),XNode.create(Properties,null)),XNode.create(BreadCrum,{selection:Bind.oneWay((()=>this.selection.element))})));this.contentEditor=this.element.querySelector(`[data-element="content-editor"]`)}))}buildXNode(node){const build=n=>{const e=this.htmlDocument.createElement(n.name);if(n.attributes){for(const key in n.attributes){if(Object.prototype.hasOwnProperty.call(n.attributes,key)){const element=n.attributes[key];e.setAttribute(key,element)}}}if(n.children){for(const iterator of n.children){if(typeof iterator==="string"){e.append(iterator);continue}e.appendChild(build(iterator))}}return e};return build(node)}deleteElement(){var _a;return __awaiter(this,void 0,void 0,(function*(){const current=this.selection.element;let previous=(_a=current.previousElementSibling)!==null&&_a!==void 0?_a:current.parentElement;current.remove();this.commit();if(!previous.textContent){previous=previous.previousElementSibling.lastElementChild}this.setSelection(previous);yield sleep(100);this.selection.update()}))}copyElement(){const current=this.selection.element;const copy=current.cloneNode(true);for(const iterator of descendentElementIterator(copy)){if(iterator.id){iterator.id=`sm-${Date.now()}`}}current.insertAdjacentElement("afterend",copy);this.commit()}moveUpElement(){const current=this.selection.element;const prevSibling=current.previousElementSibling;if(!prevSibling){return}current.remove();prevSibling.insertAdjacentElement("beforebegin",current);this.commit()}moveDownElement(){const current=this.selection.element;const nextSibling=current.nextElementSibling;if(!nextSibling){return}current.remove();nextSibling.insertAdjacentElement("afterend",current);this.commit()}changeImage(){return __awaiter(this,void 0,void 0,(function*(){return this.insertImage({src:prompt("Image Src","")})}))}changeBackgroundImage(){return __awaiter(this,void 0,void 0,(function*(){const img=prompt("Image Src","");this.selection.element.style.setProperty("--styler-background-image",`url(${JSON.stringify(img)})`);return}))}extractElement(){return __awaiter(this,void 0,void 0,(function*(){alert("Not implemented")}))}onKeyUp(d,ke){if(ke.ctrlKey){switch(ke.key){case"z":ke.preventDefault();this.undo();break;case"y":ke.preventDefault();this.redo();break}}}insertImage(...images){var _a;return __awaiter(this,void 0,void 0,(function*(){let img=((_a=this.selection)===null||_a===void 0?void 0:_a.isImage)?this.selection.element:null;const container=img?img.parentElement:this.selection.element;for(let _b of images){const{src,style}=_b,a=__rest(_b,["src","style"]);if(!img){img=this.htmlDocument.createElement("img");container.appendChild(img);container.appendChild(document.createTextNode("\n"))}img.src=src;const i=img;img.onload=()=>{this.selection.update();i.onload=null};if(style){for(const key in style){if(Object.prototype.hasOwnProperty.call(style,key)){const element=style[key];img.style[key]=element}}}if(a){for(const key in a){if(Object.prototype.hasOwnProperty.call(a,key)){const element=a[key];img.setAttribute(key,element)}}}img=null}this.commit()}))}insertElement(e,parent=this.selection.element,preferMain=false){if(preferMain){while(parent.parentElement!==this.htmlDocument.body){parent=parent.parentElement}}parent.appendChild(e);if(!e.id){e.id="sm-"+Date.now().toString()}setTimeout((()=>{this.setSelection(e);this.commit()}),100)}deferUpdate(){var _a,_b;return __awaiter(this,void 0,void 0,(function*(){yield sleep(100);(_a=this.hover)===null||_a===void 0?void 0:_a.update();(_b=this.selection)===null||_b===void 0?void 0:_b.update()}))}setSelection(element,commit=true){var _a;const old=(_a=this.selection)===null||_a===void 0?void 0:_a.element;if(old===null||old===void 0?void 0:old.draggable){old.removeAttribute("draggable")}this.selection.update(element);if(commit){this.commit()}}commit(){}undo(){var _a;(_a=this.undoRedo)===null||_a===void 0?void 0:_a.undo()}redo(){var _a;(_a=this.undoRedo)===null||_a===void 0?void 0:_a.redo()}merge(text){return __awaiter(this,void 0,void 0,(function*(){const parser=new this.htmlDocument.defaultView.DOMParser;const dom=parser.parseFromString(text,"text/html");yield DomHelper.applyChanges(this.htmlDocument,dom);yield this.updateEditable(this.htmlDocument)}))}initDocument(prev,v,ct){return __awaiter(this,void 0,void 0,(function*(){try{yield prev}catch(_a){}this.undoRedo.dispose();this.contentEditor.srcdoc="about:empty";const dom=new DOMParser;const doc=dom.parseFromString(v,"text/html");yield this.updateEditable(doc);this.htmlDocument=void 0;yield this.loadContentDocument();this.htmlDocument.open();this.htmlDocument.write(doc.documentElement.outerHTML);this.htmlDocument.close();yield sleep(1e3);yield WebComponents.run(this.contentEditor,this.htmlDocument);this.htmlDocument.addEventListener("click",(e=>{const target=e.target;const previous=this.selection.element;if(previous===null||previous===void 0?void 0:previous.isContentEditable){let start=target;while(start){if(previous===target){return}start=start.parentElement}if(previous!==this.htmlDocument.body){previous.removeAttribute("contentEditable")}this.queueCommit()}e.preventDefault();this.setSelection(target)}));this.htmlDocument.addEventListener("dblclick",(e=>{const target=e.target;e.preventDefault();const element=target.nodeType===Node.ELEMENT_NODE?target:target.parentElement;if(/^(IMG|INJECT|VIDEO|PDF)/.test(element.tagName)){this.changeImage().catch(console.error);return}if(element.getAttribute("data-editable")==="false"){return}if(element.hasAttribute("data-web-atoms-view")){return}this.setSelection(element)}));this.htmlDocument.addEventListener("scroll",(e=>{this.hover.update();this.selection.update()}),{passive:true});this.htmlDocument.addEventListener("pointerover",(e=>{let target=e.target;target=target.nodeType===Node.ELEMENT_NODE&&target.tagName?target:target.parentElement;if(this.hover.element===target){return}this.hover.update(target)}),{capture:true});this.htmlDocument.addEventListener("keydown",(e=>{if(e.ctrlKey||e.metaKey){switch(e.key){case"s":this.contentEditor.dispatchEvent(new CustomEvent("savePage",{bubbles:true}));e.preventDefault();break;case"z":this.contentEditor.dispatchEvent(new CustomEvent("undo",{bubbles:true}));e.preventDefault();break;case"y":this.contentEditor.dispatchEvent(new CustomEvent("redo",{bubbles:true}));e.preventDefault();break}}}));this.htmlDocument.addEventListener("input",(()=>this.queueCommit()));InstallDragDropHelper(this);setTimeout((()=>{this.undoRedo=new UndoRedo(this.htmlDocument,this);const clone=this.htmlDocument;if(clone.querySelector(`[styler-layout="component"]`)){let componentScript=clone.querySelector("[styler-component-script]");if(!componentScript){componentScript=this.htmlDocument.createElement("script");componentScript.setAttribute("styler-component-script","component-script");const head=clone.querySelector("head");head.appendChild(componentScript);const scripts=clone.querySelectorAll("script[src]");for(let index=0;index<scripts.length;index++){const script=scripts[index];const srcScript=script.getAttribute("src");if(srcScript.includes("@social-mail/social-mail-client/")||srcScript.includes("/component.js")){script.remove();break}}}const src=UMD.resolvePath("@social-mail/social-mail-client/component.js");if(componentScript.getAttribute("src")!==src){componentScript.setAttribute("src",src)}}}),10)}))}updateEditable(doc){return __awaiter(this,void 0,void 0,(function*(){doc.body.contentEditable="true";doc.body.setAttribute("editing","true");this.updateBaseUrl(doc);yield this.setStylerSheet(doc);const lc=doc.querySelector("language-chooser");const languageStyles=[];if(lc){const languages=[{label:"Lang",value:"all"}];const list=lc.getAttribute("languages");if(list){for(const token of list.split(/[\,\;\s]+/)){const lang=token.trim();if(!lang){continue}languageStyles.push(`body[editing-lang=${lang}] *[lang]:not([lang=${lang}]) { display: none; }`);languages.push({label:lang,value:lang})}}this.languages=languages;const current=localStorage.getItem("editing-lang");if(current){doc.body.setAttribute("editing-lang",current);this[languageSymbol]=current;AtomBinder.refreshValue(this,"language")}else{this[languageSymbol]="all"}}doc.body.removeAttribute("data-lang");const cursorStyle=doc.createElement("style");cursorStyle.textContent=`* {\n caret-color: currentColor !important;\n }\n ${languageStyles.join("\n")}\n `;cursorStyle.setAttribute("data-cursor-style","editing");doc.head.append(cursorStyle)}))}queueCommit(){const id=this.lastCommitTimerID;if(id){clearTimeout(id)}this.lastCommitTimerID=setTimeout((()=>this.commit()),1e3)}setStylerSheet(doc=this.htmlDocument){return __awaiter(this,void 0,void 0,(function*(){let style=doc.querySelector(`[styler-style-sheet]`);if(!style){style=doc.createElement("style");style.setAttribute("styler-style-sheet","inline");doc.head.appendChild(style)}style.textContent=StylerSet.instance.toString()}))}updateBaseUrl(doc){var _a;let baseElement=doc.querySelector("base");if((_a=baseElement===null||baseElement===void 0?void 0:baseElement.getAttribute("href"))===null||_a===void 0?void 0:_a.startsWith("/api/site/")){baseElement.remove();baseElement=null}if(baseElement){const href=baseElement.getAttribute("href");if(href!==this.baseUrl){this.originalBaseUrl=href;baseElement.setAttribute("href",this.baseUrl)}}else{baseElement=doc.createElement("base");baseElement.setAttribute("href",this.baseUrl);doc.head.insertAdjacentElement("afterbegin",baseElement)}}loadContentDocument(){return __awaiter(this,void 0,void 0,(function*(){this.contentEditor=this.element.querySelector(`[data-element="content-editor"]`);while(!this.htmlDocument){this.htmlDocument=this.contentEditor.contentDocument;yield sleep(100)}}))}});__decorate([BindableProperty,__metadata("design:type",String)],HtmlPageEditor.prototype,"baseUrl",void 0);__decorate([Action({onEvent:"delete-element"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"deleteElement",null);__decorate([Action({onEvent:"copy-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"copyElement",null);__decorate([Action({onEvent:"move-up-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"moveUpElement",null);__decorate([Action({onEvent:"move-down-element",blockMultipleExecution:false}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"moveDownElement",null);__decorate([Action({onEvent:"change-image"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"changeImage",null);__decorate([Action({onEvent:"change-background-image"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"changeBackgroundImage",null);__decorate([Action({onEvent:"extract-element"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",Promise)],HtmlPageEditor.prototype,"extractElement",null);__decorate([Action({onEvent:"keyup"}),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,KeyboardEvent]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"onKeyUp",null);__decorate([Action({onEvent:"undo"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"undo",null);__decorate([Action({onEvent:"redo"}),__metadata("design:type",Function),__metadata("design:paramtypes",[]),__metadata("design:returntype",void 0)],HtmlPageEditor.prototype,"redo",null)}}}));AmdLoader.instance.setup("@social-mail/social-mail-client/dist/site-editor/editor/HtmlPageEditor");System.register(["tslib","@web-atoms/web-controls/dist/mobile-app/MobileApp","@web-atoms/core/dist/core/XNode","../../../../common/controls/tree/FileTreeView","@web-atoms/web-controls/dist/basic/AtomRepeater","@web-atoms/core/dist/core/Bind","@web-atoms/core/dist/core/InjectProperty","../service/CloudFileService","@web-atoms/core/dist/style/styled","../../../../common/controls/drag-drop/FilesDragDrop","@web-atoms/core/dist/view-model/Action","@web-atoms/web-controls/dist/basic/UploadEvent","../../../../common/controls/buttons/IconButton","../../../../common/fileUrl"],(function(_export,_context){"use strict";var __awaiter,__decorate,__metadata,PopupWindowPage,XNode,FolderTreeView,AtomRepeater,SelectAll,SelectorCheckBox,Bind,InjectProperty,CloudFileService,styled,FilesDragDrop,Action,UploadEvent,SaveIconTextButton,fileUrl,ChooseMediaPage,css;_export("default",void 0);return{setters:[function(_tslib){__awaiter=_tslib.__awaiter;__decorate=_tslib.__decorate;__metadata=_tslib.__metadata},function(_webAtomsWebControlsDistMobileAppMobileApp){PopupWindowPage=_webAtomsWebControlsDistMobileAppMobileApp.PopupWindowPage},function(_webAtomsCoreDistCoreXNode){XNode=_webAtomsCoreDistCoreXNode.default},function(_commonControlsTreeFileTreeView){FolderTreeView=_commonControlsTreeFileTreeView.FolderTreeView},function(_webAtomsWebControlsDistBasicAtomRepeater){AtomRepeater=_webAtomsWebControlsDistBasicAtomRepeater.default;SelectAll=_webAtomsWebControlsDistBasicAtomRepeater.SelectAll;SelectorCheckBox=_webAtomsWebControlsDistBasicAtomRepeater.SelectorCheckBox},function(_webAtomsCoreDistCoreBind){Bind=_webAtomsCoreDistCoreBind.default},function(_webAtomsCoreDistCoreInjectProperty){InjectProperty=_webAtomsCoreDistCoreInjectProperty.default},function(_serviceCloudFileService){CloudFileService=_serviceCloudFileService.default},function(_webAtomsCoreDistStyleStyled){styled=_webAtomsCoreDistStyleStyled.default},function(_commonControlsDragDropFilesDragDrop){FilesDragDrop=_commonControlsDragDropFilesDragDrop.FilesDragDrop},function(_webAtomsCoreDistViewModelAction){Action=_webAtomsCoreDistViewModelAction.default},function(_webAtomsWebControlsDistBasicUploadEvent){UploadEvent=_webAtomsWebControlsDistBasicUploadEvent.default},function(_commonControlsButtonsIconButton){SaveIconTextButton=_commonControlsButtonsIconButton.SaveIconTextButton},function(_commonFileUrl){fileUrl=_commonFileUrl.fileUrl}],execute:function(){css=styled.css`
|
|
4556
4556
|
display: grid;
|
|
4557
4557
|
grid-template-columns: 200px 1fr;
|
|
4558
4558
|
grid-template-rows: auto 1fr;
|