@social-mail/social-mail-client 1.5.2 → 1.5.4
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/site-editor/editor/CssParser.d.ts +12 -0
- package/dist/site-editor/editor/CssParser.d.ts.map +1 -0
- package/dist/site-editor/editor/CssParser.js +119 -0
- package/dist/site-editor/editor/CssParser.js.map +1 -0
- package/dist/site-editor/editor/HtmlPageEditor.d.ts.map +1 -1
- package/dist/site-editor/editor/HtmlPageEditor.js +6 -3
- package/dist/site-editor/editor/HtmlPageEditor.js.map +1 -1
- package/dist/site-editor/properties/controls/PropertyEditor.d.ts +0 -1
- package/dist/site-editor/properties/controls/PropertyEditor.d.ts.map +1 -1
- package/dist/site-editor/properties/controls/PropertyEditor.js +1 -6
- package/dist/site-editor/properties/controls/PropertyEditor.js.map +1 -1
- package/dist/site-editor/styler/styles/properties/layouts/layouts.less.css +40 -0
- package/dist/site-editor/styler/styles/properties/layouts/layouts.less.css.map +1 -0
- package/dist/site-editor-app/SiteEditorApp.pack.js +130 -10
- package/dist/site-editor-app/SiteEditorApp.pack.js.map +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.min.js +1 -1
- package/dist/site-editor-app/SiteEditorApp.pack.min.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/site-editor/editor/CssParser.ts +108 -0
- package/src/site-editor/editor/HtmlPageEditor.tsx +3 -0
- package/src/site-editor/properties/controls/PropertyEditor.tsx +0 -6
- package/src/site-editor/styler/styles/properties/layouts/layouts.less +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import sleep from "@web-atoms/core/dist/core/sleep";
|
|
2
|
+
import type HtmlPageEditor from "./HtmlPageEditor";
|
|
3
|
+
import FetchBuilder from "@web-atoms/core/dist/services/FetchBuilder";
|
|
4
|
+
import { AtomBinder } from "@web-atoms/core/dist/core/AtomBinder";
|
|
5
|
+
|
|
6
|
+
export default class CssParser {
|
|
7
|
+
|
|
8
|
+
static async parse(editor: HtmlPageEditor) {
|
|
9
|
+
const cp = new CssParser(editor);
|
|
10
|
+
await cp.parse();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(private editor: HtmlPageEditor) {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async parse() {
|
|
18
|
+
const { editor } = this;
|
|
19
|
+
const r = {};
|
|
20
|
+
editor.suggestions = r;
|
|
21
|
+
const doc = editor.htmlDocument;
|
|
22
|
+
|
|
23
|
+
const tasks = [];
|
|
24
|
+
|
|
25
|
+
const styleSheets = doc.styleSheets;
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
28
|
+
for (let index = 0; index < styleSheets.length; index++) {
|
|
29
|
+
const element = styleSheets[index];
|
|
30
|
+
tasks.push(this.parseSheet(element));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await Promise.all(tasks);
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async parseSheet(cssSheet: CSSStyleSheet) {
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
|
|
41
|
+
const r = this.editor.suggestions;
|
|
42
|
+
|
|
43
|
+
let css = cssSheet;
|
|
44
|
+
if (cssSheet.href) {
|
|
45
|
+
// we need to download and parse this one...
|
|
46
|
+
css = await this.downloadStyle(cssSheet.href);
|
|
47
|
+
}
|
|
48
|
+
// scan all rules...
|
|
49
|
+
const suggestions = { ... r };
|
|
50
|
+
const cssRules = css.cssRules;
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
52
|
+
for (let i = 0; i < cssRules.length;i++) {
|
|
53
|
+
const rule = cssRules[i] as CSSStyleRule;
|
|
54
|
+
const match = /\[(styler\-[^=\]]+)=([^\]]+)\]/g.exec(rule.selectorText);
|
|
55
|
+
if (!match) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const {1: styler, 2: value } = match;
|
|
59
|
+
this.parseRule(suggestions, styler.trim(), this.unescape(value.trim()));
|
|
60
|
+
}
|
|
61
|
+
let modified = false;
|
|
62
|
+
for (const key in suggestions) {
|
|
63
|
+
if (Object.prototype.hasOwnProperty.call(suggestions, key)) {
|
|
64
|
+
const element = suggestions[key];
|
|
65
|
+
r[key] = element;
|
|
66
|
+
modified = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (modified) {
|
|
70
|
+
AtomBinder.refreshValue(this.editor, "suggestions");
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async downloadStyle(href: string) {
|
|
78
|
+
const style = await FetchBuilder.get(href).asText();
|
|
79
|
+
const parser = new DOMParser();
|
|
80
|
+
|
|
81
|
+
const html = `<!DOCTYPE html>
|
|
82
|
+
<html>
|
|
83
|
+
<head>
|
|
84
|
+
<style style-rules="rules">
|
|
85
|
+
${style}
|
|
86
|
+
</style>
|
|
87
|
+
</head>
|
|
88
|
+
<body></body>
|
|
89
|
+
</html>`;
|
|
90
|
+
|
|
91
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
92
|
+
const css = doc.querySelector(`style[style-rules=rules]`);
|
|
93
|
+
return (css as any).sheet;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
parseRule(suggestions: any, styler: string, value: string) {
|
|
97
|
+
const a = (suggestions[styler] ??= [ { label: "-", value: "" }]) as { label: string , value: string }[];
|
|
98
|
+
a.add({ label: value, value });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
unescape(value: string) {
|
|
102
|
+
if (value.startsWith('"')) {
|
|
103
|
+
return JSON.parse(value).trim();
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
@@ -57,6 +57,7 @@ import { ScrollAware } from "../blocks/ScrollAware";
|
|
|
57
57
|
import { InlineSvg } from "../blocks/InlineSvg";
|
|
58
58
|
|
|
59
59
|
import "./HtmlPageEditor.global.less";
|
|
60
|
+
import CssParser from "./CssParser";
|
|
60
61
|
|
|
61
62
|
const desktopWidth = 992;
|
|
62
63
|
const tabletWidth = 768;
|
|
@@ -708,6 +709,8 @@ export default class HtmlPageEditor extends AtomControl {
|
|
|
708
709
|
|
|
709
710
|
await WebComponents.run(this.contentEditor, this.htmlDocument);
|
|
710
711
|
|
|
712
|
+
CssParser.parse(this).catch(console.error);
|
|
713
|
+
|
|
711
714
|
this.htmlDocument.addEventListener("click", (e) => {
|
|
712
715
|
const target = e.target as HTMLAnchorElement;
|
|
713
716
|
const previous = this.selection.element;
|
|
@@ -31,12 +31,6 @@ export const BindStyleCustom = AtomControl.registerProperty("data-style-property
|
|
|
31
31
|
value={Bind.sourceTwoWays(pv, (s) => s.source.custom)}></div>, e, c);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
export const BindSuggestions = AtomControl.registerProperty("data-style-property", "value", (c, e, v) => {
|
|
35
|
-
(c as any).render(<div
|
|
36
|
-
items={Bind.oneWay<HtmlPageEditor>((s) => s.suggestions[v])}></div>, e, c);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
34
|
document.addEventListener("input", (e: InputEvent) => {
|
|
41
35
|
const target = e.target as HTMLSelectElement;
|
|
42
36
|
if (!/select/i.test(target.tagName)) {
|