Overview
Comment:Progress on web editor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: 879ddf7e697a9ff97172d78ae70828d4003fea9734490d28eb817ee177924c04
User & Date: bohwaz on 2021-05-07 01:00:35
Other Links: branch diff | manifest | tags
Context
2021-06-07
19:23
Merge trunk/stable changes Leaf check-in: b7a5f89a8c user: bohwaz tags: dev
2021-05-07
01:00
Progress on web editor check-in: 879ddf7e69 user: bohwaz tags: dev
2021-05-06
14:10
Merge trunk changes check-in: a8800bc992 user: bohwaz tags: dev
Changes

Modified src/www/admin/static/scripts/web_editor.js from [882b005b1b] to [af0473f426].

1
2
3
4
5
6


7
8
9



10








11



12


13






























































14
15
16
17
18
19
20
21

22
23


24
25





26
27










28
29
30
31
32

33
34






35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function () {

const TYPES = ['code', ];

window.WebEditor = class {
	constructor(textarea) {


		this.textarea = textarea;
		this.parse(textarea.value)
		this.editor = 



	}












	build() {

































































	}

	parse(text) {
		var blocks = text.split("\n\n----\n\n");
		this.blocks = [];

		for (var i = 0; i < blocks.length; i++) {
			let block = blocks[i];


			if ((i % 1) == 0) {


				this.blocks.push(this.parseMeta(block));
			}





			else {
				this.blocks[this.blocks.length - 1].content = block.trim("\r\n");










			}
		}
	}

	parseMeta(text) {

		var lines = text.split("\n");
		var meta = {};







		for (var i = 0; i < lines.length; i++) {
			var line = lines[i].split(':', 2);

			if (line.length != 2) {
				continue;
			}

			meta[line[0].trim().toLowerCase()] = line[1].trim();
		}

		return meta;
	}
}

})();





|
>
>
|
|
<
>
>
>
|
>
>
>
>
>
>
>
>

>
>
>
|
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|


|
|
>

<
>
>
|

>
>
>
>
>
|
<
>
>
>
>
>
>
>
>
>
>




|
>
|
<
>
>
>
>
>
>








|


|




1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(function () {

const TYPES = ['code', ];

window.WebEditor = class {
	constructor() {
	}

	editor(textarea) {
		this.parse(textarea.value);

		this.textarea = textarea;
		this.form = textarea.form;
		textarea.style.display = 'none';

		this.form.addEventListener('submit', () => {
			let e = document.createElement('input');
			e.type = 'hidden';
			e.name = this.textarea.name;
			e.value = this.export();
			this.textarea.remove();
			form.appendChild(e);
		});

		this.textarea.parentNode.insertBefore(this.buildEditor(), this.textarea);
	}

	buildEditor() {
		var e = document.createElement('div');
		e.className = 'web-editor';

		e.appendChild(this.buildToolbar());

		var c = document.createElement('div');
		c.className = 'web-editor-content';

		for (var i = 0; i < this.blocks; i++) {
			c.appendChild(this.buildBlock(this.blocks[i]));
		}

		e.appendChild(c);

		return e;
	}

	buildToolbar() {
		// add column, add row, move up, move down, change type, delete + block buttons
	}

	buildBlock(block) {
		let o = document.createElement('div');

		switch (block.type) {
			case 'columns':
				o.className = 'web-columns';
				block.columns.forEach((b) => o.appendChild(this.buildBlock(b)));
				break;
			case 'column':
				o.className = 'web-column';
				block.blocks.forEach((b) => o.appendChild(this.buildBlock(b)));
				break;
			case 'heading':
				var i = document.createElement('input');
				i.value = block.content;
				o.appendChild(i);
				break;
			case 'markdown':
				o.appendChild(this.buildMarkdownEditor(block));
				break;
			case 'skriv':
				o.appendChild(this.buildSkrivEditor(block));
				break;
			case 'video':
				o.appendChild(this.buildVideoEditor(block));
				break;
			case 'image':
				o.appendChild(this.buildImageEditor(block));
				break;
			case 'gallery':
				o.appendChild(this.buildGalleryEditor(block));
				break;
			case 'code':
			case 'quote':
			default:
				var i = document.createElement('textarea');
				i.value = block.content;
				o.appendChild(i);
				break;
				//throw Error('Unknown block type');
		}
	}

	buildMarkdownEditor(block) {
	}

	parse(text) {
		var raw_blocks = text.split("\n\n----\n\n");
		this.blocks = [];

		for (var i = 0; i < raw_blocks.length; i++) {
			let block = this.parseBlock(raw_blocks[i]);
			let last = this.blocks.length ? this.blocks[this.blocks.length - 1] : null;


			if (block.type == 'columns') {
				block.columns = [];
				this.blocks.push(block);
			}
			else if (block.type == 'column') {
				if (last && last.type == 'columns') {
					block.blocks = [];
					last.columns.push(block);
				}
				else {

					console.log("Invalid column", block);
				}
			}
			else {
				if (last && last.columns.length) {
					last.columns[last.columns.length - 1].blocks = block;
				}
				else {
					console.log("Invalid block", block);
				}
			}
		}
	}

	parseBlock(text) {
		text = text.replace("\r", "");
		var parts = text.split("\n\n", 2);

		var headers = {};
		var content = parts.length == 2 ? parts[1] : '';
		var lines = parts[0].split("\n");

		// Un-escape line separators
		content = content.replace("\n\n\\----\n\n", "\n\n----\n\n");

		for (var i = 0; i < lines.length; i++) {
			var line = lines[i].split(':', 2);

			if (line.length != 2) {
				continue;
			}

			headers[line[0].trim().toLowerCase()] = line[1].trim();
		}

		return {'content': content, 'headers': headers};
	}
}

})();