@contentful/field-editor-rich-text 2.3.6 → 2.3.7

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.
@@ -1,4 +1,4 @@
1
- import React__default, { createContext, useContext, useMemo, useState, useEffect, useRef, createElement, Fragment, memo, useCallback } from 'react';
1
+ import React__default, { createContext, useContext, useMemo, useState, useEffect, useRef, createElement, Fragment, useCallback, useLayoutEffect, memo } from 'react';
2
2
  import { useEntities, MissingEntityCard, WrappedAssetCard, WrappedEntryCard, ScheduledIconWithTooltip, EntityProvider, getScheduleTooltipContent } from '@contentful/field-editor-reference';
3
3
  import { entityHelpers, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
4
4
  import { BLOCKS, INLINES, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
@@ -2179,6 +2179,27 @@ function useFetchedEntity(_ref) {
2179
2179
  return entity;
2180
2180
  }
2181
2181
 
2182
+ /**
2183
+ * A userland implementation of useEvent RFC
2184
+ *
2185
+ * See: https://github.com/reactjs/rfcs/pull/220
2186
+ */
2187
+
2188
+ var useStableCallback = function useStableCallback(callback) {
2189
+ var callbackRef = useRef(callback); // Makes sure the callbackRef points to the latest `callback` props
2190
+ // The useLayoutEffect is here for concurrent safety. It has the
2191
+ // disadvantage of not being able to use the result callback during
2192
+ // the render but that's Ok.
2193
+
2194
+ useLayoutEffect(function () {
2195
+ callbackRef.current = callback;
2196
+ }); // The stable callback that won't change
2197
+
2198
+ return useCallback(function () {
2199
+ return callbackRef.current.apply(callbackRef, arguments);
2200
+ }, []);
2201
+ };
2202
+
2182
2203
  var InternalAssetCard = /*#__PURE__*/memo(function (props) {
2183
2204
  if (props.asset === undefined) {
2184
2205
  return /*#__PURE__*/createElement(AssetCard, {
@@ -2214,8 +2235,11 @@ function FetchingWrappedAssetCard(props) {
2214
2235
  assetId = props.assetId;
2215
2236
 
2216
2237
  var _useEntities = useEntities(),
2217
- loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
2238
+ loadEntityScheduledActions = _useEntities.loadEntityScheduledActions; // FIXME: remove when useEntities() has been refactored to avoid
2239
+ // unnecessary re-rendering
2218
2240
 
2241
+
2242
+ var stableLoadEntityScheduledActions = useStableCallback(loadEntityScheduledActions);
2219
2243
  var asset = useFetchedEntity({
2220
2244
  type: 'Asset',
2221
2245
  id: assetId,
@@ -2226,7 +2250,7 @@ function FetchingWrappedAssetCard(props) {
2226
2250
  sdk: props.sdk,
2227
2251
  isDisabled: props.isDisabled,
2228
2252
  isSelected: props.isSelected,
2229
- loadEntityScheduledActions: loadEntityScheduledActions,
2253
+ loadEntityScheduledActions: stableLoadEntityScheduledActions,
2230
2254
  locale: props.locale,
2231
2255
  onEdit: props.onEdit,
2232
2256
  onRemove: props.onRemove
@@ -2276,8 +2300,11 @@ var FetchingWrappedEntryCard = function FetchingWrappedEntryCard(props) {
2276
2300
  onEntityFetchComplete = props.onEntityFetchComplete;
2277
2301
 
2278
2302
  var _useEntities = useEntities(),
2279
- loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
2303
+ loadEntityScheduledActions = _useEntities.loadEntityScheduledActions; // FIXME: remove when useEntities() has been refactored to avoid
2304
+ // unnecessary re-rendering
2305
+
2280
2306
 
2307
+ var stableLoadEntityScheduledActions = useStableCallback(loadEntityScheduledActions);
2281
2308
  var entry = useFetchedEntity({
2282
2309
  type: 'Entry',
2283
2310
  id: entryId,
@@ -2291,7 +2318,7 @@ var FetchingWrappedEntryCard = function FetchingWrappedEntryCard(props) {
2291
2318
  isSelected: props.isSelected,
2292
2319
  onEdit: props.onEdit,
2293
2320
  onRemove: props.onRemove,
2294
- loadEntityScheduledActions: loadEntityScheduledActions
2321
+ loadEntityScheduledActions: stableLoadEntityScheduledActions
2295
2322
  });
2296
2323
  };
2297
2324