@contentful/field-editor-reference 6.19.0 → 6.19.2-alpha.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.
@@ -149,7 +149,7 @@ function handleResourceFetchError(resourceFetchError, resourceTypeEntity) {
149
149
  throw resourceFetchError;
150
150
  }
151
151
  const isEntityQueryKey = (queryKey)=>{
152
- return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
152
+ return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && (queryKey.length === 4 || queryKey.length === 5);
153
153
  };
154
154
  async function fetchContentfulEntry({ urn, fetch, options }) {
155
155
  const resourceId = urn.split(':', 6)[5];
@@ -470,10 +470,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
470
470
  const onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
471
471
  (0, _react.useEffect)(()=>{
472
472
  function findSameSpaceQueries() {
473
- return queryCache.findAll({
473
+ const queries = queryCache.findAll({
474
474
  type: 'active',
475
475
  predicate: (query)=>isSameSpaceEntityQueryKey(query.queryKey)
476
476
  });
477
+ return queries;
477
478
  }
478
479
  if (typeof onEntityChanged !== 'function') {
479
480
  return onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
@@ -487,8 +488,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
487
488
  const subscribeQuery = ({ queryKey, queryHash })=>{
488
489
  const [entityType, entityId, , , releaseId] = queryKey;
489
490
  entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
490
- if ((0, _lodash.get)(data, 'sys.release.id') === releaseId) {
491
+ const dataReleaseId = (0, _lodash.get)(data, 'sys.release.id');
492
+ if (dataReleaseId === releaseId) {
491
493
  queryClient.setQueryData(queryKey, data);
494
+ } else if (releaseId && !dataReleaseId) {
495
+ void queryClient.invalidateQueries(queryKey);
492
496
  }
493
497
  });
494
498
  };
@@ -10,100 +10,13 @@ function _export(target, all) {
10
10
  }
11
11
  _export(exports, {
12
12
  SharedQueryClientProvider: function() {
13
- return SharedQueryClientProvider;
13
+ return _fieldeditorshared.SharedQueryClientProvider;
14
14
  },
15
15
  useQuery: function() {
16
- return useQuery;
16
+ return _fieldeditorshared.useQuery;
17
17
  },
18
18
  useQueryClient: function() {
19
- return useQueryClient;
19
+ return _fieldeditorshared.useQueryClient;
20
20
  }
21
21
  });
22
- const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
23
- const _reactquery = require("@tanstack/react-query");
24
- function _getRequireWildcardCache(nodeInterop) {
25
- if (typeof WeakMap !== "function") return null;
26
- var cacheBabelInterop = new WeakMap();
27
- var cacheNodeInterop = new WeakMap();
28
- return (_getRequireWildcardCache = function(nodeInterop) {
29
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
30
- })(nodeInterop);
31
- }
32
- function _interop_require_wildcard(obj, nodeInterop) {
33
- if (!nodeInterop && obj && obj.__esModule) {
34
- return obj;
35
- }
36
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
37
- return {
38
- default: obj
39
- };
40
- }
41
- var cache = _getRequireWildcardCache(nodeInterop);
42
- if (cache && cache.has(obj)) {
43
- return cache.get(obj);
44
- }
45
- var newObj = {
46
- __proto__: null
47
- };
48
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
49
- for(var key in obj){
50
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
51
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
52
- if (desc && (desc.get || desc.set)) {
53
- Object.defineProperty(newObj, key, desc);
54
- } else {
55
- newObj[key] = obj[key];
56
- }
57
- }
58
- }
59
- newObj.default = obj;
60
- if (cache) {
61
- cache.set(obj, newObj);
62
- }
63
- return newObj;
64
- }
65
- const clientContext = /*#__PURE__*/ _react.createContext(undefined);
66
- function useMaybeHostQueryClient() {
67
- try {
68
- return (0, _reactquery.useQueryClient)();
69
- } catch {
70
- return undefined;
71
- }
72
- }
73
- function useQueryClient() {
74
- const client = _react.useContext(clientContext);
75
- const hostClient = useMaybeHostQueryClient();
76
- return _react.useMemo(()=>{
77
- if (client) {
78
- return client;
79
- }
80
- if (hostClient) return hostClient;
81
- return new _reactquery.QueryClient({
82
- defaultOptions: {
83
- queries: {
84
- useErrorBoundary: false,
85
- refetchOnWindowFocus: false,
86
- refetchOnReconnect: true,
87
- refetchOnMount: false,
88
- staleTime: Infinity,
89
- retry: false
90
- }
91
- }
92
- });
93
- }, [
94
- client,
95
- hostClient
96
- ]);
97
- }
98
- const useQuery = (key, fn, opt)=>{
99
- return (0, _reactquery.useQuery)(key, fn, {
100
- ...opt,
101
- context: clientContext
102
- });
103
- };
104
- function SharedQueryClientProvider({ children }) {
105
- const client = useQueryClient();
106
- return /*#__PURE__*/ _react.createElement(clientContext.Provider, {
107
- value: client
108
- }, children);
109
- }
22
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
@@ -61,7 +61,7 @@ function handleResourceFetchError(resourceFetchError, resourceTypeEntity) {
61
61
  throw resourceFetchError;
62
62
  }
63
63
  const isEntityQueryKey = (queryKey)=>{
64
- return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
64
+ return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && (queryKey.length === 4 || queryKey.length === 5);
65
65
  };
66
66
  async function fetchContentfulEntry({ urn, fetch, options }) {
67
67
  const resourceId = urn.split(':', 6)[5];
@@ -382,10 +382,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
382
382
  const onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
383
383
  useEffect(()=>{
384
384
  function findSameSpaceQueries() {
385
- return queryCache.findAll({
385
+ const queries = queryCache.findAll({
386
386
  type: 'active',
387
387
  predicate: (query)=>isSameSpaceEntityQueryKey(query.queryKey)
388
388
  });
389
+ return queries;
389
390
  }
390
391
  if (typeof onEntityChanged !== 'function') {
391
392
  return onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
@@ -399,8 +400,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
399
400
  const subscribeQuery = ({ queryKey, queryHash })=>{
400
401
  const [entityType, entityId, , , releaseId] = queryKey;
401
402
  entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
402
- if (get(data, 'sys.release.id') === releaseId) {
403
+ const dataReleaseId = get(data, 'sys.release.id');
404
+ if (dataReleaseId === releaseId) {
403
405
  queryClient.setQueryData(queryKey, data);
406
+ } else if (releaseId && !dataReleaseId) {
407
+ void queryClient.invalidateQueries(queryKey);
404
408
  }
405
409
  });
406
410
  };
@@ -1,47 +1 @@
1
- import * as React from 'react';
2
- import { QueryClient, useQuery as useRQ, useQueryClient as useHostQueryClient } from '@tanstack/react-query';
3
- const clientContext = /*#__PURE__*/ React.createContext(undefined);
4
- function useMaybeHostQueryClient() {
5
- try {
6
- return useHostQueryClient();
7
- } catch {
8
- return undefined;
9
- }
10
- }
11
- export function useQueryClient() {
12
- const client = React.useContext(clientContext);
13
- const hostClient = useMaybeHostQueryClient();
14
- return React.useMemo(()=>{
15
- if (client) {
16
- return client;
17
- }
18
- if (hostClient) return hostClient;
19
- return new QueryClient({
20
- defaultOptions: {
21
- queries: {
22
- useErrorBoundary: false,
23
- refetchOnWindowFocus: false,
24
- refetchOnReconnect: true,
25
- refetchOnMount: false,
26
- staleTime: Infinity,
27
- retry: false
28
- }
29
- }
30
- });
31
- }, [
32
- client,
33
- hostClient
34
- ]);
35
- }
36
- export const useQuery = (key, fn, opt)=>{
37
- return useRQ(key, fn, {
38
- ...opt,
39
- context: clientContext
40
- });
41
- };
42
- export function SharedQueryClientProvider({ children }) {
43
- const client = useQueryClient();
44
- return /*#__PURE__*/ React.createElement(clientContext.Provider, {
45
- value: client
46
- }, children);
47
- }
1
+ export { SharedQueryClientProvider, useQueryClient, useQuery } from '@contentful/field-editor-shared';
@@ -88,12 +88,12 @@ declare const useEntityLoader: () => {
88
88
  };
89
89
  export declare function useEntity<E extends FetchableEntity>(entityType: FetchableEntityType, entityId: string, options?: Omit<UseEntityOptions, 'releaseId'>): UseEntityResult<E>;
90
90
  export declare function useResource<R extends Resource = Resource>(resourceType: string, urn: string, { locale, referencingEntryId, ...options }?: UseResourceOptions): {
91
- status: "error" | "success" | "loading";
91
+ status: "loading" | "error" | "success";
92
92
  data: ResourceInfo<R> | undefined;
93
93
  error: unknown;
94
94
  };
95
95
  export declare function useResourceProvider(organizationId: string, appDefinitionId: string): {
96
- status: "error" | "success" | "loading";
96
+ status: "loading" | "error" | "success";
97
97
  data: ResourceProvider | undefined;
98
98
  error: unknown;
99
99
  };
@@ -1,9 +1,5 @@
1
- import * as React from 'react';
2
- import { QueryClient, useQuery as useRQ } from '@tanstack/react-query';
3
- export declare function useQueryClient(): QueryClient;
4
- export declare const useQuery: typeof useRQ;
5
1
  /**
6
- * Provides access to a query client either by sharing an existing client or
7
- * creating a new one.
2
+ * Re-export query client utilities from shared package.
3
+ * This maintains backwards compatibility while using the shared implementation.
8
4
  */
9
- export declare function SharedQueryClientProvider({ children }: React.PropsWithChildren<{}>): React.JSX.Element;
5
+ export { SharedQueryClientProvider, useQueryClient, useQuery, } from '@contentful/field-editor-shared';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-reference",
3
- "version": "6.19.0",
3
+ "version": "6.19.2-alpha.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "@contentful/f36-components": "^5.8.1",
40
40
  "@contentful/f36-icons": "^5.8.1",
41
41
  "@contentful/f36-tokens": "^5.1.0",
42
- "@contentful/field-editor-shared": "^2.17.0",
42
+ "@contentful/field-editor-shared": "^2.17.1-alpha.0",
43
43
  "@contentful/mimetype": "^2.2.29",
44
44
  "@dnd-kit/core": "^6.0.8",
45
45
  "@dnd-kit/sortable": "^8.0.0",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "registry": "https://npm.pkg.github.com/"
70
70
  },
71
- "gitHead": "67068016b57ce3057ddddfb8dd3a53ef86499a02"
71
+ "gitHead": "447875c5a2ef25eb4552c29b990d90ec40bc6985"
72
72
  }