@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.js CHANGED
@@ -57613,6 +57613,13 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57613
57613
  },
57614
57614
  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"),
57615
57615
  children: "Listeners"
57616
+ }), /*#__PURE__*/jsxRuntime.jsx("button", {
57617
+ type: "button",
57618
+ onClick: function onClick() {
57619
+ return setActiveTab("notifications");
57620
+ },
57621
+ 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"),
57622
+ children: "Notifications"
57616
57623
  }), /*#__PURE__*/jsxRuntime.jsx("button", {
57617
57624
  type: "button",
57618
57625
  onClick: function onClick() {
@@ -57646,6 +57653,8 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57646
57653
  providersByType: providersByType,
57647
57654
  onBulk: stageBulk,
57648
57655
  onPerWidget: stageBinding
57656
+ }), activeTab === "notifications" && /*#__PURE__*/jsxRuntime.jsx(NotificationsTab, {
57657
+ workspace: workspace
57649
57658
  }), activeTab === "widgets" && /*#__PURE__*/jsxRuntime.jsx(WidgetsTab, {
57650
57659
  workspace: workspace,
57651
57660
  getWidgetConfig: getWidgetConfig,
@@ -57670,25 +57679,248 @@ var DashboardConfigModal = function DashboardConfigModal(_ref) {
57670
57679
  });
57671
57680
  };
57672
57681
 
57682
+ /**
57683
+ * Notifications tab — dashboard-scoped view of every widget instance
57684
+ * in the current workspace that declares notifications. Bulk Enable
57685
+ * all / Disable all controls flip every notification toggle in the
57686
+ * filtered list at once. Per-widget toggles persist immediately via
57687
+ * `mainApi.notifications.setPreferences` — same path Settings →
57688
+ * Notifications uses, so the two views stay consistent.
57689
+ *
57690
+ * Toggles are uncontrolled-with-respect-to-the-server: we mirror them
57691
+ * locally for snappy UI but the IPC call is fire-and-forget. If a
57692
+ * write fails the user can re-toggle. No staging — the bulk modal
57693
+ * doesn't gate the user behind a Save button for boolean prefs.
57694
+ */
57695
+ function NotificationsTab(_ref4) {
57696
+ var workspace = _ref4.workspace;
57697
+ var _useState9 = React.useState(""),
57698
+ _useState0 = _slicedToArray(_useState9, 2),
57699
+ searchQuery = _useState0[0],
57700
+ setSearchQuery = _useState0[1];
57701
+ // Local mirror of widgetUuid -> { typeKey: bool }. Seeded from the
57702
+ // main process on mount; updated optimistically on toggle.
57703
+ var _useState1 = React.useState({}),
57704
+ _useState10 = _slicedToArray(_useState1, 2),
57705
+ prefs = _useState10[0],
57706
+ setPrefs = _useState10[1];
57707
+ var _useState11 = React.useState(false),
57708
+ _useState12 = _slicedToArray(_useState11, 2),
57709
+ loaded = _useState12[0],
57710
+ setLoaded = _useState12[1];
57711
+ React.useEffect(function () {
57712
+ var _window$mainApi;
57713
+ var cancelled = false;
57714
+ if (!((_window$mainApi = window.mainApi) !== null && _window$mainApi !== void 0 && (_window$mainApi = _window$mainApi.notifications) !== null && _window$mainApi !== void 0 && _window$mainApi.getPreferences)) {
57715
+ setLoaded(true);
57716
+ return function () {
57717
+ cancelled = true;
57718
+ };
57719
+ }
57720
+ window.mainApi.notifications.getPreferences().then(function (p) {
57721
+ if (cancelled) return;
57722
+ setPrefs((p === null || p === void 0 ? void 0 : p.instances) || {});
57723
+ setLoaded(true);
57724
+ });
57725
+ return function () {
57726
+ cancelled = true;
57727
+ };
57728
+ }, []);
57729
+
57730
+ // Collect every widget instance in THIS workspace that declares
57731
+ // notifications, alphabetized by title. Mirrors the Settings →
57732
+ // Notifications collection logic but scoped to one workspace.
57733
+ var widgetInstances = React.useMemo(function () {
57734
+ var out = [];
57735
+ var _visit = function visit(item) {
57736
+ if (!item) return;
57737
+ if (Array.isArray(item)) {
57738
+ item.forEach(_visit);
57739
+ return;
57740
+ }
57741
+ if (item.component) {
57742
+ var _config$notifications;
57743
+ var config = ComponentManager.resolve(item.component, item);
57744
+ if ((config === null || config === void 0 || (_config$notifications = config.notifications) === null || _config$notifications === void 0 ? void 0 : _config$notifications.length) > 0) {
57745
+ var _item$userPrefs;
57746
+ out.push({
57747
+ uuid: item.uuid || item.uuidString,
57748
+ title: ((_item$userPrefs = item.userPrefs) === null || _item$userPrefs === void 0 ? void 0 : _item$userPrefs.title) || config.displayName || item.component,
57749
+ "package": config["package"] || "Other",
57750
+ notifications: config.notifications
57751
+ });
57752
+ }
57753
+ }
57754
+ if (Array.isArray(item.children)) item.children.forEach(_visit);
57755
+ if (Array.isArray(item.layout)) item.layout.forEach(_visit);
57756
+ if (Array.isArray(item.items)) item.items.forEach(_visit);
57757
+ };
57758
+ _visit(workspace === null || workspace === void 0 ? void 0 : workspace.layout);
57759
+ if (Array.isArray(workspace === null || workspace === void 0 ? void 0 : workspace.pages)) {
57760
+ workspace.pages.forEach(function (p) {
57761
+ return _visit(p === null || p === void 0 ? void 0 : p.layout);
57762
+ });
57763
+ }
57764
+ _visit(workspace === null || workspace === void 0 ? void 0 : workspace.sidebarLayout);
57765
+ return out.sort(function (a, b) {
57766
+ return String(a.title).localeCompare(String(b.title), undefined, {
57767
+ sensitivity: "base"
57768
+ });
57769
+ });
57770
+ }, [workspace]);
57771
+ var filtered = React.useMemo(function () {
57772
+ var q = searchQuery.trim().toLowerCase();
57773
+ if (!q) return widgetInstances;
57774
+ return widgetInstances.filter(function (wi) {
57775
+ var hay = [wi.title, wi["package"]].concat(_toConsumableArray(wi.notifications.map(function (n) {
57776
+ return "".concat(n.key, " ").concat(n.displayName || "");
57777
+ }))).join(" ").toLowerCase();
57778
+ return hay.includes(q);
57779
+ });
57780
+ }, [widgetInstances, searchQuery]);
57781
+ var isEnabled = function isEnabled(uuid, typeKey, defaultEnabled) {
57782
+ var w = prefs[uuid];
57783
+ if (w && typeof w[typeKey] === "boolean") return w[typeKey];
57784
+ return !!defaultEnabled;
57785
+ };
57786
+ var setOne = function setOne(uuid, typeKey, value) {
57787
+ var _window$mainApi2;
57788
+ setPrefs(function (prev) {
57789
+ return _objectSpread$a(_objectSpread$a({}, prev), {}, _defineProperty({}, uuid, _objectSpread$a(_objectSpread$a({}, prev[uuid] || {}), {}, _defineProperty({}, typeKey, value))));
57790
+ });
57791
+ (_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));
57792
+ };
57793
+ var setAllVisible = function setAllVisible(value) {
57794
+ // Update local state in one pass + fire one IPC per widget.
57795
+ setPrefs(function (prev) {
57796
+ var next = _objectSpread$a({}, prev);
57797
+ filtered.forEach(function (wi) {
57798
+ var w = _objectSpread$a({}, next[wi.uuid] || {});
57799
+ wi.notifications.forEach(function (n) {
57800
+ w[n.key] = value;
57801
+ });
57802
+ next[wi.uuid] = w;
57803
+ });
57804
+ return next;
57805
+ });
57806
+ filtered.forEach(function (wi) {
57807
+ var _window$mainApi3;
57808
+ var update = {};
57809
+ wi.notifications.forEach(function (n) {
57810
+ update[n.key] = value;
57811
+ });
57812
+ (_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);
57813
+ });
57814
+ };
57815
+ if (!loaded) {
57816
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
57817
+ className: "p-4 text-sm opacity-50",
57818
+ children: "Loading\u2026"
57819
+ });
57820
+ }
57821
+ if (widgetInstances.length === 0) {
57822
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
57823
+ className: "p-4 text-sm opacity-50",
57824
+ children: "No widgets in this dashboard declare notifications. Add widgets that declare notifications to see per-type controls here."
57825
+ });
57826
+ }
57827
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
57828
+ className: "flex flex-col h-full",
57829
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
57830
+ className: "flex flex-col gap-2 px-2 py-2 flex-shrink-0 border-b border-white/10",
57831
+ children: [/*#__PURE__*/jsxRuntime.jsx(DashReact.SearchInput, {
57832
+ value: searchQuery,
57833
+ onChange: setSearchQuery,
57834
+ placeholder: "Search widgets...",
57835
+ inputClassName: "py-1.5 text-xs"
57836
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
57837
+ className: "flex flex-row items-center justify-between text-[10px]",
57838
+ children: [/*#__PURE__*/jsxRuntime.jsxs("span", {
57839
+ className: "opacity-50",
57840
+ children: [filtered.length, " of ", widgetInstances.length, " widget", widgetInstances.length === 1 ? "" : "s"]
57841
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
57842
+ className: "flex flex-row items-center gap-2",
57843
+ children: [/*#__PURE__*/jsxRuntime.jsx("button", {
57844
+ type: "button",
57845
+ onClick: function onClick() {
57846
+ return setAllVisible(true);
57847
+ },
57848
+ className: "px-2 py-1 rounded bg-green-700 hover:bg-green-600 text-white text-xs font-medium transition-colors",
57849
+ "data-testid": "bulk-notifications-enable-all",
57850
+ children: "Enable all"
57851
+ }), /*#__PURE__*/jsxRuntime.jsx("button", {
57852
+ type: "button",
57853
+ onClick: function onClick() {
57854
+ return setAllVisible(false);
57855
+ },
57856
+ className: "px-2 py-1 rounded bg-gray-700 hover:bg-gray-600 text-gray-200 text-xs font-medium transition-colors",
57857
+ "data-testid": "bulk-notifications-disable-all",
57858
+ children: "Disable all"
57859
+ })]
57860
+ })]
57861
+ })]
57862
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
57863
+ className: "flex-1 overflow-y-auto px-2 py-2 space-y-3",
57864
+ children: filtered.map(function (wi) {
57865
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
57866
+ className: "border border-white/10 rounded p-3 space-y-2",
57867
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
57868
+ className: "flex flex-col",
57869
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
57870
+ className: "text-sm font-medium",
57871
+ children: wi.title
57872
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
57873
+ className: "text-[10px] opacity-50",
57874
+ children: wi["package"]
57875
+ })]
57876
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
57877
+ className: "flex flex-col gap-1.5 pl-2 border-l border-white/10",
57878
+ children: wi.notifications.map(function (notif) {
57879
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
57880
+ className: "flex flex-row items-center justify-between py-0.5",
57881
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
57882
+ className: "flex flex-col",
57883
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
57884
+ className: "text-xs",
57885
+ children: notif.displayName
57886
+ }), notif.description && /*#__PURE__*/jsxRuntime.jsx("span", {
57887
+ className: "text-[10px] opacity-50",
57888
+ children: notif.description
57889
+ })]
57890
+ }), /*#__PURE__*/jsxRuntime.jsx(DashReact.Switch, {
57891
+ checked: isEnabled(wi.uuid, notif.key, notif.defaultEnabled),
57892
+ onChange: function onChange(value) {
57893
+ return setOne(wi.uuid, notif.key, value);
57894
+ }
57895
+ })]
57896
+ }, notif.key);
57897
+ })
57898
+ })]
57899
+ }, wi.uuid);
57900
+ })
57901
+ })]
57902
+ });
57903
+ }
57904
+
57673
57905
  /**
57674
57906
  * Providers tab with a sidebar/detail layout mirroring the Listeners
57675
57907
  * tab. Column 1 lists provider types in this workspace (with an amber
57676
57908
  * dot per-type when any widget of that type is unresolved). Column 2
57677
57909
  * shows the selected type's bulk dropdown + per-widget dropdowns.
57678
57910
  */
57679
- function ProvidersTab(_ref4) {
57911
+ function ProvidersTab(_ref5) {
57680
57912
  var _typeEntries$, _selectedRows$;
57681
- var grouped = _ref4.grouped,
57682
- providersByType = _ref4.providersByType,
57683
- onBulk = _ref4.onBulk,
57684
- onPerWidget = _ref4.onPerWidget;
57913
+ var grouped = _ref5.grouped,
57914
+ providersByType = _ref5.providersByType,
57915
+ onBulk = _ref5.onBulk,
57916
+ onPerWidget = _ref5.onPerWidget;
57685
57917
  var typeEntries = React.useMemo(function () {
57686
57918
  return Array.from(grouped.entries());
57687
57919
  }, [grouped]);
57688
- var _useState9 = React.useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
57689
- _useState0 = _slicedToArray(_useState9, 2),
57690
- selectedType = _useState0[0],
57691
- setSelectedType = _useState0[1];
57920
+ var _useState13 = React.useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
57921
+ _useState14 = _slicedToArray(_useState13, 2),
57922
+ selectedType = _useState14[0],
57923
+ setSelectedType = _useState14[1];
57692
57924
 
57693
57925
  // If the selected type disappears (workspace changed), fall back.
57694
57926
  React.useMemo(function () {
@@ -57718,10 +57950,10 @@ function ProvidersTab(_ref4) {
57718
57950
  children: "Provider Types"
57719
57951
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
57720
57952
  className: "overflow-y-auto flex-1",
57721
- children: typeEntries.map(function (_ref5) {
57722
- var _ref6 = _slicedToArray(_ref5, 2),
57723
- providerType = _ref6[0],
57724
- rows = _ref6[1];
57953
+ children: typeEntries.map(function (_ref6) {
57954
+ var _ref7 = _slicedToArray(_ref6, 2),
57955
+ providerType = _ref7[0],
57956
+ rows = _ref7[1];
57725
57957
  var isActive = selectedType === providerType;
57726
57958
  var unresolvedHere = rows.filter(function (r) {
57727
57959
  return r.required && !r.resolvedProviderName;
@@ -57875,8 +58107,8 @@ function ProvidersTab(_ref4) {
57875
58107
  * package (no `config.id` / `config.package` / item.workspace hint).
57876
58108
  * Usually this is a stale layout item whose widget got uninstalled.
57877
58109
  */
57878
- function DependenciesTab(_ref8) {
57879
- var dependencies = _ref8.dependencies;
58110
+ function DependenciesTab(_ref9) {
58111
+ var dependencies = _ref9.dependencies;
57880
58112
  if (!dependencies || dependencies.length === 0) {
57881
58113
  return /*#__PURE__*/jsxRuntime.jsx("div", {
57882
58114
  className: "flex items-center justify-center h-full text-sm opacity-60 text-center",
@@ -57949,21 +58181,21 @@ function sameWiringEntry(a, b) {
57949
58181
  * adjusts wiring per handler from a single dropdown of all emitters'
57950
58182
  * (widget × event) pairs.
57951
58183
  */
57952
- function ListenersTab(_ref9) {
58184
+ function ListenersTab(_ref0) {
57953
58185
  var _receivers$;
57954
- var emitters = _ref9.emitters,
57955
- receivers = _ref9.receivers,
57956
- wiring = _ref9.wiring,
57957
- onAdd = _ref9.onAdd,
57958
- onRemove = _ref9.onRemove;
57959
- var _useState11 = React.useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
57960
- _useState12 = _slicedToArray(_useState11, 2),
57961
- selectedReceiverKey = _useState12[0],
57962
- setSelectedReceiverKey = _useState12[1];
57963
- var _useState13 = React.useState(null),
57964
- _useState14 = _slicedToArray(_useState13, 2),
57965
- selectedHandler = _useState14[0],
57966
- setSelectedHandler = _useState14[1];
58186
+ var emitters = _ref0.emitters,
58187
+ receivers = _ref0.receivers,
58188
+ wiring = _ref0.wiring,
58189
+ onAdd = _ref0.onAdd,
58190
+ onRemove = _ref0.onRemove;
58191
+ var _useState17 = React.useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
58192
+ _useState18 = _slicedToArray(_useState17, 2),
58193
+ selectedReceiverKey = _useState18[0],
58194
+ setSelectedReceiverKey = _useState18[1];
58195
+ var _useState19 = React.useState(null),
58196
+ _useState20 = _slicedToArray(_useState19, 2),
58197
+ selectedHandler = _useState20[0],
58198
+ setSelectedHandler = _useState20[1];
57967
58199
 
57968
58200
  // Re-anchor selection if the previously-selected widget disappeared
57969
58201
  // (workspace switched, widget deleted, etc.).
@@ -58067,11 +58299,11 @@ function ListenersTab(_ref9) {
58067
58299
  * third column. Matches the left-column look from
58068
58300
  * PanelEditItemHandlers.
58069
58301
  */
58070
- function HandlersColumn(_ref1) {
58071
- var receiver = _ref1.receiver,
58072
- myWiring = _ref1.myWiring,
58073
- selectedHandler = _ref1.selectedHandler,
58074
- onSelectHandler = _ref1.onSelectHandler;
58302
+ function HandlersColumn(_ref10) {
58303
+ var receiver = _ref10.receiver,
58304
+ myWiring = _ref10.myWiring,
58305
+ selectedHandler = _ref10.selectedHandler,
58306
+ onSelectHandler = _ref10.onSelectHandler;
58075
58307
  var countsByHandler = React.useMemo(function () {
58076
58308
  var m = new Map();
58077
58309
  var _iterator9 = _createForOfIteratorHelper$6(myWiring),
@@ -58132,13 +58364,13 @@ function HandlersColumn(_ref1) {
58132
58364
  * Checked = wired; toggling commits an add/remove. Mirrors the
58133
58365
  * right-column UX of PanelEditItemHandlers.
58134
58366
  */
58135
- function EventsColumn(_ref10) {
58136
- var receiver = _ref10.receiver,
58137
- handlerName = _ref10.handlerName,
58138
- myWiring = _ref10.myWiring,
58139
- emitters = _ref10.emitters,
58140
- onAdd = _ref10.onAdd,
58141
- onRemove = _ref10.onRemove;
58367
+ function EventsColumn(_ref11) {
58368
+ var receiver = _ref11.receiver,
58369
+ handlerName = _ref11.handlerName,
58370
+ myWiring = _ref11.myWiring,
58371
+ emitters = _ref11.emitters,
58372
+ onAdd = _ref11.onAdd,
58373
+ onRemove = _ref11.onRemove;
58142
58374
  // Wired-for-this-handler: dedupe defensively (legacy workspaces
58143
58375
  // occasionally contain duplicate entries under the same handler).
58144
58376
  var wiredHere = React.useMemo(function () {