@jinntec/fore 1.7.2 → 1.8.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 +7 -7
- package/dist/fore-dev.js +2 -2
- package/dist/fore-dev.js.map +1 -1
- package/dist/fore.js +2 -2
- package/dist/fore.js.map +1 -1
- package/index.js +1 -0
- package/package.json +2 -2
- package/src/actions/fx-call.js +74 -0
- package/src/fx-instance.js +5 -2
- package/src/fx-submission.js +17 -4
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jinntec/fore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Fore - declarative user interfaces in plain HTML",
|
|
5
5
|
"module": "./index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"start:build": "cd dist && es-dev-server --open",
|
|
83
83
|
"build": "rimraf dist && rollup -c rollup.config.js",
|
|
84
84
|
"start": "es-dev-server --app-index doc/index.html --node-resolve --watch --open",
|
|
85
|
-
"
|
|
85
|
+
"install-demos": "cd demo && npm i"
|
|
86
86
|
},
|
|
87
87
|
"keywords": [
|
|
88
88
|
"Fore",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import '../fx-model.js';
|
|
2
|
+
import {AbstractAction} from './abstract-action.js';
|
|
3
|
+
import {evaluateXPath, evaluateXPathToString} from "../xpath-evaluation.js";
|
|
4
|
+
import {Fore} from "../fore";
|
|
5
|
+
import getInScopeContext from "../getInScopeContext";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `fx-call`
|
|
9
|
+
*
|
|
10
|
+
* @customElement
|
|
11
|
+
*/
|
|
12
|
+
export default class FxCall extends AbstractAction {
|
|
13
|
+
static get properties() {
|
|
14
|
+
return {
|
|
15
|
+
...super.properties,
|
|
16
|
+
action: {
|
|
17
|
+
type: String,
|
|
18
|
+
},
|
|
19
|
+
fn: {
|
|
20
|
+
type: String,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.action = '';
|
|
28
|
+
this.fn = '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
if (super.connectedCallback) {
|
|
33
|
+
super.connectedCallback();
|
|
34
|
+
}
|
|
35
|
+
if (this.hasAttribute('action')) {
|
|
36
|
+
this.action = this.getAttribute('action');
|
|
37
|
+
} else if(this.hasAttribute('function')){
|
|
38
|
+
this.fn = this.getAttribute('function');
|
|
39
|
+
|
|
40
|
+
}else{
|
|
41
|
+
throw new Error('fx-call must specify an "action" or "function" attribute');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async perform() {
|
|
46
|
+
super.perform();
|
|
47
|
+
if(this.action){
|
|
48
|
+
await this._callAction();
|
|
49
|
+
}
|
|
50
|
+
// execute function
|
|
51
|
+
if(this.fn){
|
|
52
|
+
this._callFunction();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* find action and execute it
|
|
58
|
+
*/
|
|
59
|
+
async _callAction(){
|
|
60
|
+
const action = document.querySelector(`#${this.action}`);
|
|
61
|
+
if(action){
|
|
62
|
+
await action.perform();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_callFunction(){
|
|
67
|
+
const inscope = getInScopeContext(this, 'instance()',this);
|
|
68
|
+
evaluateXPath(this.fn, inscope, this);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!customElements.get('fx-call')) {
|
|
73
|
+
window.customElements.define('fx-call', FxCall);
|
|
74
|
+
}
|
package/src/fx-instance.js
CHANGED
|
@@ -20,8 +20,7 @@ async function handleResponse(response) {
|
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
if (
|
|
23
|
-
responseContentType.startsWith('text/
|
|
24
|
-
responseContentType.startsWith('text/markdown')
|
|
23
|
+
responseContentType.startsWith('text/')
|
|
25
24
|
) {
|
|
26
25
|
// console.log("********** inside res plain *********");
|
|
27
26
|
return response.text();
|
|
@@ -207,6 +206,10 @@ export class FxInstance extends HTMLElement {
|
|
|
207
206
|
this.instanceData = {};
|
|
208
207
|
this.originalInstance = [...this.instanceData];
|
|
209
208
|
}
|
|
209
|
+
if(this.type === 'text'){
|
|
210
|
+
this.instanceData = '';
|
|
211
|
+
this.originalInstance = '';
|
|
212
|
+
}
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
async _loadData() {
|
package/src/fx-submission.js
CHANGED
|
@@ -242,6 +242,9 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
242
242
|
if (serialized && instance.getAttribute('type') === 'json') {
|
|
243
243
|
data = JSON.parse(serialized);
|
|
244
244
|
}
|
|
245
|
+
if (serialized && instance.getAttribute('type') === 'text') {
|
|
246
|
+
data = serialized;
|
|
247
|
+
}
|
|
245
248
|
return data;
|
|
246
249
|
}
|
|
247
250
|
|
|
@@ -263,6 +266,9 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
263
266
|
// console.warn('JSON serialization is not yet supported')
|
|
264
267
|
return JSON.stringify(relevantNodes);
|
|
265
268
|
}
|
|
269
|
+
if (instanceType === 'text') {
|
|
270
|
+
return relevantNodes;
|
|
271
|
+
}
|
|
266
272
|
throw new Error('unknown instance type ', instanceType);
|
|
267
273
|
}
|
|
268
274
|
|
|
@@ -394,10 +400,17 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
394
400
|
}
|
|
395
401
|
|
|
396
402
|
if (this.replace === 'all') {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
403
|
+
const target = this._getProperty('target');
|
|
404
|
+
if(target && target === '_blank'){
|
|
405
|
+
const win = window.open("", "_blank");
|
|
406
|
+
win.document.write(data);
|
|
407
|
+
win.document.close();
|
|
408
|
+
}else{
|
|
409
|
+
document.open();
|
|
410
|
+
document.write(data);
|
|
411
|
+
document.close();
|
|
412
|
+
window.location.href = resolvedUrl;
|
|
413
|
+
}
|
|
401
414
|
// document.getElementsByTagName('html')[0].innerHTML = data;
|
|
402
415
|
}
|
|
403
416
|
if (this.replace === 'target' && contentType.startsWith('text/html')) {
|