@contember/interface 1.3.0-alpha.25 → 1.3.0-alpha.26
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/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/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/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/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.26",
|
|
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.26",
|
|
39
|
+
"@contember/react-client": "1.3.0-alpha.26",
|
|
40
|
+
"@contember/react-dataview": "1.3.0-alpha.26",
|
|
41
|
+
"@contember/react-devbar": "1.3.0-alpha.26",
|
|
42
|
+
"@contember/react-identity": "1.3.0-alpha.26",
|
|
43
|
+
"@contember/react-routing": "1.3.0-alpha.26",
|
|
44
|
+
"@contember/utilities": "1.3.0-alpha.26",
|
|
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",
|
|
@@ -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
|
+
}
|