@cocreate/server-side-render 1.3.53 → 1.4.0
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/CHANGELOG.md +22 -0
- package/CoCreate.config.js +2 -2
- package/docs/index.html +8 -12
- package/package.json +3 -4
- package/src/index.js +41 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.3.54...v1.4.0) (2023-08-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* crud attributes renamed ([029f963](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/029f963ce7e4951da22d2eceaae3f056a16d5d6f))
|
|
7
|
+
* Refactor SSR rendering logic in index.js ([5150fe8](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/5150fe8c3b4049b5b65c46689a7da6a19e95031b))
|
|
8
|
+
* Refactored *-target to *-selector ([58865ac](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/58865ac647a87798df0f8bbf431c19aa637c3aff))
|
|
9
|
+
* webpack.config and package.json make use of mode=production instead of process.env ([1ab8258](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/1ab825827fd6e2f0d9a33722d20be9f8e830e1ce))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* name attribute and variable renamed to key ([dc98ef7](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/dc98ef76b3d60bd187b1fcb72072f501d4124334))
|
|
15
|
+
|
|
16
|
+
## [1.3.54](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.3.53...v1.3.54) (2023-06-14)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* Update dependencies versions for [@cocreate](https://github.com/cocreate) libraries ([8132ac9](https://github.com/CoCreate-app/CoCreate-server-side-render/commit/8132ac9b5f30e912b07023e3c46ca85a365d3aa3))
|
|
22
|
+
|
|
1
23
|
## [1.3.53](https://github.com/CoCreate-app/CoCreate-server-side-render/compare/v1.3.52...v1.3.53) (2023-06-11)
|
|
2
24
|
|
|
3
25
|
|
package/CoCreate.config.js
CHANGED
package/docs/index.html
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
sizes="32x32"
|
|
12
12
|
href="https://cocreate.app/images/favicon.ico" />
|
|
13
13
|
<meta
|
|
14
|
-
|
|
14
|
+
key="description"
|
|
15
15
|
content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
|
|
16
16
|
<meta
|
|
17
|
-
|
|
17
|
+
key="keywords"
|
|
18
18
|
content="helper classes, utility classes, css framework, css library, inline style classes" />
|
|
19
19
|
<meta name="robots" content="index,follow" />
|
|
20
20
|
|
|
@@ -26,11 +26,7 @@
|
|
|
26
26
|
</head>
|
|
27
27
|
|
|
28
28
|
<body>
|
|
29
|
-
<div
|
|
30
|
-
collection=""
|
|
31
|
-
document_id=""
|
|
32
|
-
name=""
|
|
33
|
-
id="cocreate-server-side-render">
|
|
29
|
+
<div array="" object="" key="" id="cocreate-server-side-render">
|
|
34
30
|
<div
|
|
35
31
|
class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
|
|
36
32
|
<div class="display:flex align-items:center">
|
|
@@ -158,9 +154,9 @@
|
|
|
158
154
|
<textarea
|
|
159
155
|
type="code"
|
|
160
156
|
lang="html"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
array="demos"
|
|
158
|
+
object=""
|
|
159
|
+
key="demo"
|
|
164
160
|
save="false"
|
|
165
161
|
id="demo"
|
|
166
162
|
class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
|
|
@@ -183,7 +179,7 @@
|
|
|
183
179
|
show="#eye-slash"
|
|
184
180
|
hide="#eye, #demo-preview"
|
|
185
181
|
toggle="code-height"
|
|
186
|
-
toggle-
|
|
182
|
+
toggle-selector="#demo-code"
|
|
187
183
|
><i class="far fa-eye"></i
|
|
188
184
|
></a>
|
|
189
185
|
<a
|
|
@@ -193,7 +189,7 @@
|
|
|
193
189
|
show="#eye, #demo-preview"
|
|
194
190
|
hide="#eye-slash"
|
|
195
191
|
toggle="code-height"
|
|
196
|
-
toggle-
|
|
192
|
+
toggle-selector="#demo-code"
|
|
197
193
|
><i class="fas fa-eye-slash"></i
|
|
198
194
|
></a>
|
|
199
195
|
<a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/server-side-render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A simple server-side-render component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"server-side-render",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"start": "npx webpack --config webpack.config.js",
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "npx webpack --mode=production --config webpack.config.js",
|
|
29
29
|
"dev": "npx webpack --config webpack.config.js --watch",
|
|
30
30
|
"postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
|
|
31
31
|
},
|
|
@@ -45,8 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"main": "./src/index.js",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@cocreate/
|
|
49
|
-
"@cocreate/utils": "^1.21.14",
|
|
48
|
+
"@cocreate/utils": "^1.21.16",
|
|
50
49
|
"node-html-parser": "^6.1.4"
|
|
51
50
|
}
|
|
52
51
|
}
|
package/src/index.js
CHANGED
|
@@ -2,86 +2,89 @@ const { parse } = require("node-html-parser");
|
|
|
2
2
|
const { checkValue } = require("@cocreate/utils");
|
|
3
3
|
|
|
4
4
|
class CoCreateServerSideRender {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(crud) {
|
|
6
|
+
this.crud = crud;
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
async HTML(html, organization_id) {
|
|
10
10
|
const self = this
|
|
11
|
-
|
|
11
|
+
let ignoreElement = { INPUT: true, TEXTAREA: true, SELECT: true, LINK: true, IFRAME: true, "COCREATE-SELECT": true }
|
|
12
12
|
|
|
13
13
|
let dep = [];
|
|
14
14
|
let dbCache = new Map();
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
async function render(html, lastKey) {
|
|
17
17
|
const dom = parse(html);
|
|
18
18
|
for (let el of dom.querySelectorAll(
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
"[array][name][object]"
|
|
20
|
+
)) {
|
|
21
21
|
let meta = el.attributes;
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
if (ignoreElement[el.tagName])
|
|
24
24
|
continue;
|
|
25
|
-
|
|
26
|
-
if (el.
|
|
25
|
+
|
|
26
|
+
if (el.closest('.template, [template], template, [render]'))
|
|
27
|
+
continue;
|
|
28
|
+
|
|
29
|
+
if (el.hasAttribute('render-selector') || el.hasAttribute('render-closest') || el.hasAttribute('render-parent') || el.hasAttribute('render-next') || el.hasAttribute('render-next'))
|
|
27
30
|
continue;
|
|
28
|
-
|
|
29
|
-
if (el.
|
|
31
|
+
|
|
32
|
+
if (el.hasAttribute('component') || el.hasAttribute('plugin'))
|
|
30
33
|
continue;
|
|
31
|
-
|
|
34
|
+
|
|
32
35
|
if (el.hasAttribute('actions'))
|
|
33
36
|
continue;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
collection = meta['collection'],
|
|
37
|
+
let _id = meta["object"],
|
|
38
|
+
array = meta['array'],
|
|
37
39
|
name = meta['name'];
|
|
38
|
-
let key = _id +
|
|
39
|
-
if (!_id || !name || !
|
|
40
|
-
if (!checkValue(_id) || !checkValue(name) || !checkValue(
|
|
40
|
+
let key = _id + array + name;
|
|
41
|
+
if (!_id || !name || !array) continue;
|
|
42
|
+
if (!checkValue(_id) || !checkValue(name) || !checkValue(array)) continue;
|
|
41
43
|
if (dep.includes(key))
|
|
42
44
|
throw new Error(
|
|
43
|
-
`infinite loop: ${lastKey} ${
|
|
45
|
+
`infinite loop: ${lastKey} ${array} ${name} ${_id} has been already rendered`
|
|
44
46
|
);
|
|
45
47
|
else
|
|
46
48
|
dep.push(key)
|
|
47
|
-
|
|
48
|
-
let cacheKey = _id +
|
|
49
|
-
let
|
|
49
|
+
|
|
50
|
+
let cacheKey = _id + array;
|
|
51
|
+
let data;
|
|
50
52
|
if (dbCache.has(cacheKey))
|
|
51
|
-
|
|
53
|
+
data = dbCache.get(cacheKey)
|
|
52
54
|
else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
data = await self.crud.send({
|
|
56
|
+
method: 'read.object',
|
|
57
|
+
array,
|
|
58
|
+
object: {
|
|
56
59
|
_id
|
|
57
60
|
},
|
|
58
61
|
organization_id
|
|
59
62
|
});
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
dbCache.set(cacheKey,
|
|
63
|
+
if (data && data.object && data.object[0])
|
|
64
|
+
data = data.object[0]
|
|
65
|
+
|
|
66
|
+
dbCache.set(cacheKey, data)
|
|
64
67
|
}
|
|
65
|
-
|
|
66
|
-
if (!
|
|
68
|
+
|
|
69
|
+
if (!data || !data[name]) {
|
|
67
70
|
dep.pop();
|
|
68
71
|
continue;
|
|
69
72
|
}
|
|
70
|
-
let chunk =
|
|
73
|
+
let chunk = data[name];
|
|
71
74
|
if (!chunk) {
|
|
72
75
|
dep.pop();
|
|
73
76
|
continue;
|
|
74
77
|
}
|
|
75
78
|
let dom = await render(chunk);
|
|
76
|
-
|
|
79
|
+
|
|
77
80
|
el.setAttribute('rendered', '')
|
|
78
81
|
el.innerHTML = "";
|
|
79
82
|
el.appendChild(dom);
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
|
|
82
85
|
dep.pop();
|
|
83
86
|
}
|
|
84
|
-
|
|
87
|
+
|
|
85
88
|
return dom;
|
|
86
89
|
}
|
|
87
90
|
let result = await render(html, 'root');
|