@bpmn-io/properties-panel 0.13.0 → 0.14.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/CHANGELOG.md +15 -0
- package/assets/properties-panel.css +35 -7
- package/dist/index.esm.js +126 -493
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +126 -491
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useEffect, useRef, useMemo, useState, useCallback } from '../preact/hooks';
|
|
2
|
-
import {
|
|
2
|
+
import { isFunction, isArray, get, assign, set, sortBy, find, isNumber, debounce } from 'min-dash';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import '../preact/compat';
|
|
5
5
|
import { jsx, jsxs } from '../preact/jsx-runtime';
|
|
@@ -153,6 +153,7 @@ function Header(props) {
|
|
|
153
153
|
rel: "noopener",
|
|
154
154
|
class: "bio-properties-panel-header-link",
|
|
155
155
|
href: documentationRef,
|
|
156
|
+
title: "Open documentation",
|
|
156
157
|
target: "_blank",
|
|
157
158
|
children: jsx(ExternalLinkIcon, {})
|
|
158
159
|
}) : null
|
|
@@ -165,480 +166,6 @@ const DescriptionContext = createContext({
|
|
|
165
166
|
getDescriptionForId: () => {}
|
|
166
167
|
});
|
|
167
168
|
|
|
168
|
-
var FN_REF = '__fn';
|
|
169
|
-
var DEFAULT_PRIORITY$1 = 1000;
|
|
170
|
-
var slice = Array.prototype.slice;
|
|
171
|
-
/**
|
|
172
|
-
* A general purpose event bus.
|
|
173
|
-
*
|
|
174
|
-
* This component is used to communicate across a diagram instance.
|
|
175
|
-
* Other parts of a diagram can use it to listen to and broadcast events.
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* ## Registering for Events
|
|
179
|
-
*
|
|
180
|
-
* The event bus provides the {@link EventBus#on} and {@link EventBus#once}
|
|
181
|
-
* methods to register for events. {@link EventBus#off} can be used to
|
|
182
|
-
* remove event registrations. Listeners receive an instance of {@link Event}
|
|
183
|
-
* as the first argument. It allows them to hook into the event execution.
|
|
184
|
-
*
|
|
185
|
-
* ```javascript
|
|
186
|
-
*
|
|
187
|
-
* // listen for event
|
|
188
|
-
* eventBus.on('foo', function(event) {
|
|
189
|
-
*
|
|
190
|
-
* // access event type
|
|
191
|
-
* event.type; // 'foo'
|
|
192
|
-
*
|
|
193
|
-
* // stop propagation to other listeners
|
|
194
|
-
* event.stopPropagation();
|
|
195
|
-
*
|
|
196
|
-
* // prevent event default
|
|
197
|
-
* event.preventDefault();
|
|
198
|
-
* });
|
|
199
|
-
*
|
|
200
|
-
* // listen for event with custom payload
|
|
201
|
-
* eventBus.on('bar', function(event, payload) {
|
|
202
|
-
* console.log(payload);
|
|
203
|
-
* });
|
|
204
|
-
*
|
|
205
|
-
* // listen for event returning value
|
|
206
|
-
* eventBus.on('foobar', function(event) {
|
|
207
|
-
*
|
|
208
|
-
* // stop event propagation + prevent default
|
|
209
|
-
* return false;
|
|
210
|
-
*
|
|
211
|
-
* // stop event propagation + return custom result
|
|
212
|
-
* return {
|
|
213
|
-
* complex: 'listening result'
|
|
214
|
-
* };
|
|
215
|
-
* });
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* // listen with custom priority (default=1000, higher is better)
|
|
219
|
-
* eventBus.on('priorityfoo', 1500, function(event) {
|
|
220
|
-
* console.log('invoked first!');
|
|
221
|
-
* });
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* // listen for event and pass the context (`this`)
|
|
225
|
-
* eventBus.on('foobar', function(event) {
|
|
226
|
-
* this.foo();
|
|
227
|
-
* }, this);
|
|
228
|
-
* ```
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* ## Emitting Events
|
|
232
|
-
*
|
|
233
|
-
* Events can be emitted via the event bus using {@link EventBus#fire}.
|
|
234
|
-
*
|
|
235
|
-
* ```javascript
|
|
236
|
-
*
|
|
237
|
-
* // false indicates that the default action
|
|
238
|
-
* // was prevented by listeners
|
|
239
|
-
* if (eventBus.fire('foo') === false) {
|
|
240
|
-
* console.log('default has been prevented!');
|
|
241
|
-
* };
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
* // custom args + return value listener
|
|
245
|
-
* eventBus.on('sum', function(event, a, b) {
|
|
246
|
-
* return a + b;
|
|
247
|
-
* });
|
|
248
|
-
*
|
|
249
|
-
* // you can pass custom arguments + retrieve result values.
|
|
250
|
-
* var sum = eventBus.fire('sum', 1, 2);
|
|
251
|
-
* console.log(sum); // 3
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
|
|
255
|
-
function EventBus() {
|
|
256
|
-
this._listeners = {}; // cleanup on destroy on lowest priority to allow
|
|
257
|
-
// message passing until the bitter end
|
|
258
|
-
|
|
259
|
-
this.on('diagram.destroy', 1, this._destroy, this);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Register an event listener for events with the given name.
|
|
263
|
-
*
|
|
264
|
-
* The callback will be invoked with `event, ...additionalArguments`
|
|
265
|
-
* that have been passed to {@link EventBus#fire}.
|
|
266
|
-
*
|
|
267
|
-
* Returning false from a listener will prevent the events default action
|
|
268
|
-
* (if any is specified). To stop an event from being processed further in
|
|
269
|
-
* other listeners execute {@link Event#stopPropagation}.
|
|
270
|
-
*
|
|
271
|
-
* Returning anything but `undefined` from a listener will stop the listener propagation.
|
|
272
|
-
*
|
|
273
|
-
* @param {string|Array<string>} events
|
|
274
|
-
* @param {number} [priority=1000] the priority in which this listener is called, larger is higher
|
|
275
|
-
* @param {Function} callback
|
|
276
|
-
* @param {Object} [that] Pass context (`this`) to the callback
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
EventBus.prototype.on = function (events, priority, callback, that) {
|
|
280
|
-
events = isArray(events) ? events : [events];
|
|
281
|
-
|
|
282
|
-
if (isFunction(priority)) {
|
|
283
|
-
that = callback;
|
|
284
|
-
callback = priority;
|
|
285
|
-
priority = DEFAULT_PRIORITY$1;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (!isNumber(priority)) {
|
|
289
|
-
throw new Error('priority must be a number');
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
var actualCallback = callback;
|
|
293
|
-
|
|
294
|
-
if (that) {
|
|
295
|
-
actualCallback = bind(callback, that); // make sure we remember and are able to remove
|
|
296
|
-
// bound callbacks via {@link #off} using the original
|
|
297
|
-
// callback
|
|
298
|
-
|
|
299
|
-
actualCallback[FN_REF] = callback[FN_REF] || callback;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
var self = this;
|
|
303
|
-
events.forEach(function (e) {
|
|
304
|
-
self._addListener(e, {
|
|
305
|
-
priority: priority,
|
|
306
|
-
callback: actualCallback,
|
|
307
|
-
next: null
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* Register an event listener that is executed only once.
|
|
313
|
-
*
|
|
314
|
-
* @param {string} event the event name to register for
|
|
315
|
-
* @param {number} [priority=1000] the priority in which this listener is called, larger is higher
|
|
316
|
-
* @param {Function} callback the callback to execute
|
|
317
|
-
* @param {Object} [that] Pass context (`this`) to the callback
|
|
318
|
-
*/
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
EventBus.prototype.once = function (event, priority, callback, that) {
|
|
322
|
-
var self = this;
|
|
323
|
-
|
|
324
|
-
if (isFunction(priority)) {
|
|
325
|
-
that = callback;
|
|
326
|
-
callback = priority;
|
|
327
|
-
priority = DEFAULT_PRIORITY$1;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!isNumber(priority)) {
|
|
331
|
-
throw new Error('priority must be a number');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function wrappedCallback() {
|
|
335
|
-
wrappedCallback.__isTomb = true;
|
|
336
|
-
var result = callback.apply(that, arguments);
|
|
337
|
-
self.off(event, wrappedCallback);
|
|
338
|
-
return result;
|
|
339
|
-
} // make sure we remember and are able to remove
|
|
340
|
-
// bound callbacks via {@link #off} using the original
|
|
341
|
-
// callback
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
wrappedCallback[FN_REF] = callback;
|
|
345
|
-
this.on(event, priority, wrappedCallback);
|
|
346
|
-
};
|
|
347
|
-
/**
|
|
348
|
-
* Removes event listeners by event and callback.
|
|
349
|
-
*
|
|
350
|
-
* If no callback is given, all listeners for a given event name are being removed.
|
|
351
|
-
*
|
|
352
|
-
* @param {string|Array<string>} events
|
|
353
|
-
* @param {Function} [callback]
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
EventBus.prototype.off = function (events, callback) {
|
|
358
|
-
events = isArray(events) ? events : [events];
|
|
359
|
-
var self = this;
|
|
360
|
-
events.forEach(function (event) {
|
|
361
|
-
self._removeListener(event, callback);
|
|
362
|
-
});
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Create an EventBus event.
|
|
366
|
-
*
|
|
367
|
-
* @param {Object} data
|
|
368
|
-
*
|
|
369
|
-
* @return {Object} event, recognized by the eventBus
|
|
370
|
-
*/
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
EventBus.prototype.createEvent = function (data) {
|
|
374
|
-
var event = new InternalEvent();
|
|
375
|
-
event.init(data);
|
|
376
|
-
return event;
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* Fires a named event.
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
*
|
|
383
|
-
* // fire event by name
|
|
384
|
-
* events.fire('foo');
|
|
385
|
-
*
|
|
386
|
-
* // fire event object with nested type
|
|
387
|
-
* var event = { type: 'foo' };
|
|
388
|
-
* events.fire(event);
|
|
389
|
-
*
|
|
390
|
-
* // fire event with explicit type
|
|
391
|
-
* var event = { x: 10, y: 20 };
|
|
392
|
-
* events.fire('element.moved', event);
|
|
393
|
-
*
|
|
394
|
-
* // pass additional arguments to the event
|
|
395
|
-
* events.on('foo', function(event, bar) {
|
|
396
|
-
* alert(bar);
|
|
397
|
-
* });
|
|
398
|
-
*
|
|
399
|
-
* events.fire({ type: 'foo' }, 'I am bar!');
|
|
400
|
-
*
|
|
401
|
-
* @param {string} [name] the optional event name
|
|
402
|
-
* @param {Object} [event] the event object
|
|
403
|
-
* @param {...Object} additional arguments to be passed to the callback functions
|
|
404
|
-
*
|
|
405
|
-
* @return {boolean} the events return value, if specified or false if the
|
|
406
|
-
* default action was prevented by listeners
|
|
407
|
-
*/
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
EventBus.prototype.fire = function (type, data) {
|
|
411
|
-
var event, firstListener, returnValue, args;
|
|
412
|
-
args = slice.call(arguments);
|
|
413
|
-
|
|
414
|
-
if (typeof type === 'object') {
|
|
415
|
-
data = type;
|
|
416
|
-
type = data.type;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (!type) {
|
|
420
|
-
throw new Error('no event type specified');
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
firstListener = this._listeners[type];
|
|
424
|
-
|
|
425
|
-
if (!firstListener) {
|
|
426
|
-
return;
|
|
427
|
-
} // we make sure we fire instances of our home made
|
|
428
|
-
// events here. We wrap them only once, though
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (data instanceof InternalEvent) {
|
|
432
|
-
// we are fine, we alread have an event
|
|
433
|
-
event = data;
|
|
434
|
-
} else {
|
|
435
|
-
event = this.createEvent(data);
|
|
436
|
-
} // ensure we pass the event as the first parameter
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
args[0] = event; // original event type (in case we delegate)
|
|
440
|
-
|
|
441
|
-
var originalType = event.type; // update event type before delegation
|
|
442
|
-
|
|
443
|
-
if (type !== originalType) {
|
|
444
|
-
event.type = type;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
try {
|
|
448
|
-
returnValue = this._invokeListeners(event, args, firstListener);
|
|
449
|
-
} finally {
|
|
450
|
-
// reset event type after delegation
|
|
451
|
-
if (type !== originalType) {
|
|
452
|
-
event.type = originalType;
|
|
453
|
-
}
|
|
454
|
-
} // set the return value to false if the event default
|
|
455
|
-
// got prevented and no other return value exists
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (returnValue === undefined && event.defaultPrevented) {
|
|
459
|
-
returnValue = false;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return returnValue;
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
EventBus.prototype.handleError = function (error) {
|
|
466
|
-
return this.fire('error', {
|
|
467
|
-
error: error
|
|
468
|
-
}) === false;
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
EventBus.prototype._destroy = function () {
|
|
472
|
-
this._listeners = {};
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
EventBus.prototype._invokeListeners = function (event, args, listener) {
|
|
476
|
-
var returnValue;
|
|
477
|
-
|
|
478
|
-
while (listener) {
|
|
479
|
-
// handle stopped propagation
|
|
480
|
-
if (event.cancelBubble) {
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
returnValue = this._invokeListener(event, args, listener);
|
|
485
|
-
listener = listener.next;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return returnValue;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
EventBus.prototype._invokeListener = function (event, args, listener) {
|
|
492
|
-
var returnValue;
|
|
493
|
-
|
|
494
|
-
if (listener.callback.__isTomb) {
|
|
495
|
-
return returnValue;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
try {
|
|
499
|
-
// returning false prevents the default action
|
|
500
|
-
returnValue = invokeFunction(listener.callback, args); // stop propagation on return value
|
|
501
|
-
|
|
502
|
-
if (returnValue !== undefined) {
|
|
503
|
-
event.returnValue = returnValue;
|
|
504
|
-
event.stopPropagation();
|
|
505
|
-
} // prevent default on return false
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (returnValue === false) {
|
|
509
|
-
event.preventDefault();
|
|
510
|
-
}
|
|
511
|
-
} catch (error) {
|
|
512
|
-
if (!this.handleError(error)) {
|
|
513
|
-
console.error('unhandled error in event listener', error);
|
|
514
|
-
throw error;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
return returnValue;
|
|
519
|
-
};
|
|
520
|
-
/*
|
|
521
|
-
* Add new listener with a certain priority to the list
|
|
522
|
-
* of listeners (for the given event).
|
|
523
|
-
*
|
|
524
|
-
* The semantics of listener registration / listener execution are
|
|
525
|
-
* first register, first serve: New listeners will always be inserted
|
|
526
|
-
* after existing listeners with the same priority.
|
|
527
|
-
*
|
|
528
|
-
* Example: Inserting two listeners with priority 1000 and 1300
|
|
529
|
-
*
|
|
530
|
-
* * before: [ 1500, 1500, 1000, 1000 ]
|
|
531
|
-
* * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
|
|
532
|
-
*
|
|
533
|
-
* @param {string} event
|
|
534
|
-
* @param {Object} listener { priority, callback }
|
|
535
|
-
*/
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
EventBus.prototype._addListener = function (event, newListener) {
|
|
539
|
-
var listener = this._getListeners(event),
|
|
540
|
-
previousListener; // no prior listeners
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (!listener) {
|
|
544
|
-
this._setListeners(event, newListener);
|
|
545
|
-
|
|
546
|
-
return;
|
|
547
|
-
} // ensure we order listeners by priority from
|
|
548
|
-
// 0 (high) to n > 0 (low)
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
while (listener) {
|
|
552
|
-
if (listener.priority < newListener.priority) {
|
|
553
|
-
newListener.next = listener;
|
|
554
|
-
|
|
555
|
-
if (previousListener) {
|
|
556
|
-
previousListener.next = newListener;
|
|
557
|
-
} else {
|
|
558
|
-
this._setListeners(event, newListener);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
previousListener = listener;
|
|
565
|
-
listener = listener.next;
|
|
566
|
-
} // add new listener to back
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
previousListener.next = newListener;
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
EventBus.prototype._getListeners = function (name) {
|
|
573
|
-
return this._listeners[name];
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
EventBus.prototype._setListeners = function (name, listener) {
|
|
577
|
-
this._listeners[name] = listener;
|
|
578
|
-
};
|
|
579
|
-
|
|
580
|
-
EventBus.prototype._removeListener = function (event, callback) {
|
|
581
|
-
var listener = this._getListeners(event),
|
|
582
|
-
nextListener,
|
|
583
|
-
previousListener,
|
|
584
|
-
listenerCallback;
|
|
585
|
-
|
|
586
|
-
if (!callback) {
|
|
587
|
-
// clear listeners
|
|
588
|
-
this._setListeners(event, null);
|
|
589
|
-
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
while (listener) {
|
|
594
|
-
nextListener = listener.next;
|
|
595
|
-
listenerCallback = listener.callback;
|
|
596
|
-
|
|
597
|
-
if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
|
|
598
|
-
if (previousListener) {
|
|
599
|
-
previousListener.next = nextListener;
|
|
600
|
-
} else {
|
|
601
|
-
// new first listener
|
|
602
|
-
this._setListeners(event, nextListener);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
previousListener = listener;
|
|
607
|
-
listener = nextListener;
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
/**
|
|
611
|
-
* A event that is emitted via the event bus.
|
|
612
|
-
*/
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
function InternalEvent() {}
|
|
616
|
-
|
|
617
|
-
InternalEvent.prototype.stopPropagation = function () {
|
|
618
|
-
this.cancelBubble = true;
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
InternalEvent.prototype.preventDefault = function () {
|
|
622
|
-
this.defaultPrevented = true;
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
InternalEvent.prototype.init = function (data) {
|
|
626
|
-
assign(this, data || {});
|
|
627
|
-
};
|
|
628
|
-
/**
|
|
629
|
-
* Invoke function. Be fast...
|
|
630
|
-
*
|
|
631
|
-
* @param {Function} fn
|
|
632
|
-
* @param {Array<Object>} args
|
|
633
|
-
*
|
|
634
|
-
* @return {Any}
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
function invokeFunction(fn, args) {
|
|
639
|
-
return fn.apply(null, args);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
169
|
/**
|
|
643
170
|
* @typedef {Function} <propertiesPanel.showEntry> callback
|
|
644
171
|
*
|
|
@@ -653,9 +180,8 @@ function invokeFunction(fn, args) {
|
|
|
653
180
|
*
|
|
654
181
|
* @returns void
|
|
655
182
|
*/
|
|
656
|
-
const eventBus = new EventBus();
|
|
657
183
|
const EventContext = createContext({
|
|
658
|
-
eventBus
|
|
184
|
+
eventBus: null
|
|
659
185
|
});
|
|
660
186
|
|
|
661
187
|
const LayoutContext = createContext({
|
|
@@ -676,7 +202,7 @@ const LayoutContext = createContext({
|
|
|
676
202
|
* ```
|
|
677
203
|
*
|
|
678
204
|
* @param {string} id
|
|
679
|
-
* @param {
|
|
205
|
+
* @param {object} element
|
|
680
206
|
*
|
|
681
207
|
* @returns {string}
|
|
682
208
|
*/
|
|
@@ -704,9 +230,13 @@ function useEvent(event, callback, priority = DEFAULT_PRIORITY) {
|
|
|
704
230
|
eventBus
|
|
705
231
|
} = useContext(EventContext);
|
|
706
232
|
useEffect(() => {
|
|
233
|
+
if (!eventBus) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
707
237
|
eventBus.on(event, priority, callback);
|
|
708
238
|
return () => eventBus.off(event, callback);
|
|
709
|
-
}, [event, eventBus,
|
|
239
|
+
}, [callback, event, eventBus, priority]);
|
|
710
240
|
}
|
|
711
241
|
|
|
712
242
|
const HIGH_PRIORITY = 10000;
|
|
@@ -912,7 +442,10 @@ function useShowErrorEvent(show) {
|
|
|
912
442
|
setTemporaryError(null);
|
|
913
443
|
|
|
914
444
|
if (show(event)) {
|
|
915
|
-
eventBus
|
|
445
|
+
if (eventBus) {
|
|
446
|
+
eventBus.fire('propertiesPanel.showEntry', event);
|
|
447
|
+
}
|
|
448
|
+
|
|
916
449
|
setTemporaryError(event.message);
|
|
917
450
|
}
|
|
918
451
|
}, [show]);
|
|
@@ -920,6 +453,57 @@ function useShowErrorEvent(show) {
|
|
|
920
453
|
return temporaryError;
|
|
921
454
|
}
|
|
922
455
|
|
|
456
|
+
/**
|
|
457
|
+
* @callback setSticky
|
|
458
|
+
* @param {boolean} value
|
|
459
|
+
*/
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Use IntersectionObserver to identify when DOM element is in sticky mode.
|
|
463
|
+
* If sticky is observered setSticky(true) will be called.
|
|
464
|
+
* If sticky mode is left, setSticky(false) will be called.
|
|
465
|
+
*
|
|
466
|
+
*
|
|
467
|
+
* @param {Object} ref
|
|
468
|
+
* @param {string} scrollContainerSelector
|
|
469
|
+
* @param {setSticky} setSticky
|
|
470
|
+
*/
|
|
471
|
+
|
|
472
|
+
function useStickyIntersectionObserver(ref, scrollContainerSelector, setSticky) {
|
|
473
|
+
useEffect(() => {
|
|
474
|
+
// return early if IntersectionObserver is not available
|
|
475
|
+
if (!IntersectionObserver) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let observer;
|
|
480
|
+
|
|
481
|
+
if (ref.current) {
|
|
482
|
+
const scrollContainer = query(scrollContainerSelector);
|
|
483
|
+
observer = new IntersectionObserver(entries => {
|
|
484
|
+
if (entries[0].intersectionRatio < 1) {
|
|
485
|
+
setSticky(true);
|
|
486
|
+
} else if (entries[0].intersectionRatio === 1) {
|
|
487
|
+
setSticky(false);
|
|
488
|
+
}
|
|
489
|
+
}, {
|
|
490
|
+
root: scrollContainer,
|
|
491
|
+
rootMargin: '0px 0px 999999% 0px',
|
|
492
|
+
// Use bottom margin to avoid stickyness when scrolling out to bottom
|
|
493
|
+
threshold: [1]
|
|
494
|
+
});
|
|
495
|
+
observer.observe(ref.current);
|
|
496
|
+
} // Unobserve if unmounted
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
return () => {
|
|
500
|
+
if (ref.current && observer) {
|
|
501
|
+
observer.unobserve(ref.current);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}, [ref]);
|
|
505
|
+
}
|
|
506
|
+
|
|
923
507
|
function Group(props) {
|
|
924
508
|
const {
|
|
925
509
|
element,
|
|
@@ -928,12 +512,14 @@ function Group(props) {
|
|
|
928
512
|
label,
|
|
929
513
|
shouldOpen = false
|
|
930
514
|
} = props;
|
|
515
|
+
const groupRef = useRef(null);
|
|
931
516
|
const [open, setOpen] = useLayoutState(['groups', id, 'open'], shouldOpen);
|
|
932
517
|
const onShow = useCallback(() => setOpen(true), [setOpen]);
|
|
933
518
|
|
|
934
519
|
const toggleOpen = () => setOpen(!open);
|
|
935
520
|
|
|
936
|
-
const [edited, setEdited] = useState(false);
|
|
521
|
+
const [edited, setEdited] = useState(false);
|
|
522
|
+
const [sticky, setSticky] = useState(false); // set edited state depending on all entries
|
|
937
523
|
|
|
938
524
|
useEffect(() => {
|
|
939
525
|
const hasOneEditedEntry = entries.find(entry => {
|
|
@@ -951,15 +537,18 @@ function Group(props) {
|
|
|
951
537
|
return isEdited(inputNode);
|
|
952
538
|
});
|
|
953
539
|
setEdited(hasOneEditedEntry);
|
|
954
|
-
}, [entries]);
|
|
540
|
+
}, [entries]); // set css class when group is sticky to top
|
|
541
|
+
|
|
542
|
+
useStickyIntersectionObserver(groupRef, 'div.bio-properties-panel-scroll-container', setSticky);
|
|
955
543
|
const propertiesPanelContext = { ...useContext(LayoutContext),
|
|
956
544
|
onShow
|
|
957
545
|
};
|
|
958
546
|
return jsxs("div", {
|
|
959
547
|
class: "bio-properties-panel-group",
|
|
960
548
|
"data-group-id": 'group-' + id,
|
|
549
|
+
ref: groupRef,
|
|
961
550
|
children: [jsxs("div", {
|
|
962
|
-
class: classnames('bio-properties-panel-group-header', edited ? '' : 'empty', open ? 'open' : ''),
|
|
551
|
+
class: classnames('bio-properties-panel-group-header', edited ? '' : 'empty', open ? 'open' : '', sticky && open ? 'sticky' : ''),
|
|
963
552
|
onClick: toggleOpen,
|
|
964
553
|
children: [jsx("div", {
|
|
965
554
|
title: label,
|
|
@@ -1001,6 +590,33 @@ function DataMarker() {
|
|
|
1001
590
|
});
|
|
1002
591
|
}
|
|
1003
592
|
|
|
593
|
+
/**
|
|
594
|
+
* @typedef { {
|
|
595
|
+
* text: (element: object) => string,
|
|
596
|
+
* icon?: (element: Object) => import('preact').Component
|
|
597
|
+
* } } PlaceholderDefinition
|
|
598
|
+
*
|
|
599
|
+
* @param { PlaceholderDefinition } props
|
|
600
|
+
*/
|
|
601
|
+
function Placeholder(props) {
|
|
602
|
+
const {
|
|
603
|
+
text,
|
|
604
|
+
icon: Icon
|
|
605
|
+
} = props;
|
|
606
|
+
return jsx("div", {
|
|
607
|
+
class: "bio-properties-panel open",
|
|
608
|
+
children: jsxs("section", {
|
|
609
|
+
class: "bio-properties-panel-placeholder",
|
|
610
|
+
children: [Icon && jsx(Icon, {
|
|
611
|
+
class: "bio-properties-panel-placeholder-icon"
|
|
612
|
+
}), jsx("p", {
|
|
613
|
+
class: "bio-properties-panel-placeholder-text",
|
|
614
|
+
children: text
|
|
615
|
+
})]
|
|
616
|
+
})
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
|
|
1004
620
|
const DEFAULT_LAYOUT = {
|
|
1005
621
|
open: true
|
|
1006
622
|
};
|
|
@@ -1047,10 +663,15 @@ const bufferedEvents = ['propertiesPanel.showEntry', 'propertiesPanel.showError'
|
|
|
1047
663
|
*
|
|
1048
664
|
* @callback { {
|
|
1049
665
|
* @param {string} id
|
|
1050
|
-
* @param {
|
|
666
|
+
* @param {Object} element
|
|
1051
667
|
* @returns {string}
|
|
1052
668
|
* } } GetDescriptionFunction
|
|
1053
669
|
*
|
|
670
|
+
* @typedef { {
|
|
671
|
+
* getEmpty: (element: object) => import('./components/Placeholder').PlaceholderDefinition,
|
|
672
|
+
* getMultiple: (element: Object) => import('./components/Placeholder').PlaceholderDefinition
|
|
673
|
+
* } } PlaceholderProvider
|
|
674
|
+
*
|
|
1054
675
|
*/
|
|
1055
676
|
|
|
1056
677
|
/**
|
|
@@ -1058,19 +679,22 @@ const bufferedEvents = ['propertiesPanel.showEntry', 'propertiesPanel.showError'
|
|
|
1058
679
|
* data from implementor to describe *what* will be rendered.
|
|
1059
680
|
*
|
|
1060
681
|
* @param {Object} props
|
|
1061
|
-
* @param {Object} props.element
|
|
682
|
+
* @param {Object|Array} props.element
|
|
1062
683
|
* @param {import('./components/Header').HeaderProvider} props.headerProvider
|
|
684
|
+
* @param {PlaceholderProvider} [props.placeholderProvider]
|
|
1063
685
|
* @param {Array<GroupDefinition|ListGroupDefinition>} props.groups
|
|
1064
686
|
* @param {Object} [props.layoutConfig]
|
|
1065
687
|
* @param {Function} [props.layoutChanged]
|
|
1066
688
|
* @param {DescriptionConfig} [props.descriptionConfig]
|
|
1067
689
|
* @param {Function} [props.descriptionLoaded]
|
|
690
|
+
* @param {Object} [props.eventBus]
|
|
1068
691
|
*/
|
|
1069
692
|
|
|
1070
693
|
function PropertiesPanel(props) {
|
|
1071
694
|
const {
|
|
1072
695
|
element,
|
|
1073
696
|
headerProvider,
|
|
697
|
+
placeholderProvider,
|
|
1074
698
|
groups,
|
|
1075
699
|
layoutConfig = {},
|
|
1076
700
|
layoutChanged,
|
|
@@ -1123,12 +747,16 @@ function PropertiesPanel(props) {
|
|
|
1123
747
|
};
|
|
1124
748
|
const propertiesPanelContext = {
|
|
1125
749
|
element
|
|
1126
|
-
};
|
|
750
|
+
}; // empty state
|
|
1127
751
|
|
|
1128
|
-
if (!element) {
|
|
1129
|
-
return jsx(
|
|
1130
|
-
|
|
1131
|
-
|
|
752
|
+
if (placeholderProvider && !element) {
|
|
753
|
+
return jsx(Placeholder, { ...placeholderProvider.getEmpty()
|
|
754
|
+
});
|
|
755
|
+
} // multiple state
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
if (placeholderProvider && isArray(element)) {
|
|
759
|
+
return jsx(Placeholder, { ...placeholderProvider.getMultiple()
|
|
1132
760
|
});
|
|
1133
761
|
}
|
|
1134
762
|
|
|
@@ -1400,7 +1028,9 @@ function ListGroup(props) {
|
|
|
1400
1028
|
shouldOpen = true,
|
|
1401
1029
|
shouldSort = true
|
|
1402
1030
|
} = props;
|
|
1031
|
+
const groupRef = useRef(null);
|
|
1403
1032
|
const [open, setOpen] = useLayoutState(['groups', id, 'open'], false);
|
|
1033
|
+
const [sticky, setSticky] = useState(false);
|
|
1404
1034
|
const onShow = useCallback(() => setOpen(true), [setOpen]);
|
|
1405
1035
|
const [ordering, setOrdering] = useState([]);
|
|
1406
1036
|
const [newItemAdded, setNewItemAdded] = useState(false);
|
|
@@ -1471,7 +1101,9 @@ function ListGroup(props) {
|
|
|
1471
1101
|
});
|
|
1472
1102
|
setOrdering(keep);
|
|
1473
1103
|
}
|
|
1474
|
-
}, [items, shouldHandleEffects]);
|
|
1104
|
+
}, [items, shouldHandleEffects]); // set css class when group is sticky to top
|
|
1105
|
+
|
|
1106
|
+
useStickyIntersectionObserver(groupRef, 'div.bio-properties-panel-scroll-container', setSticky);
|
|
1475
1107
|
|
|
1476
1108
|
const toggleOpen = () => setOpen(!open);
|
|
1477
1109
|
|
|
@@ -1482,8 +1114,9 @@ function ListGroup(props) {
|
|
|
1482
1114
|
return jsxs("div", {
|
|
1483
1115
|
class: "bio-properties-panel-group",
|
|
1484
1116
|
"data-group-id": 'group-' + id,
|
|
1117
|
+
ref: groupRef,
|
|
1485
1118
|
children: [jsxs("div", {
|
|
1486
|
-
class: classnames('bio-properties-panel-group-header', hasItems ? '' : 'empty', hasItems && open ? 'open' : ''),
|
|
1119
|
+
class: classnames('bio-properties-panel-group-header', hasItems ? '' : 'empty', hasItems && open ? 'open' : '', sticky && open ? 'sticky' : ''),
|
|
1487
1120
|
onClick: hasItems ? toggleOpen : noop$3,
|
|
1488
1121
|
children: [jsx("div", {
|
|
1489
1122
|
title: label,
|
|
@@ -2465,5 +2098,5 @@ var index = {
|
|
|
2465
2098
|
debounceInput: ['factory', debounceInput]
|
|
2466
2099
|
};
|
|
2467
2100
|
|
|
2468
|
-
export { ArrowIcon, CheckboxEntry, CollapsibleEntry, CreateIcon, index as DebounceInputModule, DeleteIcon, DescriptionContext, Description as DescriptionEntry, DropdownButton, EventContext, ExternalLinkIcon, FeelOptionalIcon, FeelRequiredIcon, Group, Header, HeaderButton, LayoutContext, List as ListEntry, ListGroup, ListItem, NumberFieldEntry, PropertiesPanel, LayoutContext as PropertiesPanelContext, SelectEntry, Simple as SimpleEntry, TextAreaEntry, TextfieldEntry as TextFieldEntry, ToggleSwitchEntry, isEdited$6 as isCheckboxEntryEdited, isEdited$5 as isNumberFieldEntryEdited, isEdited$4 as isSelectEntryEdited, isEdited$3 as isSimpleEntryEdited, isEdited$2 as isTextAreaEntryEdited, isEdited$1 as isTextFieldEntryEdited, isEdited as isToggleSwitchEntryEdited, useDescriptionContext, useEvent, useEventBuffer, useKeyFactory, useLayoutState, usePrevious, useShowEntryEvent, useShowErrorEvent };
|
|
2101
|
+
export { ArrowIcon, CheckboxEntry, CollapsibleEntry, CreateIcon, index as DebounceInputModule, DeleteIcon, DescriptionContext, Description as DescriptionEntry, DropdownButton, EventContext, ExternalLinkIcon, FeelOptionalIcon, FeelRequiredIcon, Group, Header, HeaderButton, LayoutContext, List as ListEntry, ListGroup, ListItem, NumberFieldEntry, Placeholder, PropertiesPanel, LayoutContext as PropertiesPanelContext, SelectEntry, Simple as SimpleEntry, TextAreaEntry, TextfieldEntry as TextFieldEntry, ToggleSwitchEntry, isEdited$6 as isCheckboxEntryEdited, isEdited$5 as isNumberFieldEntryEdited, isEdited$4 as isSelectEntryEdited, isEdited$3 as isSimpleEntryEdited, isEdited$2 as isTextAreaEntryEdited, isEdited$1 as isTextFieldEntryEdited, isEdited as isToggleSwitchEntryEdited, useDescriptionContext, useEvent, useEventBuffer, useKeyFactory, useLayoutState, usePrevious, useShowEntryEvent, useShowErrorEvent, useStickyIntersectionObserver };
|
|
2469
2102
|
//# sourceMappingURL=index.esm.js.map
|