@bpmn-io/properties-panel 3.21.0 → 3.22.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.
package/dist/index.esm.js CHANGED
@@ -3183,7 +3183,7 @@ function ListGroup(props) {
3183
3183
  id,
3184
3184
  items,
3185
3185
  label,
3186
- shouldOpen = true,
3186
+ shouldOpen = false,
3187
3187
  translate = translateFallback
3188
3188
  } = props;
3189
3189
  useEffect(() => {
@@ -3192,57 +3192,25 @@ function ListGroup(props) {
3192
3192
  }
3193
3193
  }, [props.shouldSort]);
3194
3194
  const groupRef = useRef(null);
3195
- const [open, setOpen] = useLayoutState(['groups', id, 'open'], false);
3195
+ const [open, setOpen] = useLayoutState(['groups', id, 'open'], shouldOpen);
3196
3196
  const [sticky, setSticky] = useState(false);
3197
3197
  const onShow = useCallback(() => setOpen(true), [setOpen]);
3198
3198
  const [localItems, setLocalItems] = useState([]);
3199
- const [newlyAddedItemIds, setNewlyAddedItemIds] = useState([]);
3200
3199
 
3201
3200
  // Flag to mark that add button was clicked in the last render cycle
3202
3201
  const [addTriggered, setAddTriggered] = useState(false);
3203
3202
  const prevElement = usePrevious(element);
3204
- const elementChanged = element !== prevElement;
3205
- const shouldHandleEffects = !elementChanged && shouldOpen;
3206
-
3207
- // (0) delay setting items
3208
- //
3209
- // We need to this to align the render cycles of items
3210
- // with the detection of newly added items.
3211
- // This is important, because the autoOpen property can
3212
- // only set per list item on its very first render.
3213
- useEffect(() => {
3214
- setLocalItems(items);
3215
- }, [items]);
3203
+ const toggleOpen = useCallback(() => setOpen(!open), [open]);
3204
+ const openItemIds = element === prevElement && open && addTriggered ? getNewItemIds(items, localItems) : [];
3216
3205
 
3217
- // (1) handle auto opening when items were added
3206
+ // reset local state after items changed
3218
3207
  useEffect(() => {
3219
- // reset addTriggered flag
3208
+ setLocalItems(items);
3220
3209
  setAddTriggered(false);
3221
- if (shouldHandleEffects && localItems) {
3222
- if (addTriggered) {
3223
- const previousItemIds = localItems.map(item => item.id);
3224
- const currentItemsIds = items.map(item => item.id);
3225
- const newItemIds = currentItemsIds.filter(itemId => !previousItemIds.includes(itemId));
3226
-
3227
- // open if not open, configured and triggered by add button
3228
- //
3229
- // TODO(marstamm): remove once we refactor layout handling for listGroups.
3230
- // Ideally, opening should be handled as part of the `add` callback and
3231
- // not be a concern for the ListGroup component.
3232
- if (!open && shouldOpen && newItemIds.length > 0) {
3233
- toggleOpen();
3234
- }
3235
- setNewlyAddedItemIds(newItemIds);
3236
- } else {
3237
- // ignore newly added items that do not result from a triggered add
3238
- setNewlyAddedItemIds([]);
3239
- }
3240
- }
3241
- }, [items, open, shouldHandleEffects, addTriggered, localItems]);
3210
+ }, [items]);
3242
3211
 
3243
3212
  // set css class when group is sticky to top
3244
3213
  useStickyIntersectionObserver(groupRef, 'div.bio-properties-panel-scroll-container', setSticky);
3245
- const toggleOpen = () => setOpen(!open);
3246
3214
  const hasItems = !!items.length;
3247
3215
  const propertiesPanelContext = {
3248
3216
  ...useContext(LayoutContext),
@@ -3250,6 +3218,7 @@ function ListGroup(props) {
3250
3218
  };
3251
3219
  const handleAddClick = e => {
3252
3220
  setAddTriggered(true);
3221
+ setOpen(true);
3253
3222
  add(e);
3254
3223
  };
3255
3224
  const allErrors = useErrors();
@@ -3312,7 +3281,7 @@ function ListGroup(props) {
3312
3281
  class: classnames('bio-properties-panel-list', open && hasItems ? 'open' : ''),
3313
3282
  children: jsx(LayoutContext.Provider, {
3314
3283
  value: propertiesPanelContext,
3315
- children: localItems.map((item, index) => {
3284
+ children: items.map((item, index) => {
3316
3285
  if (!item) {
3317
3286
  return;
3318
3287
  }
@@ -3321,8 +3290,9 @@ function ListGroup(props) {
3321
3290
  } = item;
3322
3291
 
3323
3292
  // if item was added, open it
3324
- // Existing items will not be affected as autoOpen is only applied on first render
3325
- const autoOpen = newlyAddedItemIds.includes(item.id);
3293
+ // existing items will not be affected as autoOpen
3294
+ // is only applied on first render
3295
+ const autoOpen = openItemIds.includes(item.id);
3326
3296
  return createElement(ListItem, {
3327
3297
  ...item,
3328
3298
  autoOpen: autoOpen,
@@ -3336,6 +3306,11 @@ function ListGroup(props) {
3336
3306
  })]
3337
3307
  });
3338
3308
  }
3309
+ function getNewItemIds(newItems, oldItems) {
3310
+ const newIds = newItems.map(item => item.id);
3311
+ const oldIds = oldItems.map(item => item.id);
3312
+ return newIds.filter(itemId => !oldIds.includes(itemId));
3313
+ }
3339
3314
 
3340
3315
  function Checkbox(props) {
3341
3316
  const {