@contember/interface 1.3.0-alpha.24 → 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.
Files changed (37) hide show
  1. package/dist/development/components/binding/DeleteEntityTrigger.cjs.map +1 -1
  2. package/dist/development/components/binding/DeleteEntityTrigger.js.map +1 -1
  3. package/dist/development/hooks/useIsApplicationOutdated.cjs +55 -0
  4. package/dist/development/hooks/useIsApplicationOutdated.cjs.map +1 -0
  5. package/dist/development/hooks/useIsApplicationOutdated.js +55 -0
  6. package/dist/development/hooks/useIsApplicationOutdated.js.map +1 -0
  7. package/dist/development/index.cjs +2 -0
  8. package/dist/development/index.cjs.map +1 -1
  9. package/dist/development/index.js +3 -1
  10. package/dist/development/index.js.map +1 -1
  11. package/dist/production/components/binding/DeleteEntityTrigger.cjs.map +1 -1
  12. package/dist/production/components/binding/DeleteEntityTrigger.js.map +1 -1
  13. package/dist/production/hooks/useIsApplicationOutdated.cjs +55 -0
  14. package/dist/production/hooks/useIsApplicationOutdated.cjs.map +1 -0
  15. package/dist/production/hooks/useIsApplicationOutdated.js +55 -0
  16. package/dist/production/hooks/useIsApplicationOutdated.js.map +1 -0
  17. package/dist/production/index.cjs +2 -0
  18. package/dist/production/index.cjs.map +1 -1
  19. package/dist/production/index.js +3 -1
  20. package/dist/production/index.js.map +1 -1
  21. package/dist/types/bootstrap/DataViewPageNameKeyProvider.d.ts.map +1 -1
  22. package/dist/types/components/binding/DeleteEntityTrigger.d.ts +1 -1
  23. package/dist/types/components/binding/DeleteEntityTrigger.d.ts.map +1 -1
  24. package/dist/types/components/binding/EntityBeforePersist.d.ts.map +1 -1
  25. package/dist/types/components/binding/RedirectOnPersist.d.ts.map +1 -1
  26. package/dist/types/hooks/index.d.ts +2 -0
  27. package/dist/types/hooks/index.d.ts.map +1 -0
  28. package/dist/types/hooks/useIsApplicationOutdated.d.ts +4 -0
  29. package/dist/types/hooks/useIsApplicationOutdated.d.ts.map +1 -0
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +12 -12
  34. package/src/components/binding/DeleteEntityTrigger.tsx +1 -1
  35. package/src/hooks/index.ts +1 -0
  36. package/src/hooks/useIsApplicationOutdated.ts +62 -0
  37. 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.24",
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.24",
39
- "@contember/react-client": "1.3.0-alpha.24",
40
- "@contember/react-dataview": "1.3.0-alpha.24",
41
- "@contember/react-devbar": "1.3.0-alpha.24",
42
- "@contember/react-identity": "1.3.0-alpha.24",
43
- "@contember/react-routing": "1.3.0-alpha.24",
44
- "@contember/utilities": "1.3.0-alpha.24",
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": "^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",
@@ -6,7 +6,7 @@ import { ErrorPersistResult, SuccessfulPersistResult, useEntity, useMutationStat
6
6
  const SlotButton = Slot as ComponentType<React.ButtonHTMLAttributes<HTMLButtonElement>>
7
7
 
8
8
  export interface DeleteEntityTriggerProps {
9
- immediatePersist?: true
9
+ immediatePersist?: boolean
10
10
  children: ReactNode
11
11
  onPersistSuccess?: (result: SuccessfulPersistResult) => void
12
12
  onPersistError?: (result: ErrorPersistResult) => void
@@ -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'