@bpmn-io/properties-panel 3.21.0 → 3.22.1

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.js CHANGED
@@ -3204,7 +3204,7 @@ function ListGroup(props) {
3204
3204
  id,
3205
3205
  items,
3206
3206
  label,
3207
- shouldOpen = true,
3207
+ shouldOpen = false,
3208
3208
  translate = translateFallback
3209
3209
  } = props;
3210
3210
  hooks.useEffect(() => {
@@ -3213,57 +3213,25 @@ function ListGroup(props) {
3213
3213
  }
3214
3214
  }, [props.shouldSort]);
3215
3215
  const groupRef = hooks.useRef(null);
3216
- const [open, setOpen] = useLayoutState(['groups', id, 'open'], false);
3216
+ const [open, setOpen] = useLayoutState(['groups', id, 'open'], shouldOpen);
3217
3217
  const [sticky, setSticky] = hooks.useState(false);
3218
3218
  const onShow = hooks.useCallback(() => setOpen(true), [setOpen]);
3219
3219
  const [localItems, setLocalItems] = hooks.useState([]);
3220
- const [newlyAddedItemIds, setNewlyAddedItemIds] = hooks.useState([]);
3221
3220
 
3222
3221
  // Flag to mark that add button was clicked in the last render cycle
3223
3222
  const [addTriggered, setAddTriggered] = hooks.useState(false);
3224
3223
  const prevElement = usePrevious(element);
3225
- const elementChanged = element !== prevElement;
3226
- const shouldHandleEffects = !elementChanged && shouldOpen;
3227
-
3228
- // (0) delay setting items
3229
- //
3230
- // We need to this to align the render cycles of items
3231
- // with the detection of newly added items.
3232
- // This is important, because the autoOpen property can
3233
- // only set per list item on its very first render.
3234
- hooks.useEffect(() => {
3235
- setLocalItems(items);
3236
- }, [items]);
3224
+ const toggleOpen = hooks.useCallback(() => setOpen(!open), [open]);
3225
+ const openItemIds = element === prevElement && open && addTriggered ? getNewItemIds(items, localItems) : [];
3237
3226
 
3238
- // (1) handle auto opening when items were added
3227
+ // reset local state after items changed
3239
3228
  hooks.useEffect(() => {
3240
- // reset addTriggered flag
3229
+ setLocalItems(items);
3241
3230
  setAddTriggered(false);
3242
- if (shouldHandleEffects && localItems) {
3243
- if (addTriggered) {
3244
- const previousItemIds = localItems.map(item => item.id);
3245
- const currentItemsIds = items.map(item => item.id);
3246
- const newItemIds = currentItemsIds.filter(itemId => !previousItemIds.includes(itemId));
3247
-
3248
- // open if not open, configured and triggered by add button
3249
- //
3250
- // TODO(marstamm): remove once we refactor layout handling for listGroups.
3251
- // Ideally, opening should be handled as part of the `add` callback and
3252
- // not be a concern for the ListGroup component.
3253
- if (!open && shouldOpen && newItemIds.length > 0) {
3254
- toggleOpen();
3255
- }
3256
- setNewlyAddedItemIds(newItemIds);
3257
- } else {
3258
- // ignore newly added items that do not result from a triggered add
3259
- setNewlyAddedItemIds([]);
3260
- }
3261
- }
3262
- }, [items, open, shouldHandleEffects, addTriggered, localItems]);
3231
+ }, [items]);
3263
3232
 
3264
3233
  // set css class when group is sticky to top
3265
3234
  useStickyIntersectionObserver(groupRef, 'div.bio-properties-panel-scroll-container', setSticky);
3266
- const toggleOpen = () => setOpen(!open);
3267
3235
  const hasItems = !!items.length;
3268
3236
  const propertiesPanelContext = {
3269
3237
  ...hooks.useContext(LayoutContext),
@@ -3271,6 +3239,7 @@ function ListGroup(props) {
3271
3239
  };
3272
3240
  const handleAddClick = e => {
3273
3241
  setAddTriggered(true);
3242
+ setOpen(true);
3274
3243
  add(e);
3275
3244
  };
3276
3245
  const allErrors = useErrors();
@@ -3333,7 +3302,7 @@ function ListGroup(props) {
3333
3302
  class: classnames('bio-properties-panel-list', open && hasItems ? 'open' : ''),
3334
3303
  children: jsxRuntime.jsx(LayoutContext.Provider, {
3335
3304
  value: propertiesPanelContext,
3336
- children: localItems.map((item, index) => {
3305
+ children: items.map((item, index) => {
3337
3306
  if (!item) {
3338
3307
  return;
3339
3308
  }
@@ -3342,8 +3311,9 @@ function ListGroup(props) {
3342
3311
  } = item;
3343
3312
 
3344
3313
  // if item was added, open it
3345
- // Existing items will not be affected as autoOpen is only applied on first render
3346
- const autoOpen = newlyAddedItemIds.includes(item.id);
3314
+ // existing items will not be affected as autoOpen
3315
+ // is only applied on first render
3316
+ const autoOpen = openItemIds.includes(item.id);
3347
3317
  return preact.createElement(ListItem, {
3348
3318
  ...item,
3349
3319
  autoOpen: autoOpen,
@@ -3357,6 +3327,11 @@ function ListGroup(props) {
3357
3327
  })]
3358
3328
  });
3359
3329
  }
3330
+ function getNewItemIds(newItems, oldItems) {
3331
+ const newIds = newItems.map(item => item.id);
3332
+ const oldIds = oldItems.map(item => item.id);
3333
+ return newIds.filter(itemId => !oldIds.includes(itemId));
3334
+ }
3360
3335
 
3361
3336
  function Checkbox(props) {
3362
3337
  const {
@@ -4027,7 +4002,7 @@ function TextArea(props) {
4027
4002
  };
4028
4003
  hooks.useLayoutEffect(() => {
4029
4004
  autoResize && resizeToContents(ref.current);
4030
- }, []);
4005
+ });
4031
4006
  hooks.useEffect(() => {
4032
4007
  if (value === localValue) {
4033
4008
  return;