@contentful/field-editor-reference 6.19.2 → 6.19.3-canary.25

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.
@@ -41,6 +41,7 @@ _export(exports, {
41
41
  }
42
42
  });
43
43
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
44
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
44
45
  const _constate = /*#__PURE__*/ _interop_require_default(require("constate"));
45
46
  const _contentfulmanagement = require("contentful-management");
46
47
  const _lodash = require("lodash");
@@ -162,18 +163,10 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
162
163
  const environmentId = resourceIdMatch?.groups?.environmentId || 'master';
163
164
  const entryId = resourceIdMatch.groups.entityId;
164
165
  const [space, entry] = await Promise.all([
165
- fetch([
166
- 'space',
167
- spaceId
168
- ], ({ cmaClient })=>cmaClient.space.get({
166
+ fetch((0, _fieldeditorshared.createGetSpaceKey)(spaceId), ({ cmaClient })=>cmaClient.space.get({
169
167
  spaceId
170
168
  }), options),
171
- fetch([
172
- 'entry',
173
- spaceId,
174
- environmentId,
175
- entryId
176
- ], ({ cmaClient })=>cmaClient.entry.get({
169
+ fetch((0, _fieldeditorshared.createGetEntryKey)(spaceId, environmentId, entryId), ({ cmaClient })=>cmaClient.entry.get({
177
170
  spaceId,
178
171
  environmentId,
179
172
  entryId
@@ -181,12 +174,7 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
181
174
  ]);
182
175
  const contentTypeId = entry.sys.contentType.sys.id;
183
176
  const [contentType, defaultLocaleCode] = await Promise.all([
184
- fetch([
185
- 'contentType',
186
- spaceId,
187
- environmentId,
188
- contentTypeId
189
- ], ({ cmaClient })=>cmaClient.contentType.get({
177
+ fetch((0, _fieldeditorshared.createGetContentTypeKey)(spaceId, environmentId, contentTypeId), ({ cmaClient })=>cmaClient.contentType.get({
190
178
  contentTypeId,
191
179
  spaceId,
192
180
  environmentId
@@ -471,17 +459,41 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
471
459
  (0, _react.useEffect)(()=>{
472
460
  function findSameSpaceQueries() {
473
461
  const queries = queryCache.findAll({
474
- type: 'active',
475
462
  predicate: (query)=>isSameSpaceEntityQueryKey(query.queryKey)
476
463
  });
477
464
  return queries;
478
465
  }
479
466
  if (typeof onEntityChanged !== 'function') {
480
- return onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
467
+ return onSlideInNavigation(async ({ oldSlideLevel, newSlideLevel })=>{
481
468
  if (oldSlideLevel > newSlideLevel) {
482
- findSameSpaceQueries().forEach((query)=>{
483
- void queryClient.invalidateQueries(query.queryKey);
484
- });
469
+ const queries = findSameSpaceQueries();
470
+ await Promise.all(queries.map(async (query)=>{
471
+ const [entityType, entityId, spaceId, environmentId, releaseId] = query.queryKey;
472
+ try {
473
+ let freshData;
474
+ if (entityType === 'Entry') {
475
+ freshData = await cmaClient.entry.get({
476
+ entryId: entityId,
477
+ spaceId: spaceId,
478
+ environmentId: environmentId,
479
+ releaseId: releaseId
480
+ });
481
+ } else if (entityType === 'Asset') {
482
+ freshData = await cmaClient.asset.get({
483
+ assetId: entityId,
484
+ spaceId: spaceId,
485
+ environmentId: environmentId,
486
+ releaseId: releaseId
487
+ });
488
+ } else {
489
+ await queryClient.invalidateQueries(query.queryKey);
490
+ return;
491
+ }
492
+ queryClient.setQueryData(query.queryKey, freshData);
493
+ } catch (error) {
494
+ await queryClient.invalidateQueries(query.queryKey);
495
+ }
496
+ }));
485
497
  }
486
498
  });
487
499
  }
@@ -524,7 +536,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
524
536
  isSameSpaceEntityQueryKey,
525
537
  queryClient,
526
538
  getEntity,
527
- onSlideInNavigation
539
+ onSlideInNavigation,
540
+ cmaClient
528
541
  ]);
529
542
  const getResourceProvider = (0, _react.useCallback)(function getResourceProvider(organizationId, appDefinitionId) {
530
543
  const queryKey = [
@@ -9,10 +9,12 @@ Object.defineProperty(exports, "MultipleReferenceEditor", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
12
13
  const _sortable = require("@dnd-kit/sortable");
13
14
  const _components = require("../components");
14
15
  const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
15
16
  const _useSortIDs = require("../utils/useSortIDs");
17
+ const _queryClient = require("./queryClient");
16
18
  const _ReferenceEditor = require("./ReferenceEditor");
17
19
  const _useEditorPermissions = require("./useEditorPermissions");
18
20
  function _getRequireWildcardCache(nodeInterop) {
@@ -145,7 +147,10 @@ function Editor(props) {
145
147
  }));
146
148
  }
147
149
  function MultipleReferenceEditor(props) {
148
- const allContentTypes = props.sdk.space.getCachedContentTypes();
150
+ return /*#__PURE__*/ _react.createElement(_queryClient.SharedQueryClientProvider, null, /*#__PURE__*/ _react.createElement(MultipleReferenceEditorInner, props));
151
+ }
152
+ function MultipleReferenceEditorInner(props) {
153
+ const { contentTypes: allContentTypes } = (0, _fieldeditorshared.useContentTypes)(props.sdk);
149
154
  return /*#__PURE__*/ _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value, disabled, setValue, externalReset })=>{
150
155
  return /*#__PURE__*/ _react.createElement(Editor, {
151
156
  ...props,
@@ -9,8 +9,10 @@ Object.defineProperty(exports, "SingleReferenceEditor", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
+ const _fieldeditorshared = require("@contentful/field-editor-shared");
12
13
  const _components = require("../components");
13
14
  const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
15
+ const _queryClient = require("./queryClient");
14
16
  const _ReferenceEditor = require("./ReferenceEditor");
15
17
  const _useEditorPermissions = require("./useEditorPermissions");
16
18
  function _getRequireWildcardCache(nodeInterop) {
@@ -102,7 +104,10 @@ function Editor(props) {
102
104
  });
103
105
  }
104
106
  function SingleReferenceEditor(props) {
105
- const allContentTypes = props.sdk.space.getCachedContentTypes();
107
+ return /*#__PURE__*/ _react.createElement(_queryClient.SharedQueryClientProvider, null, /*#__PURE__*/ _react.createElement(SingleReferenceEditorInner, props));
108
+ }
109
+ function SingleReferenceEditorInner(props) {
110
+ const { contentTypes: allContentTypes } = (0, _fieldeditorshared.useContentTypes)(props.sdk);
106
111
  return /*#__PURE__*/ _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value, setValue, disabled, externalReset })=>{
107
112
  return /*#__PURE__*/ _react.createElement(Editor, {
108
113
  ...props,
@@ -12,6 +12,7 @@ function _define_property(obj, key, value) {
12
12
  return obj;
13
13
  }
14
14
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
15
+ import { createGetContentTypeKey, createGetEntryKey, createGetSpaceKey } from '@contentful/field-editor-shared';
15
16
  import constate from 'constate';
16
17
  import { fetchAll } from 'contentful-management';
17
18
  import { get } from 'lodash';
@@ -74,18 +75,10 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
74
75
  const environmentId = resourceIdMatch?.groups?.environmentId || 'master';
75
76
  const entryId = resourceIdMatch.groups.entityId;
76
77
  const [space, entry] = await Promise.all([
77
- fetch([
78
- 'space',
79
- spaceId
80
- ], ({ cmaClient })=>cmaClient.space.get({
78
+ fetch(createGetSpaceKey(spaceId), ({ cmaClient })=>cmaClient.space.get({
81
79
  spaceId
82
80
  }), options),
83
- fetch([
84
- 'entry',
85
- spaceId,
86
- environmentId,
87
- entryId
88
- ], ({ cmaClient })=>cmaClient.entry.get({
81
+ fetch(createGetEntryKey(spaceId, environmentId, entryId), ({ cmaClient })=>cmaClient.entry.get({
89
82
  spaceId,
90
83
  environmentId,
91
84
  entryId
@@ -93,12 +86,7 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
93
86
  ]);
94
87
  const contentTypeId = entry.sys.contentType.sys.id;
95
88
  const [contentType, defaultLocaleCode] = await Promise.all([
96
- fetch([
97
- 'contentType',
98
- spaceId,
99
- environmentId,
100
- contentTypeId
101
- ], ({ cmaClient })=>cmaClient.contentType.get({
89
+ fetch(createGetContentTypeKey(spaceId, environmentId, contentTypeId), ({ cmaClient })=>cmaClient.contentType.get({
102
90
  contentTypeId,
103
91
  spaceId,
104
92
  environmentId
@@ -383,17 +371,41 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
383
371
  useEffect(()=>{
384
372
  function findSameSpaceQueries() {
385
373
  const queries = queryCache.findAll({
386
- type: 'active',
387
374
  predicate: (query)=>isSameSpaceEntityQueryKey(query.queryKey)
388
375
  });
389
376
  return queries;
390
377
  }
391
378
  if (typeof onEntityChanged !== 'function') {
392
- return onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
379
+ return onSlideInNavigation(async ({ oldSlideLevel, newSlideLevel })=>{
393
380
  if (oldSlideLevel > newSlideLevel) {
394
- findSameSpaceQueries().forEach((query)=>{
395
- void queryClient.invalidateQueries(query.queryKey);
396
- });
381
+ const queries = findSameSpaceQueries();
382
+ await Promise.all(queries.map(async (query)=>{
383
+ const [entityType, entityId, spaceId, environmentId, releaseId] = query.queryKey;
384
+ try {
385
+ let freshData;
386
+ if (entityType === 'Entry') {
387
+ freshData = await cmaClient.entry.get({
388
+ entryId: entityId,
389
+ spaceId: spaceId,
390
+ environmentId: environmentId,
391
+ releaseId: releaseId
392
+ });
393
+ } else if (entityType === 'Asset') {
394
+ freshData = await cmaClient.asset.get({
395
+ assetId: entityId,
396
+ spaceId: spaceId,
397
+ environmentId: environmentId,
398
+ releaseId: releaseId
399
+ });
400
+ } else {
401
+ await queryClient.invalidateQueries(query.queryKey);
402
+ return;
403
+ }
404
+ queryClient.setQueryData(query.queryKey, freshData);
405
+ } catch (error) {
406
+ await queryClient.invalidateQueries(query.queryKey);
407
+ }
408
+ }));
397
409
  }
398
410
  });
399
411
  }
@@ -436,7 +448,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
436
448
  isSameSpaceEntityQueryKey,
437
449
  queryClient,
438
450
  getEntity,
439
- onSlideInNavigation
451
+ onSlideInNavigation,
452
+ cmaClient
440
453
  ]);
441
454
  const getResourceProvider = useCallback(function getResourceProvider(organizationId, appDefinitionId) {
442
455
  const queryKey = [
@@ -1,9 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { useCallback } from 'react';
3
+ import { useContentTypes } from '@contentful/field-editor-shared';
3
4
  import { arrayMove } from '@dnd-kit/sortable';
4
5
  import { LinkEntityActions } from '../components';
5
6
  import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions';
6
7
  import { useSortIDs } from '../utils/useSortIDs';
8
+ import { SharedQueryClientProvider } from './queryClient';
7
9
  import { ReferenceEditor } from './ReferenceEditor';
8
10
  import { useEditorPermissions } from './useEditorPermissions';
9
11
  function onLinkOrCreate(setValue, entityType, items, ids, index = items.length) {
@@ -95,7 +97,10 @@ function Editor(props) {
95
97
  }));
96
98
  }
97
99
  export function MultipleReferenceEditor(props) {
98
- const allContentTypes = props.sdk.space.getCachedContentTypes();
100
+ return /*#__PURE__*/ React.createElement(SharedQueryClientProvider, null, /*#__PURE__*/ React.createElement(MultipleReferenceEditorInner, props));
101
+ }
102
+ function MultipleReferenceEditorInner(props) {
103
+ const { contentTypes: allContentTypes } = useContentTypes(props.sdk);
99
104
  return /*#__PURE__*/ React.createElement(ReferenceEditor, props, ({ value, disabled, setValue, externalReset })=>{
100
105
  return /*#__PURE__*/ React.createElement(Editor, {
101
106
  ...props,
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { useCallback } from 'react';
3
+ import { useContentTypes } from '@contentful/field-editor-shared';
3
4
  import { LinkEntityActions } from '../components';
4
5
  import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions';
6
+ import { SharedQueryClientProvider } from './queryClient';
5
7
  import { ReferenceEditor } from './ReferenceEditor';
6
8
  import { useEditorPermissions } from './useEditorPermissions';
7
9
  function Editor(props) {
@@ -52,7 +54,10 @@ function Editor(props) {
52
54
  });
53
55
  }
54
56
  export function SingleReferenceEditor(props) {
55
- const allContentTypes = props.sdk.space.getCachedContentTypes();
57
+ return /*#__PURE__*/ React.createElement(SharedQueryClientProvider, null, /*#__PURE__*/ React.createElement(SingleReferenceEditorInner, props));
58
+ }
59
+ function SingleReferenceEditorInner(props) {
60
+ const { contentTypes: allContentTypes } = useContentTypes(props.sdk);
56
61
  return /*#__PURE__*/ React.createElement(ReferenceEditor, props, ({ value, setValue, disabled, externalReset })=>{
57
62
  return /*#__PURE__*/ React.createElement(Editor, {
58
63
  ...props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-reference",
3
- "version": "6.19.2",
3
+ "version": "6.19.3-canary.25+a4f2df74",
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.1",
42
+ "@contentful/field-editor-shared": "^2.17.2-canary.25+a4f2df74",
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": "c8fbf95fbb880df05fd011b8892523c135c2a5fd"
71
+ "gitHead": "a4f2df742d1cb10986f9c465824fd5b88d092d8a"
72
72
  }