@trops/dash-core 0.1.473 → 0.1.474

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
@@ -57595,6 +57595,13 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57595
57595
  },
57596
57596
  className: "px-3 py-1.5 text-sm font-medium -mb-px border-b-2 ".concat(activeTab === "listeners" ? "border-indigo-400" : "border-transparent opacity-60 hover:opacity-100"),
57597
57597
  children: "Listeners"
57598
+ }), /*#__PURE__*/jsx("button", {
57599
+ type: "button",
57600
+ onClick: function onClick() {
57601
+ return setActiveTab("notifications");
57602
+ },
57603
+ className: "px-3 py-1.5 text-sm font-medium -mb-px border-b-2 ".concat(activeTab === "notifications" ? "border-indigo-400" : "border-transparent opacity-60 hover:opacity-100"),
57604
+ children: "Notifications"
57598
57605
  }), /*#__PURE__*/jsx("button", {
57599
57606
  type: "button",
57600
57607
  onClick: function onClick() {
@@ -57628,6 +57635,8 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57628
57635
  providersByType: providersByType,
57629
57636
  onBulk: stageBulk,
57630
57637
  onPerWidget: stageBinding
57638
+ }), activeTab === "notifications" && /*#__PURE__*/jsx(NotificationsTab, {
57639
+ workspace: workspace
57631
57640
  }), activeTab === "widgets" && /*#__PURE__*/jsx(WidgetsTab, {
57632
57641
  workspace: workspace,
57633
57642
  getWidgetConfig: getWidgetConfig,
@@ -57652,25 +57661,248 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57652
57661
  });
57653
57662
  };
57654
57663
 
57664
+ /**
57665
+ * Notifications tab — dashboard-scoped view of every widget instance
57666
+ * in the current workspace that declares notifications. Bulk Enable
57667
+ * all / Disable all controls flip every notification toggle in the
57668
+ * filtered list at once. Per-widget toggles persist immediately via
57669
+ * `mainApi.notifications.setPreferences` — same path Settings →
57670
+ * Notifications uses, so the two views stay consistent.
57671
+ *
57672
+ * Toggles are uncontrolled-with-respect-to-the-server: we mirror them
57673
+ * locally for snappy UI but the IPC call is fire-and-forget. If a
57674
+ * write fails the user can re-toggle. No staging — the bulk modal
57675
+ * doesn't gate the user behind a Save button for boolean prefs.
57676
+ */
57677
+ function NotificationsTab(_ref4) {
57678
+ var workspace = _ref4.workspace;
57679
+ var _useState9 = useState(""),
57680
+ _useState0 = _slicedToArray(_useState9, 2),
57681
+ searchQuery = _useState0[0],
57682
+ setSearchQuery = _useState0[1];
57683
+ // Local mirror of widgetUuid -> { typeKey: bool }. Seeded from the
57684
+ // main process on mount; updated optimistically on toggle.
57685
+ var _useState1 = useState({}),
57686
+ _useState10 = _slicedToArray(_useState1, 2),
57687
+ prefs = _useState10[0],
57688
+ setPrefs = _useState10[1];
57689
+ var _useState11 = useState(false),
57690
+ _useState12 = _slicedToArray(_useState11, 2),
57691
+ loaded = _useState12[0],
57692
+ setLoaded = _useState12[1];
57693
+ React__default.useEffect(function () {
57694
+ var _window$mainApi;
57695
+ var cancelled = false;
57696
+ if (!((_window$mainApi = window.mainApi) !== null && _window$mainApi !== void 0 && (_window$mainApi = _window$mainApi.notifications) !== null && _window$mainApi !== void 0 && _window$mainApi.getPreferences)) {
57697
+ setLoaded(true);
57698
+ return function () {
57699
+ cancelled = true;
57700
+ };
57701
+ }
57702
+ window.mainApi.notifications.getPreferences().then(function (p) {
57703
+ if (cancelled) return;
57704
+ setPrefs((p === null || p === void 0 ? void 0 : p.instances) || {});
57705
+ setLoaded(true);
57706
+ });
57707
+ return function () {
57708
+ cancelled = true;
57709
+ };
57710
+ }, []);
57711
+
57712
+ // Collect every widget instance in THIS workspace that declares
57713
+ // notifications, alphabetized by title. Mirrors the Settings →
57714
+ // Notifications collection logic but scoped to one workspace.
57715
+ var widgetInstances = useMemo(function () {
57716
+ var out = [];
57717
+ var _visit = function visit(item) {
57718
+ if (!item) return;
57719
+ if (Array.isArray(item)) {
57720
+ item.forEach(_visit);
57721
+ return;
57722
+ }
57723
+ if (item.component) {
57724
+ var _config$notifications;
57725
+ var config = ComponentManager.resolve(item.component, item);
57726
+ if ((config === null || config === void 0 || (_config$notifications = config.notifications) === null || _config$notifications === void 0 ? void 0 : _config$notifications.length) > 0) {
57727
+ var _item$userPrefs;
57728
+ out.push({
57729
+ uuid: item.uuid || item.uuidString,
57730
+ title: ((_item$userPrefs = item.userPrefs) === null || _item$userPrefs === void 0 ? void 0 : _item$userPrefs.title) || config.displayName || item.component,
57731
+ "package": config["package"] || "Other",
57732
+ notifications: config.notifications
57733
+ });
57734
+ }
57735
+ }
57736
+ if (Array.isArray(item.children)) item.children.forEach(_visit);
57737
+ if (Array.isArray(item.layout)) item.layout.forEach(_visit);
57738
+ if (Array.isArray(item.items)) item.items.forEach(_visit);
57739
+ };
57740
+ _visit(workspace === null || workspace === void 0 ? void 0 : workspace.layout);
57741
+ if (Array.isArray(workspace === null || workspace === void 0 ? void 0 : workspace.pages)) {
57742
+ workspace.pages.forEach(function (p) {
57743
+ return _visit(p === null || p === void 0 ? void 0 : p.layout);
57744
+ });
57745
+ }
57746
+ _visit(workspace === null || workspace === void 0 ? void 0 : workspace.sidebarLayout);
57747
+ return out.sort(function (a, b) {
57748
+ return String(a.title).localeCompare(String(b.title), undefined, {
57749
+ sensitivity: "base"
57750
+ });
57751
+ });
57752
+ }, [workspace]);
57753
+ var filtered = useMemo(function () {
57754
+ var q = searchQuery.trim().toLowerCase();
57755
+ if (!q) return widgetInstances;
57756
+ return widgetInstances.filter(function (wi) {
57757
+ var hay = [wi.title, wi["package"]].concat(_toConsumableArray(wi.notifications.map(function (n) {
57758
+ return "".concat(n.key, " ").concat(n.displayName || "");
57759
+ }))).join(" ").toLowerCase();
57760
+ return hay.includes(q);
57761
+ });
57762
+ }, [widgetInstances, searchQuery]);
57763
+ var isEnabled = function isEnabled(uuid, typeKey, defaultEnabled) {
57764
+ var w = prefs[uuid];
57765
+ if (w && typeof w[typeKey] === "boolean") return w[typeKey];
57766
+ return !!defaultEnabled;
57767
+ };
57768
+ var setOne = function setOne(uuid, typeKey, value) {
57769
+ var _window$mainApi2;
57770
+ setPrefs(function (prev) {
57771
+ return _objectSpread$a(_objectSpread$a({}, prev), {}, _defineProperty({}, uuid, _objectSpread$a(_objectSpread$a({}, prev[uuid] || {}), {}, _defineProperty({}, typeKey, value))));
57772
+ });
57773
+ (_window$mainApi2 = window.mainApi) === null || _window$mainApi2 === void 0 || (_window$mainApi2 = _window$mainApi2.notifications) === null || _window$mainApi2 === void 0 || _window$mainApi2.setPreferences(uuid, _defineProperty({}, typeKey, value));
57774
+ };
57775
+ var setAllVisible = function setAllVisible(value) {
57776
+ // Update local state in one pass + fire one IPC per widget.
57777
+ setPrefs(function (prev) {
57778
+ var next = _objectSpread$a({}, prev);
57779
+ filtered.forEach(function (wi) {
57780
+ var w = _objectSpread$a({}, next[wi.uuid] || {});
57781
+ wi.notifications.forEach(function (n) {
57782
+ w[n.key] = value;
57783
+ });
57784
+ next[wi.uuid] = w;
57785
+ });
57786
+ return next;
57787
+ });
57788
+ filtered.forEach(function (wi) {
57789
+ var _window$mainApi3;
57790
+ var update = {};
57791
+ wi.notifications.forEach(function (n) {
57792
+ update[n.key] = value;
57793
+ });
57794
+ (_window$mainApi3 = window.mainApi) === null || _window$mainApi3 === void 0 || (_window$mainApi3 = _window$mainApi3.notifications) === null || _window$mainApi3 === void 0 || _window$mainApi3.setPreferences(wi.uuid, update);
57795
+ });
57796
+ };
57797
+ if (!loaded) {
57798
+ return /*#__PURE__*/jsx("div", {
57799
+ className: "p-4 text-sm opacity-50",
57800
+ children: "Loading\u2026"
57801
+ });
57802
+ }
57803
+ if (widgetInstances.length === 0) {
57804
+ return /*#__PURE__*/jsx("div", {
57805
+ className: "p-4 text-sm opacity-50",
57806
+ children: "No widgets in this dashboard declare notifications. Add widgets that declare notifications to see per-type controls here."
57807
+ });
57808
+ }
57809
+ return /*#__PURE__*/jsxs("div", {
57810
+ className: "flex flex-col h-full",
57811
+ children: [/*#__PURE__*/jsxs("div", {
57812
+ className: "flex flex-col gap-2 px-2 py-2 flex-shrink-0 border-b border-white/10",
57813
+ children: [/*#__PURE__*/jsx(SearchInput, {
57814
+ value: searchQuery,
57815
+ onChange: setSearchQuery,
57816
+ placeholder: "Search widgets...",
57817
+ inputClassName: "py-1.5 text-xs"
57818
+ }), /*#__PURE__*/jsxs("div", {
57819
+ className: "flex flex-row items-center justify-between text-[10px]",
57820
+ children: [/*#__PURE__*/jsxs("span", {
57821
+ className: "opacity-50",
57822
+ children: [filtered.length, " of ", widgetInstances.length, " widget", widgetInstances.length === 1 ? "" : "s"]
57823
+ }), /*#__PURE__*/jsxs("div", {
57824
+ className: "flex flex-row items-center gap-2",
57825
+ children: [/*#__PURE__*/jsx("button", {
57826
+ type: "button",
57827
+ onClick: function onClick() {
57828
+ return setAllVisible(true);
57829
+ },
57830
+ className: "px-2 py-1 rounded bg-green-700 hover:bg-green-600 text-white text-xs font-medium transition-colors",
57831
+ "data-testid": "bulk-notifications-enable-all",
57832
+ children: "Enable all"
57833
+ }), /*#__PURE__*/jsx("button", {
57834
+ type: "button",
57835
+ onClick: function onClick() {
57836
+ return setAllVisible(false);
57837
+ },
57838
+ className: "px-2 py-1 rounded bg-gray-700 hover:bg-gray-600 text-gray-200 text-xs font-medium transition-colors",
57839
+ "data-testid": "bulk-notifications-disable-all",
57840
+ children: "Disable all"
57841
+ })]
57842
+ })]
57843
+ })]
57844
+ }), /*#__PURE__*/jsx("div", {
57845
+ className: "flex-1 overflow-y-auto px-2 py-2 space-y-3",
57846
+ children: filtered.map(function (wi) {
57847
+ return /*#__PURE__*/jsxs("div", {
57848
+ className: "border border-white/10 rounded p-3 space-y-2",
57849
+ children: [/*#__PURE__*/jsxs("div", {
57850
+ className: "flex flex-col",
57851
+ children: [/*#__PURE__*/jsx("span", {
57852
+ className: "text-sm font-medium",
57853
+ children: wi.title
57854
+ }), /*#__PURE__*/jsx("span", {
57855
+ className: "text-[10px] opacity-50",
57856
+ children: wi["package"]
57857
+ })]
57858
+ }), /*#__PURE__*/jsx("div", {
57859
+ className: "flex flex-col gap-1.5 pl-2 border-l border-white/10",
57860
+ children: wi.notifications.map(function (notif) {
57861
+ return /*#__PURE__*/jsxs("div", {
57862
+ className: "flex flex-row items-center justify-between py-0.5",
57863
+ children: [/*#__PURE__*/jsxs("div", {
57864
+ className: "flex flex-col",
57865
+ children: [/*#__PURE__*/jsx("span", {
57866
+ className: "text-xs",
57867
+ children: notif.displayName
57868
+ }), notif.description && /*#__PURE__*/jsx("span", {
57869
+ className: "text-[10px] opacity-50",
57870
+ children: notif.description
57871
+ })]
57872
+ }), /*#__PURE__*/jsx(Switch, {
57873
+ checked: isEnabled(wi.uuid, notif.key, notif.defaultEnabled),
57874
+ onChange: function onChange(value) {
57875
+ return setOne(wi.uuid, notif.key, value);
57876
+ }
57877
+ })]
57878
+ }, notif.key);
57879
+ })
57880
+ })]
57881
+ }, wi.uuid);
57882
+ })
57883
+ })]
57884
+ });
57885
+ }
57886
+
57655
57887
  /**
57656
57888
  * Providers tab with a sidebar/detail layout mirroring the Listeners
57657
57889
  * tab. Column 1 lists provider types in this workspace (with an amber
57658
57890
  * dot per-type when any widget of that type is unresolved). Column 2
57659
57891
  * shows the selected type's bulk dropdown + per-widget dropdowns.
57660
57892
  */
57661
- function ProvidersTab(_ref4) {
57893
+ function ProvidersTab(_ref5) {
57662
57894
  var _typeEntries$, _selectedRows$;
57663
- var grouped = _ref4.grouped,
57664
- providersByType = _ref4.providersByType,
57665
- onBulk = _ref4.onBulk,
57666
- onPerWidget = _ref4.onPerWidget;
57895
+ var grouped = _ref5.grouped,
57896
+ providersByType = _ref5.providersByType,
57897
+ onBulk = _ref5.onBulk,
57898
+ onPerWidget = _ref5.onPerWidget;
57667
57899
  var typeEntries = useMemo(function () {
57668
57900
  return Array.from(grouped.entries());
57669
57901
  }, [grouped]);
57670
- var _useState9 = useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
57671
- _useState0 = _slicedToArray(_useState9, 2),
57672
- selectedType = _useState0[0],
57673
- setSelectedType = _useState0[1];
57902
+ var _useState13 = useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
57903
+ _useState14 = _slicedToArray(_useState13, 2),
57904
+ selectedType = _useState14[0],
57905
+ setSelectedType = _useState14[1];
57674
57906
 
57675
57907
  // If the selected type disappears (workspace changed), fall back.
57676
57908
  useMemo(function () {
@@ -57700,10 +57932,10 @@ function ProvidersTab(_ref4) {
57700
57932
  children: "Provider Types"
57701
57933
  }), /*#__PURE__*/jsx("div", {
57702
57934
  className: "overflow-y-auto flex-1",
57703
- children: typeEntries.map(function (_ref5) {
57704
- var _ref6 = _slicedToArray(_ref5, 2),
57705
- providerType = _ref6[0],
57706
- rows = _ref6[1];
57935
+ children: typeEntries.map(function (_ref6) {
57936
+ var _ref7 = _slicedToArray(_ref6, 2),
57937
+ providerType = _ref7[0],
57938
+ rows = _ref7[1];
57707
57939
  var isActive = selectedType === providerType;
57708
57940
  var unresolvedHere = rows.filter(function (r) {
57709
57941
  return r.required && !r.resolvedProviderName;
@@ -57857,8 +58089,8 @@ function ProvidersTab(_ref4) {
57857
58089
  * package (no `config.id` / `config.package` / item.workspace hint).
57858
58090
  * Usually this is a stale layout item whose widget got uninstalled.
57859
58091
  */
57860
- function DependenciesTab(_ref8) {
57861
- var dependencies = _ref8.dependencies;
58092
+ function DependenciesTab(_ref9) {
58093
+ var dependencies = _ref9.dependencies;
57862
58094
  if (!dependencies || dependencies.length === 0) {
57863
58095
  return /*#__PURE__*/jsx("div", {
57864
58096
  className: "flex items-center justify-center h-full text-sm opacity-60 text-center",
@@ -57931,21 +58163,21 @@ function sameWiringEntry(a, b) {
57931
58163
  * adjusts wiring per handler from a single dropdown of all emitters'
57932
58164
  * (widget × event) pairs.
57933
58165
  */
57934
- function ListenersTab(_ref9) {
58166
+ function ListenersTab(_ref0) {
57935
58167
  var _receivers$;
57936
- var emitters = _ref9.emitters,
57937
- receivers = _ref9.receivers,
57938
- wiring = _ref9.wiring,
57939
- onAdd = _ref9.onAdd,
57940
- onRemove = _ref9.onRemove;
57941
- var _useState11 = useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
57942
- _useState12 = _slicedToArray(_useState11, 2),
57943
- selectedReceiverKey = _useState12[0],
57944
- setSelectedReceiverKey = _useState12[1];
57945
- var _useState13 = useState(null),
57946
- _useState14 = _slicedToArray(_useState13, 2),
57947
- selectedHandler = _useState14[0],
57948
- setSelectedHandler = _useState14[1];
58168
+ var emitters = _ref0.emitters,
58169
+ receivers = _ref0.receivers,
58170
+ wiring = _ref0.wiring,
58171
+ onAdd = _ref0.onAdd,
58172
+ onRemove = _ref0.onRemove;
58173
+ var _useState17 = useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
58174
+ _useState18 = _slicedToArray(_useState17, 2),
58175
+ selectedReceiverKey = _useState18[0],
58176
+ setSelectedReceiverKey = _useState18[1];
58177
+ var _useState19 = useState(null),
58178
+ _useState20 = _slicedToArray(_useState19, 2),
58179
+ selectedHandler = _useState20[0],
58180
+ setSelectedHandler = _useState20[1];
57949
58181
 
57950
58182
  // Re-anchor selection if the previously-selected widget disappeared
57951
58183
  // (workspace switched, widget deleted, etc.).
@@ -58049,11 +58281,11 @@ function ListenersTab(_ref9) {
58049
58281
  * third column. Matches the left-column look from
58050
58282
  * PanelEditItemHandlers.
58051
58283
  */
58052
- function HandlersColumn(_ref1) {
58053
- var receiver = _ref1.receiver,
58054
- myWiring = _ref1.myWiring,
58055
- selectedHandler = _ref1.selectedHandler,
58056
- onSelectHandler = _ref1.onSelectHandler;
58284
+ function HandlersColumn(_ref10) {
58285
+ var receiver = _ref10.receiver,
58286
+ myWiring = _ref10.myWiring,
58287
+ selectedHandler = _ref10.selectedHandler,
58288
+ onSelectHandler = _ref10.onSelectHandler;
58057
58289
  var countsByHandler = useMemo(function () {
58058
58290
  var m = new Map();
58059
58291
  var _iterator9 = _createForOfIteratorHelper$6(myWiring),
@@ -58114,13 +58346,13 @@ function HandlersColumn(_ref1) {
58114
58346
  * Checked = wired; toggling commits an add/remove. Mirrors the
58115
58347
  * right-column UX of PanelEditItemHandlers.
58116
58348
  */
58117
- function EventsColumn(_ref10) {
58118
- var receiver = _ref10.receiver,
58119
- handlerName = _ref10.handlerName,
58120
- myWiring = _ref10.myWiring,
58121
- emitters = _ref10.emitters,
58122
- onAdd = _ref10.onAdd,
58123
- onRemove = _ref10.onRemove;
58349
+ function EventsColumn(_ref11) {
58350
+ var receiver = _ref11.receiver,
58351
+ handlerName = _ref11.handlerName,
58352
+ myWiring = _ref11.myWiring,
58353
+ emitters = _ref11.emitters,
58354
+ onAdd = _ref11.onAdd,
58355
+ onRemove = _ref11.onRemove;
58124
58356
  // Wired-for-this-handler: dedupe defensively (legacy workspaces
58125
58357
  // occasionally contain duplicate entries under the same handler).
58126
58358
  var wiredHere = useMemo(function () {