5htp-core 0.4.1-2 → 0.4.1-4

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,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.4.1-2",
4
+ "version": "0.4.1-4",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -88,13 +88,12 @@ export default abstract class Application {
88
88
  public bindErrorHandlers() {
89
89
 
90
90
  // Impossible de recup le stacktrace ...
91
- /*window.addEventListener("unhandledrejection", (e) => {
92
- clientBug(JSON.stringify(e))
93
- console.log("unhandledrejection", e.stack);
94
-
95
- });*/
91
+ window.addEventListener("unhandledrejection", (e) => {
92
+ console.error(`Exception catched by method A`, e);
93
+ });
96
94
 
97
- window.onerror = (message, file, line, col, stacktrace) =>
95
+ window.onerror = (message, file, line, col, stacktrace) => {
96
+ console.error(`Exception catched by method B`, message);
98
97
  this.reportBug({
99
98
  stacktrace: stacktrace?.stack || JSON.stringify({ message, file, line, col })
100
99
  }).then(() => {
@@ -106,9 +105,10 @@ export default abstract class Application {
106
105
  { autohide: false });*/
107
106
 
108
107
  })
108
+ }
109
109
  }
110
110
 
111
- public abstract handleError( error: CoreError | Error, httpCode?: number );
111
+ public abstract handleError( error: CoreError | Error );
112
112
 
113
113
  // TODO: move on app side
114
114
  public reportBug = (infos: TBugReportInfos) => fetch('/feedback/bug/ui', {
@@ -9,7 +9,7 @@ table {
9
9
  width: 100%;
10
10
  padding: 0;
11
11
  border-collapse: separate;
12
- border-spacing: 0 0.5em;
12
+ border-spacing: 0 0; // must be fully managed by padding
13
13
 
14
14
  // By default, chrome disables text inherits
15
15
  line-height: inherit;
@@ -48,6 +48,14 @@ table {
48
48
  }
49
49
  }
50
50
 
51
+ // Size
52
+ &.s {
53
+ td, th {
54
+ padding: 0.5em 1em;
55
+ font-size: 0.9rem;
56
+ }
57
+ }
58
+
51
59
  // Tableua responsive
52
60
  // Utilisation déconseillée (lauvaise utilisation de l'espace, ergonomie horrible
53
61
  /*@media (max-width: @responsive2) {
@@ -225,7 +225,13 @@ export default function useForm<TFormData extends {}>(
225
225
  const form = {
226
226
  fields: fields.current,
227
227
  data,
228
- set: setData,
228
+ set: data => {
229
+ setState(current => ({
230
+ ...current,
231
+ hasChanged: true
232
+ }));
233
+ setData(data);
234
+ },
229
235
  validate,
230
236
  submit,
231
237
  options,
@@ -168,7 +168,7 @@ export default ({
168
168
 
169
169
  return dropdown ? (
170
170
  <Popover content={(
171
- <div class="card col">
171
+ <div class="card col al-top">
172
172
 
173
173
  <div class="col">
174
174
 
@@ -448,7 +448,8 @@ export default class ClientRouter<
448
448
  // Nor page configurated for this error
449
449
  if (route === undefined) {
450
450
  console.error(`Error page for http error code ${code} not found.`, this.errors, this.routes);
451
- this.app.handleError(e, 404);
451
+ e.http = 404;
452
+ this.app.handleError(e);
452
453
  throw new Error(`Error page for http error code ${code} not found.`);
453
454
  }
454
455
 
@@ -117,11 +117,28 @@ export default class ApiClient implements ApiClientService {
117
117
  const [method, path, data, options] = args;
118
118
  return {
119
119
  method, path, data, options,
120
+
120
121
  // For async calls: api.post(...).then((data) => ...)
121
- then: (callback: (data: any) => void) => this.fetchAsync<TData>(...args).then(callback),
122
- catch: (callback: (data: any) => void) => this.fetchAsync<TData>(...args).catch(callback),
123
- finally: (callback: () => void) => this.fetchAsync<TData>(...args).finally(callback),
122
+ then: (callback: (data: any) => void) => this.fetchAsync<TData>(...args)
123
+ .then(callback)
124
+ .catch( e => this.app.handleError(e)),
125
+
126
+ // Default error behavior only if not handled before by the app
127
+ catch: (callback: (data: any) => void) => this.fetchAsync<TData>(...args)
128
+ .catch((e) => {
129
+ try {
130
+ callback(e);
131
+ } catch (error) {
132
+ this.app.handleError(e)
133
+ }
134
+ }),
135
+
136
+ finally: (callback: () => void) => this.fetchAsync<TData>(...args)
137
+ .finally(callback)
138
+ .catch( e => this.app.handleError(e)),
139
+
124
140
  run: () => this.fetchAsync<TData>(...args)
141
+ .catch( e => this.app.handleError(e)),
125
142
  };
126
143
  }
127
144
 
@@ -132,10 +149,7 @@ export default class ApiClient implements ApiClientService {
132
149
  /*if (options?.captcha !== undefined)
133
150
  await this.gui.captcha.check(options?.captcha);*/
134
151
 
135
- return await this.execute<TData>(method, path, data, options).catch((e) => {
136
- this.app.handleError(e);
137
- throw e; // Throw to break the loop
138
- })
152
+ return await this.execute<TData>(method, path, data, options);
139
153
  }
140
154
 
141
155
  public async fetchSync(fetchers: TFetcherList, alreadyLoadedData: {}): Promise<TObjetDonnees> {
@@ -163,6 +177,12 @@ export default class ApiClient implements ApiClientService {
163
177
 
164
178
  return data;
165
179
 
180
+ }).catch(e => {
181
+
182
+ // API Error hook
183
+ this.app.handleError(e);
184
+
185
+ throw e;
166
186
  })
167
187
 
168
188
  // Errors will be catched in the caller
@@ -239,9 +259,6 @@ export default class ApiClient implements ApiClientService {
239
259
  e.response.data
240
260
  );
241
261
 
242
- // API Error hook
243
- this.app.handleError(error, e.response.status);
244
-
245
262
  throw error;
246
263
 
247
264
  // Erreur réseau: l'utilisateur n'ets probablement plus connecté à internet
@@ -139,7 +139,7 @@ export default class DocumentRenderer<TRouter extends Router> {
139
139
 
140
140
  private styles( page: Page ) {
141
141
  return <>
142
- <link rel="stylesheet" type="text/css" href="/public/icons.css" />
142
+ <link rel="stylesheet" type="text/css" href={"/public/icons.css?" + BUILD_ID} />
143
143
  <link rel="preload" href="/public/client.css" as="style" />
144
144
  <link rel="stylesheet" type="text/css" href="/public/client.css" />
145
145