@jinntec/fore 1.0.0-4 → 1.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 +26 -38
- package/dist/fore-dev.js +43 -0
- package/dist/fore-dev.js.map +1 -0
- package/dist/fore.js +37 -0
- package/dist/fore.js.map +1 -0
- package/index.js +4 -0
- package/package.json +42 -42
- package/resources/fore.css +186 -0
- package/resources/toastify.css +87 -0
- package/resources/{fore-styles.css → vars.css} +0 -292
- package/src/DependencyNotifyingDomFacade.js +10 -16
- package/src/ForeElementMixin.js +26 -19
- package/src/actions/abstract-action.js +30 -9
- package/src/actions/fx-action.js +6 -4
- package/src/actions/fx-append.js +8 -17
- package/src/actions/fx-confirm.js +5 -3
- package/src/actions/fx-delete.js +6 -3
- package/src/actions/fx-dispatch.js +9 -8
- package/src/actions/fx-hide.js +10 -6
- package/src/actions/fx-insert.js +49 -39
- package/src/actions/fx-message.js +3 -1
- package/src/actions/fx-refresh.js +15 -1
- package/src/actions/fx-replace.js +73 -0
- package/src/actions/fx-return.js +42 -0
- package/src/actions/fx-send.js +3 -1
- package/src/actions/fx-setfocus.js +37 -0
- package/src/actions/fx-setvalue.js +58 -51
- package/src/actions/fx-show.js +12 -4
- package/src/actions/fx-toggle.js +15 -10
- package/src/actions/fx-update.js +3 -1
- package/src/dep_graph.js +4 -2
- package/src/drawdown.js +67 -82
- package/src/fore.js +158 -12
- package/src/functions/fx-function.js +17 -3
- package/src/fx-bind.js +42 -202
- package/src/fx-fore.js +599 -567
- package/src/fx-header.js +3 -1
- package/src/fx-instance.js +9 -1
- package/src/fx-model.js +59 -23
- package/src/fx-submission.js +106 -48
- package/src/fx-var.js +7 -4
- package/src/getInScopeContext.js +37 -11
- package/src/modelitem.js +4 -4
- package/src/relevance.js +64 -0
- package/src/ui/abstract-control.js +64 -37
- package/src/ui/fx-alert.js +7 -1
- package/src/ui/fx-case.js +4 -3
- package/src/ui/fx-container.js +7 -1
- package/src/ui/fx-control.js +309 -34
- package/src/ui/fx-dialog.js +54 -40
- package/src/ui/fx-group.js +3 -1
- package/src/ui/fx-hint.js +4 -1
- package/src/ui/fx-inspector.js +120 -17
- package/src/ui/fx-items.js +8 -8
- package/src/ui/fx-output.js +16 -5
- package/src/ui/fx-repeat.js +33 -41
- package/src/ui/fx-repeatitem.js +10 -4
- package/src/ui/fx-switch.js +5 -3
- package/src/ui/fx-trigger.js +3 -1
- package/src/xpath-evaluation.js +621 -576
- package/src/xpath-util.js +15 -8
- package/dist/fore-all.js +0 -140
- package/dist/fore-debug.js +0 -140
- package/src/.DS_Store +0 -0
- package/src/actions/.DS_Store +0 -0
- package/src/ui/.DS_Store +0 -0
package/src/fx-header.js
CHANGED
package/src/fx-instance.js
CHANGED
|
@@ -166,6 +166,12 @@ export class FxInstance extends HTMLElement {
|
|
|
166
166
|
},
|
|
167
167
|
})
|
|
168
168
|
.then(response => {
|
|
169
|
+
const { status } = response;
|
|
170
|
+
if (status >= 400) {
|
|
171
|
+
console.log('response status', status);
|
|
172
|
+
alert(`response status: ${status} - failed to load data for '${this.src}' - stopping.`);
|
|
173
|
+
throw new Error(`failed to load data - status: ${status}`);
|
|
174
|
+
}
|
|
169
175
|
const responseContentType = response.headers.get('content-type').toLowerCase();
|
|
170
176
|
console.log('********** responseContentType *********', responseContentType);
|
|
171
177
|
if (responseContentType.startsWith('text/html')) {
|
|
@@ -257,4 +263,6 @@ export class FxInstance extends HTMLElement {
|
|
|
257
263
|
console.log('_handleResponse ', loader.lastError);
|
|
258
264
|
}
|
|
259
265
|
}
|
|
260
|
-
customElements.
|
|
266
|
+
if (!customElements.get('fx-instance')) {
|
|
267
|
+
customElements.define('fx-instance', FxInstance);
|
|
268
|
+
}
|
package/src/fx-model.js
CHANGED
|
@@ -35,11 +35,11 @@ export class FxModel extends HTMLElement {
|
|
|
35
35
|
<slot></slot>
|
|
36
36
|
`;
|
|
37
37
|
|
|
38
|
-
this.addEventListener('model-construct-done',
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
38
|
+
this.addEventListener('model-construct-done', () => {
|
|
39
|
+
this.modelConstructed = true;
|
|
40
|
+
// console.log('model-construct-done fired ', this.modelConstructed);
|
|
41
|
+
// console.log('model-construct-done fired ', e.detail.model.instances);
|
|
42
|
+
},{ once: true });
|
|
43
43
|
|
|
44
44
|
this.skipUpdate = false;
|
|
45
45
|
}
|
|
@@ -95,8 +95,15 @@ export class FxModel extends HTMLElement {
|
|
|
95
95
|
*
|
|
96
96
|
*/
|
|
97
97
|
modelConstruct() {
|
|
98
|
-
console.log('### <<<<< dispatching model-construct >>>>>');
|
|
99
|
-
this.dispatchEvent(new CustomEvent('model-construct', { detail: this }));
|
|
98
|
+
// console.log('### <<<<< dispatching model-construct >>>>>');
|
|
99
|
+
// this.dispatchEvent(new CustomEvent('model-construct', { detail: this }));
|
|
100
|
+
this.dispatchEvent(
|
|
101
|
+
new CustomEvent('model-construct', {
|
|
102
|
+
composed: false,
|
|
103
|
+
bubbles: true,
|
|
104
|
+
detail: { model: this },
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
100
107
|
|
|
101
108
|
console.time('instance-loading');
|
|
102
109
|
const instances = this.querySelectorAll('fx-instance');
|
|
@@ -109,14 +116,14 @@ export class FxModel extends HTMLElement {
|
|
|
109
116
|
|
|
110
117
|
Promise.all(promises).then(() => {
|
|
111
118
|
this.instances = Array.from(instances);
|
|
112
|
-
console.log('_modelConstruct this.instances ', this.instances);
|
|
119
|
+
// console.log('_modelConstruct this.instances ', this.instances);
|
|
113
120
|
this.updateModel();
|
|
114
121
|
this.inited = true;
|
|
115
122
|
|
|
116
|
-
console.log('### <<<<< dispatching model-construct-done >>>>>');
|
|
123
|
+
// console.log('### <<<<< dispatching model-construct-done >>>>>');
|
|
117
124
|
this.dispatchEvent(
|
|
118
125
|
new CustomEvent('model-construct-done', {
|
|
119
|
-
composed:
|
|
126
|
+
composed: false,
|
|
120
127
|
bubbles: true,
|
|
121
128
|
detail: { model: this },
|
|
122
129
|
}),
|
|
@@ -127,7 +134,7 @@ export class FxModel extends HTMLElement {
|
|
|
127
134
|
// ### if there's no instance one will created
|
|
128
135
|
this.dispatchEvent(
|
|
129
136
|
new CustomEvent('model-construct-done', {
|
|
130
|
-
composed:
|
|
137
|
+
composed: false,
|
|
131
138
|
bubbles: true,
|
|
132
139
|
detail: { model: this },
|
|
133
140
|
}),
|
|
@@ -146,32 +153,32 @@ export class FxModel extends HTMLElement {
|
|
|
146
153
|
* update action triggering the update cycle
|
|
147
154
|
*/
|
|
148
155
|
updateModel() {
|
|
149
|
-
console.time('updateModel');
|
|
156
|
+
// console.time('updateModel');
|
|
150
157
|
this.rebuild();
|
|
151
|
-
if(this.skipUpdate) return;
|
|
158
|
+
if (this.skipUpdate) return;
|
|
152
159
|
this.recalculate();
|
|
153
160
|
this.revalidate();
|
|
154
|
-
console.timeEnd('updateModel');
|
|
161
|
+
// console.timeEnd('updateModel');
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
rebuild() {
|
|
158
165
|
console.group('### rebuild');
|
|
159
166
|
console.time('rebuild');
|
|
160
|
-
this.mainGraph = new DepGraph(false); //do: should be moved down below binds.length check but causes errors in tests.
|
|
167
|
+
this.mainGraph = new DepGraph(false); // do: should be moved down below binds.length check but causes errors in tests.
|
|
161
168
|
this.modelItems = [];
|
|
162
169
|
|
|
163
170
|
// trigger recursive initialization of the fx-bind elements
|
|
164
171
|
const binds = this.querySelectorAll('fx-model > fx-bind');
|
|
165
|
-
if(binds.length === 0
|
|
166
|
-
console.log('skipped model update');
|
|
172
|
+
if (binds.length === 0) {
|
|
173
|
+
// console.log('skipped model update');
|
|
167
174
|
this.skipUpdate = true;
|
|
168
|
-
return
|
|
175
|
+
return;
|
|
169
176
|
}
|
|
170
177
|
|
|
171
178
|
binds.forEach(bind => {
|
|
172
179
|
bind.init(this);
|
|
173
180
|
});
|
|
174
|
-
console.timeEnd('rebuild');
|
|
181
|
+
// console.timeEnd('rebuild');
|
|
175
182
|
|
|
176
183
|
// console.log(`dependencies of a `, this.mainGraph.dependenciesOf("/Q{}data[1]/Q{}a[1]:required"));
|
|
177
184
|
// console.log(`dependencies of b `, this.mainGraph.dependenciesOf("/Q{}data[1]/Q{}b[1]:required"));
|
|
@@ -195,9 +202,14 @@ export class FxModel extends HTMLElement {
|
|
|
195
202
|
* todo: use 'changed' flag on modelItems to determine subgraph for recalculation. Flag already exists but is not used.
|
|
196
203
|
*/
|
|
197
204
|
recalculate() {
|
|
205
|
+
if(!this.mainGraph){
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
198
209
|
console.group('### recalculate');
|
|
199
210
|
console.log('changed nodes ', this.changed);
|
|
200
211
|
|
|
212
|
+
|
|
201
213
|
console.time('recalculate');
|
|
202
214
|
this.computes = 0;
|
|
203
215
|
|
|
@@ -364,8 +376,9 @@ export class FxModel extends HTMLElement {
|
|
|
364
376
|
*
|
|
365
377
|
*/
|
|
366
378
|
revalidate() {
|
|
367
|
-
|
|
379
|
+
if(this.modelItems.length === 0) return true;
|
|
368
380
|
|
|
381
|
+
console.group('### revalidate');
|
|
369
382
|
console.time('revalidate');
|
|
370
383
|
let valid = true;
|
|
371
384
|
this.modelItems.forEach(modelItem => {
|
|
@@ -395,6 +408,28 @@ export class FxModel extends HTMLElement {
|
|
|
395
408
|
}
|
|
396
409
|
}
|
|
397
410
|
}
|
|
411
|
+
if (typeof bind.hasAttribute === 'function' && bind.hasAttribute('required')) {
|
|
412
|
+
const required = bind.getAttribute('required');
|
|
413
|
+
if (required) {
|
|
414
|
+
const compute = evaluateXPathToBoolean(required, modelItem.node, this);
|
|
415
|
+
console.log('modelItem required computed: ', compute);
|
|
416
|
+
modelItem.required = compute;
|
|
417
|
+
this.formElement.addToRefresh(modelItem); // let fore know that modelItem needs refresh
|
|
418
|
+
if(!modelItem.node.textContent){
|
|
419
|
+
valid = false;
|
|
420
|
+
}
|
|
421
|
+
// if (!compute) valid = false;
|
|
422
|
+
/*
|
|
423
|
+
if (!this.modelConstructed) {
|
|
424
|
+
// todo: get alert from attribute or child element
|
|
425
|
+
const alert = bind.getAlert();
|
|
426
|
+
if (alert) {
|
|
427
|
+
modelItem.addAlert(alert);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
*/
|
|
431
|
+
}
|
|
432
|
+
}
|
|
398
433
|
}
|
|
399
434
|
});
|
|
400
435
|
console.timeEnd('revalidate');
|
|
@@ -421,7 +456,7 @@ export class FxModel extends HTMLElement {
|
|
|
421
456
|
}
|
|
422
457
|
|
|
423
458
|
getDefaultInstance() {
|
|
424
|
-
return this
|
|
459
|
+
return this?.instances[0];
|
|
425
460
|
}
|
|
426
461
|
|
|
427
462
|
getDefaultInstanceData() {
|
|
@@ -445,5 +480,6 @@ export class FxModel extends HTMLElement {
|
|
|
445
480
|
return result;
|
|
446
481
|
}
|
|
447
482
|
}
|
|
448
|
-
|
|
449
|
-
customElements.define('fx-model', FxModel);
|
|
483
|
+
if (!customElements.get('fx-model')) {
|
|
484
|
+
customElements.define('fx-model', FxModel);
|
|
485
|
+
}
|
package/src/fx-submission.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fore } from './fore.js';
|
|
2
|
+
import { Relevance } from './relevance.js';
|
|
2
3
|
import { foreElementMixin } from './ForeElementMixin.js';
|
|
3
4
|
import { evaluateXPathToString, evaluateXPath } from './xpath-evaluation.js';
|
|
4
5
|
import getInScopeContext from './getInScopeContext.js';
|
|
@@ -66,7 +67,7 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
async submit() {
|
|
69
|
-
await
|
|
70
|
+
await Fore.dispatch(this, 'submit', { submission: this });
|
|
70
71
|
this._submit();
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -77,12 +78,13 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
77
78
|
|
|
78
79
|
model.recalculate();
|
|
79
80
|
|
|
80
|
-
if (this.validate) {
|
|
81
|
+
if (this.validate==='true') {
|
|
81
82
|
const valid = model.revalidate();
|
|
82
83
|
if (!valid) {
|
|
83
84
|
console.log('validation failed. Bubmission stopped');
|
|
84
85
|
// ### allow alerts to pop up
|
|
85
|
-
this.dispatch('submit-error', {});
|
|
86
|
+
// this.dispatch('submit-error', {});
|
|
87
|
+
Fore.dispatch(this, 'submit-error', {});
|
|
86
88
|
this.getModel().parentNode.refresh();
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
@@ -117,24 +119,20 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
117
119
|
/**
|
|
118
120
|
* sends the data after evaluating
|
|
119
121
|
*
|
|
120
|
-
* todo: can send only XML at the moment
|
|
121
122
|
* @private
|
|
122
123
|
*/
|
|
123
124
|
async _serializeAndSend() {
|
|
124
125
|
const resolvedUrl = this._evaluateAttributeTemplateExpression(this.url, this);
|
|
125
126
|
|
|
126
127
|
const instance = this.getInstance();
|
|
127
|
-
|
|
128
|
-
console.error('JSON serialization is not supported yet');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
128
|
+
console.log('instance type', instance.type);
|
|
131
129
|
|
|
132
|
-
// let serialized = serializer.serializeToString(this.nodeset);
|
|
133
130
|
let serialized;
|
|
134
131
|
if (this.serialization === 'none') {
|
|
135
132
|
serialized = undefined;
|
|
136
133
|
} else {
|
|
137
|
-
const relevant = this.selectRelevant();
|
|
134
|
+
// const relevant = this.selectRelevant(instance.type);
|
|
135
|
+
const relevant = Relevance.selectRelevant(this, instance.type);
|
|
138
136
|
serialized = this._serialize(instance.type, relevant);
|
|
139
137
|
}
|
|
140
138
|
|
|
@@ -145,19 +143,41 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
145
143
|
// console.log('data being send', serialized);
|
|
146
144
|
// console.log('submitting data',serialized);
|
|
147
145
|
|
|
148
|
-
if (resolvedUrl === '#echo') {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
// if (resolvedUrl === '#echo') {
|
|
147
|
+
if (resolvedUrl.startsWith('#echo')) {
|
|
148
|
+
let data = this._parse(serialized, instance);
|
|
149
|
+
this._handleResponse(data);
|
|
150
|
+
// this.dispatch('submit-done', {});
|
|
151
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if(resolvedUrl.startsWith('localStore:') && this.method === 'post'){
|
|
156
|
+
// let data = this._parse(serialized, instance);
|
|
157
|
+
const key = resolvedUrl.substring(resolvedUrl.indexOf(':')+1);
|
|
158
|
+
localStorage.setItem(key,serialized);
|
|
159
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if(resolvedUrl.startsWith('localStore:') && (this.method === 'consume' || this.method === 'get')){
|
|
164
|
+
// let data = this._parse(serialized, instance);
|
|
165
|
+
this.replace = 'instance';
|
|
166
|
+
const key = resolvedUrl.substring(resolvedUrl.indexOf(':')+1);
|
|
167
|
+
const serialized = localStorage.getItem(key);
|
|
168
|
+
if(!serialized){
|
|
169
|
+
Fore.dispatch(this, 'submit-error', { message: `Error reading key ${key} from localstorage` });
|
|
170
|
+
return;
|
|
154
171
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
|
|
172
|
+
let data = this._parse(serialized, instance);
|
|
173
|
+
this._handleResponse(data);
|
|
174
|
+
if(this.method === 'consume'){
|
|
175
|
+
localStorage.removeItem(key);
|
|
176
|
+
}
|
|
177
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
159
178
|
return;
|
|
160
179
|
}
|
|
180
|
+
|
|
161
181
|
// ### setting headers
|
|
162
182
|
const headers = this._getHeaders();
|
|
163
183
|
console.log('headers', headers);
|
|
@@ -168,7 +188,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
168
188
|
}
|
|
169
189
|
|
|
170
190
|
if (!this.methods.includes(this.method.toLowerCase())) {
|
|
171
|
-
this.dispatch('error', { message: `Unknown method ${this.method}` });
|
|
191
|
+
// this.dispatch('error', { message: `Unknown method ${this.method}` });
|
|
192
|
+
Fore.dispatch(this, 'error', { message: `Unknown method ${this.method}` });
|
|
172
193
|
return;
|
|
173
194
|
}
|
|
174
195
|
const response = await fetch(resolvedUrl, {
|
|
@@ -180,7 +201,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
180
201
|
});
|
|
181
202
|
|
|
182
203
|
if (!response.ok || response.status > 400) {
|
|
183
|
-
this.dispatch('submit-error', { message: `Error while submitting ${this.id}` });
|
|
204
|
+
// this.dispatch('submit-error', { message: `Error while submitting ${this.id}` });
|
|
205
|
+
Fore.dispatch(this, 'submit-error', { message: `Error while submitting ${this.id}` });
|
|
184
206
|
return;
|
|
185
207
|
}
|
|
186
208
|
|
|
@@ -204,7 +226,19 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
204
226
|
this._handleResponse(blob);
|
|
205
227
|
}
|
|
206
228
|
|
|
207
|
-
this.dispatch('submit-done', {});
|
|
229
|
+
// this.dispatch('submit-done', {});
|
|
230
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
_parse(serialized, instance) {
|
|
234
|
+
let data = null;
|
|
235
|
+
if (serialized && instance.type === 'xml') {
|
|
236
|
+
data = new DOMParser().parseFromString(serialized, 'application/xml');
|
|
237
|
+
}
|
|
238
|
+
if (serialized && instance.type === 'json') {
|
|
239
|
+
data = JSON.parse(serialized);
|
|
240
|
+
}
|
|
241
|
+
return data;
|
|
208
242
|
}
|
|
209
243
|
|
|
210
244
|
_serialize(instanceType, relevantNodes) {
|
|
@@ -221,11 +255,10 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
221
255
|
const serializer = new XMLSerializer();
|
|
222
256
|
return serializer.serializeToString(relevantNodes);
|
|
223
257
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*/
|
|
258
|
+
if (instanceType === 'json') {
|
|
259
|
+
// console.warn('JSON serialization is not yet supported')
|
|
260
|
+
return JSON.stringify(relevantNodes);
|
|
261
|
+
}
|
|
229
262
|
throw new Error('unknown instance type ', instanceType);
|
|
230
263
|
}
|
|
231
264
|
|
|
@@ -269,13 +302,28 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
269
302
|
return targetInstance;
|
|
270
303
|
}
|
|
271
304
|
|
|
305
|
+
/**
|
|
306
|
+
* handles replacement of instance data from response data.
|
|
307
|
+
*
|
|
308
|
+
* Please note that data might be
|
|
309
|
+
* @param data
|
|
310
|
+
* @private
|
|
311
|
+
*/
|
|
272
312
|
_handleResponse(data) {
|
|
273
313
|
console.log('_handleResponse ', data);
|
|
314
|
+
|
|
315
|
+
/*
|
|
316
|
+
// ### responses need to be handled depending on their type.
|
|
317
|
+
if(this.type === 'json'){
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
*/
|
|
321
|
+
|
|
274
322
|
if (this.replace === 'instance') {
|
|
275
323
|
const targetInstance = this._getTargetInstance();
|
|
276
324
|
if (targetInstance) {
|
|
277
325
|
if (this.targetref) {
|
|
278
|
-
const theTarget = evaluateXPath(
|
|
326
|
+
const [theTarget] = evaluateXPath(
|
|
279
327
|
this.targetref,
|
|
280
328
|
targetInstance.instanceData.firstElementChild,
|
|
281
329
|
this,
|
|
@@ -286,7 +334,7 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
286
334
|
parent.replaceChild(clone, theTarget);
|
|
287
335
|
console.log('finally ', parent);
|
|
288
336
|
} else if (this.into) {
|
|
289
|
-
const theTarget = evaluateXPath(
|
|
337
|
+
const [theTarget] = evaluateXPath(
|
|
290
338
|
this.into,
|
|
291
339
|
targetInstance.instanceData.firstElementChild,
|
|
292
340
|
this,
|
|
@@ -296,6 +344,7 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
296
344
|
} else {
|
|
297
345
|
const instanceData = data;
|
|
298
346
|
targetInstance.instanceData = instanceData;
|
|
347
|
+
console.log('### replaced instance ', this.getModel().instances);
|
|
299
348
|
console.log('### replaced instance ', targetInstance.instanceData);
|
|
300
349
|
}
|
|
301
350
|
|
|
@@ -318,26 +367,29 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
318
367
|
if (this.replace === 'redirect') {
|
|
319
368
|
window.location.href = data;
|
|
320
369
|
}
|
|
321
|
-
|
|
322
|
-
/*
|
|
323
|
-
const event = new CustomEvent('submit-done', {
|
|
324
|
-
composed: true,
|
|
325
|
-
bubbles: true,
|
|
326
|
-
detail: {},
|
|
327
|
-
});
|
|
328
|
-
console.log('firing',event);
|
|
329
|
-
this.dispatchEvent(event);
|
|
330
|
-
*/
|
|
331
|
-
// this.dispatch('submit-done', {});
|
|
332
370
|
}
|
|
333
371
|
|
|
334
372
|
/**
|
|
335
373
|
* select relevant nodes
|
|
336
374
|
*
|
|
337
|
-
* todo: support for 'empty'
|
|
338
375
|
* @returns {*}
|
|
339
376
|
*/
|
|
340
|
-
|
|
377
|
+
/*
|
|
378
|
+
selectRelevant(type) {
|
|
379
|
+
console.log('selectRelevant' ,type)
|
|
380
|
+
switch (type){
|
|
381
|
+
case 'xml':
|
|
382
|
+
return this._relevantXmlNodes();
|
|
383
|
+
default:
|
|
384
|
+
console.warn(`relevance selection not supported for type:${this.type}`);
|
|
385
|
+
return this.nodeset;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
// todo: support for 'empty'
|
|
391
|
+
/*
|
|
392
|
+
_relevantXmlNodes() {
|
|
341
393
|
// ### no relevance selection - current nodeset is used 'as-is'
|
|
342
394
|
if (this.nonrelevant === 'keep') {
|
|
343
395
|
return this.nodeset;
|
|
@@ -353,10 +405,11 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
353
405
|
if (this.nodeset.children.length === 0 && this._isRelevant(this.nodeset)) {
|
|
354
406
|
return this.nodeset;
|
|
355
407
|
}
|
|
356
|
-
|
|
357
|
-
return result;
|
|
408
|
+
return this._filterRelevant(this.nodeset, root);
|
|
358
409
|
}
|
|
410
|
+
*/
|
|
359
411
|
|
|
412
|
+
/*
|
|
360
413
|
_filterRelevant(node, result) {
|
|
361
414
|
const { childNodes } = node;
|
|
362
415
|
Array.from(childNodes).forEach(n => {
|
|
@@ -381,7 +434,9 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
381
434
|
});
|
|
382
435
|
return result;
|
|
383
436
|
}
|
|
437
|
+
*/
|
|
384
438
|
|
|
439
|
+
/*
|
|
385
440
|
_isRelevant(node) {
|
|
386
441
|
const mi = this.getModel().getModelItem(node);
|
|
387
442
|
if (!mi || mi.relevant) {
|
|
@@ -389,9 +444,11 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
389
444
|
}
|
|
390
445
|
return false;
|
|
391
446
|
}
|
|
447
|
+
*/
|
|
392
448
|
|
|
393
449
|
_handleError() {
|
|
394
|
-
this.dispatch('submit-error', {});
|
|
450
|
+
// this.dispatch('submit-error', {});
|
|
451
|
+
Fore.dispatch(this, 'submit-error', {});
|
|
395
452
|
/*
|
|
396
453
|
console.log('ERRRORRRRR');
|
|
397
454
|
this.dispatchEvent(
|
|
@@ -404,5 +461,6 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
404
461
|
*/
|
|
405
462
|
}
|
|
406
463
|
}
|
|
407
|
-
|
|
408
|
-
customElements.define('fx-submission', FxSubmission);
|
|
464
|
+
if (!customElements.get('fx-submission')) {
|
|
465
|
+
customElements.define('fx-submission', FxSubmission);
|
|
466
|
+
}
|
package/src/fx-var.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fore } from './fore.js';
|
|
1
2
|
import './fx-instance.js';
|
|
2
3
|
import { evaluateXPath } from './xpath-evaluation.js';
|
|
3
4
|
import { foreElementMixin } from './ForeElementMixin.js';
|
|
@@ -24,13 +25,14 @@ export class FxVariable extends foreElementMixin(HTMLElement) {
|
|
|
24
25
|
refresh() {
|
|
25
26
|
const inscope = getInScopeContext(this, this.valueQuery);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
const values = evaluateXPath(this.valueQuery, inscope, this, this.precedingVariables);
|
|
29
|
+
[this.value] = values;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
setInScopeVariables(inScopeVariables) {
|
|
31
33
|
if (inScopeVariables.has(this.name)) {
|
|
32
34
|
console.error(`The variable ${this.name} is declared more than once`);
|
|
33
|
-
|
|
35
|
+
Fore.dispatch(this, 'xforms-binding-error', {});
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
inScopeVariables.set(this.name, this);
|
|
@@ -39,5 +41,6 @@ export class FxVariable extends foreElementMixin(HTMLElement) {
|
|
|
39
41
|
this.inScopeVariables = new Map(inScopeVariables);
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
customElements.define('fx-var', FxVariable);
|
|
44
|
+
if (!customElements.get('fx-var')) {
|
|
45
|
+
customElements.define('fx-var', FxVariable);
|
|
46
|
+
}
|
package/src/getInScopeContext.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { evaluateXPathToFirstNode } from './xpath-evaluation.js';
|
|
2
|
+
import { Fore } from './fore.js';
|
|
2
3
|
|
|
3
4
|
import { XPathUtil } from './xpath-util.js';
|
|
4
5
|
|
|
5
6
|
function _getElement(node) {
|
|
6
|
-
if (node.nodeType === Node.ATTRIBUTE_NODE) {
|
|
7
|
+
if (node && node.nodeType && node.nodeType === Node.ATTRIBUTE_NODE) {
|
|
7
8
|
// The context of an attribute is the ref of the element it's defined on
|
|
8
9
|
return node.ownerElement;
|
|
9
10
|
}
|
|
@@ -28,16 +29,28 @@ function _getModelInContext(node) {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
function _getInitialContext(node, ref) {
|
|
31
|
-
const parentBind =
|
|
32
|
+
const parentBind = Fore.getClosest('[ref]', node);
|
|
33
|
+
const localFore = Fore.getClosest('fx-fore', node);
|
|
34
|
+
|
|
35
|
+
const model = _getModelInContext(node);
|
|
32
36
|
|
|
33
37
|
if (parentBind !== null) {
|
|
34
|
-
|
|
38
|
+
/*
|
|
39
|
+
make sure that the closest ref belongs to the same fx-fore element
|
|
40
|
+
*/
|
|
41
|
+
const parentBindFore = parentBind.closest('fx-fore');
|
|
42
|
+
if (localFore === parentBindFore) {
|
|
43
|
+
return parentBind.nodeset;
|
|
44
|
+
}
|
|
45
|
+
return model.getDefaultInstance().getDefaultContext();
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
const model = _getModelInContext(node);
|
|
38
48
|
if (XPathUtil.isAbsolutePath(ref)) {
|
|
39
49
|
const instanceId = XPathUtil.getInstanceId(ref);
|
|
40
|
-
|
|
50
|
+
if (instanceId) {
|
|
51
|
+
return model.getInstance(instanceId).getDefaultContext();
|
|
52
|
+
}
|
|
53
|
+
return model.getDefaultInstance().getDefaultContext();
|
|
41
54
|
}
|
|
42
55
|
if (model.getDefaultInstance() !== null && model.inited) {
|
|
43
56
|
return model.getDefaultInstance().getDefaultContext();
|
|
@@ -47,17 +60,30 @@ function _getInitialContext(node, ref) {
|
|
|
47
60
|
|
|
48
61
|
export default function getInScopeContext(node, ref) {
|
|
49
62
|
const parentElement = _getElement(node);
|
|
50
|
-
/*
|
|
51
|
-
if(parentElement.nodeName.toUpperCase() === 'FX-REPEATITEM'){
|
|
52
|
-
return parentElement.nodeset;
|
|
53
|
-
}
|
|
54
|
-
*/
|
|
55
63
|
|
|
56
|
-
const repeatItem =
|
|
64
|
+
const repeatItem = Fore.getClosest('fx-repeatitem', parentElement);
|
|
57
65
|
if (repeatItem) {
|
|
66
|
+
if (node.nodeName === 'context') {
|
|
67
|
+
return evaluateXPathToFirstNode(
|
|
68
|
+
node.nodeValue,
|
|
69
|
+
repeatItem.nodeset,
|
|
70
|
+
_getForeContext(parentElement),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
58
73
|
return repeatItem.nodeset;
|
|
59
74
|
}
|
|
60
75
|
|
|
76
|
+
if (parentElement.hasAttribute('context')) {
|
|
77
|
+
const initialContext = _getInitialContext(parentElement.parentNode, ref);
|
|
78
|
+
const contextAttr = parentElement.getAttribute('context');
|
|
79
|
+
return evaluateXPathToFirstNode(contextAttr, initialContext, _getForeContext(parentElement));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (node.nodeType === Node.ATTRIBUTE_NODE && node.nodeName === 'context') {
|
|
83
|
+
const initialContext = _getInitialContext(node.ownerElement.parentNode, ref);
|
|
84
|
+
const contextAttr = node.ownerElement.getAttribute('context');
|
|
85
|
+
return evaluateXPathToFirstNode(contextAttr, initialContext, _getForeContext(parentElement));
|
|
86
|
+
}
|
|
61
87
|
if (node.nodeType === Node.ATTRIBUTE_NODE && node.nodeName === 'ref') {
|
|
62
88
|
// Note: do not consider the ref of the owner element since it should not be used to define the
|
|
63
89
|
// context
|
package/src/modelitem.js
CHANGED
|
@@ -54,11 +54,11 @@ export class ModelItem {
|
|
|
54
54
|
console.log('modelitem.setvalue newVal', newVal);
|
|
55
55
|
|
|
56
56
|
if (newVal.nodeType === Node.DOCUMENT_NODE) {
|
|
57
|
-
|
|
58
|
-
this.node.appendChild(newVal.firstElementChild);
|
|
57
|
+
this.node.replaceWith(newVal.firstElementChild);
|
|
58
|
+
// this.node.appendChild(newVal.firstElementChild);
|
|
59
59
|
} else if (newVal.nodeType === Node.ELEMENT_NODE) {
|
|
60
|
-
|
|
61
|
-
this.node.appendChild(newVal);
|
|
60
|
+
this.node.replaceWith(newVal);
|
|
61
|
+
// this.node.appendChild(newVal);
|
|
62
62
|
} else if (this.node.nodeType === Node.ATTRIBUTE_NODE) {
|
|
63
63
|
this.node.nodeValue = newVal;
|
|
64
64
|
} else {
|