@contember/interface 1.3.0-alpha.25 → 1.3.0-alpha.27
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/dist/development/bootstrap/ApplicationEntrypoint.cjs +8 -8
- package/dist/development/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
- package/dist/development/bootstrap/ApplicationEntrypoint.js +10 -10
- package/dist/development/bootstrap/ApplicationEntrypoint.js.map +1 -1
- package/dist/development/hooks/useIsApplicationOutdated.cjs +55 -0
- package/dist/development/hooks/useIsApplicationOutdated.cjs.map +1 -0
- package/dist/development/hooks/useIsApplicationOutdated.js +55 -0
- package/dist/development/hooks/useIsApplicationOutdated.js.map +1 -0
- package/dist/development/index.cjs +2 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +3 -1
- package/dist/development/index.js.map +1 -1
- package/dist/production/bootstrap/ApplicationEntrypoint.cjs +3 -3
- package/dist/production/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
- package/dist/production/bootstrap/ApplicationEntrypoint.js +5 -5
- package/dist/production/bootstrap/ApplicationEntrypoint.js.map +1 -1
- package/dist/production/hooks/useIsApplicationOutdated.cjs +55 -0
- package/dist/production/hooks/useIsApplicationOutdated.cjs.map +1 -0
- package/dist/production/hooks/useIsApplicationOutdated.js +55 -0
- package/dist/production/hooks/useIsApplicationOutdated.js.map +1 -0
- package/dist/production/index.cjs +2 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +3 -1
- package/dist/production/index.js.map +1 -1
- package/dist/types/bootstrap/ApplicationEntrypoint.d.ts.map +1 -1
- package/dist/types/bootstrap/DataViewPageNameKeyProvider.d.ts.map +1 -1
- package/dist/types/components/binding/EntityBeforePersist.d.ts.map +1 -1
- package/dist/types/components/binding/RedirectOnPersist.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/useIsApplicationOutdated.d.ts +4 -0
- package/dist/types/hooks/useIsApplicationOutdated.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/bootstrap/ApplicationEntrypoint.tsx +20 -20
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useIsApplicationOutdated.ts +62 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/interface",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.3.0-alpha.
|
|
4
|
+
"version": "1.3.0-alpha.27",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"test": "vitest"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contember/react-binding": "1.3.0-alpha.
|
|
39
|
-
"@contember/react-client": "1.3.0-alpha.
|
|
40
|
-
"@contember/react-dataview": "1.3.0-alpha.
|
|
41
|
-
"@contember/react-devbar": "1.3.0-alpha.
|
|
42
|
-
"@contember/react-identity": "1.3.0-alpha.
|
|
43
|
-
"@contember/react-routing": "1.3.0-alpha.
|
|
44
|
-
"@contember/utilities": "1.3.0-alpha.
|
|
38
|
+
"@contember/react-binding": "1.3.0-alpha.27",
|
|
39
|
+
"@contember/react-client": "1.3.0-alpha.27",
|
|
40
|
+
"@contember/react-dataview": "1.3.0-alpha.27",
|
|
41
|
+
"@contember/react-devbar": "1.3.0-alpha.27",
|
|
42
|
+
"@contember/react-identity": "1.3.0-alpha.27",
|
|
43
|
+
"@contember/react-routing": "1.3.0-alpha.27",
|
|
44
|
+
"@contember/utilities": "1.3.0-alpha.27",
|
|
45
45
|
"@radix-ui/react-slot": "^1.0.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"react": "^
|
|
49
|
-
"react-dom": "^
|
|
48
|
+
"react": "^18 || ^19",
|
|
49
|
+
"react-dom": "^18 || ^19"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"react": "^18.
|
|
53
|
-
"react-dom": "^18.
|
|
52
|
+
"react": "^18.3.1",
|
|
53
|
+
"react-dom": "^18.3.1"
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Environment, EnvironmentContext, EnvironmentExtensionProvider } from '@contember/react-binding'
|
|
2
2
|
import { ContemberClient, ContemberClientProps } from '@contember/react-client'
|
|
3
3
|
import { ReactNode } from 'react'
|
|
4
|
-
import { RequestProvider, RouteMap, RoutingContext, RoutingContextValue, SelectedDimension } from '@contember/react-routing'
|
|
4
|
+
import { RequestProvider, RouteMap, RoutingContext, RoutingContextValue, RoutingProvider, SelectedDimension } from '@contember/react-routing'
|
|
5
5
|
import { DataViewPageNameKeyProvider } from './DataViewPageNameKeyProvider'
|
|
6
|
-
import { IdentityProvider, projectEnvironmentExtension } from '@contember/react-identity'
|
|
6
|
+
import { IdentityEnvironmentProvider, IdentityProvider, projectEnvironmentExtension } from '@contember/react-identity'
|
|
7
7
|
|
|
8
8
|
export interface ApplicationEntrypointProps extends ContemberClientProps {
|
|
9
9
|
basePath: string
|
|
@@ -36,25 +36,25 @@ export const ApplicationEntrypoint = (props: ApplicationEntrypointProps) => {
|
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<EnvironmentContext.Provider value={rootEnv}>
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
>
|
|
48
|
-
<
|
|
49
|
-
<
|
|
50
|
-
<
|
|
39
|
+
<RoutingProvider {...routing}>
|
|
40
|
+
<ContemberClient
|
|
41
|
+
apiBaseUrl={props.apiBaseUrl}
|
|
42
|
+
sessionToken={props.sessionToken}
|
|
43
|
+
loginToken={props.loginToken}
|
|
44
|
+
project={props.project}
|
|
45
|
+
stage={props.stage}
|
|
46
|
+
>
|
|
47
|
+
<EnvironmentExtensionProvider extension={projectEnvironmentExtension} state={props.project ?? null}>
|
|
48
|
+
<DataViewPageNameKeyProvider>
|
|
49
|
+
<IdentityProvider>
|
|
50
|
+
<IdentityEnvironmentProvider>
|
|
51
51
|
{props.children}
|
|
52
|
-
</
|
|
53
|
-
</
|
|
54
|
-
</
|
|
55
|
-
</
|
|
56
|
-
</
|
|
57
|
-
</
|
|
52
|
+
</IdentityEnvironmentProvider>
|
|
53
|
+
</IdentityProvider>
|
|
54
|
+
</DataViewPageNameKeyProvider>
|
|
55
|
+
</EnvironmentExtensionProvider>
|
|
56
|
+
</ContemberClient>
|
|
57
|
+
</RoutingProvider>
|
|
58
58
|
</EnvironmentContext.Provider>
|
|
59
59
|
)
|
|
60
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIsApplicationOutdated'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const defaultCheckIntervalMs = 30_000
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const useIsApplicationOutdated = ({ checkIntervalMs = defaultCheckIntervalMs }: {
|
|
7
|
+
checkIntervalMs?: number
|
|
8
|
+
} = {}) => {
|
|
9
|
+
const [initialVersion] = useState(() => {
|
|
10
|
+
return getVersionFromDocument(document.head)
|
|
11
|
+
})
|
|
12
|
+
const [isOutdated, setIsOutdated] = useState(false)
|
|
13
|
+
const fetchVersion = useFetchVersion()
|
|
14
|
+
|
|
15
|
+
const checkVersion = useCallback(async () => {
|
|
16
|
+
if (document.hidden) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
const version = await fetchVersion()
|
|
20
|
+
if (version !== initialVersion) {
|
|
21
|
+
setIsOutdated(true)
|
|
22
|
+
}
|
|
23
|
+
}, [fetchVersion, initialVersion])
|
|
24
|
+
const shouldCheck = !!initialVersion && !isOutdated
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!shouldCheck) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
const handle = setInterval(checkVersion, checkIntervalMs)
|
|
31
|
+
return () => clearInterval(handle)
|
|
32
|
+
}, [checkIntervalMs, checkVersion, shouldCheck])
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!shouldCheck) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
document.addEventListener('visibilitychange', checkVersion)
|
|
39
|
+
return () => document.removeEventListener('visibilitychange', checkVersion)
|
|
40
|
+
}, [checkVersion, shouldCheck])
|
|
41
|
+
|
|
42
|
+
return isOutdated
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getVersionFromDocument = (node: ParentNode) => {
|
|
46
|
+
const meta = node.querySelector<HTMLMetaElement>('meta[name=contember-build-version]')
|
|
47
|
+
return meta?.content
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const useFetchVersion = () => {
|
|
51
|
+
return useCallback(async () => {
|
|
52
|
+
try {
|
|
53
|
+
const result = await (await fetch(window.location.href)).text()
|
|
54
|
+
const html = document.createElement('html')
|
|
55
|
+
html.innerHTML = result
|
|
56
|
+
return getVersionFromDocument(html)
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error(e)
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
}, [])
|
|
62
|
+
}
|