@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.
Files changed (40) hide show
  1. package/dist/development/bootstrap/ApplicationEntrypoint.cjs +8 -8
  2. package/dist/development/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
  3. package/dist/development/bootstrap/ApplicationEntrypoint.js +10 -10
  4. package/dist/development/bootstrap/ApplicationEntrypoint.js.map +1 -1
  5. package/dist/development/hooks/useIsApplicationOutdated.cjs +55 -0
  6. package/dist/development/hooks/useIsApplicationOutdated.cjs.map +1 -0
  7. package/dist/development/hooks/useIsApplicationOutdated.js +55 -0
  8. package/dist/development/hooks/useIsApplicationOutdated.js.map +1 -0
  9. package/dist/development/index.cjs +2 -0
  10. package/dist/development/index.cjs.map +1 -1
  11. package/dist/development/index.js +3 -1
  12. package/dist/development/index.js.map +1 -1
  13. package/dist/production/bootstrap/ApplicationEntrypoint.cjs +3 -3
  14. package/dist/production/bootstrap/ApplicationEntrypoint.cjs.map +1 -1
  15. package/dist/production/bootstrap/ApplicationEntrypoint.js +5 -5
  16. package/dist/production/bootstrap/ApplicationEntrypoint.js.map +1 -1
  17. package/dist/production/hooks/useIsApplicationOutdated.cjs +55 -0
  18. package/dist/production/hooks/useIsApplicationOutdated.cjs.map +1 -0
  19. package/dist/production/hooks/useIsApplicationOutdated.js +55 -0
  20. package/dist/production/hooks/useIsApplicationOutdated.js.map +1 -0
  21. package/dist/production/index.cjs +2 -0
  22. package/dist/production/index.cjs.map +1 -1
  23. package/dist/production/index.js +3 -1
  24. package/dist/production/index.js.map +1 -1
  25. package/dist/types/bootstrap/ApplicationEntrypoint.d.ts.map +1 -1
  26. package/dist/types/bootstrap/DataViewPageNameKeyProvider.d.ts.map +1 -1
  27. package/dist/types/components/binding/EntityBeforePersist.d.ts.map +1 -1
  28. package/dist/types/components/binding/RedirectOnPersist.d.ts.map +1 -1
  29. package/dist/types/hooks/index.d.ts +2 -0
  30. package/dist/types/hooks/index.d.ts.map +1 -0
  31. package/dist/types/hooks/useIsApplicationOutdated.d.ts +4 -0
  32. package/dist/types/hooks/useIsApplicationOutdated.d.ts.map +1 -0
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +12 -12
  37. package/src/bootstrap/ApplicationEntrypoint.tsx +20 -20
  38. package/src/hooks/index.ts +1 -0
  39. package/src/hooks/useIsApplicationOutdated.ts +62 -0
  40. 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.25",
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.25",
39
- "@contember/react-client": "1.3.0-alpha.25",
40
- "@contember/react-dataview": "1.3.0-alpha.25",
41
- "@contember/react-devbar": "1.3.0-alpha.25",
42
- "@contember/react-identity": "1.3.0-alpha.25",
43
- "@contember/react-routing": "1.3.0-alpha.25",
44
- "@contember/utilities": "1.3.0-alpha.25",
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": "^17 || ^18",
49
- "react-dom": "^17 || ^18"
48
+ "react": "^18 || ^19",
49
+ "react-dom": "^18 || ^19"
50
50
  },
51
51
  "devDependencies": {
52
- "react": "^18.2.0",
53
- "react-dom": "^18.2.0"
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
- <RoutingContext.Provider value={routing}>
40
- <RequestProvider>
41
- <ContemberClient
42
- apiBaseUrl={props.apiBaseUrl}
43
- sessionToken={props.sessionToken}
44
- loginToken={props.loginToken}
45
- project={props.project}
46
- stage={props.stage}
47
- >
48
- <EnvironmentExtensionProvider extension={projectEnvironmentExtension} state={props.project ?? null}>
49
- <DataViewPageNameKeyProvider>
50
- <IdentityProvider>
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
- </IdentityProvider>
53
- </DataViewPageNameKeyProvider>
54
- </EnvironmentExtensionProvider>
55
- </ContemberClient>
56
- </RequestProvider>
57
- </RoutingContext.Provider>
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
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './bootstrap'
2
2
  export * from './components'
3
+ export * from './hooks'
3
4
  export * from '@contember/react-routing'
4
5
  export * from '@contember/react-binding'
5
6
  export * from '@contember/react-identity'