5htp-core 0.1.2 → 0.2.1

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 (148) hide show
  1. package/changelog.md +5 -0
  2. package/doc/TODO.md +71 -0
  3. package/package.json +5 -4
  4. package/src/client/{App.tsx → app/component.tsx} +15 -11
  5. package/src/client/app/index.ts +128 -0
  6. package/src/client/app/service.ts +34 -0
  7. package/src/client/app.tsconfig.json +0 -4
  8. package/src/client/assets/css/components.less +52 -0
  9. package/src/client/assets/css/core.less +7 -28
  10. package/src/client/assets/css/theme.less +1 -1
  11. package/src/client/assets/css/{borders.less → utils/borders.less} +0 -0
  12. package/src/client/assets/css/{layouts.less → utils/layouts.less} +0 -0
  13. package/src/client/assets/css/{medias.less → utils/medias.less} +14 -1
  14. package/src/client/assets/css/{sizing.less → utils/sizing.less} +0 -0
  15. package/src/client/assets/css/{spacing.less → utils/spacing.less} +0 -0
  16. package/src/client/components/Card/index.tsx +13 -7
  17. package/src/client/components/Dialog/Manager.tsx +41 -14
  18. package/src/client/components/Dialog/index.less +2 -4
  19. package/src/client/components/Form/index.tsx +1 -1
  20. package/src/client/components/Row/index.less +0 -2
  21. package/src/client/components/Table/index.tsx +3 -2
  22. package/src/client/components/button.tsx +2 -2
  23. package/src/client/components/containers/Popover/index.tsx +1 -1
  24. package/src/client/components/containers/champs.less +0 -2
  25. package/src/client/components/data/spintext/index.tsx +1 -1
  26. package/src/client/components/dropdown/index.tsx +1 -1
  27. package/src/client/components/index.ts +23 -0
  28. package/src/client/components/input/BaseV2/index.less +0 -2
  29. package/src/client/components/input/BaseV2/index.tsx +1 -1
  30. package/src/client/components/input/Date/index.less +0 -2
  31. package/src/client/components/input/Periode/index.less +0 -2
  32. package/src/client/components/input/Radio/index.less +0 -2
  33. package/src/client/components/input/UploadImage/index.less +0 -2
  34. package/src/client/components/input/UploadImage/index.tsx +1 -1
  35. package/src/client/hooks/index.ts +5 -0
  36. package/src/client/hooks/useState/index.tsx +2 -2
  37. package/src/client/hooks.ts +22 -0
  38. package/src/client/index.ts +5 -0
  39. package/src/client/pages/_layout/landing/index.tsx +0 -2
  40. package/src/client/pages/_messages/400.tsx +2 -2
  41. package/src/client/pages/_messages/401.tsx +2 -2
  42. package/src/client/pages/_messages/403.tsx +2 -2
  43. package/src/client/pages/_messages/404.tsx +2 -2
  44. package/src/client/pages/_messages/500.tsx +2 -2
  45. package/src/client/pages/bug.tsx +1 -1
  46. package/src/client/pages/useHeader.tsx +1 -1
  47. package/src/client/{context/captcha.ts → services/captcha/index.ts} +0 -0
  48. package/src/client/services/metrics/index.ts +37 -0
  49. package/src/client/{router → services/router/components}/Link.tsx +1 -1
  50. package/src/client/services/router/components/Page.tsx +59 -0
  51. package/src/client/{router/component.tsx → services/router/components/router.tsx} +52 -74
  52. package/src/client/services/router/index.tsx +453 -0
  53. package/src/client/services/router/request/api.ts +227 -0
  54. package/src/client/{router → services/router}/request/history.ts +0 -0
  55. package/src/client/services/router/request/index.ts +52 -0
  56. package/src/client/services/router/response/index.tsx +107 -0
  57. package/src/client/services/router/response/page.ts +90 -0
  58. package/src/client/{context/socket.ts → services/socket/index.ts} +2 -2
  59. package/src/client/utils/dom.ts +1 -1
  60. package/src/common/app/index.ts +9 -0
  61. package/src/common/data/chaines/index.ts +9 -6
  62. package/src/common/data/input/validate.ts +3 -166
  63. package/src/common/data/objets.ts +25 -0
  64. package/src/common/data/tableaux.ts +8 -0
  65. package/src/common/errors/index.ts +3 -1
  66. package/src/common/router/index.ts +67 -88
  67. package/src/common/router/layouts.ts +50 -0
  68. package/src/common/router/register.ts +62 -0
  69. package/src/common/router/request/api.ts +72 -0
  70. package/src/common/router/request/index.ts +31 -0
  71. package/src/common/router/{response.ts → response/index.ts} +9 -13
  72. package/src/common/router/response/page.ts +46 -54
  73. package/src/common/validation/index.ts +3 -0
  74. package/src/common/validation/schema.ts +185 -0
  75. package/src/common/validation/validator.ts +95 -0
  76. package/src/common/validation/validators.ts +313 -0
  77. package/src/server/app/config.ts +9 -27
  78. package/src/server/app/index.ts +81 -124
  79. package/src/server/app/service.ts +98 -0
  80. package/src/server/app.tsconfig.json +0 -8
  81. package/src/server/index.ts +5 -0
  82. package/src/server/patch.ts +0 -6
  83. package/src/server/{data/Cache.ts → services/cache/index.ts} +79 -47
  84. package/src/server/services/console/bugReporter.ts +26 -16
  85. package/src/server/services/console/index.ts +59 -51
  86. package/src/server/services/cron/index.ts +12 -26
  87. package/src/server/services/database/bucket.ts +40 -0
  88. package/src/server/services/database/connection.ts +213 -80
  89. package/src/server/services/database/datatypes.ts +63 -40
  90. package/src/server/services/database/debug.ts +20 -0
  91. package/src/server/services/database/index.ts +295 -272
  92. package/src/server/services/database/metas.ts +246 -135
  93. package/src/server/services/database/stats.ts +151 -126
  94. package/src/server/services/email/index.ts +30 -62
  95. package/src/server/services/email/transporter.ts +38 -0
  96. package/src/server/services/{router/request/services → metrics}/detect.ts +8 -10
  97. package/src/server/services/{router/request/services/tracking.ts → metrics/index.ts} +68 -45
  98. package/src/server/services/{http → router/http}/index.ts +28 -70
  99. package/src/server/services/{http → router/http}/multipart.ts +0 -0
  100. package/src/server/services/{http → router/http}/session.ts.old +0 -0
  101. package/src/server/services/router/index.ts +273 -202
  102. package/src/server/services/router/request/api.ts +76 -0
  103. package/src/server/services/router/request/index.ts +16 -97
  104. package/src/server/services/router/request/service.ts +21 -0
  105. package/src/server/services/router/response/index.ts +131 -65
  106. package/src/server/services/router/response/{filter → mask}/Filter.ts +0 -0
  107. package/src/server/services/router/response/{filter → mask}/index.ts +0 -2
  108. package/src/server/services/router/response/{filter → mask}/selecteurs.ts +0 -0
  109. package/src/server/services/router/response/page/document.tsx +194 -0
  110. package/src/server/services/router/response/page/index.tsx +157 -0
  111. package/src/server/{libs/pages → services/router/response/page}/schemaGenerator.ts +0 -0
  112. package/src/server/services/router/service.ts +48 -0
  113. package/src/server/services/schema/index.ts +47 -0
  114. package/src/server/services/schema/request.ts +55 -0
  115. package/src/server/services/schema/router.ts +33 -0
  116. package/src/server/services/socket/index.ts +38 -43
  117. package/src/server/services/socket/scope.ts +6 -4
  118. package/src/server/services/users/index.ts +203 -0
  119. package/src/server/services/{auth/base.ts → users/old.ts} +28 -112
  120. package/src/server/services/users/router/index.ts +72 -0
  121. package/src/server/services/users/router/request.ts +49 -0
  122. package/src/server/{data → services_old}/SocketClient.ts +0 -0
  123. package/src/server/{data/Token.olg.ts → services_old/Token.old.ts} +0 -0
  124. package/src/server/{data → services_old}/aes.ts +0 -0
  125. package/src/types/aliases.d.ts +43 -2
  126. package/templates/composant.tsx +1 -1
  127. package/templates/modal.tsx +1 -1
  128. package/templates/page.tsx +1 -1
  129. package/tsconfig.common.json +0 -4
  130. package/src/client/assets/css/components/components.less +0 -31
  131. package/src/client/context/api.ts +0 -92
  132. package/src/client/context/index.ts +0 -246
  133. package/src/client/index.tsx +0 -129
  134. package/src/client/router/index.ts +0 -286
  135. package/src/client/router/request/index.ts +0 -106
  136. package/src/client/router/response/index.ts +0 -38
  137. package/src/client/router/route.ts +0 -75
  138. package/src/common/data/input/validators/basic.ts +0 -299
  139. package/src/common/data/input/validators/build.ts +0 -63
  140. package/src/common/router/request.ts +0 -83
  141. package/src/server/data/ApiClient.ts +0 -119
  142. package/src/server/data/input.ts +0 -41
  143. package/src/server/libs/pages/document.static.tsx +0 -41
  144. package/src/server/libs/pages/document.tsx +0 -203
  145. package/src/server/libs/pages/render.tsx +0 -90
  146. package/src/server/routes/auth.ts +0 -151
  147. package/src/server/services/redis/index.ts +0 -71
  148. package/src/server/services/router/request/services/auth.ts +0 -177
package/changelog.md ADDED
@@ -0,0 +1,5 @@
1
+ # 01/01/2023:
2
+
3
+ * Redesigned systems service. Pass app instance servces list through constructor attribute instead of importing instance
4
+ * Update babel-plugn-glob-import
5
+ *
package/doc/TODO.md ADDED
@@ -0,0 +1,71 @@
1
+ * Fix erreurs type Client / Server context
2
+ * Server side: ServerContext
3
+ * Client side: ClientContext | ServerContext
4
+ * PageResponse extends Response
5
+ * Toast service
6
+ * ClientApplication hooks
7
+ app.on('bug')
8
+ app.on('error')
9
+
10
+
11
+ # Dependancies injection
12
+
13
+ # Full stack Pages
14
+
15
+ ```typescript
16
+ import Router from '@server/services/router';
17
+ import { TRouterContext as ServerServices } from '@server/services/router/response';
18
+ import { TRouterContext as ClientServices } from '@client/services/router/response';
19
+
20
+ abstract class Controller<
21
+ TRouter extends Router,
22
+ TData extends any = any,
23
+ TUserAccess extends string = string
24
+ > {
25
+
26
+ abstract auth: TUserAccess;
27
+
28
+ abstract get( services: ServerServices<TRouter> ): Promise<TData>;
29
+
30
+ abstract render( context: TData, services: ClientServices<TRouter> ): ComponentChild;
31
+
32
+ }
33
+ ```
34
+
35
+ ```typescript
36
+ //? /headhunter/missions/suggested'
37
+ class Missions extends Controller<CrossPath["router"]> {
38
+
39
+ auth = 'USER';
40
+
41
+ async get({ headhunting, response, auth }) {
42
+
43
+ const user = await auth.check('USER');
44
+
45
+ const suggested = await headhunting.missions.Suggest( user );
46
+
47
+ return { suggested }
48
+ }
49
+
50
+ render({ page, api, suggested }) {
51
+ return (
52
+ <Page title="App title here" subtitle="SEO description here">{page.loading || <>
53
+
54
+ <section class="col">
55
+
56
+ <header class="row">
57
+ <h2 class="col-1">Suggested Missions</h2>
58
+ </header>
59
+
60
+ <div class="grid xa3">
61
+ {suggested.map( mission => (
62
+ <MissionCard mission={mission} />
63
+ ))}
64
+ </div>
65
+ </section>
66
+
67
+ </>}</Page>
68
+ )
69
+ }
70
+ }
71
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp-core",
3
- "description": "5-HTP, scientifically called 5-Hydroxytryptophan, is the precursor of happiness neurotransmitter.",
4
- "version": "0.1.2",
3
+ "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
+ "version": "0.2.1",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp-core.git",
7
7
  "license": "MIT",
@@ -13,11 +13,11 @@
13
13
  "framework"
14
14
  ],
15
15
  "dependencies": {
16
- "@sendgrid/mail": "^7.4.6",
17
16
  "accepts": "^1.3.7",
18
17
  "activity-detector": "^3.0.0",
19
18
  "ansi-to-html": "^0.7.1",
20
19
  "array-move": "^3.0.1",
20
+ "axios": "^1.2.1",
21
21
  "bowser": "^2.11.0",
22
22
  "chart.js": "^3.6.2",
23
23
  "cli-highlight": "^2.1.11",
@@ -83,6 +83,7 @@
83
83
  "@types/nodemailer": "^6.4.4",
84
84
  "@types/universal-analytics": "^0.4.5",
85
85
  "@types/webpack-env": "^1.16.2",
86
- "@types/ws": "^7.4.7"
86
+ "@types/ws": "^7.4.7",
87
+ "babel-plugin-glob-import": "^0.0.3"
87
88
  }
88
89
  }
@@ -6,33 +6,37 @@
6
6
  import React from 'react';
7
7
 
8
8
  // Core
9
- import { ReactClientContext, ClientContext } from '@client/context';
10
- import DialogManager from '@client/components/Dialog/Manager'
11
9
  import type { Layout } from '@common/router';
10
+ import { ReactClientContext } from '@/client/context';
11
+ import DialogManager from '@client/components/Dialog/Manager'
12
12
 
13
13
  // Core components
14
- import Router from '@client/router/component';
15
-
16
- // Resources
17
- import "@client/assets/css/core.less";
14
+ import Router from '@client/services/router/components/router';
15
+ import type { TClientOrServerContext } from '@common/router';
18
16
 
19
17
  /*----------------------------------
20
18
  - COMPOSANT
21
19
  ----------------------------------*/
22
- export default function App ({ context }: { context: ClientContext }) {
20
+ export default function App ({ context }: {
21
+ context: TClientOrServerContext,
22
+ }) {
23
23
 
24
- const route = context.page?.route;
24
+ const route = context.route;
25
25
  const curLayout = route.options.layout;
26
26
  const [layout, setLayout] = React.useState<Layout | false | undefined>(curLayout);
27
- context.setLayout = setLayout;
27
+
28
+ // TODO: context.page is always provided in the context on the client side
29
+ if (context.app.side === "client")
30
+ context.app.setLayout = setLayout;
28
31
 
29
32
  return (
30
33
  <ReactClientContext.Provider value={context}>
31
34
 
32
- <DialogManager />
35
+ <DialogManager context={context} />
33
36
 
34
37
  {!layout ? <>
35
- <Router />
38
+ {/* TODO: move to app, because here, we're not aware that the router service has been defined */}
39
+ <Router service={context.router} />
36
40
  </> : <>
37
41
  <layout.Component context={context} />
38
42
  </>}
@@ -0,0 +1,128 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ if (typeof window === 'undefined')
6
+ throw new Error(`This file shouldn't be loaded on server side !!!!`);
7
+
8
+ window.dev && require('preact/debug');
9
+
10
+ // Core
11
+ import { Erreur } from '@common/errors';
12
+ import type { Layout } from '@common/router';
13
+ import { createDialog } from '@client/components/Dialog/Manager';
14
+
15
+ // Local
16
+ import type { AnyService } from './service';
17
+
18
+ export { default as Service } from './service';
19
+
20
+ /*----------------------------------
21
+ - TYPES
22
+ ----------------------------------*/
23
+
24
+ declare global {
25
+ interface Window {
26
+ dev: boolean,
27
+ // Defined by loading gtag.js
28
+ gtag: (action: string, name: string, params?: any) => void,
29
+ /*context: ClientContext,
30
+ user: User,*/
31
+ }
32
+ }
33
+
34
+ export type TBugReportInfos = {
35
+ stacktrace?: string,
36
+ observation?: string,
37
+ before?: string,
38
+ }
39
+
40
+ /*----------------------------------
41
+ - CLASS
42
+ ----------------------------------*/
43
+ export default abstract class Application {
44
+
45
+ public side = 'client' as 'client';
46
+
47
+ private servicesList: AnyService[] = []
48
+
49
+ // TODO: merge modal and toast in the same instance
50
+ public modal = createDialog(this, false);
51
+ public toast = createDialog(this, true);
52
+
53
+ public constructor() {
54
+
55
+ }
56
+
57
+ public registerService( service: AnyService ) {
58
+ console.log(`[app] Register service`, service.constructor?.name);
59
+ this.servicesList.push(service);
60
+ }
61
+
62
+ public start() {
63
+ this.bindErrorHandlers();
64
+ this.startServices();
65
+ this.boot();
66
+ }
67
+
68
+ public abstract boot(): void;
69
+
70
+ public startServices() {
71
+
72
+ console.log(`[app] Starting ${this.servicesList.length} services.`);
73
+
74
+ for (const service of this.servicesList) {
75
+ console.log(`[app] Start service`, service);
76
+ service.start();
77
+ }
78
+
79
+ console.log(`[app] All ${this.servicesList.length} services were started.`);
80
+ }
81
+
82
+ public bindErrorHandlers() {
83
+
84
+ // Impossible de recup le stacktrace ...
85
+ /*window.addEventListener("unhandledrejection", (e) => {
86
+ clientBug(JSON.stringify(e))
87
+ console.log("unhandledrejection", e.stack);
88
+
89
+ });*/
90
+
91
+ window.onerror = (message, file, line, col, stacktrace) =>
92
+ this.reportBug({
93
+ stacktrace: stacktrace?.stack || JSON.stringify({ message, file, line, col })
94
+ }).then(() => {
95
+
96
+ // TODO in toas service: app.on('bug', () => toast.warning( ... ))
97
+ /*context?.toast.warning("Bug detected",
98
+ "A bug report has been sent, because I've detected a bug on the interface. I'm really sorry for the interruption.",
99
+ null,
100
+ { autohide: false });*/
101
+
102
+ })
103
+ }
104
+
105
+ public handleError( error: Erreur | Error, httpCode?: number ) {
106
+
107
+ /*console.error(`[api] Network error:`, e);
108
+ context.toast.error("Please check your internet connection and try again.", undefined, null, { autohide: false });*/
109
+ }
110
+
111
+ public reportBug = (infos: TBugReportInfos) => fetch('/help/bug/gui', {
112
+ method: 'POST',
113
+ headers: {
114
+ 'Accept': "application/json",
115
+ 'Content-Type': 'application/json'
116
+ },
117
+ body: JSON.stringify({
118
+ url: window.location.pathname,
119
+ ssrData: JSON.stringify(window["ssr"]),
120
+ guiVersion: BUILD_DATE,
121
+ ...infos
122
+ })
123
+ })
124
+
125
+ public setLayout(layout: Layout) {
126
+ throw new Error(`page.setLayout has been called before the function is assigned from the <App /> component.`);
127
+ };
128
+ }
@@ -0,0 +1,34 @@
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
+
5
+ import type Application from ".";
6
+
7
+ /*----------------------------------
8
+ - TYPES: OPTIONS
9
+ ----------------------------------*/
10
+
11
+ export type AnyService = Service<{}, Application>
12
+
13
+ /*----------------------------------
14
+ - CLASS
15
+ ----------------------------------*/
16
+ export default abstract class Service<
17
+ TConfig extends {},
18
+ TApplication extends Application
19
+ > {
20
+ public constructor(
21
+ public app: TApplication,
22
+ public config: TConfig,
23
+ ) {
24
+
25
+ // No client service should be loaded from server side
26
+ if (typeof window === 'undefined')
27
+ throw new Error(`Client services shouldn't be loaded on server side.`);
28
+
29
+ // Make the app aware of his services
30
+ app.registerService(this);
31
+ }
32
+
33
+ public abstract start(): void;
34
+ }
@@ -11,10 +11,6 @@
11
11
  // Only used for typings (ex: ServerResponse)
12
12
  // Removed before webpack compilation
13
13
  "@server/*": ["../node_modules/5htp-core/src/server/*"],
14
- "@validator": ["../node_modules/5htp-core/src/client/data/input"],
15
- "@router": ["../node_modules/5htp-core/src/client/router"],
16
- "@errors": ["../node_modules/5htp-core/src/common/errors"],
17
- "@models": ["../.cache/client/models"],
18
14
  "@/*": ["./*"],
19
15
 
20
16
  // ATTENTION: Les références à preact doivent toujours pointer vers la même instance
@@ -0,0 +1,52 @@
1
+ // Text
2
+ @import './text/text.less';
3
+ @import './text/icons.less';
4
+ @import './text/icons.less';
5
+ @import './text/titres.less';
6
+
7
+ // Components
8
+ @import './components/input.less';
9
+ @import './components/button.less';
10
+ @import './components/lists.less';
11
+ @import './components/card.less';
12
+ @import './components/logo.less';
13
+ @import './components/table.less';
14
+ @import './components/other.less';
15
+ @import '@client/components/chart/chart.less';
16
+ @import '@client/components/data/progressbar/index.less';
17
+
18
+ // Les classes utilitaires override les classes de composant
19
+ @import './utils/borders.less';
20
+ @import './utils/layouts.less';
21
+
22
+ .white-card() {
23
+ background: white;
24
+ box-shadow: 0 3px 2px fade(#000, 10%);
25
+ border: solid 1px fade(#000, 10%);
26
+ border-radius: @radius;
27
+ }
28
+
29
+ .card,
30
+ .input.text,
31
+ .btn,
32
+ .table,
33
+ i.solid {
34
+
35
+ .build-theme-bg( #fff, #8E8E8E);
36
+
37
+ &:not(.bg) {
38
+ .white-card();
39
+ }
40
+
41
+ .bg & {
42
+ box-shadow: none;
43
+ border: none;
44
+ }
45
+ }
46
+
47
+ //.card.clickable:hover,
48
+ .btn:hover,
49
+ .input.text.focus {
50
+ z-index: 5;
51
+ box-shadow: 0 10px 50px fade(#000, 15%);
52
+ }
@@ -1,35 +1,14 @@
1
+ // Utils
2
+ @import './utils/medias.less';
3
+ @import './utils/sizing.less';
4
+ @import './utils/spacing.less';
5
+ @import (reference) "./theme.less";
6
+
7
+ // Fonts
1
8
  @import '../fonts/Inter/index.less';
2
9
  @import '../fonts/Rubik/index.less';
3
10
  @import '../fonts/Lato/index.less';
4
11
 
5
- @import './text/text.less';
6
- @import './text/icons.less';
7
- @import './text/icons.less';
8
- @import './text/titres.less';
9
-
10
- @import './components/components.less';
11
- @import './components/input.less';
12
- @import './components/button.less';
13
- @import './components/lists.less';
14
- @import './components/card.less';
15
- @import './components/logo.less';
16
- @import './components/table.less';
17
- @import './components/other.less';
18
-
19
- // Les classes utilitaires override les classes de composant
20
- @import './borders.less';
21
- @import './spacing.less';
22
- @import './layouts.less';
23
-
24
- @import './medias.less';
25
- @import './sizing.less';
26
-
27
- @import '@client/components/chart/chart.less';
28
- @import '@client/components/data/progressbar/index.less';
29
-
30
- @import (reference) "./theme.less";
31
- @import "~@/client/assets/theme.less";
32
-
33
12
  // Apply the theme class
34
13
  .bg {
35
14
  background: var(--cBg);
@@ -17,7 +17,7 @@
17
17
  // Background
18
18
  // TODO: Nettoyer
19
19
  @bg2: darken(@bg, 8%);
20
- @bgDark: darken(@bg, 5%);
20
+ @bgDark: darken(@bg, 7%);
21
21
  @bgDarkPlus: darken(@bg, 10%);
22
22
  --cBg: @bg;
23
23
  --cBg2: @bg2;
@@ -1,4 +1,3 @@
1
- @import (reference) "~@/client/assets/theme.less";
2
1
 
3
2
  img.img,
4
3
  .bg.img {
@@ -8,6 +7,20 @@ img.img,
8
7
  .bg.img {
9
8
  .build-theme-bg(#000, #fff);
10
9
  text-shadow: 0 0 10px fade(#000, 20%);
10
+
11
+ --cTxtDiscret: fade(#fff, 40%)
12
+ --cTxtDesc: fade(#fff, 60%);
13
+ --cTxtBase: fade(#fff, 80%);
14
+ --cTxtImportant: fade(#fff, 100%);
15
+ --cTxtAccent: fade(#fff, 20%);
16
+
17
+ &.light {
18
+ --cTxtDiscret: fade(#000, 40%)
19
+ --cTxtDesc: fade(#000, 60%);
20
+ --cTxtBase: fade(#000, 80%);
21
+ --cTxtImportant: fade(#000, 100%);
22
+ --cTxtAccent: fade(#000, 20%);
23
+ }
11
24
  }
12
25
 
13
26
  img {
@@ -7,8 +7,8 @@ import React from 'react';
7
7
  import type { ComponentChild } from 'preact';
8
8
 
9
9
  // Core components
10
- import Button from '@client/components/button';
11
- import { Link } from '@client/router';
10
+ import { Logo } from '@client/components';
11
+ import { Link } from '@client/services/router';
12
12
 
13
13
  // Resources
14
14
  import './index.less';
@@ -28,8 +28,9 @@ export type Props = {
28
28
  link?: string,
29
29
  cover?: {
30
30
  color?: string,
31
+ image?: string,
31
32
  title?: string,
32
- logo?: string
33
+ logo?: ComponentChild
33
34
  },
34
35
  metas: TMeta[],
35
36
  class?: string,
@@ -49,10 +50,15 @@ export default ({ title, link, cover, metas, class: className = '' }: Props) =>
49
50
 
50
51
  {cover && (
51
52
  <header class="bg img row al-left cover pdb-1" style={{
52
- backgroundColor: cover.color
53
+ backgroundColor: cover.color,
54
+ backgroundImage: cover.image
55
+ ? 'url(' + cover.image + ')'
56
+ : undefined
53
57
  }}>
54
58
 
55
- {cover?.logo}
59
+ {typeof cover.logo === 'string'
60
+ ? <Logo src={cover.logo} size="xl" />
61
+ : cover.logo}
56
62
 
57
63
  {cover.title && (
58
64
  <strong>
@@ -72,9 +78,9 @@ export default ({ title, link, cover, metas, class: className = '' }: Props) =>
72
78
  )}
73
79
 
74
80
  {metas && (
75
- <ul class="row fill">
81
+ <ul class="row fill al-top">
76
82
  {metas.map(({ label, value, class: className }) => (
77
- <li class={"col al-left sp-05"}>
83
+ <li class={"col al-left txt-left sp-05"}>
78
84
  {label}
79
85
  <strong class={className}>{value}</strong>
80
86
  </li>
@@ -7,11 +7,10 @@ import React from 'react';
7
7
  import { ComponentChild } from 'preact';
8
8
 
9
9
  // Libs
10
- import useContext, { ClientContext } from '@client/context';
11
- import { ClientResponse } from '@client/router';
12
- import { initStateAsync, execFetchersState } from '@client/hooks/useState/fetchers';
10
+ import useContext from '@/client/context';
13
11
 
14
12
  // Métier
13
+ import type Application from '../../app';
15
14
  import Card, { Props as CardInfos } from './card';
16
15
  import Button from '../button';
17
16
 
@@ -43,11 +42,34 @@ export type TDialogControls = {
43
42
  then: (cb: TOnCloseCallback<any>) => any
44
43
  }
45
44
 
45
+ type DialogActions = {
46
+
47
+ setToasts: ( setter: (old: ComponentChild[]) => ComponentChild[]) => void,
48
+
49
+ show: (
50
+ // On utilise une fonction pour pouvoir accéder aux fonctions (close, ...) lors de la déclaration des infos de la toast
51
+ Content: ComposantToast | Promise<{ default: ComposantToast }> | TOptsToast,
52
+ paramsInit?: TParams
53
+ ) => TDialogControls,
54
+
55
+ confirm: (title: string, content: string | ComponentChild, defaultBtn: 'Yes'|'No') => TDialogControls,
56
+
57
+ loading: (title: string) => TDialogControls,
58
+
59
+ info: (...[title, content, boutons, options]: TToastShortcutArgs) => TDialogControls,
60
+
61
+ success: (...[title, content, boutons, options]: TToastShortcutArgs) => TDialogControls,
62
+
63
+ warning: (...[title, content, boutons, options]: TToastShortcutArgs) => TDialogControls,
64
+
65
+ error: (...[title, content, boutons, options]: TToastShortcutArgs) => TDialogControls,
66
+ }
67
+
46
68
  /*----------------------------------
47
69
  - SERVICE CONTEXTE
48
70
  ----------------------------------*/
49
71
  let idA: number = 0;
50
- export const createDialog = (ctx: ClientContext, isToast: boolean) => {
72
+ export const createDialog = (app: Application, isToast: boolean): DialogActions => {
51
73
 
52
74
  const show = <TReturnType extends any = true>(
53
75
  // On utilise une fonction pour pouvoir accéder aux fonctions (close, ...) lors de la déclaration des infos de la toast
@@ -60,7 +82,7 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
60
82
 
61
83
  const close = (retour: TReturnType) => {
62
84
 
63
- ctx.bridges.setToasts(q => q.filter(m => m.id !== id))
85
+ instance.setToasts(q => q.filter(m => m.id !== id))
64
86
 
65
87
  if (onClose !== undefined)
66
88
  onClose(retour);
@@ -105,7 +127,7 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
105
127
  // Chargeur de données
106
128
  /*if (('data' in ComposantCharge) && typeof ComposantCharge.data === 'function') {
107
129
 
108
- propsRendu.data = await ComposantCharge.data(ctx, paramsInit);
130
+ propsRendu.data = await ComposantCharge.data(app, paramsInit);
109
131
 
110
132
  const { fetchersStateA } = initStateAsync(propsRendu.data, {}, false);
111
133
 
@@ -125,7 +147,7 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
125
147
 
126
148
  render["id"] = id;
127
149
 
128
- ctx.bridges.setToasts(q => [...q, render]);
150
+ instance.setToasts(q => [...q, render]);
129
151
  });
130
152
 
131
153
  return {
@@ -134,13 +156,16 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
134
156
  }
135
157
  };
136
158
 
137
- return {
159
+ const instance: DialogActions = {
160
+
138
161
  show: show,
139
162
 
163
+ setToasts: undefined as unknown as DialogActions["setToasts"],
164
+
140
165
  confirm: (title: string, content: string | ComponentChild, defaultBtn: 'Yes'|'No' = 'No') => show<boolean>(({ close }) => (
141
- <div class="col">
166
+ <div class="card col">
142
167
  <header>
143
- <h1>{title}</h1>
168
+ <h2>{title}</h2>
144
169
  </header>
145
170
  {typeof content === 'string' ? <p>{content}</p> : content}
146
171
  <footer class="row fill">
@@ -156,7 +181,7 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
156
181
  </div>
157
182
  )),
158
183
 
159
- loading: (title: string) => ctx.loadIndicator = show({
184
+ loading: (title: string) => app.loading = show({
160
185
  title: title,
161
186
  type: 'loading'
162
187
  }),
@@ -193,6 +218,8 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
193
218
  ...options
194
219
  }),
195
220
  }
221
+
222
+ return instance;
196
223
  }
197
224
 
198
225
  /*----------------------------------
@@ -201,12 +228,12 @@ export const createDialog = (ctx: ClientContext, isToast: boolean) => {
201
228
  import './index.less';
202
229
  export default () => {
203
230
 
204
- const ctx = useContext();
231
+ const app = useContext();
205
232
 
206
233
  const [rendered, setRendered] = React.useState<ComponentChild[]>([]);
207
234
 
208
- ctx.bridges.setToasts = setRendered;
209
- //ctx.register({}, { setToasts: setRendered });
235
+ if (app.side === 'client')
236
+ app.modal.setToasts = app.toast.setToasts = setRendered;
210
237
 
211
238
  React.useEffect(() => {
212
239
 
@@ -1,5 +1,3 @@
1
- @import (reference) "~@/client/assets/theme.less";
2
-
3
1
  @toast-zindex: 999;
4
2
 
5
3
  #dialog {
@@ -89,10 +87,10 @@
89
87
  border-radius: @radius;
90
88
 
91
89
  // Desktop = vertically center the modal
92
- /*@media (min-width: @responsive1) {
90
+ @media (min-width: 900px) {
93
91
  justify-content: center;
94
92
  padding: @spacing;
95
- }*/
93
+ }
96
94
 
97
95
  // Pour les animations (ex: conffetis
98
96
  > canvas {