@freeseller/wappler-server-data 0.1.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/README.md +30 -0
- package/app_connect/components.hjson +55 -0
- package/includes/dmx-server-data.js +56 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @freeseller/wappler-server-data
|
|
2
|
+
|
|
3
|
+
Wappler App Connect component for exposing server-side rendered JSON to App Connect as `component.data`.
|
|
4
|
+
|
|
5
|
+
## Component
|
|
6
|
+
|
|
7
|
+
Use the component in your page markup like this:
|
|
8
|
+
|
|
9
|
+
`<dmx-server-data id="serverData"><script type="application/json"><%- JSON.stringify(typeof server_data !== 'undefined' ? server_data : null) %></script></dmx-server-data>`
|
|
10
|
+
|
|
11
|
+
Then access the data in App Connect as:
|
|
12
|
+
|
|
13
|
+
- `serverData.data`
|
|
14
|
+
- `serverData.data.uuid`
|
|
15
|
+
- `serverData.data.title`
|
|
16
|
+
|
|
17
|
+
## Included files
|
|
18
|
+
|
|
19
|
+
- `app_connect/components.hjson`
|
|
20
|
+
- `includes/dmx-server-data.js`
|
|
21
|
+
|
|
22
|
+
## Publish
|
|
23
|
+
|
|
24
|
+
Package name:
|
|
25
|
+
|
|
26
|
+
`@freeseller/wappler-server-data`
|
|
27
|
+
|
|
28
|
+
## Notes
|
|
29
|
+
|
|
30
|
+
This component reads JSON only from an embedded `script[type="application/json"]` block.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
components: [
|
|
3
|
+
{
|
|
4
|
+
type: 'dmx-server-data',
|
|
5
|
+
selector: 'dmx-server-data',
|
|
6
|
+
groupTitle: 'Data',
|
|
7
|
+
groupIcon: 'fa-solid fa-database',
|
|
8
|
+
title: 'Server Data',
|
|
9
|
+
icon: 'fa-solid fa-server',
|
|
10
|
+
state: 'opened',
|
|
11
|
+
anyParent: true,
|
|
12
|
+
template: '<dmx-server-data id="server_data" servervar="my_server_var"><script type="application/json"><%- JSON.stringify(typeof my_server_var !== \'undefined\' ? my_server_var : null) %></script></dmx-server-data>',
|
|
13
|
+
baseName: 'serverData',
|
|
14
|
+
help: 'Expose server-side rendered JSON to App Connect as component.data.',
|
|
15
|
+
dataScheme: [
|
|
16
|
+
{ name: 'loaded', type: 'boolean' },
|
|
17
|
+
{ name: 'data', type: 'object' }
|
|
18
|
+
],
|
|
19
|
+
outputType: 'object',
|
|
20
|
+
dataPick: true,
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
group: 'Server Data Properties',
|
|
24
|
+
variables: [
|
|
25
|
+
{ name: 'id', attribute: 'id', title: 'ID', type: 'text', defaultValue: '', required: true },
|
|
26
|
+
{ name: 'servervar', attribute: 'servervar', title: 'Server Variable', type: 'text', defaultValue: 'my_server_var', required: false }
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
actionsScheme: [
|
|
31
|
+
{
|
|
32
|
+
addTitle: 'Refresh',
|
|
33
|
+
title: 'Refresh',
|
|
34
|
+
name: 'refresh',
|
|
35
|
+
icon: 'fa fa-lg fa-refresh',
|
|
36
|
+
state: 'opened',
|
|
37
|
+
help: 'Re-read the embedded or attribute JSON and update component.data.',
|
|
38
|
+
properties: []
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
children: [],
|
|
42
|
+
allowed_children: {},
|
|
43
|
+
copyFiles: [
|
|
44
|
+
{ src: 'includes/dmx-server-data.js', dst: 'js/dmx-server-data.js' }
|
|
45
|
+
],
|
|
46
|
+
linkFiles: [
|
|
47
|
+
{ src: 'js/dmx-server-data.js', type: 'js', defer: true }
|
|
48
|
+
],
|
|
49
|
+
cssOrder: [],
|
|
50
|
+
jsOrder: []
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
attributes: [],
|
|
54
|
+
events: []
|
|
55
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
dmx.Component('server-data', {
|
|
2
|
+
initialData: {
|
|
3
|
+
loaded: false,
|
|
4
|
+
data: null
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
attributes: {
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
render(node) {
|
|
11
|
+
this._sourceNode = node;
|
|
12
|
+
this._applyServerValue(this._readServerValue());
|
|
13
|
+
node.innerHTML = '';
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
performUpdate(props) {
|
|
17
|
+
if (props.size) {
|
|
18
|
+
this._applyServerValue(this._readServerValue());
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
methods: {
|
|
23
|
+
refresh() {
|
|
24
|
+
this._applyServerValue(this._readServerValue());
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
_readServerValue() {
|
|
29
|
+
const node = this._sourceNode || this.$node;
|
|
30
|
+
if (!node) return null;
|
|
31
|
+
|
|
32
|
+
const script = node.querySelector('script[type="application/json"]');
|
|
33
|
+
if (script && script.textContent.trim()) {
|
|
34
|
+
return this._parseJson(script.textContent);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const text = node.textContent.trim();
|
|
38
|
+
return text ? this._parseJson(text) : null;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
_parseJson(json) {
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(json);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.warn('dmx-server-data: invalid JSON for', this.$node.id, error);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
_applyServerValue(value) {
|
|
51
|
+
this.set({
|
|
52
|
+
data: value,
|
|
53
|
+
loaded: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@freeseller/wappler-server-data",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Wappler App Connect server-side rendered JSON data component.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Vladimir Busov"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wappler-extension"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=12.0.0"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"app_connect/",
|
|
20
|
+
"includes/"
|
|
21
|
+
]
|
|
22
|
+
}
|