@social-mail/social-mail-client 1.2.237 → 1.2.239

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.
Files changed (32) hide show
  1. package/dist/admin/AdminAppIndex.pack.js +212 -28
  2. package/dist/admin/AdminAppIndex.pack.js.map +1 -1
  3. package/dist/admin/AdminAppIndex.pack.min.js +3 -3
  4. package/dist/admin/AdminAppIndex.pack.min.js.map +1 -1
  5. package/dist/common/SocialMailApp.d.ts +1 -0
  6. package/dist/common/SocialMailApp.d.ts.map +1 -1
  7. package/dist/common/SocialMailApp.js.map +1 -1
  8. package/dist/common/fileUrl.d.ts.map +1 -1
  9. package/dist/common/fileUrl.js +3 -2
  10. package/dist/common/fileUrl.js.map +1 -1
  11. package/dist/common/pages/websites/templates/ChooseWebSiteTemplatePage.d.ts +3 -1
  12. package/dist/common/pages/websites/templates/ChooseWebSiteTemplatePage.d.ts.map +1 -1
  13. package/dist/common/pages/websites/templates/ChooseWebSiteTemplatePage.js +7 -23
  14. package/dist/common/pages/websites/templates/ChooseWebSiteTemplatePage.js.map +1 -1
  15. package/dist/common/pages/websites/templates/TemplateService.d.ts +14 -1
  16. package/dist/common/pages/websites/templates/TemplateService.d.ts.map +1 -1
  17. package/dist/common/pages/websites/templates/TemplateService.js +200 -3
  18. package/dist/common/pages/websites/templates/TemplateService.js.map +1 -1
  19. package/dist/site-editor/editor/WebSitePageEditor.d.ts.map +1 -1
  20. package/dist/site-editor/editor/WebSitePageEditor.js +2 -0
  21. package/dist/site-editor/editor/WebSitePageEditor.js.map +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/web/AppIndex.pack.js +212 -28
  24. package/dist/web/AppIndex.pack.js.map +1 -1
  25. package/dist/web/AppIndex.pack.min.js +3 -3
  26. package/dist/web/AppIndex.pack.min.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/common/SocialMailApp.ts +1 -0
  29. package/src/common/fileUrl.ts +3 -2
  30. package/src/common/pages/websites/templates/ChooseWebSiteTemplatePage.tsx +8 -33
  31. package/src/common/pages/websites/templates/TemplateService.ts +238 -2
  32. package/src/site-editor/editor/WebSitePageEditor.tsx +2 -0
@@ -42797,10 +42797,10 @@ System.register(["tslib", "@web-atoms/core/dist/di/DISingleton", "@web-atoms/cor
42797
42797
 
42798
42798
  AmdLoader.instance.setup("@social-mail/social-mail-client/dist/services/files/MimeTypeService");
42799
42799
 
42800
- System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/core/dist/di/Inject", "../../../../services/EntityService", "../../../../model/model", "../../../Sql"], function (_export, _context) {
42800
+ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/core/dist/di/Inject", "../../../../services/EntityService", "../../../../model/model", "../../../Sql", "@web-atoms/core/dist/services/FetchBuilder", "../../../../web/page/files/service/CloudFileService", "@web-atoms/entity/dist/models/TaskManager"], function (_export, _context) {
42801
42801
  "use strict";
42802
42802
 
42803
- var __awaiter, __decorate, __metadata, DITransient, Inject, EntityService, WebSiteFolder, Sql, TemplateService;
42803
+ var __awaiter, __decorate, __metadata, DITransient, Inject, EntityService, AppFile, WebSiteFolder, Sql, FetchBuilder, CloudFileService, TaskManager, TemplateService;
42804
42804
  return {
42805
42805
  setters: [function (_tslib) {
42806
42806
  __awaiter = _tslib.__awaiter;
@@ -42813,12 +42813,19 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
42813
42813
  }, function (_servicesEntityService) {
42814
42814
  EntityService = _servicesEntityService.default;
42815
42815
  }, function (_modelModel) {
42816
+ AppFile = _modelModel.AppFile;
42816
42817
  WebSiteFolder = _modelModel.WebSiteFolder;
42817
42818
  }, function (_Sql) {
42818
42819
  Sql = _Sql.Sql;
42820
+ }, function (_webAtomsCoreDistServicesFetchBuilder) {
42821
+ FetchBuilder = _webAtomsCoreDistServicesFetchBuilder.default;
42822
+ }, function (_webPageFilesServiceCloudFileService) {
42823
+ CloudFileService = _webPageFilesServiceCloudFileService.default;
42824
+ }, function (_webAtomsEntityDistModelsTaskManager) {
42825
+ TaskManager = _webAtomsEntityDistModelsTaskManager.default;
42819
42826
  }],
42820
42827
  execute: function () {
42821
- TemplateService = class TemplateService {
42828
+ TemplateService = class TemplateService extends TaskManager {
42822
42829
  search({
42823
42830
  search = "",
42824
42831
  start = 0,
@@ -42841,8 +42848,198 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
42841
42848
  });
42842
42849
  });
42843
42850
  }
42851
+ copyTemplate(templateFolderID, destFolderID, siteRoot = "/") {
42852
+ return __awaiter(this, void 0, void 0, function* () {
42853
+ const allFiles = yield this.entityService.query(AppFile, "templateSnapshot", templateFolderID).toArray();
42854
+ const fileMap = this.fileMap = new Map();
42855
+ const fcMap = this.fcMap = new Map();
42856
+ this.absolutePaths = new Map();
42857
+ for (const iterator of allFiles) {
42858
+ fileMap.set(iterator.appFileID, iterator);
42859
+ if (iterator.fileContentID) {
42860
+ fcMap.set(iterator.fileContentID, iterator);
42861
+ }
42862
+ if (iterator.contentType === "snapshot" && !iterator.parent) {
42863
+ this.root = iterator;
42864
+ continue;
42865
+ }
42866
+ }
42867
+ for (const iterator of this.root.children) {
42868
+ yield this.copyFile(iterator, destFolderID, siteRoot);
42869
+ }
42870
+ this.fcMap = null;
42871
+ this.fileMap = null;
42872
+ this.absolutePaths = null;
42873
+ });
42874
+ }
42875
+ copyFile(source, destFolderID, siteRoot) {
42876
+ return __awaiter(this, void 0, void 0, function* () {
42877
+ siteRoot = siteRoot + source.name + "/";
42878
+ let destFile = yield this.entityService.query(AppFile).where({
42879
+ destFolderID,
42880
+ name: source.name
42881
+ }, p => x => x.parentID === p.destFolderID && x.isDeleted === false && x.name === p.name).firstOrDefault();
42882
+ destFile !== null && destFile !== void 0 ? destFile : destFile = AppFile.create(Object.assign(Object.assign({}, source), {
42883
+ fileContentID: void 0,
42884
+ appFileID: void 0,
42885
+ parentID: destFolderID
42886
+ }));
42887
+ if (destFile.fileContentID !== source.fileContentID) {
42888
+ destFile.fileContentID = source.fileContentID;
42889
+ yield this.entityService.save(destFile, c => c);
42890
+ destFile.downloadUrl = source.downloadUrl;
42891
+ destFile.url = source.url;
42892
+ }
42893
+ const tasks = [];
42894
+ if (source.isFolder && source.children) {
42895
+ for (const child of source.children) {
42896
+ tasks.push(this.run(() => this.copyFile(child, destFile.appFileID, siteRoot)));
42897
+ }
42898
+ }
42899
+ if (tasks.length) {
42900
+ yield Promise.all(tasks);
42901
+ }
42902
+ if (!destFile.fileContentID) {
42903
+ return;
42904
+ }
42905
+ if (/\.html?$/i.test(destFile.name)) {
42906
+ yield this.updateHtmlReferences(source, destFile, siteRoot);
42907
+ return;
42908
+ }
42909
+ if (/\.css$/i.test(destFile.name)) {
42910
+ let css = yield FetchBuilder.get(destFile.downloadUrl).responseAsText();
42911
+ css = this.updateCssReferences(source, destFile, css);
42912
+ if (css) {
42913
+ yield this.cloudFileService.saveFile({
42914
+ appFileID: destFile.appFileID,
42915
+ content: new File([css], destFile.name, {
42916
+ type: destFile.contentType
42917
+ })
42918
+ });
42919
+ }
42920
+ }
42921
+ });
42922
+ }
42923
+ updateCssReferences(source, destFile, css) {
42924
+ const regex = /url\(((\"[^\"]+\")|([^\)]+))\)/gmi;
42925
+ let updated = false;
42926
+ let m;
42927
+ const list = new Set();
42928
+ while ((m = regex.exec(css)) !== null) {
42929
+ if (m.index === regex.lastIndex) {
42930
+ regex.lastIndex++;
42931
+ }
42932
+ if (m.length) {
42933
+ const [matched, group] = m;
42934
+ if (group) {
42935
+ list.add(group);
42936
+ }
42937
+ }
42938
+ }
42939
+ for (const fg of list.values()) {
42940
+ let link = fg;
42941
+ const first = link[0];
42942
+ const encoded = first === '"' || first === "'";
42943
+ if (encoded) {
42944
+ link = link.substring(1, link.length - 1);
42945
+ }
42946
+ if (!/(https?\:)?\/\//i.test(link)) {
42947
+ continue;
42948
+ }
42949
+ const url = new URL(link, "https://socialmail.in");
42950
+ if (!url.pathname.startsWith("/api/site/snapshot/")) {
42951
+ continue;
42952
+ }
42953
+ const {
42954
+ 6: fcID
42955
+ } = url.pathname.split("/");
42956
+ const resource = this.fcMap.get(fcID);
42957
+ link = this.getRelativePath(source, resource);
42958
+ css = css.split(fg).join(link);
42959
+ updated = true;
42960
+ }
42961
+ if (updated) {
42962
+ return css;
42963
+ }
42964
+ return null;
42965
+ }
42966
+ updateHtmlReferences(source, destFile, siteRoot) {
42967
+ return __awaiter(this, void 0, void 0, function* () {
42968
+ const parser = new DOMParser();
42969
+ const text = yield FetchBuilder.get(destFile.downloadUrl).responseAsText();
42970
+ const dom = parser.parseFromString(text, "text/html");
42971
+ let modified = false;
42972
+ for (const iterator of Array.from(dom.documentElement.querySelectorAll("*"))) {
42973
+ let attributeName = "src";
42974
+ switch (iterator.tagName) {
42975
+ case "LINK":
42976
+ attributeName = "href";
42977
+ break;
42978
+ case "IMG":
42979
+ break;
42980
+ case "STYLE":
42981
+ const css = this.updateCssReferences(source, destFile, iterator.textContent);
42982
+ if (css) {
42983
+ iterator.textContent = css;
42984
+ }
42985
+ continue;
42986
+ default:
42987
+ continue;
42988
+ }
42989
+ let link = iterator[attributeName];
42990
+ const url = new URL(link);
42991
+ if (!url.pathname.startsWith("/api/site/snapshot/")) {
42992
+ continue;
42993
+ }
42994
+ const {
42995
+ 6: fcID
42996
+ } = url.pathname.split("/");
42997
+ const resource = this.fcMap.get(fcID);
42998
+ link = this.getRelativePath(source, resource);
42999
+ iterator.setAttribute(attributeName, link);
43000
+ modified = true;
43001
+ }
43002
+ if (!modified) {
43003
+ return;
43004
+ }
43005
+ const content = dom.documentElement.outerHTML;
43006
+ const fileName = destFile.name;
43007
+ yield this.cloudFileService.saveFile({
43008
+ content: new File([content], fileName, {
43009
+ type: "text/html"
43010
+ }),
43011
+ appFileID: destFile.appFileID
43012
+ });
43013
+ });
43014
+ }
43015
+ getRelativePath(destFile, resource, prefix = "") {
43016
+ const destPath = this.toAbsolutePath(destFile.parent);
43017
+ const resPath = this.toAbsolutePath(resource);
43018
+ if (resPath.startsWith(destPath)) {
43019
+ prefix = prefix ? "../" : "./";
43020
+ return prefix + resPath.substring(destPath.length + 1);
43021
+ }
43022
+ prefix = prefix ? prefix + "../" : "../";
43023
+ return this.getRelativePath(destFile.parent, resource, prefix);
43024
+ }
43025
+ toAbsolutePath(resource) {
43026
+ let path = this.absolutePaths.get(resource);
43027
+ if (path) {
43028
+ return path;
43029
+ }
43030
+ const parent = resource.parent;
43031
+ if (parent) {
43032
+ path = this.toAbsolutePath(parent) + "/" + resource.name;
43033
+ this.absolutePaths.set(resource, path);
43034
+ return path;
43035
+ }
43036
+ path = "/" + resource.name;
43037
+ this.absolutePaths.set(resource, path);
43038
+ return path;
43039
+ }
42844
43040
  };
42845
43041
  __decorate([Inject, __metadata("design:type", EntityService)], TemplateService.prototype, "entityService", void 0);
43042
+ __decorate([Inject, __metadata("design:type", CloudFileService)], TemplateService.prototype, "cloudFileService", void 0);
42846
43043
  TemplateService = __decorate([DITransient()], TemplateService);
42847
43044
  _export("default", TemplateService);
42848
43045
  }
@@ -42852,10 +43049,10 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
42852
43049
 
42853
43050
  AmdLoader.instance.setup("@social-mail/social-mail-client/dist/common/pages/websites/templates/TemplateService");
42854
43051
 
42855
- System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "@web-atoms/core/dist/core/XNode", "@web-atoms/core/dist/view-model/Action", "@web-atoms/core/dist/core/types", "@web-atoms/core/dist/services/FetchBuilder", "@web-atoms/core/dist/core/InjectProperty", "../../../../web/page/files/service/CloudFileService", "../../../../services/files/MimeTypeService", "@web-atoms/web-controls/dist/basic/AtomRepeater", "../../../controls/repeater/InfiniteRepeater", "./TemplateService", "@web-atoms/core/dist/style/styled", "@web-atoms/core/dist/core/Bind", "../../../controls/buttons/IconButton"], function (_export, _context) {
43052
+ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "@web-atoms/core/dist/core/XNode", "@web-atoms/core/dist/view-model/Action", "@web-atoms/core/dist/core/types", "@web-atoms/core/dist/services/FetchBuilder", "@web-atoms/core/dist/core/InjectProperty", "../../../../web/page/files/service/CloudFileService", "../../../../services/files/MimeTypeService", "@web-atoms/web-controls/dist/basic/AtomRepeater", "../../../controls/repeater/InfiniteRepeater", "./TemplateService", "@web-atoms/core/dist/style/styled", "@web-atoms/core/dist/core/Bind", "../../../controls/buttons/IconButton", "../../../../services/EntityService"], function (_export, _context) {
42856
43053
  "use strict";
42857
43054
 
42858
- var __awaiter, __decorate, __metadata, PopupWindowPage, XNode, Action, UMD, FetchBuilder, InjectProperty, CloudFileService, MimeTypeService, AtomRepeater, InfiniteRepeater, TemplateService, styled, Bind, AddIconTextButton, ChooseWebSiteTemplatePage, css;
43055
+ var __awaiter, __decorate, __metadata, PopupWindowPage, XNode, Action, UMD, FetchBuilder, InjectProperty, CloudFileService, MimeTypeService, AtomRepeater, InfiniteRepeater, TemplateService, styled, Bind, AddIconTextButton, EntityService, ChooseWebSiteTemplatePage, css;
42859
43056
  _export("default", void 0);
42860
43057
  return {
42861
43058
  setters: [function (_tslib) {
@@ -42890,6 +43087,8 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
42890
43087
  Bind = _webAtomsCoreDistCoreBind.default;
42891
43088
  }, function (_controlsButtonsIconButton) {
42892
43089
  AddIconTextButton = _controlsButtonsIconButton.AddIconTextButton;
43090
+ }, function (_servicesEntityService) {
43091
+ EntityService = _servicesEntityService.default;
42893
43092
  }],
42894
43093
  execute: function () {
42895
43094
  css = styled.css`
@@ -42995,27 +43194,8 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
42995
43194
  }
42996
43195
  useTemplate(item) {
42997
43196
  return __awaiter(this, void 0, void 0, function* () {
42998
- const host = `/api/site/draft/${item.folderID}`;
42999
- let html = yield FetchBuilder.get(`${host}/index.html`).responseAsText();
43000
- const parser = new DOMParser();
43001
- const doc = parser.parseFromString(html, "text/html");
43002
- let modified = false;
43003
- for (const iterator of Array.from(doc.querySelectorAll(`link[rel="stylesheet"]`))) {
43004
- const href = iterator.getAttribute("href");
43005
- if (/vars\.css/i.test(href)) {
43006
- continue;
43007
- }
43008
- modified = true;
43009
- const path = href.split("#")[0].split("?")[0];
43010
- const name = path.split("/").pop();
43011
- const style = yield this.upload(void 0, name, "styles", void 0, href);
43012
- iterator.setAttribute("href", `/api/site/asset/download/${this.parameters.appFileID}/${style.appFileID}/${style.fileContentID}/${name}`);
43013
- }
43014
- if (modified) {
43015
- html = doc.documentElement.outerHTML;
43016
- }
43017
- yield this.upload(host, "index.html", void 0, html);
43018
- yield this.upload(host, "vars.css", "styles");
43197
+ yield this.templateService.copyTemplate(item.folderID, this.parameters.appFileID);
43198
+ return true;
43019
43199
  });
43020
43200
  }
43021
43201
  upload(host, fileName, folder = void 0, content = void 0, url = void 0) {
@@ -43057,6 +43237,7 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
43057
43237
  }
43058
43238
  });
43059
43239
  __decorate([InjectProperty, __metadata("design:type", CloudFileService)], ChooseWebSiteTemplatePage.prototype, "cloudFileService", void 0);
43240
+ __decorate([InjectProperty, __metadata("design:type", EntityService)], ChooseWebSiteTemplatePage.prototype, "entityService", void 0);
43060
43241
  __decorate([InjectProperty, __metadata("design:type", MimeTypeService)], ChooseWebSiteTemplatePage.prototype, "mimeTypeService", void 0);
43061
43242
  __decorate([InjectProperty, __metadata("design:type", TemplateService)], ChooseWebSiteTemplatePage.prototype, "templateService", void 0);
43062
43243
  __decorate([Action({
@@ -48693,10 +48874,11 @@ System.register(["./apiPath"], function (_export, _context) {
48693
48874
  }],
48694
48875
  execute: function () {
48695
48876
  _export("imageUrl", imageUrl = (site, file, size) => {
48877
+ const name = encodeURIComponent(file.name);
48696
48878
  if (!size) {
48697
- return apiPath(`/api/site/asset/webp/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${file.name}.webp`);
48879
+ return apiPath(`/api/site/asset/webp/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${name}.webp`);
48698
48880
  }
48699
- return apiPath(`/api/site/asset/webp(${size})/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${file.name}.${size}.webp`);
48881
+ return apiPath(`/api/site/asset/webp(${size})/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${name}.${size}.webp`);
48700
48882
  });
48701
48883
  _export("srcSetUrl", srcSetUrl = (site, file) => {
48702
48884
  const small = imageUrl(site, file, 480) + " 640w";
@@ -48812,6 +48994,7 @@ System.register(["tslib", "@web-atoms/core/dist/core/BindableProperty", "./HtmlP
48812
48994
  script.setAttribute("web-components", "social");
48813
48995
  script.setAttribute("async", "true");
48814
48996
  script.setAttribute("defer", "true");
48997
+ this.htmlDocument.head.appendChild(this.htmlDocument.createTextNode("\n"));
48815
48998
  this.htmlDocument.head.appendChild(script);
48816
48999
  }
48817
49000
  script.setAttribute("src", "//cdn.jsdelivr.net/npm/@social-mail/web-components@1.0.48/dist/components.webpack.js");
@@ -48830,6 +49013,7 @@ System.register(["tslib", "@web-atoms/core/dist/core/BindableProperty", "./HtmlP
48830
49013
  }
48831
49014
  if (!link) {
48832
49015
  link !== null && link !== void 0 ? link : link = document.createElement("link");
49016
+ document.head.appendChild(this.htmlDocument.createTextNode("\n"));
48833
49017
  document.head.appendChild(link);
48834
49018
  link.rel = "stylesheet";
48835
49019
  link.setAttribute("styler-css", file.name);