@jinntec/fore 1.0.0-5 → 1.0.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 +6 -27
- 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 +2 -1
- package/package.json +35 -39
- package/resources/fore.css +22 -54
- package/src/DependencyNotifyingDomFacade.js +5 -13
- package/src/ForeElementMixin.js +13 -20
- package/src/actions/abstract-action.js +14 -9
- package/src/actions/fx-action.js +6 -5
- package/src/actions/fx-append.js +8 -17
- package/src/actions/fx-confirm.js +3 -1
- package/src/actions/fx-delete.js +6 -3
- package/src/actions/fx-dispatch.js +9 -8
- package/src/actions/fx-hide.js +9 -6
- package/src/actions/fx-insert.js +27 -14
- package/src/actions/fx-message.js +3 -1
- package/src/actions/fx-refresh.js +11 -1
- package/src/actions/fx-replace.js +68 -0
- package/src/actions/fx-return.js +42 -0
- package/src/actions/fx-send.js +3 -1
- package/src/actions/fx-setvalue.js +58 -51
- package/src/actions/fx-show.js +8 -4
- package/src/actions/fx-toggle.js +13 -9
- package/src/actions/fx-update.js +3 -1
- package/src/dep_graph.js +1 -1
- package/src/drawdown.js +67 -82
- package/src/fore.js +141 -25
- package/src/functions/fx-function.js +11 -3
- package/src/fx-bind.js +39 -199
- package/src/fx-fore.js +101 -68
- package/src/fx-header.js +3 -1
- package/src/fx-instance.js +9 -1
- package/src/fx-model.js +31 -23
- package/src/fx-submission.js +73 -47
- package/src/fx-var.js +7 -4
- package/src/getInScopeContext.js +23 -16
- package/src/modelitem.js +4 -4
- package/src/relevance.js +65 -0
- package/src/ui/abstract-control.js +55 -35
- package/src/ui/fx-alert.js +7 -1
- package/src/ui/fx-case.js +3 -1
- package/src/ui/fx-container.js +4 -2
- package/src/ui/fx-control.js +283 -33
- package/src/ui/fx-dialog.js +50 -45
- package/src/ui/fx-group.js +3 -1
- package/src/ui/fx-hint.js +4 -1
- package/src/ui/fx-inspector.js +117 -17
- package/src/ui/fx-items.js +7 -5
- package/src/ui/fx-output.js +14 -5
- package/src/ui/fx-repeat.js +13 -26
- package/src/ui/fx-repeatitem.js +10 -4
- package/src/ui/fx-switch.js +3 -1
- package/src/ui/fx-trigger.js +3 -1
- package/src/xpath-evaluation.js +114 -102
- package/src/xpath-util.js +1 -5
- 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-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"));
|
|
@@ -208,7 +215,7 @@ export class FxModel extends HTMLElement {
|
|
|
208
215
|
this.subgraph.addNode(modelItem.path, modelItem.node);
|
|
209
216
|
// const dependents = this.mainGraph.dependantsOf(modelItem.path, false);
|
|
210
217
|
// this._addSubgraphDependencies(modelItem.path);
|
|
211
|
-
if (this.mainGraph.hasNode(modelItem.path)) {
|
|
218
|
+
if (this.mainGraph && this.mainGraph.hasNode(modelItem.path)) {
|
|
212
219
|
// const dependents = this.mainGraph.directDependantsOf(modelItem.path)
|
|
213
220
|
|
|
214
221
|
const all = this.mainGraph.dependantsOf(modelItem.path, false);
|
|
@@ -238,7 +245,7 @@ export class FxModel extends HTMLElement {
|
|
|
238
245
|
// ### compute the subgraph
|
|
239
246
|
const ordered = this.subgraph.overallOrder(false);
|
|
240
247
|
ordered.forEach(path => {
|
|
241
|
-
if (this.mainGraph.hasNode(path)) {
|
|
248
|
+
if (this.mainGraph && this.mainGraph.hasNode(path)) {
|
|
242
249
|
const node = this.mainGraph.getNodeData(path);
|
|
243
250
|
this.compute(node, path);
|
|
244
251
|
}
|
|
@@ -445,5 +452,6 @@ export class FxModel extends HTMLElement {
|
|
|
445
452
|
return result;
|
|
446
453
|
}
|
|
447
454
|
}
|
|
448
|
-
|
|
449
|
-
customElements.define('fx-model', FxModel);
|
|
455
|
+
if (!customElements.get('fx-model')) {
|
|
456
|
+
customElements.define('fx-model', FxModel);
|
|
457
|
+
}
|
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
|
|
|
@@ -82,7 +83,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
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,17 +143,18 @@ 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 = null;
|
|
149
|
+
if (serialized && instance.type === 'xml') {
|
|
150
|
+
data = new DOMParser().parseFromString(serialized, 'application/xml');
|
|
151
|
+
}
|
|
152
|
+
if (serialized && instance.type === 'json') {
|
|
153
|
+
data = JSON.parse(serialized);
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
this.dispatch('submit-done', {});
|
|
155
|
+
this._handleResponse(data);
|
|
156
|
+
// this.dispatch('submit-done', {});
|
|
157
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
159
158
|
return;
|
|
160
159
|
}
|
|
161
160
|
// ### setting headers
|
|
@@ -168,7 +167,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
if (!this.methods.includes(this.method.toLowerCase())) {
|
|
171
|
-
this.dispatch('error', { message: `Unknown method ${this.method}` });
|
|
170
|
+
// this.dispatch('error', { message: `Unknown method ${this.method}` });
|
|
171
|
+
Fore.dispatch(this, 'error', { message: `Unknown method ${this.method}` });
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
const response = await fetch(resolvedUrl, {
|
|
@@ -180,7 +180,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
180
180
|
});
|
|
181
181
|
|
|
182
182
|
if (!response.ok || response.status > 400) {
|
|
183
|
-
this.dispatch('submit-error', { message: `Error while submitting ${this.id}` });
|
|
183
|
+
// this.dispatch('submit-error', { message: `Error while submitting ${this.id}` });
|
|
184
|
+
Fore.dispatch(this, 'submit-error', { message: `Error while submitting ${this.id}` });
|
|
184
185
|
return;
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -204,7 +205,8 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
204
205
|
this._handleResponse(blob);
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
this.dispatch('submit-done', {});
|
|
208
|
+
// this.dispatch('submit-done', {});
|
|
209
|
+
Fore.dispatch(this, 'submit-done', {});
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
_serialize(instanceType, relevantNodes) {
|
|
@@ -221,11 +223,10 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
221
223
|
const serializer = new XMLSerializer();
|
|
222
224
|
return serializer.serializeToString(relevantNodes);
|
|
223
225
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*/
|
|
226
|
+
if (instanceType === 'json') {
|
|
227
|
+
// console.warn('JSON serialization is not yet supported')
|
|
228
|
+
return JSON.stringify(relevantNodes);
|
|
229
|
+
}
|
|
229
230
|
throw new Error('unknown instance type ', instanceType);
|
|
230
231
|
}
|
|
231
232
|
|
|
@@ -269,13 +270,28 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
269
270
|
return targetInstance;
|
|
270
271
|
}
|
|
271
272
|
|
|
273
|
+
/**
|
|
274
|
+
* handles replacement of instance data from response data.
|
|
275
|
+
*
|
|
276
|
+
* Please note that data might be
|
|
277
|
+
* @param data
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
272
280
|
_handleResponse(data) {
|
|
273
281
|
console.log('_handleResponse ', data);
|
|
282
|
+
|
|
283
|
+
/*
|
|
284
|
+
// ### responses need to be handled depending on their type.
|
|
285
|
+
if(this.type === 'json'){
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
*/
|
|
289
|
+
|
|
274
290
|
if (this.replace === 'instance') {
|
|
275
291
|
const targetInstance = this._getTargetInstance();
|
|
276
292
|
if (targetInstance) {
|
|
277
293
|
if (this.targetref) {
|
|
278
|
-
const theTarget = evaluateXPath(
|
|
294
|
+
const [theTarget] = evaluateXPath(
|
|
279
295
|
this.targetref,
|
|
280
296
|
targetInstance.instanceData.firstElementChild,
|
|
281
297
|
this,
|
|
@@ -286,7 +302,7 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
286
302
|
parent.replaceChild(clone, theTarget);
|
|
287
303
|
console.log('finally ', parent);
|
|
288
304
|
} else if (this.into) {
|
|
289
|
-
const theTarget = evaluateXPath(
|
|
305
|
+
const [theTarget] = evaluateXPath(
|
|
290
306
|
this.into,
|
|
291
307
|
targetInstance.instanceData.firstElementChild,
|
|
292
308
|
this,
|
|
@@ -296,6 +312,7 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
296
312
|
} else {
|
|
297
313
|
const instanceData = data;
|
|
298
314
|
targetInstance.instanceData = instanceData;
|
|
315
|
+
console.log('### replaced instance ', this.getModel().instances);
|
|
299
316
|
console.log('### replaced instance ', targetInstance.instanceData);
|
|
300
317
|
}
|
|
301
318
|
|
|
@@ -318,26 +335,29 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
318
335
|
if (this.replace === 'redirect') {
|
|
319
336
|
window.location.href = data;
|
|
320
337
|
}
|
|
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
338
|
}
|
|
333
339
|
|
|
334
340
|
/**
|
|
335
341
|
* select relevant nodes
|
|
336
342
|
*
|
|
337
|
-
* todo: support for 'empty'
|
|
338
343
|
* @returns {*}
|
|
339
344
|
*/
|
|
340
|
-
|
|
345
|
+
/*
|
|
346
|
+
selectRelevant(type) {
|
|
347
|
+
console.log('selectRelevant' ,type)
|
|
348
|
+
switch (type){
|
|
349
|
+
case 'xml':
|
|
350
|
+
return this._relevantXmlNodes();
|
|
351
|
+
default:
|
|
352
|
+
console.warn(`relevance selection not supported for type:${this.type}`);
|
|
353
|
+
return this.nodeset;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
// todo: support for 'empty'
|
|
359
|
+
/*
|
|
360
|
+
_relevantXmlNodes() {
|
|
341
361
|
// ### no relevance selection - current nodeset is used 'as-is'
|
|
342
362
|
if (this.nonrelevant === 'keep') {
|
|
343
363
|
return this.nodeset;
|
|
@@ -353,10 +373,11 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
353
373
|
if (this.nodeset.children.length === 0 && this._isRelevant(this.nodeset)) {
|
|
354
374
|
return this.nodeset;
|
|
355
375
|
}
|
|
356
|
-
|
|
357
|
-
return result;
|
|
376
|
+
return this._filterRelevant(this.nodeset, root);
|
|
358
377
|
}
|
|
378
|
+
*/
|
|
359
379
|
|
|
380
|
+
/*
|
|
360
381
|
_filterRelevant(node, result) {
|
|
361
382
|
const { childNodes } = node;
|
|
362
383
|
Array.from(childNodes).forEach(n => {
|
|
@@ -381,7 +402,9 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
381
402
|
});
|
|
382
403
|
return result;
|
|
383
404
|
}
|
|
405
|
+
*/
|
|
384
406
|
|
|
407
|
+
/*
|
|
385
408
|
_isRelevant(node) {
|
|
386
409
|
const mi = this.getModel().getModelItem(node);
|
|
387
410
|
if (!mi || mi.relevant) {
|
|
@@ -389,9 +412,11 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
389
412
|
}
|
|
390
413
|
return false;
|
|
391
414
|
}
|
|
415
|
+
*/
|
|
392
416
|
|
|
393
417
|
_handleError() {
|
|
394
|
-
this.dispatch('submit-error', {});
|
|
418
|
+
// this.dispatch('submit-error', {});
|
|
419
|
+
Fore.dispatch(this, 'submit-error', {});
|
|
395
420
|
/*
|
|
396
421
|
console.log('ERRRORRRRR');
|
|
397
422
|
this.dispatchEvent(
|
|
@@ -404,5 +429,6 @@ export class FxSubmission extends foreElementMixin(HTMLElement) {
|
|
|
404
429
|
*/
|
|
405
430
|
}
|
|
406
431
|
}
|
|
407
|
-
|
|
408
|
-
customElements.define('fx-submission', FxSubmission);
|
|
432
|
+
if (!customElements.get('fx-submission')) {
|
|
433
|
+
customElements.define('fx-submission', FxSubmission);
|
|
434
|
+
}
|
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,15 +1,14 @@
|
|
|
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
6
|
function _getElement(node) {
|
|
7
7
|
if (node && node.nodeType && node.nodeType === Node.ATTRIBUTE_NODE) {
|
|
8
8
|
// The context of an attribute is the ref of the element it's defined on
|
|
9
9
|
return node.ownerElement;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
14
13
|
// The context of a query should be the element having a ref
|
|
15
14
|
return node;
|
|
@@ -30,16 +29,25 @@ function _getModelInContext(node) {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
function _getInitialContext(node, ref) {
|
|
33
|
-
const parentBind =
|
|
32
|
+
const parentBind = Fore.getClosest('[ref]', node);
|
|
33
|
+
const localFore = Fore.getClosest('fx-fore', node);
|
|
34
|
+
|
|
35
|
+
const model = _getModelInContext(node);
|
|
34
36
|
|
|
35
37
|
if (parentBind !== null) {
|
|
36
|
-
|
|
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();
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
const model = _getModelInContext(node);
|
|
40
48
|
if (XPathUtil.isAbsolutePath(ref)) {
|
|
41
49
|
const instanceId = XPathUtil.getInstanceId(ref);
|
|
42
|
-
if(instanceId){
|
|
50
|
+
if (instanceId) {
|
|
43
51
|
return model.getInstance(instanceId).getDefaultContext();
|
|
44
52
|
}
|
|
45
53
|
return model.getDefaultInstance().getDefaultContext();
|
|
@@ -52,23 +60,22 @@ function _getInitialContext(node, ref) {
|
|
|
52
60
|
|
|
53
61
|
export default function getInScopeContext(node, ref) {
|
|
54
62
|
const parentElement = _getElement(node);
|
|
55
|
-
/*
|
|
56
|
-
if(parentElement.nodeName.toUpperCase() === 'FX-REPEATITEM'){
|
|
57
|
-
return parentElement.nodeset;
|
|
58
|
-
}
|
|
59
|
-
*/
|
|
60
63
|
|
|
61
|
-
const repeatItem =
|
|
64
|
+
const repeatItem = Fore.getClosest('fx-repeatitem', parentElement);
|
|
62
65
|
if (repeatItem) {
|
|
63
|
-
if(node.nodeName === 'context'){
|
|
64
|
-
return evaluateXPathToFirstNode(
|
|
66
|
+
if (node.nodeName === 'context') {
|
|
67
|
+
return evaluateXPathToFirstNode(
|
|
68
|
+
node.nodeValue,
|
|
69
|
+
repeatItem.nodeset,
|
|
70
|
+
_getForeContext(parentElement),
|
|
71
|
+
);
|
|
65
72
|
}
|
|
66
73
|
return repeatItem.nodeset;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
if (parentElement.hasAttribute('context')) {
|
|
70
|
-
const initialContext = _getInitialContext(
|
|
71
|
-
const contextAttr =
|
|
77
|
+
const initialContext = _getInitialContext(parentElement.parentNode, ref);
|
|
78
|
+
const contextAttr = parentElement.getAttribute('context');
|
|
72
79
|
return evaluateXPathToFirstNode(contextAttr, initialContext, _getForeContext(parentElement));
|
|
73
80
|
}
|
|
74
81
|
|
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 {
|
package/src/relevance.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export class Relevance {
|
|
2
|
+
static selectRelevant(element, type) {
|
|
3
|
+
console.log('selectRelevant', type);
|
|
4
|
+
switch (type) {
|
|
5
|
+
case 'xml':
|
|
6
|
+
return Relevance._relevantXmlNodes(element);
|
|
7
|
+
default:
|
|
8
|
+
console.warn(`relevance selection not supported for type:${element.type}`);
|
|
9
|
+
return element.nodeset;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static _relevantXmlNodes(element) {
|
|
14
|
+
// ### no relevance selection - current nodeset is used 'as-is'
|
|
15
|
+
const nonrelevant = element.getAttribute('nonrelevant');
|
|
16
|
+
if (nonrelevant === 'keep') {
|
|
17
|
+
return element.nodeset;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// first check if nodeset of submission is relevant - otherwise bail out
|
|
21
|
+
const mi = element.getModel().getModelItem(element.nodeset);
|
|
22
|
+
if (mi && !mi.relevant) return null;
|
|
23
|
+
|
|
24
|
+
const doc = new DOMParser().parseFromString('<data></data>', 'application/xml');
|
|
25
|
+
const root = doc.firstElementChild;
|
|
26
|
+
|
|
27
|
+
if (element.nodeset.children.length === 0 && Relevance._isRelevant(element, element.nodeset)) {
|
|
28
|
+
return element.nodeset;
|
|
29
|
+
}
|
|
30
|
+
return Relevance._filterRelevant(element, element.nodeset, root);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static _filterRelevant(element, node, result) {
|
|
34
|
+
const { childNodes } = node;
|
|
35
|
+
Array.from(childNodes).forEach(n => {
|
|
36
|
+
if (Relevance._isRelevant(element, n)) {
|
|
37
|
+
const clone = n.cloneNode(false);
|
|
38
|
+
result.appendChild(clone);
|
|
39
|
+
const { attributes } = n;
|
|
40
|
+
if (attributes) {
|
|
41
|
+
Array.from(attributes).forEach(attr => {
|
|
42
|
+
if (Relevance._isRelevant(element, attr)) {
|
|
43
|
+
clone.setAttribute(attr.nodeName, attr.value);
|
|
44
|
+
} else if (element.nonrelevant === 'empty') {
|
|
45
|
+
clone.setAttribute(attr.nodeName, '');
|
|
46
|
+
} else {
|
|
47
|
+
clone.removeAttribute(attr.nodeName);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return Relevance._filterRelevant(element, n, clone);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
});
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static _isRelevant(element, node) {
|
|
59
|
+
const mi = element.getModel().getModelItem(node);
|
|
60
|
+
if (!mi || mi.relevant) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|