@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
@@ -38961,10 +38961,10 @@ System.register(["tslib", "@web-atoms/core/dist/di/DISingleton", "@web-atoms/cor
38961
38961
 
38962
38962
  AmdLoader.instance.setup("@social-mail/social-mail-client/dist/services/files/MimeTypeService");
38963
38963
 
38964
- System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/core/dist/di/Inject", "../../../../services/EntityService", "../../../../model/model", "../../../Sql"], function (_export, _context) {
38964
+ 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) {
38965
38965
  "use strict";
38966
38966
 
38967
- var __awaiter, __decorate, __metadata, DITransient, Inject, EntityService, WebSiteFolder, Sql, TemplateService;
38967
+ var __awaiter, __decorate, __metadata, DITransient, Inject, EntityService, AppFile, WebSiteFolder, Sql, FetchBuilder, CloudFileService, TaskManager, TemplateService;
38968
38968
  return {
38969
38969
  setters: [function (_tslib) {
38970
38970
  __awaiter = _tslib.__awaiter;
@@ -38977,12 +38977,19 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
38977
38977
  }, function (_servicesEntityService) {
38978
38978
  EntityService = _servicesEntityService.default;
38979
38979
  }, function (_modelModel) {
38980
+ AppFile = _modelModel.AppFile;
38980
38981
  WebSiteFolder = _modelModel.WebSiteFolder;
38981
38982
  }, function (_Sql) {
38982
38983
  Sql = _Sql.Sql;
38984
+ }, function (_webAtomsCoreDistServicesFetchBuilder) {
38985
+ FetchBuilder = _webAtomsCoreDistServicesFetchBuilder.default;
38986
+ }, function (_webPageFilesServiceCloudFileService) {
38987
+ CloudFileService = _webPageFilesServiceCloudFileService.default;
38988
+ }, function (_webAtomsEntityDistModelsTaskManager) {
38989
+ TaskManager = _webAtomsEntityDistModelsTaskManager.default;
38983
38990
  }],
38984
38991
  execute: function () {
38985
- TemplateService = class TemplateService {
38992
+ TemplateService = class TemplateService extends TaskManager {
38986
38993
  search({
38987
38994
  search = "",
38988
38995
  start = 0,
@@ -39005,8 +39012,198 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
39005
39012
  });
39006
39013
  });
39007
39014
  }
39015
+ copyTemplate(templateFolderID, destFolderID, siteRoot = "/") {
39016
+ return __awaiter(this, void 0, void 0, function* () {
39017
+ const allFiles = yield this.entityService.query(AppFile, "templateSnapshot", templateFolderID).toArray();
39018
+ const fileMap = this.fileMap = new Map();
39019
+ const fcMap = this.fcMap = new Map();
39020
+ this.absolutePaths = new Map();
39021
+ for (const iterator of allFiles) {
39022
+ fileMap.set(iterator.appFileID, iterator);
39023
+ if (iterator.fileContentID) {
39024
+ fcMap.set(iterator.fileContentID, iterator);
39025
+ }
39026
+ if (iterator.contentType === "snapshot" && !iterator.parent) {
39027
+ this.root = iterator;
39028
+ continue;
39029
+ }
39030
+ }
39031
+ for (const iterator of this.root.children) {
39032
+ yield this.copyFile(iterator, destFolderID, siteRoot);
39033
+ }
39034
+ this.fcMap = null;
39035
+ this.fileMap = null;
39036
+ this.absolutePaths = null;
39037
+ });
39038
+ }
39039
+ copyFile(source, destFolderID, siteRoot) {
39040
+ return __awaiter(this, void 0, void 0, function* () {
39041
+ siteRoot = siteRoot + source.name + "/";
39042
+ let destFile = yield this.entityService.query(AppFile).where({
39043
+ destFolderID,
39044
+ name: source.name
39045
+ }, p => x => x.parentID === p.destFolderID && x.isDeleted === false && x.name === p.name).firstOrDefault();
39046
+ destFile !== null && destFile !== void 0 ? destFile : destFile = AppFile.create(Object.assign(Object.assign({}, source), {
39047
+ fileContentID: void 0,
39048
+ appFileID: void 0,
39049
+ parentID: destFolderID
39050
+ }));
39051
+ if (destFile.fileContentID !== source.fileContentID) {
39052
+ destFile.fileContentID = source.fileContentID;
39053
+ yield this.entityService.save(destFile, c => c);
39054
+ destFile.downloadUrl = source.downloadUrl;
39055
+ destFile.url = source.url;
39056
+ }
39057
+ const tasks = [];
39058
+ if (source.isFolder && source.children) {
39059
+ for (const child of source.children) {
39060
+ tasks.push(this.run(() => this.copyFile(child, destFile.appFileID, siteRoot)));
39061
+ }
39062
+ }
39063
+ if (tasks.length) {
39064
+ yield Promise.all(tasks);
39065
+ }
39066
+ if (!destFile.fileContentID) {
39067
+ return;
39068
+ }
39069
+ if (/\.html?$/i.test(destFile.name)) {
39070
+ yield this.updateHtmlReferences(source, destFile, siteRoot);
39071
+ return;
39072
+ }
39073
+ if (/\.css$/i.test(destFile.name)) {
39074
+ let css = yield FetchBuilder.get(destFile.downloadUrl).responseAsText();
39075
+ css = this.updateCssReferences(source, destFile, css);
39076
+ if (css) {
39077
+ yield this.cloudFileService.saveFile({
39078
+ appFileID: destFile.appFileID,
39079
+ content: new File([css], destFile.name, {
39080
+ type: destFile.contentType
39081
+ })
39082
+ });
39083
+ }
39084
+ }
39085
+ });
39086
+ }
39087
+ updateCssReferences(source, destFile, css) {
39088
+ const regex = /url\(((\"[^\"]+\")|([^\)]+))\)/gmi;
39089
+ let updated = false;
39090
+ let m;
39091
+ const list = new Set();
39092
+ while ((m = regex.exec(css)) !== null) {
39093
+ if (m.index === regex.lastIndex) {
39094
+ regex.lastIndex++;
39095
+ }
39096
+ if (m.length) {
39097
+ const [matched, group] = m;
39098
+ if (group) {
39099
+ list.add(group);
39100
+ }
39101
+ }
39102
+ }
39103
+ for (const fg of list.values()) {
39104
+ let link = fg;
39105
+ const first = link[0];
39106
+ const encoded = first === '"' || first === "'";
39107
+ if (encoded) {
39108
+ link = link.substring(1, link.length - 1);
39109
+ }
39110
+ if (!/(https?\:)?\/\//i.test(link)) {
39111
+ continue;
39112
+ }
39113
+ const url = new URL(link, "https://socialmail.in");
39114
+ if (!url.pathname.startsWith("/api/site/snapshot/")) {
39115
+ continue;
39116
+ }
39117
+ const {
39118
+ 6: fcID
39119
+ } = url.pathname.split("/");
39120
+ const resource = this.fcMap.get(fcID);
39121
+ link = this.getRelativePath(source, resource);
39122
+ css = css.split(fg).join(link);
39123
+ updated = true;
39124
+ }
39125
+ if (updated) {
39126
+ return css;
39127
+ }
39128
+ return null;
39129
+ }
39130
+ updateHtmlReferences(source, destFile, siteRoot) {
39131
+ return __awaiter(this, void 0, void 0, function* () {
39132
+ const parser = new DOMParser();
39133
+ const text = yield FetchBuilder.get(destFile.downloadUrl).responseAsText();
39134
+ const dom = parser.parseFromString(text, "text/html");
39135
+ let modified = false;
39136
+ for (const iterator of Array.from(dom.documentElement.querySelectorAll("*"))) {
39137
+ let attributeName = "src";
39138
+ switch (iterator.tagName) {
39139
+ case "LINK":
39140
+ attributeName = "href";
39141
+ break;
39142
+ case "IMG":
39143
+ break;
39144
+ case "STYLE":
39145
+ const css = this.updateCssReferences(source, destFile, iterator.textContent);
39146
+ if (css) {
39147
+ iterator.textContent = css;
39148
+ }
39149
+ continue;
39150
+ default:
39151
+ continue;
39152
+ }
39153
+ let link = iterator[attributeName];
39154
+ const url = new URL(link);
39155
+ if (!url.pathname.startsWith("/api/site/snapshot/")) {
39156
+ continue;
39157
+ }
39158
+ const {
39159
+ 6: fcID
39160
+ } = url.pathname.split("/");
39161
+ const resource = this.fcMap.get(fcID);
39162
+ link = this.getRelativePath(source, resource);
39163
+ iterator.setAttribute(attributeName, link);
39164
+ modified = true;
39165
+ }
39166
+ if (!modified) {
39167
+ return;
39168
+ }
39169
+ const content = dom.documentElement.outerHTML;
39170
+ const fileName = destFile.name;
39171
+ yield this.cloudFileService.saveFile({
39172
+ content: new File([content], fileName, {
39173
+ type: "text/html"
39174
+ }),
39175
+ appFileID: destFile.appFileID
39176
+ });
39177
+ });
39178
+ }
39179
+ getRelativePath(destFile, resource, prefix = "") {
39180
+ const destPath = this.toAbsolutePath(destFile.parent);
39181
+ const resPath = this.toAbsolutePath(resource);
39182
+ if (resPath.startsWith(destPath)) {
39183
+ prefix = prefix ? "../" : "./";
39184
+ return prefix + resPath.substring(destPath.length + 1);
39185
+ }
39186
+ prefix = prefix ? prefix + "../" : "../";
39187
+ return this.getRelativePath(destFile.parent, resource, prefix);
39188
+ }
39189
+ toAbsolutePath(resource) {
39190
+ let path = this.absolutePaths.get(resource);
39191
+ if (path) {
39192
+ return path;
39193
+ }
39194
+ const parent = resource.parent;
39195
+ if (parent) {
39196
+ path = this.toAbsolutePath(parent) + "/" + resource.name;
39197
+ this.absolutePaths.set(resource, path);
39198
+ return path;
39199
+ }
39200
+ path = "/" + resource.name;
39201
+ this.absolutePaths.set(resource, path);
39202
+ return path;
39203
+ }
39008
39204
  };
39009
39205
  __decorate([Inject, __metadata("design:type", EntityService)], TemplateService.prototype, "entityService", void 0);
39206
+ __decorate([Inject, __metadata("design:type", CloudFileService)], TemplateService.prototype, "cloudFileService", void 0);
39010
39207
  TemplateService = __decorate([DITransient()], TemplateService);
39011
39208
  _export("default", TemplateService);
39012
39209
  }
@@ -39016,10 +39213,10 @@ System.register(["tslib", "@web-atoms/core/dist/di/DITransient", "@web-atoms/cor
39016
39213
 
39017
39214
  AmdLoader.instance.setup("@social-mail/social-mail-client/dist/common/pages/websites/templates/TemplateService");
39018
39215
 
39019
- 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) {
39216
+ 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) {
39020
39217
  "use strict";
39021
39218
 
39022
- var __awaiter, __decorate, __metadata, PopupWindowPage, XNode, Action, UMD, FetchBuilder, InjectProperty, CloudFileService, MimeTypeService, AtomRepeater, InfiniteRepeater, TemplateService, styled, Bind, AddIconTextButton, ChooseWebSiteTemplatePage, css;
39219
+ var __awaiter, __decorate, __metadata, PopupWindowPage, XNode, Action, UMD, FetchBuilder, InjectProperty, CloudFileService, MimeTypeService, AtomRepeater, InfiniteRepeater, TemplateService, styled, Bind, AddIconTextButton, EntityService, ChooseWebSiteTemplatePage, css;
39023
39220
  _export("default", void 0);
39024
39221
  return {
39025
39222
  setters: [function (_tslib) {
@@ -39054,6 +39251,8 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
39054
39251
  Bind = _webAtomsCoreDistCoreBind.default;
39055
39252
  }, function (_controlsButtonsIconButton) {
39056
39253
  AddIconTextButton = _controlsButtonsIconButton.AddIconTextButton;
39254
+ }, function (_servicesEntityService) {
39255
+ EntityService = _servicesEntityService.default;
39057
39256
  }],
39058
39257
  execute: function () {
39059
39258
  css = styled.css`
@@ -39159,27 +39358,8 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
39159
39358
  }
39160
39359
  useTemplate(item) {
39161
39360
  return __awaiter(this, void 0, void 0, function* () {
39162
- const host = `/api/site/draft/${item.folderID}`;
39163
- let html = yield FetchBuilder.get(`${host}/index.html`).responseAsText();
39164
- const parser = new DOMParser();
39165
- const doc = parser.parseFromString(html, "text/html");
39166
- let modified = false;
39167
- for (const iterator of Array.from(doc.querySelectorAll(`link[rel="stylesheet"]`))) {
39168
- const href = iterator.getAttribute("href");
39169
- if (/vars\.css/i.test(href)) {
39170
- continue;
39171
- }
39172
- modified = true;
39173
- const path = href.split("#")[0].split("?")[0];
39174
- const name = path.split("/").pop();
39175
- const style = yield this.upload(void 0, name, "styles", void 0, href);
39176
- iterator.setAttribute("href", `/api/site/asset/download/${this.parameters.appFileID}/${style.appFileID}/${style.fileContentID}/${name}`);
39177
- }
39178
- if (modified) {
39179
- html = doc.documentElement.outerHTML;
39180
- }
39181
- yield this.upload(host, "index.html", void 0, html);
39182
- yield this.upload(host, "vars.css", "styles");
39361
+ yield this.templateService.copyTemplate(item.folderID, this.parameters.appFileID);
39362
+ return true;
39183
39363
  });
39184
39364
  }
39185
39365
  upload(host, fileName, folder = void 0, content = void 0, url = void 0) {
@@ -39221,6 +39401,7 @@ System.register(["tslib", "@web-atoms/web-controls/dist/mobile-app/MobileApp", "
39221
39401
  }
39222
39402
  });
39223
39403
  __decorate([InjectProperty, __metadata("design:type", CloudFileService)], ChooseWebSiteTemplatePage.prototype, "cloudFileService", void 0);
39404
+ __decorate([InjectProperty, __metadata("design:type", EntityService)], ChooseWebSiteTemplatePage.prototype, "entityService", void 0);
39224
39405
  __decorate([InjectProperty, __metadata("design:type", MimeTypeService)], ChooseWebSiteTemplatePage.prototype, "mimeTypeService", void 0);
39225
39406
  __decorate([InjectProperty, __metadata("design:type", TemplateService)], ChooseWebSiteTemplatePage.prototype, "templateService", void 0);
39226
39407
  __decorate([Action({
@@ -45007,10 +45188,11 @@ System.register(["./apiPath"], function (_export, _context) {
45007
45188
  }],
45008
45189
  execute: function () {
45009
45190
  _export("imageUrl", imageUrl = (site, file, size) => {
45191
+ const name = encodeURIComponent(file.name);
45010
45192
  if (!size) {
45011
- return apiPath(`/api/site/asset/webp/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${file.name}.webp`);
45193
+ return apiPath(`/api/site/asset/webp/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${name}.webp`);
45012
45194
  }
45013
- return apiPath(`/api/site/asset/webp(${size})/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${file.name}.${size}.webp`);
45195
+ return apiPath(`/api/site/asset/webp(${size})/${site.appFileID}/${file.appFileID}/${file.fileContentID}/${name}.${size}.webp`);
45014
45196
  });
45015
45197
  _export("srcSetUrl", srcSetUrl = (site, file) => {
45016
45198
  const small = imageUrl(site, file, 480) + " 640w";
@@ -45126,6 +45308,7 @@ System.register(["tslib", "@web-atoms/core/dist/core/BindableProperty", "./HtmlP
45126
45308
  script.setAttribute("web-components", "social");
45127
45309
  script.setAttribute("async", "true");
45128
45310
  script.setAttribute("defer", "true");
45311
+ this.htmlDocument.head.appendChild(this.htmlDocument.createTextNode("\n"));
45129
45312
  this.htmlDocument.head.appendChild(script);
45130
45313
  }
45131
45314
  script.setAttribute("src", "//cdn.jsdelivr.net/npm/@social-mail/web-components@1.0.48/dist/components.webpack.js");
@@ -45144,6 +45327,7 @@ System.register(["tslib", "@web-atoms/core/dist/core/BindableProperty", "./HtmlP
45144
45327
  }
45145
45328
  if (!link) {
45146
45329
  link !== null && link !== void 0 ? link : link = document.createElement("link");
45330
+ document.head.appendChild(this.htmlDocument.createTextNode("\n"));
45147
45331
  document.head.appendChild(link);
45148
45332
  link.rel = "stylesheet";
45149
45333
  link.setAttribute("styler-css", file.name);