@contentful/field-editor-rich-text 2.3.5 → 2.3.8

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';
@@ -366,6 +366,10 @@ var _constate = /*#__PURE__*/constate(useSdk),
366
366
  var useCommandList = function useCommandList(commandItems, container) {
367
367
  var _React$useState = useState(function () {
368
368
  // select the first item on initial render
369
+ if (!commandItems.length) {
370
+ return '';
371
+ }
372
+
369
373
  if ('group' in commandItems[0]) {
370
374
  return commandItems[0].commands[0].id;
371
375
  }
@@ -2179,6 +2183,27 @@ function useFetchedEntity(_ref) {
2179
2183
  return entity;
2180
2184
  }
2181
2185
 
2186
+ /**
2187
+ * A userland implementation of useEvent RFC
2188
+ *
2189
+ * See: https://github.com/reactjs/rfcs/pull/220
2190
+ */
2191
+
2192
+ var useStableCallback = function useStableCallback(callback) {
2193
+ var callbackRef = useRef(callback); // Makes sure the callbackRef points to the latest `callback` props
2194
+ // The useLayoutEffect is here for concurrent safety. It has the
2195
+ // disadvantage of not being able to use the result callback during
2196
+ // the render but that's Ok.
2197
+
2198
+ useLayoutEffect(function () {
2199
+ callbackRef.current = callback;
2200
+ }); // The stable callback that won't change
2201
+
2202
+ return useCallback(function () {
2203
+ return callbackRef.current.apply(callbackRef, arguments);
2204
+ }, []);
2205
+ };
2206
+
2182
2207
  var InternalAssetCard = /*#__PURE__*/memo(function (props) {
2183
2208
  if (props.asset === undefined) {
2184
2209
  return /*#__PURE__*/createElement(AssetCard, {
@@ -2214,8 +2239,11 @@ function FetchingWrappedAssetCard(props) {
2214
2239
  assetId = props.assetId;
2215
2240
 
2216
2241
  var _useEntities = useEntities(),
2217
- loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
2242
+ loadEntityScheduledActions = _useEntities.loadEntityScheduledActions; // FIXME: remove when useEntities() has been refactored to avoid
2243
+ // unnecessary re-rendering
2244
+
2218
2245
 
2246
+ var stableLoadEntityScheduledActions = useStableCallback(loadEntityScheduledActions);
2219
2247
  var asset = useFetchedEntity({
2220
2248
  type: 'Asset',
2221
2249
  id: assetId,
@@ -2226,7 +2254,7 @@ function FetchingWrappedAssetCard(props) {
2226
2254
  sdk: props.sdk,
2227
2255
  isDisabled: props.isDisabled,
2228
2256
  isSelected: props.isSelected,
2229
- loadEntityScheduledActions: loadEntityScheduledActions,
2257
+ loadEntityScheduledActions: stableLoadEntityScheduledActions,
2230
2258
  locale: props.locale,
2231
2259
  onEdit: props.onEdit,
2232
2260
  onRemove: props.onRemove
@@ -2276,8 +2304,11 @@ var FetchingWrappedEntryCard = function FetchingWrappedEntryCard(props) {
2276
2304
  onEntityFetchComplete = props.onEntityFetchComplete;
2277
2305
 
2278
2306
  var _useEntities = useEntities(),
2279
- loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
2307
+ loadEntityScheduledActions = _useEntities.loadEntityScheduledActions; // FIXME: remove when useEntities() has been refactored to avoid
2308
+ // unnecessary re-rendering
2309
+
2280
2310
 
2311
+ var stableLoadEntityScheduledActions = useStableCallback(loadEntityScheduledActions);
2281
2312
  var entry = useFetchedEntity({
2282
2313
  type: 'Entry',
2283
2314
  id: entryId,
@@ -2291,7 +2322,7 @@ var FetchingWrappedEntryCard = function FetchingWrappedEntryCard(props) {
2291
2322
  isSelected: props.isSelected,
2292
2323
  onEdit: props.onEdit,
2293
2324
  onRemove: props.onRemove,
2294
- loadEntityScheduledActions: loadEntityScheduledActions
2325
+ loadEntityScheduledActions: stableLoadEntityScheduledActions
2295
2326
  });
2296
2327
  };
2297
2328