dce-reactkit 5.0.6 → 5.0.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.
@@ -13,6 +13,7 @@ type Props = {
13
13
  * values updated
14
14
  */
15
15
  onChanged: (updatedItems: PickableItem[]) => void;
16
+ startWithGroupsExpanded?: boolean;
16
17
  };
17
18
  declare const NestableItemList: React.FC<Props>;
18
19
  export default NestableItemList;
@@ -15,6 +15,7 @@ type Props = {
15
15
  onChanged: (updatedItems: PickableItem[]) => void;
16
16
  noBottomMargin?: boolean;
17
17
  hideSelectAllOrNoneButtons?: boolean;
18
+ startWithGroupsExpanded?: boolean;
18
19
  };
19
20
  declare const ItemPicker: React.FC<Props>;
20
21
  export default ItemPicker;
@@ -1,11 +1,14 @@
1
+ /// <reference types="react" />
1
2
  /**
2
3
  * An item that can be chosen (for use within ItemPicker)
3
4
  * @author Gabe Abrams
4
5
  */
5
6
  type PickableItem = ({
6
7
  id: number | string;
7
- name: string;
8
+ name: React.ReactNode;
9
+ ariaLabel?: string;
8
10
  link?: string;
11
+ tooltip?: string;
9
12
  } & ({
10
13
  isGroup: false;
11
14
  checked: boolean;
@@ -22,6 +22,8 @@ export declare const _setStubResponse: (opts: {
22
22
  * @param opts.path - the path of the server endpoint
23
23
  * @param [opts.method=GET] - the method of the endpoint
24
24
  * @param [opts.params] - query/body parameters to include
25
+ * @param [opts.headers] - custom headers to include; values must already be
26
+ * string to avoid issue with header serialization
25
27
  * @returns response from server
26
28
  */
27
29
  declare const visitServerEndpoint: (opts: {
@@ -30,5 +32,8 @@ declare const visitServerEndpoint: (opts: {
30
32
  params?: {
31
33
  [x: string]: any;
32
34
  } | undefined;
35
+ headers?: {
36
+ [x: string]: string;
37
+ } | undefined;
33
38
  }) => Promise<any>;
34
39
  export default visitServerEndpoint;
package/dist/esm/index.js CHANGED
@@ -800,6 +800,8 @@ const _setStubResponse = (opts) => {
800
800
  * @param opts.path - the path of the server endpoint
801
801
  * @param [opts.method=GET] - the method of the endpoint
802
802
  * @param [opts.params] - query/body parameters to include
803
+ * @param [opts.headers] - custom headers to include; values must already be
804
+ * string to avoid issue with header serialization
803
805
  * @returns response from server
804
806
  */
805
807
  const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function* () {
@@ -849,6 +851,7 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
849
851
  path: opts.path,
850
852
  method: (_c = opts.method) !== null && _c !== void 0 ? _c : 'GET',
851
853
  params,
854
+ headers: opts.headers,
852
855
  });
853
856
  // Check for failure
854
857
  if (!response || !response.body) {
@@ -2642,6 +2645,81 @@ const CopiableBox = (props) => {
2642
2645
  "Copy")))));
2643
2646
  };
2644
2647
 
2648
+ /**
2649
+ * Simple tooltip component
2650
+ * @author Gabe Abrams
2651
+ */
2652
+ /*------------------------------------------------------------------------*/
2653
+ /* ------------------------------ Component ----------------------------- */
2654
+ /*------------------------------------------------------------------------*/
2655
+ const Tooltip = (props) => {
2656
+ /*------------------------------------------------------------------------*/
2657
+ /* -------------------------------- Setup ------------------------------- */
2658
+ /*------------------------------------------------------------------------*/
2659
+ /* -------------- Props ------------- */
2660
+ // Destructure all props
2661
+ const { text, children, } = props;
2662
+ /* -------------- Refs -------------- */
2663
+ // Child ref
2664
+ const childRef = useRef(undefined);
2665
+ /*------------------------------------------------------------------------*/
2666
+ /* ------------------------- Lifecycle Functions ------------------------ */
2667
+ /*------------------------------------------------------------------------*/
2668
+ /**
2669
+ * Update (also called on mount)
2670
+ * @author Gabe Abrams
2671
+ */
2672
+ useEffect(() => {
2673
+ // Skip if no child
2674
+ if (!childRef.current) {
2675
+ return;
2676
+ }
2677
+ // Store copy of tooltip
2678
+ let t;
2679
+ // Initialize tooltip
2680
+ (() => __awaiter(void 0, void 0, void 0, function* () {
2681
+ // Import bootstrap tooltip
2682
+ const BSTooltip = (yield import('bootstrap')).Tooltip;
2683
+ // The child may have unmounted while the dynamic import above was
2684
+ // resolving (React nulls the ref on unmount). Constructing a
2685
+ // Bootstrap tooltip with a null element causes an error,
2686
+ // so bail out instead
2687
+ if (!childRef.current) {
2688
+ return;
2689
+ }
2690
+ // Initialize
2691
+ t = new BSTooltip(childRef.current, {
2692
+ title: text,
2693
+ placement: 'top',
2694
+ trigger: 'hover',
2695
+ });
2696
+ }))();
2697
+ // Clean up tooltip
2698
+ return () => {
2699
+ if (t) {
2700
+ t.dispose();
2701
+ // Bootstrap's hide() queues a transition-end callback that can
2702
+ // fire AFTER dispose and touch the (now null) trigger map and
2703
+ // element (twbs/bootstrap issue #37474). Point those private
2704
+ // fields at harmless stand-ins so the late callback is a no-op
2705
+ // instead of a crash.
2706
+ /* eslint-disable no-underscore-dangle */
2707
+ t._activeTrigger = {};
2708
+ t._element = document.createElement('noscript');
2709
+ /* eslint-enable no-underscore-dangle */
2710
+ }
2711
+ };
2712
+ }, [text]);
2713
+ /*------------------------------------------------------------------------*/
2714
+ /* ------------------------------- Render ------------------------------- */
2715
+ /*------------------------------------------------------------------------*/
2716
+ /*----------------------------------------*/
2717
+ /* --------------- Main UI -------------- */
2718
+ /*----------------------------------------*/
2719
+ // Clone child and add ref
2720
+ return React__default.cloneElement(children, { ref: childRef });
2721
+ };
2722
+
2645
2723
  /**
2646
2724
  * Reusable nested item picker
2647
2725
  * @author Yuen Ler Chow
@@ -2679,12 +2757,12 @@ const NestableItemList = (props) => {
2679
2757
  /*------------------------------------------------------------------------*/
2680
2758
  /* -------------- Props ------------- */
2681
2759
  // Destructure all props
2682
- const { items, onChanged, } = props;
2760
+ const { items, onChanged, startWithGroupsExpanded, } = props;
2683
2761
  /* -------------- State ------------- */
2684
2762
  // Create initial map of child expanded booleans
2685
2763
  const initChildExpanded = {};
2686
2764
  items.forEach((item) => {
2687
- initChildExpanded[String(item.id)] = false;
2765
+ initChildExpanded[String(item.id)] = !!startWithGroupsExpanded;
2688
2766
  });
2689
2767
  // Initial state
2690
2768
  const initialState = {
@@ -2773,6 +2851,14 @@ const NestableItemList = (props) => {
2773
2851
  /* ------------------------------- Render ------------------------------- */
2774
2852
  /*------------------------------------------------------------------------*/
2775
2853
  return (React__default.createElement("div", null, items.map((item) => {
2854
+ var _a;
2855
+ // Human-readable label for accessibility. Prefer the explicit
2856
+ // ariaLabel, then fall back to the name if it is a plain string
2857
+ const accessibleName = ((_a = item.ariaLabel) !== null && _a !== void 0 ? _a : (typeof item.name === 'string' ? item.name : ''));
2858
+ // Checkbox and Text
2859
+ const checkbox = (React__default.createElement(CheckboxButton, { className: `NestableItemList-CheckboxButton-${item.id}`, text: item.name, checked: item.isGroup ? allChecked(item.children) : item.checked, dashed: item.isGroup ? !noneChecked(item.children) : false, onChanged: (checked) => {
2860
+ onChanged(changeChecked(item.id, checked, items));
2861
+ }, ariaLabel: `Select ${accessibleName}`, checkedVariant: Variant$1.Light, uncheckedVariant: Variant$1.Light }));
2776
2862
  return (React__default.createElement("div", { key: item.id },
2777
2863
  React__default.createElement("span", { className: "NestableItemList-dropdown-button-container d-inline-block", style: {
2778
2864
  minWidth: '2rem',
@@ -2784,17 +2870,18 @@ const NestableItemList = (props) => {
2784
2870
  type: ActionType$9.ToggleChild,
2785
2871
  id: item.id,
2786
2872
  });
2787
- }, "aria-label": `${childExpanded[item.id] ? 'Hide' : 'Show'} items in ${item.name}` },
2873
+ }, "aria-label": `${childExpanded[item.id] ? 'Hide' : 'Show'} items in ${accessibleName}` },
2788
2874
  React__default.createElement(FontAwesomeIcon, { icon: childExpanded[item.id] ? faChevronDown : faChevronRight })))),
2789
- React__default.createElement(CheckboxButton, { className: `NestableItemList-CheckboxButton-${item.id}`, text: item.name, checked: item.isGroup ? allChecked(item.children) : item.checked, dashed: item.isGroup ? !noneChecked(item.children) : false, onChanged: (checked) => {
2790
- onChanged(changeChecked(item.id, checked, items));
2791
- }, ariaLabel: `Select ${item.name}`, checkedVariant: Variant$1.Light, uncheckedVariant: Variant$1.Light }),
2875
+ item.tooltip
2876
+ ? (React__default.createElement(Tooltip, { text: item.tooltip },
2877
+ React__default.createElement("span", { className: "d-inline-block" }, checkbox)))
2878
+ : checkbox,
2792
2879
  (item.isGroup && childExpanded[item.id]) && (React__default.createElement("div", { className: "NestableItemList-children-container", style: {
2793
2880
  paddingLeft: '2.2rem',
2794
2881
  } },
2795
2882
  React__default.createElement(NestableItemList, { items: item.children, onChanged: (updatedItems) => {
2796
2883
  onChanged(changeItems(item.id, updatedItems));
2797
- } })))));
2884
+ }, startWithGroupsExpanded: startWithGroupsExpanded })))));
2798
2885
  })));
2799
2886
  };
2800
2887
 
@@ -2811,7 +2898,7 @@ const ItemPicker = (props) => {
2811
2898
  /*------------------------------------------------------------------------*/
2812
2899
  /* -------------- Props ------------- */
2813
2900
  // Destructure all props
2814
- const { title, items, onChanged, noBottomMargin, hideSelectAllOrNoneButtons, } = props;
2901
+ const { title, items, onChanged, noBottomMargin, hideSelectAllOrNoneButtons, startWithGroupsExpanded, } = props;
2815
2902
  /*------------------------------------------------------------------------*/
2816
2903
  /* ------------------------- Component Functions ------------------------ */
2817
2904
  /*------------------------------------------------------------------------*/
@@ -2868,7 +2955,7 @@ const ItemPicker = (props) => {
2868
2955
  // Main UI
2869
2956
  return (React__default.createElement(TabBox, { title: title, noBottomMargin: noBottomMargin, topRightChildren: selectAllOrNone },
2870
2957
  React__default.createElement("div", { style: { overflowX: 'auto' } },
2871
- React__default.createElement(NestableItemList, { items: items, onChanged: onChanged }))));
2958
+ React__default.createElement(NestableItemList, { items: items, onChanged: onChanged, startWithGroupsExpanded: startWithGroupsExpanded }))));
2872
2959
  };
2873
2960
 
2874
2961
  /**
@@ -13445,65 +13532,6 @@ const DBEntryManagerPanel = (props) => {
13445
13532
  return (React__default.createElement("div", null, body));
13446
13533
  };
13447
13534
 
13448
- /**
13449
- * Simple tooltip component
13450
- * @author Gabe Abrams
13451
- */
13452
- /*------------------------------------------------------------------------*/
13453
- /* ------------------------------ Component ----------------------------- */
13454
- /*------------------------------------------------------------------------*/
13455
- const Tooltip = (props) => {
13456
- /*------------------------------------------------------------------------*/
13457
- /* -------------------------------- Setup ------------------------------- */
13458
- /*------------------------------------------------------------------------*/
13459
- /* -------------- Props ------------- */
13460
- // Destructure all props
13461
- const { text, children, } = props;
13462
- /* -------------- Refs -------------- */
13463
- // Child ref
13464
- const childRef = useRef(undefined);
13465
- /*------------------------------------------------------------------------*/
13466
- /* ------------------------- Lifecycle Functions ------------------------ */
13467
- /*------------------------------------------------------------------------*/
13468
- /**
13469
- * Update (also called on mount)
13470
- * @author Gabe Abrams
13471
- */
13472
- useEffect(() => {
13473
- // Skip if no child
13474
- if (!childRef.current) {
13475
- return;
13476
- }
13477
- // Store copy of tooltip
13478
- let t;
13479
- // Initialize tooltip
13480
- (() => __awaiter(void 0, void 0, void 0, function* () {
13481
- // Import bootstrap tooltip
13482
- const BSTooltip = (yield import('bootstrap')).Tooltip;
13483
- // Initialize
13484
- t = new BSTooltip(childRef.current, {
13485
- title: text,
13486
- placement: 'top',
13487
- trigger: 'hover',
13488
- });
13489
- }))();
13490
- // Clean up tooltip
13491
- return () => {
13492
- if (t) {
13493
- t.dispose();
13494
- }
13495
- };
13496
- }, [text]);
13497
- /*------------------------------------------------------------------------*/
13498
- /* ------------------------------- Render ------------------------------- */
13499
- /*------------------------------------------------------------------------*/
13500
- /*----------------------------------------*/
13501
- /* --------------- Main UI -------------- */
13502
- /*----------------------------------------*/
13503
- // Clone child and add ref
13504
- return React__default.cloneElement(children, { ref: childRef });
13505
- };
13506
-
13507
13535
  /**
13508
13536
  * A toggle switch that toggles on or off
13509
13537
  * @author Alessandra De Lucas