@owlmeans/web-client 0.1.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 (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +617 -0
  3. package/build/components/dispatcher/component.d.ts +2 -0
  4. package/build/components/dispatcher/component.d.ts.map +1 -0
  5. package/build/components/dispatcher/component.js +41 -0
  6. package/build/components/dispatcher/component.js.map +1 -0
  7. package/build/components/dispatcher/index.d.ts +2 -0
  8. package/build/components/dispatcher/index.d.ts.map +1 -0
  9. package/build/components/dispatcher/index.js +2 -0
  10. package/build/components/dispatcher/index.js.map +1 -0
  11. package/build/components/index.d.ts +3 -0
  12. package/build/components/index.d.ts.map +1 -0
  13. package/build/components/index.js +3 -0
  14. package/build/components/index.js.map +1 -0
  15. package/build/components/uploader/component.d.ts +4 -0
  16. package/build/components/uploader/component.d.ts.map +1 -0
  17. package/build/components/uploader/component.js +10 -0
  18. package/build/components/uploader/component.js.map +1 -0
  19. package/build/components/uploader/image.d.ts +4 -0
  20. package/build/components/uploader/image.d.ts.map +1 -0
  21. package/build/components/uploader/image.js +8 -0
  22. package/build/components/uploader/image.js.map +1 -0
  23. package/build/components/uploader/index.d.ts +4 -0
  24. package/build/components/uploader/index.d.ts.map +1 -0
  25. package/build/components/uploader/index.js +3 -0
  26. package/build/components/uploader/index.js.map +1 -0
  27. package/build/components/uploader/types.d.ts +13 -0
  28. package/build/components/uploader/types.d.ts.map +1 -0
  29. package/build/components/uploader/types.js +2 -0
  30. package/build/components/uploader/types.js.map +1 -0
  31. package/build/consts.d.ts +2 -0
  32. package/build/consts.d.ts.map +1 -0
  33. package/build/consts.js +2 -0
  34. package/build/consts.js.map +1 -0
  35. package/build/context.d.ts +4 -0
  36. package/build/context.d.ts.map +1 -0
  37. package/build/context.js +18 -0
  38. package/build/context.js.map +1 -0
  39. package/build/errors.d.ts +11 -0
  40. package/build/errors.d.ts.map +1 -0
  41. package/build/errors.js +19 -0
  42. package/build/errors.js.map +1 -0
  43. package/build/exports.d.ts +9 -0
  44. package/build/exports.d.ts.map +1 -0
  45. package/build/exports.js +7 -0
  46. package/build/exports.js.map +1 -0
  47. package/build/helper.d.ts +3 -0
  48. package/build/helper.d.ts.map +1 -0
  49. package/build/helper.js +7 -0
  50. package/build/helper.js.map +1 -0
  51. package/build/i18n/auth-en.json +5 -0
  52. package/build/i18n.d.ts +2 -0
  53. package/build/i18n.d.ts.map +1 -0
  54. package/build/i18n.js +4 -0
  55. package/build/i18n.js.map +1 -0
  56. package/build/index.d.ts +13 -0
  57. package/build/index.d.ts.map +1 -0
  58. package/build/index.js +13 -0
  59. package/build/index.js.map +1 -0
  60. package/build/main.d.ts +4 -0
  61. package/build/main.d.ts.map +1 -0
  62. package/build/main.js +22 -0
  63. package/build/main.js.map +1 -0
  64. package/build/modules.d.ts +2 -0
  65. package/build/modules.d.ts.map +1 -0
  66. package/build/modules.js +8 -0
  67. package/build/modules.js.map +1 -0
  68. package/build/router.d.ts +3 -0
  69. package/build/router.d.ts.map +1 -0
  70. package/build/router.js +5 -0
  71. package/build/router.js.map +1 -0
  72. package/build/service.d.ts +6 -0
  73. package/build/service.d.ts.map +1 -0
  74. package/build/service.js +26 -0
  75. package/build/service.js.map +1 -0
  76. package/build/types.d.ts +14 -0
  77. package/build/types.d.ts.map +1 -0
  78. package/build/types.js +2 -0
  79. package/build/types.js.map +1 -0
  80. package/package.json +57 -0
  81. package/src/components/dispatcher/component.tsx +43 -0
  82. package/src/components/dispatcher/index.ts +2 -0
  83. package/src/components/index.ts +3 -0
  84. package/src/components/uploader/component.tsx +17 -0
  85. package/src/components/uploader/image.tsx +10 -0
  86. package/src/components/uploader/index.ts +4 -0
  87. package/src/components/uploader/types.ts +14 -0
  88. package/src/consts.ts +2 -0
  89. package/src/context.ts +27 -0
  90. package/src/errors.ts +25 -0
  91. package/src/exports.ts +9 -0
  92. package/src/helper.ts +8 -0
  93. package/src/i18n/auth-en.json +5 -0
  94. package/src/i18n.ts +5 -0
  95. package/src/index.ts +13 -0
  96. package/src/main.tsx +25 -0
  97. package/src/modules.ts +9 -0
  98. package/src/router.ts +7 -0
  99. package/src/service.ts +41 -0
  100. package/src/types.ts +17 -0
  101. package/tsconfig.json +15 -0
  102. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,4 @@
1
+
2
+ export type * from './types.js'
3
+ export * from './component.js'
4
+ export * from './image.js'
@@ -0,0 +1,14 @@
1
+ import type { PropsWithChildren } from 'react'
2
+ import type { FC } from 'react'
3
+ import type { DropzoneRootProps, DropzoneOptions } from 'react-dropzone'
4
+
5
+ interface RootProps extends Record<string, unknown> {
6
+ }
7
+
8
+ export interface UploaderProps extends PropsWithChildren<DropzoneOptions> {
9
+ Root?: FC<PropsWithChildren<any>>
10
+ rootProps?: RootProps
11
+ }
12
+
13
+ export interface UploaderRootProps extends PropsWithChildren<RootProps>, DropzoneRootProps {
14
+ }
package/src/consts.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export const DEFAULT_ROOT = 'root'
package/src/context.ts ADDED
@@ -0,0 +1,27 @@
1
+
2
+ import { makeClientContext } from '@owlmeans/client'
3
+ import { AppConfig, AppContext } from './types.js'
4
+ import { AUTH_RESOURCE } from '@owlmeans/client-auth'
5
+ import { appendWebDbService } from '@owlmeans/web-db'
6
+ import { appendClientResource } from '@owlmeans/client-resource'
7
+ import { useContext as useCtx } from '@owlmeans/client'
8
+ import { extractPrimaryHost } from './helper.js'
9
+ import { appendWebAuthService } from './service.js'
10
+
11
+ export const makeContext = <C extends AppConfig = AppConfig, T extends AppContext<C> = AppContext<C>>(
12
+ cfg: C
13
+ ): T => {
14
+ const context = makeClientContext(cfg) as T
15
+ extractPrimaryHost<C, T>(context)
16
+
17
+ appendWebAuthService<C, T>(context)
18
+ appendWebDbService<C, T>(context)
19
+ appendClientResource<C, T>(context, AUTH_RESOURCE)
20
+
21
+ context.makeContext = makeContext as typeof context.makeContext
22
+
23
+ return context
24
+ }
25
+
26
+ export const useContext = <C extends AppConfig = AppConfig,T extends AppContext<C> = AppContext<C>>() =>
27
+ useCtx<C,T>()
package/src/errors.ts ADDED
@@ -0,0 +1,25 @@
1
+
2
+ import {ComponentError} from '@owlmeans/client'
3
+
4
+ export class UploaderError extends ComponentError {
5
+ public static override typeName: string = `${ComponentError.typeName}Uploader`
6
+
7
+ constructor(message: string = 'error') {
8
+ super(`uploader:${message}`)
9
+ this.type = UploaderError.typeName
10
+ }
11
+ }
12
+
13
+ export class FileUploadingError extends UploaderError {
14
+ public static override typeName: string = `${UploaderError.typeName}FileUploading`
15
+
16
+ public original: Error | undefined
17
+
18
+ constructor(message: string = 'error') {
19
+ super(`file-uploading:${message}`)
20
+ this.type = FileUploadingError.typeName
21
+ }
22
+ }
23
+
24
+ ComponentError.registerErrorClass(UploaderError)
25
+ ComponentError.registerErrorClass(FileUploadingError)
package/src/exports.ts ADDED
@@ -0,0 +1,9 @@
1
+
2
+ export { handler } from '@owlmeans/client'
3
+ export { config } from '@owlmeans/client-context'
4
+ export { service } from '@owlmeans/config'
5
+ export { AppType, HOME, ROOT, BASE, GUEST } from '@owlmeans/context'
6
+ export { module, elevate, provideRequest, stab } from '@owlmeans/client-module'
7
+ export { route, frontend } from '@owlmeans/route'
8
+ export type { ClientModule as Module } from '@owlmeans/client-module'
9
+ export type { ClientRoute as Route } from '@owlmeans/client-route'
package/src/helper.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { AppConfig, AppContext } from './types.js'
2
+
3
+ export const extractPrimaryHost = <C extends AppConfig = AppConfig, T extends AppContext<C> = AppContext<C>>(context: T) => {
4
+ if (typeof window !== 'undefined') {
5
+ context.cfg.primaryHost = window.location.hostname
6
+ context.cfg.primaryPort = window.location.port != null && window.location.port != '' ? parseInt(window.location.port) : undefined
7
+ }
8
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "dispatcher": {
3
+ "loading": "Loading..."
4
+ }
5
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,5 @@
1
+
2
+ import authEn from './i18n/auth-en.json'
3
+ import { addI18nLib } from '@owlmeans/i18n'
4
+
5
+ addI18nLib('en', 'auth', authEn)
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+
2
+ export * from './consts.js'
3
+ export * from './types.js'
4
+ export * from './main.js'
5
+ export * from './router.js'
6
+ export * from './components/index.js'
7
+ export * from './modules.js'
8
+ export * from './exports.js'
9
+ export * from './context.js'
10
+ export * from './helper.js'
11
+ export * from './i18n.js'
12
+ export * from './service.js'
13
+ export * from './errors.js'
package/src/main.tsx ADDED
@@ -0,0 +1,25 @@
1
+ // import { StrictMode } from 'react'
2
+ import type { ReactNode } from 'react'
3
+ import { createRoot, hydrateRoot } from 'react-dom/client'
4
+ import { DEFAULT_ROOT } from './consts.js'
5
+ import type { RenderOptions } from './types.js'
6
+
7
+ export const render = (node: ReactNode, opts?: RenderOptions) => {
8
+ const _callback = () => {
9
+ const key = opts?.domId ?? DEFAULT_ROOT
10
+ const root = document.getElementById(key)
11
+ if (opts?.debug) {
12
+ console.debug(`Render react app to ${key}`)
13
+ }
14
+ if (root == null) {
15
+ throw new Error(`Root element not found with id: ${key}`)
16
+ }
17
+ if (opts?.hydrate === true) {
18
+ hydrateRoot(root, node)
19
+ } else {
20
+ createRoot(root).render(node)
21
+ }
22
+ }
23
+
24
+ opts?.onReady ?? true ? window.addEventListener('DOMContentLoaded', _callback) : _callback()
25
+ }
package/src/modules.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { DISPATCHER } from '@owlmeans/auth'
2
+ import { modules as list } from '@owlmeans/client-auth'
3
+ import { elevate } from '@owlmeans/client-module'
4
+ import { handler } from '@owlmeans/client'
5
+ import { Dispatcher } from './components/dispatcher/component.js'
6
+
7
+ elevate(list, DISPATCHER, handler(Dispatcher), { force: true })
8
+
9
+ export const modules = list
package/src/router.ts ADDED
@@ -0,0 +1,7 @@
1
+
2
+ import type { RouterProvider } from '@owlmeans/client'
3
+ import { createBrowserRouter } from 'react-router-dom'
4
+
5
+ export const provide: RouterProvider = (routes) => {
6
+ return createBrowserRouter(routes)
7
+ }
package/src/service.ts ADDED
@@ -0,0 +1,41 @@
1
+
2
+ import { DEFAULT_ALIAS } from '@owlmeans/client-auth'
3
+ import type { AuthServiceAppend } from '@owlmeans/client-auth'
4
+ import type { AuthService } from '@owlmeans/auth-common'
5
+ import { makeAuthService } from '@owlmeans/client-auth'
6
+ import type { ClientModule } from '@owlmeans/client-module'
7
+ import { DISPATCHER } from '@owlmeans/auth'
8
+ import type { ClientConfig, ClientContext } from '@owlmeans/client-context'
9
+ import { authMiddleware } from '@owlmeans/auth-common'
10
+
11
+ export const makeAuthWebService = (alias: string = DEFAULT_ALIAS): AuthService => {
12
+ const service = makeAuthService(alias)
13
+
14
+ const update = service.update
15
+ service.update = async token => {
16
+ await update(token)
17
+ if (token == null) {
18
+ const module = service.assertCtx().module<ClientModule<string>>(DISPATCHER)
19
+ const [url] = await module.call()
20
+ document.location.href = url
21
+ }
22
+ }
23
+
24
+ return service
25
+ }
26
+
27
+ export const appendWebAuthService = <C extends ClientConfig, T extends ClientContext<C>>(
28
+ ctx: T, alias: string = DEFAULT_ALIAS
29
+ ): T & AuthServiceAppend => {
30
+ const service = makeAuthWebService(alias)
31
+
32
+ const context = ctx as T & AuthServiceAppend
33
+
34
+ context.registerService(service)
35
+
36
+ context.registerMiddleware(authMiddleware)
37
+
38
+ context.auth = () => ctx.service(service.alias)
39
+
40
+ return context
41
+ }
package/src/types.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { AuthServiceAppend } from '@owlmeans/client-auth'
2
+ import type { ClientConfig } from '@owlmeans/client-context'
3
+ import type { ClientContext } from '@owlmeans/client'
4
+
5
+ export interface RenderOptions {
6
+ domId?: string
7
+ onReady?: boolean
8
+ hydrate?: boolean
9
+ debug?: boolean
10
+ }
11
+
12
+ export interface AppConfig extends ClientConfig {
13
+ }
14
+
15
+ export interface AppContext<C extends AppConfig = AppConfig> extends ClientContext<C>,
16
+ AuthServiceAppend {
17
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": [
3
+ "../tsconfig.default.json",
4
+ "../tsconfig.react.json",
5
+ ],
6
+ "compilerOptions": {
7
+ "rootDir": "./src/", /* Specify the root folder within your source files. */
8
+ "outDir": "./build/", /* Specify an output folder for all emitted files. */
9
+ },
10
+ "exclude": [
11
+ "./dist/**/*",
12
+ "./build/**/*",
13
+ "./*.ts"
14
+ ]
15
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/consts.ts","./src/context.ts","./src/errors.ts","./src/exports.ts","./src/helper.ts","./src/i18n.ts","./src/index.ts","./src/main.tsx","./src/modules.ts","./src/router.ts","./src/service.ts","./src/types.ts","./src/components/index.ts","./src/components/dispatcher/component.tsx","./src/components/dispatcher/index.ts","./src/components/uploader/component.tsx","./src/components/uploader/image.tsx","./src/components/uploader/index.ts","./src/components/uploader/types.ts"],"version":"5.6.3"}