@jinntec/fore 1.2.0 → 1.4.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.
Files changed (51) hide show
  1. package/dist/fore-dev.js +8 -8
  2. package/dist/fore-dev.js.map +1 -1
  3. package/dist/fore.js +7 -7
  4. package/dist/fore.js.map +1 -1
  5. package/index.js +1 -0
  6. package/package.json +2 -2
  7. package/resources/fore.css +100 -72
  8. package/src/ForeElementMixin.js +4 -0
  9. package/src/actions/abstract-action.js +102 -18
  10. package/src/actions/fx-action.js +9 -10
  11. package/src/actions/fx-append.js +1 -1
  12. package/src/actions/fx-confirm.js +3 -3
  13. package/src/actions/fx-copy.js +68 -0
  14. package/src/actions/fx-delete.js +53 -62
  15. package/src/actions/fx-dispatch.js +1 -1
  16. package/src/actions/fx-hide.js +4 -2
  17. package/src/actions/fx-insert.js +1 -1
  18. package/src/actions/fx-message.js +26 -2
  19. package/src/actions/fx-refresh.js +2 -2
  20. package/src/actions/fx-reload.js +30 -0
  21. package/src/actions/fx-replace.js +1 -1
  22. package/src/actions/fx-return.js +1 -1
  23. package/src/actions/fx-send.js +13 -3
  24. package/src/actions/fx-setfocus.js +33 -6
  25. package/src/actions/fx-setvalue.js +5 -5
  26. package/src/actions/fx-show.js +2 -1
  27. package/src/actions/fx-toggle.js +6 -1
  28. package/src/actions/fx-update.js +1 -1
  29. package/src/events.js +24 -0
  30. package/src/fore.js +128 -17
  31. package/src/fx-bind.js +6 -1
  32. package/src/fx-fore.js +93 -41
  33. package/src/fx-instance.js +95 -70
  34. package/src/fx-model.js +430 -441
  35. package/src/fx-submission.js +423 -405
  36. package/src/getInScopeContext.js +88 -82
  37. package/src/modelitem.js +5 -3
  38. package/src/relevance.js +1 -1
  39. package/src/ui/abstract-control.js +108 -22
  40. package/src/ui/fx-alert.js +0 -1
  41. package/src/ui/fx-container.js +22 -26
  42. package/src/ui/fx-control.js +84 -34
  43. package/src/ui/fx-group.js +5 -0
  44. package/src/ui/fx-inspector.js +5 -0
  45. package/src/ui/fx-output.js +14 -14
  46. package/src/ui/fx-repeat.js +2 -2
  47. package/src/ui/fx-repeatitem.js +5 -3
  48. package/src/ui/fx-switch.js +20 -8
  49. package/src/ui/fx-trigger.js +26 -19
  50. package/src/xpath-evaluation.js +49 -26
  51. package/src/xpath-util.js +26 -28
@@ -1,6 +1,43 @@
1
1
  import { Fore } from './fore.js';
2
2
  import { evaluateXPathToFirstNode } from './xpath-evaluation.js';
3
3
 
4
+ async function handleResponse(response) {
5
+ const { status } = response;
6
+ if (status >= 400) {
7
+ // console.log('response status', status);
8
+ alert(`response status: ${status} - failed to load data for '${this.src}' - stopping.`);
9
+ throw new Error(`failed to load data - status: ${status}`);
10
+ }
11
+ const responseContentType = response.headers.get('content-type').toLowerCase();
12
+ // console.log('********** responseContentType *********', responseContentType);
13
+ if (responseContentType.startsWith('text/html')) {
14
+ // const htmlResponse = response.text();
15
+ // return new DOMParser().parseFromString(htmlResponse, 'text/html');
16
+ // return response.text();
17
+ return response.text().then(result =>
18
+ // console.log('xml ********', result);
19
+ new DOMParser().parseFromString(result, 'text/html'),
20
+ );
21
+ }
22
+ if (
23
+ responseContentType.startsWith('text/plain') ||
24
+ responseContentType.startsWith('text/markdown')
25
+ ) {
26
+ // console.log("********** inside res plain *********");
27
+ return response.text();
28
+ }
29
+ if (responseContentType.startsWith('application/json')) {
30
+ // console.log("********** inside res json *********");
31
+ return response.json();
32
+ }
33
+ if (responseContentType.startsWith('application/xml')) {
34
+ const text = await response.text();
35
+ // console.log('xml ********', result);
36
+ return new DOMParser().parseFromString(text, 'application/xml');
37
+ }
38
+ return 'done';
39
+ }
40
+
4
41
  /**
5
42
  * Container for data instances.
6
43
  *
@@ -59,16 +96,15 @@ export class FxInstance extends HTMLElement {
59
96
  */
60
97
  async init() {
61
98
  // console.log('fx-instance init');
62
- await this._initInstance().then(() => {
63
- this.dispatchEvent(
64
- new CustomEvent('instance-loaded', {
65
- composed: true,
66
- bubbles: true,
67
- detail: { instance: this },
68
- }),
69
- );
70
- return this;
71
- });
99
+ await this._initInstance();
100
+ this.dispatchEvent(
101
+ new CustomEvent('instance-loaded', {
102
+ composed: true,
103
+ bubbles: true,
104
+ detail: { instance: this },
105
+ }),
106
+ );
107
+ return this;
72
108
  }
73
109
 
74
110
  evalXPath(xpath) {
@@ -84,14 +120,14 @@ export class FxInstance extends HTMLElement {
84
120
  */
85
121
  getInstanceData() {
86
122
  if (!this.instanceData) {
87
- this._createInstanceData();
123
+ this.createInstanceData();
88
124
  }
89
125
  return this.instanceData;
90
126
  }
91
127
 
92
128
  setInstanceData(data) {
93
129
  if (!data) {
94
- this._createInstanceData();
130
+ this.createInstanceData();
95
131
  return;
96
132
  }
97
133
  this.instanceData = data;
@@ -142,7 +178,7 @@ export class FxInstance extends HTMLElement {
142
178
  }
143
179
  }
144
180
 
145
- _createInstanceData() {
181
+ createInstanceData() {
146
182
  if (this.type === 'xml') {
147
183
  // const doc = new DOMParser().parseFromString('<data data-id="default"></data>', 'application/xml');
148
184
  const doc = new DOMParser().parseFromString('<data></data>', 'application/xml');
@@ -155,64 +191,53 @@ export class FxInstance extends HTMLElement {
155
191
 
156
192
  async _loadData() {
157
193
  const url = `${this.src}`;
194
+
195
+ if (url.startsWith('localStore')) {
196
+ const key = url.substring(url.indexOf(':') + 1);
197
+
198
+ const doc = new DOMParser().parseFromString('<data></data>', 'application/xml');
199
+ const root = doc.firstElementChild;
200
+ this.instanceData = doc;
201
+
202
+ if (!key) {
203
+ console.warn('no key specified for localStore');
204
+ return;
205
+ }
206
+
207
+ const serialized = localStorage.getItem(key);
208
+ if (!serialized) {
209
+ console.warn(`Data for key ${key} cannot be found`);
210
+ this._useInlineData();
211
+ return;
212
+ }
213
+ const data = new DOMParser().parseFromString(serialized, 'application/xml');
214
+ // let data = this._parse(serialized, instance);
215
+ // root.appendChild(data);
216
+ doc.firstElementChild.replaceWith(data.firstElementChild);
217
+ return;
218
+ }
158
219
  const contentType = Fore.getContentType(this, 'get');
159
220
 
160
- await fetch(url, {
161
- method: 'GET',
162
- mode: 'cors',
163
- credentials: 'include',
164
- headers: {
165
- 'Content-Type': contentType,
166
- },
167
- })
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
- }
175
- const responseContentType = response.headers.get('content-type').toLowerCase();
176
- console.log('********** responseContentType *********', responseContentType);
177
- if (responseContentType.startsWith('text/html')) {
178
- // const htmlResponse = response.text();
179
- // return new DOMParser().parseFromString(htmlResponse, 'text/html');
180
- // return response.text();
181
- return response.text().then(result =>
182
- // console.log('xml ********', result);
183
- new DOMParser().parseFromString(result, 'text/html'),
184
- );
185
- }
186
- if (
187
- responseContentType.startsWith('text/plain') ||
188
- responseContentType.startsWith('text/markdown')
189
- ) {
190
- // console.log("********** inside res plain *********");
191
- return response.text();
192
- }
193
- if (responseContentType.startsWith('application/json')) {
194
- // console.log("********** inside res json *********");
195
- return response.json();
196
- }
197
- if (responseContentType.startsWith('application/xml')) {
198
- return response.text().then(result =>
199
- // console.log('xml ********', result);
200
- new DOMParser().parseFromString(result, 'application/xml'),
201
- );
202
- }
203
- return 'done';
204
- })
205
- .then(data => {
206
- if (data.nodeType) {
207
- this.instanceData = data;
208
- console.log('instanceData loaded: ', this.instanceData);
209
- return;
210
- }
211
- this.instanceData = data;
212
- })
213
- .catch(error => {
214
- throw new Error(`failed loading data ${error}`);
221
+ try {
222
+ const response = await fetch(url, {
223
+ method: 'GET',
224
+ mode: 'cors',
225
+ credentials: 'include',
226
+ headers: {
227
+ 'Content-Type': contentType,
228
+ },
215
229
  });
230
+ const { status } = response;
231
+ const data = await handleResponse(response);
232
+ if (data.nodeType) {
233
+ this.instanceData = data;
234
+ console.log('instanceData loaded: ', this.id, this.instanceData);
235
+ return;
236
+ }
237
+ this.instanceData = data;
238
+ } catch (error) {
239
+ throw new Error(`failed loading data ${error}`);
240
+ }
216
241
  }
217
242
 
218
243
  _getContentType() {
@@ -231,12 +256,12 @@ export class FxInstance extends HTMLElement {
231
256
  // console.log('innerHTML ', this.innerHTML);
232
257
  const instanceData = new DOMParser().parseFromString(this.innerHTML, 'application/xml');
233
258
 
234
- console.log('fx-instance init id:', this.id);
259
+ // console.log('fx-instance init id:', this.id);
235
260
  this.instanceData = instanceData;
236
261
  // console.log('instanceData ', this.instanceData);
237
262
  // console.log('instanceData ', this.instanceData.firstElementChild);
238
263
 
239
- console.log('fx-instance data: ', this.instanceData);
264
+ // console.log('fx-instance data: ', this.instanceData);
240
265
  // this.instanceData.firstElementChild.setAttribute('id', this.id);
241
266
  // todo: move innerHTML out to shadowDOM (for later reset)
242
267
  } else if (this.type === 'json') {