@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.
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/build/components/dispatcher/component.d.ts +2 -0
- package/build/components/dispatcher/component.d.ts.map +1 -0
- package/build/components/dispatcher/component.js +41 -0
- package/build/components/dispatcher/component.js.map +1 -0
- package/build/components/dispatcher/index.d.ts +2 -0
- package/build/components/dispatcher/index.d.ts.map +1 -0
- package/build/components/dispatcher/index.js +2 -0
- package/build/components/dispatcher/index.js.map +1 -0
- package/build/components/index.d.ts +3 -0
- package/build/components/index.d.ts.map +1 -0
- package/build/components/index.js +3 -0
- package/build/components/index.js.map +1 -0
- package/build/components/uploader/component.d.ts +4 -0
- package/build/components/uploader/component.d.ts.map +1 -0
- package/build/components/uploader/component.js +10 -0
- package/build/components/uploader/component.js.map +1 -0
- package/build/components/uploader/image.d.ts +4 -0
- package/build/components/uploader/image.d.ts.map +1 -0
- package/build/components/uploader/image.js +8 -0
- package/build/components/uploader/image.js.map +1 -0
- package/build/components/uploader/index.d.ts +4 -0
- package/build/components/uploader/index.d.ts.map +1 -0
- package/build/components/uploader/index.js +3 -0
- package/build/components/uploader/index.js.map +1 -0
- package/build/components/uploader/types.d.ts +13 -0
- package/build/components/uploader/types.d.ts.map +1 -0
- package/build/components/uploader/types.js +2 -0
- package/build/components/uploader/types.js.map +1 -0
- package/build/consts.d.ts +2 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +2 -0
- package/build/consts.js.map +1 -0
- package/build/context.d.ts +4 -0
- package/build/context.d.ts.map +1 -0
- package/build/context.js +18 -0
- package/build/context.js.map +1 -0
- package/build/errors.d.ts +11 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +19 -0
- package/build/errors.js.map +1 -0
- package/build/exports.d.ts +9 -0
- package/build/exports.d.ts.map +1 -0
- package/build/exports.js +7 -0
- package/build/exports.js.map +1 -0
- package/build/helper.d.ts +3 -0
- package/build/helper.d.ts.map +1 -0
- package/build/helper.js +7 -0
- package/build/helper.js.map +1 -0
- package/build/i18n/auth-en.json +5 -0
- package/build/i18n.d.ts +2 -0
- package/build/i18n.d.ts.map +1 -0
- package/build/i18n.js +4 -0
- package/build/i18n.js.map +1 -0
- package/build/index.d.ts +13 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +13 -0
- package/build/index.js.map +1 -0
- package/build/main.d.ts +4 -0
- package/build/main.d.ts.map +1 -0
- package/build/main.js +22 -0
- package/build/main.js.map +1 -0
- package/build/modules.d.ts +2 -0
- package/build/modules.d.ts.map +1 -0
- package/build/modules.js +8 -0
- package/build/modules.js.map +1 -0
- package/build/router.d.ts +3 -0
- package/build/router.d.ts.map +1 -0
- package/build/router.js +5 -0
- package/build/router.js.map +1 -0
- package/build/service.d.ts +6 -0
- package/build/service.d.ts.map +1 -0
- package/build/service.js +26 -0
- package/build/service.js.map +1 -0
- package/build/types.d.ts +14 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +57 -0
- package/src/components/dispatcher/component.tsx +43 -0
- package/src/components/dispatcher/index.ts +2 -0
- package/src/components/index.ts +3 -0
- package/src/components/uploader/component.tsx +17 -0
- package/src/components/uploader/image.tsx +10 -0
- package/src/components/uploader/index.ts +4 -0
- package/src/components/uploader/types.ts +14 -0
- package/src/consts.ts +2 -0
- package/src/context.ts +27 -0
- package/src/errors.ts +25 -0
- package/src/exports.ts +9 -0
- package/src/helper.ts +8 -0
- package/src/i18n/auth-en.json +5 -0
- package/src/i18n.ts +5 -0
- package/src/index.ts +13 -0
- package/src/main.tsx +25 -0
- package/src/modules.ts +9 -0
- package/src/router.ts +7 -0
- package/src/service.ts +41 -0
- package/src/types.ts +17 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -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
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
|
+
}
|
package/src/i18n.ts
ADDED
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
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"}
|