@jinntec/fore 2.4.0 → 2.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinntec/fore",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Fore - declarative user interfaces in plain HTML",
5
5
  "module": "./index.js",
6
6
  "publishConfig": {
package/src/fore.js CHANGED
@@ -300,33 +300,29 @@ export class Fore {
300
300
  const { children } = startElement;
301
301
  if (children) {
302
302
  for (const element of Array.from(children)) {
303
- if (element.nodeName.toUpperCase() === 'FX-FORE') {
304
- break;
305
- }
306
- if (Fore.isUiElement(element.nodeName)) {
307
- /**
308
- * @type {import('./ForeElementMixin.js').default}
309
- */
310
- const foreElement = element;
311
-
312
- if (typeof foreElement.refresh === 'function') {
313
- if (
314
- force &&
315
- typeof force === 'object' &&
316
- force.reason === 'index-function' &&
317
- foreElement._dependencies.isInvalidatedByIndexFunction()
318
- ) {
319
- element.refresh(force);
320
- continue;
321
- } else if (force === true) {
322
- element.refresh(force);
323
- }
303
+ if (element.nodeName.toUpperCase() === 'FX-FORE') {
304
+ break;
305
+ }
306
+ if (Fore.isUiElement(element.nodeName) && typeof element.refresh === 'function') {
307
+ /**
308
+ * @type {import('./ForeElementMixin.js').default}
309
+ */
310
+ if (
311
+ force &&
312
+ typeof force === 'object' &&
313
+ force.reason === 'index-function' &&
314
+ element._dependencies.isInvalidatedByIndexFunction()
315
+ ) {
316
+ element.refresh(force);
317
+ continue;
318
+ } else if (force === true) {
319
+ element.refresh(force);
320
+ }
321
+ // console.log('refreshing', element, element?.ref);
322
+ // console.log('refreshing ',element);
323
+ } else if (element.nodeName.toUpperCase() !== 'FX-MODEL') {
324
+ Fore.refreshChildren(element, force);
324
325
  }
325
- // console.log('refreshing', element, element?.ref);
326
- // console.log('refreshing ',element);
327
- } else if (element.nodeName.toUpperCase() !== 'FX-MODEL') {
328
- Fore.refreshChildren(element, force);
329
- }
330
326
  }
331
327
  }
332
328
  resolve('done');
package/src/fx-model.js CHANGED
@@ -416,10 +416,12 @@ export class FxModel extends HTMLElement {
416
416
  modelItem.required = compute;
417
417
  this.formElement.addToRefresh(modelItem); // let fore know that modelItem needs refresh
418
418
  if (!modelItem.node.textContent) {
419
+ /*
419
420
  console.log(
420
421
  'node is required but has no value ',
421
422
  XPathUtil.getDocPath(modelItem.node),
422
423
  );
424
+ */
423
425
  valid = false;
424
426
  }
425
427
  // if (!compute) valid = false;
@@ -436,7 +438,7 @@ export class FxModel extends HTMLElement {
436
438
  }
437
439
  }
438
440
  });
439
- // console.log('modelItems after revalidate: ', this.modelItems);
441
+ console.log('modelItems after revalidate: ', this.modelItems);
440
442
  return valid;
441
443
  }
442
444
 
@@ -508,7 +510,7 @@ export class FxModel extends HTMLElement {
508
510
  ? this.fore.parentNode.host.closest('fx-fore')
509
511
  : this.fore.parentNode.closest('fx-fore');
510
512
  if (parentFore) {
511
- console.log('shared instances from parent', this.parentNode.id);
513
+ // console.log('shared instances from parent', this.parentNode.id);
512
514
  const parentInstances = parentFore.getModel().instances;
513
515
  const shared = parentInstances.filter(shared => shared.hasAttribute('shared'));
514
516
  found = shared.find(found => found.id === id);
@@ -50,8 +50,8 @@ export class FxSubmission extends ForeElementMixin {
50
50
  ? this.getAttribute('mediatype')
51
51
  : 'application/xml';
52
52
 
53
- this.responseMediatype = this.hasAttribute('response-mediatype')
54
- ? this.getAttribute('response-mediatype')
53
+ this.responseMediatype = this.hasAttribute('responsemediatype')
54
+ ? this.getAttribute('responsemediatype')
55
55
  : this.mediatype;
56
56
  this.url = this.hasAttribute('url') ? this.getAttribute('url') : null;
57
57
 
@@ -83,7 +83,12 @@ export class FxSubmission extends ForeElementMixin {
83
83
  }
84
84
 
85
85
  async _submit() {
86
- // console.log('submitting....', this.getAttribute('id'));
86
+ console.log('submitting....', this.getAttribute('id'));
87
+ console.info(
88
+ `%csubmitting #${this.id}`,
89
+ 'background:yellow; color:black; padding:.5rem; display:inline-block; white-space: nowrap; border-radius:0.3rem;width:100%;',
90
+ );
91
+
87
92
  this.evalInContext();
88
93
  const model = this.getModel();
89
94
 
@@ -232,6 +237,11 @@ export class FxSubmission extends ForeElementMixin {
232
237
 
233
238
  if (!response.ok || response.status > 400) {
234
239
  // this.dispatch('submit-error', { message: `Error while submitting ${this.id}` });
240
+ console.info(
241
+ `%csubmit-error #${this.id}`,
242
+ 'background:red; color:black; padding:.5rem; display:inline-block; white-space: nowrap; border-radius:0.3rem;width:100%;',
243
+ );
244
+
235
245
  Fore.dispatch(this, 'submit-error', { message: `Error while submitting ${this.id}` });
236
246
  return;
237
247
  }
@@ -255,6 +265,11 @@ export class FxSubmission extends ForeElementMixin {
255
265
  // this.dispatch('submit-done', {});
256
266
  // console.log(`### <<<<< ${this.id} submit-done >>>>>`);
257
267
  Fore.dispatch(this, 'submit-done', {});
268
+ console.info(
269
+ `%csubmit-done #${this.id}`,
270
+ 'background:green; color:white; padding:.5rem; display:inline-block; white-space: nowrap; border-radius:0.3rem;width:100%;',
271
+ );
272
+
258
273
  } catch (error) {
259
274
  Fore.dispatch(this, 'submit-error', { error: error.message });
260
275
  } finally {
@@ -354,13 +369,6 @@ export class FxSubmission extends ForeElementMixin {
354
369
  _handleResponse(data, resolvedUrl, contentType) {
355
370
  // console.log('_handleResponse ', data);
356
371
 
357
- /*
358
- // ### responses need to be handled depending on their type.
359
- if(this.type === 'json'){
360
-
361
- }
362
- */
363
-
364
372
  const targetInstance = this._getTargetInstance();
365
373
 
366
374
  /*
@@ -386,16 +394,26 @@ export class FxSubmission extends ForeElementMixin {
386
394
  if (this.replace === 'instance') {
387
395
  if (targetInstance) {
388
396
  if (this.targetref) {
397
+
389
398
  const [theTarget] = evaluateXPath(
390
- this.targetref,
391
- targetInstance.instanceData.firstElementChild,
392
- this,
399
+ this.targetref,
400
+ targetInstance.instanceData.firstElementChild,
401
+ this,
393
402
  );
394
403
  console.log('theTarget', theTarget);
395
- const clone = data.firstElementChild;
396
- const parent = theTarget.parentNode;
397
- parent.replaceChild(clone, theTarget);
398
- console.log('finally ', parent);
404
+ if(this.responseMediatype === 'application/xml' || this.responseMediatype === 'text/html'){
405
+ const clone = data.firstElementChild;
406
+ const parent = theTarget.parentNode;
407
+ parent.replaceChild(clone, theTarget);
408
+ console.log('finally ', parent);
409
+ }
410
+ if(this.responseMediatype.startsWith('text/')){
411
+ theTarget.textContent = data;
412
+ }
413
+ if(this.responseMediatype === 'application/json'){
414
+ console.warn('targetref is not supported for application/json responses')
415
+ }
416
+
399
417
  } else if (this.into) {
400
418
  const [theTarget] = evaluateXPath(
401
419
  this.into,
@@ -20,6 +20,7 @@ class FxSwitch extends FxContainer {
20
20
  this.formerCase = {};
21
21
  this.selectedCase = null;
22
22
  this.cases = null;
23
+ this.visitedResetted = false;
23
24
  }
24
25
 
25
26
  connectedCallback() {
@@ -74,10 +75,13 @@ class FxSwitch extends FxContainer {
74
75
  }
75
76
 
76
77
  _resetVisited() {
78
+ if(this.visitedResetted) return;
79
+
77
80
  const visited = this.selectedCase.querySelectorAll('.visited');
78
81
  Array.from(visited).forEach(v => {
79
82
  v.classList.remove('visited');
80
83
  });
84
+ this.visitedResetted = true;
81
85
  }
82
86
 
83
87
  /**