@trops/dash-core 0.1.355 → 0.1.357
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/electron/index.js +168 -0
- package/dist/electron/index.js.map +1 -1
- package/dist/index.esm.js +80 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +80 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
1
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
4
|
import * as DashReact from '@trops/dash-react';
|
|
3
5
|
import { isObject, ThemeContext, deepCopy, MainSection, getUUID, getStylesForItem, themeObjects, Heading, SearchInput, ButtonIcon, SubHeading3, InputText, Button, FontAwesomeIcon, Tag, Modal, Sidebar, Paragraph, Panel, Stepper, Tag2, Tag3, Card2, Card3, Heading3, MenuItem3, FormLabel, SelectMenu, Switch, SelectInput, CodeEditorInline, SettingsModal, SubHeading2, tailwindHeightFractions, Menu3, Panel3, DropdownPanel, MenuItem2, ButtonIcon2, DragComponent, ConfirmationModal, DropComponent, getStyleName, capitalizeFirstLetter, colorTypes, getCSSStyleForClassname, Panel2, Heading2, SubHeading, Paragraph2, Paragraph3, Button2, Button3, MenuItem, ButtonIcon3, DashPanel, colorNames, shades, themeVariants, Tabs3, DataList, Checkbox, StatCard, Card, Tabs, Accordion, Alert, Toast, ProgressBar, Toggle, Breadcrumbs, Tabs2, Accordion2, Alert2, Toast2, ProgressBar2, Toggle2, Breadcrumbs2, Accordion3, Alert3, Toast3, ProgressBar3, Toggle3, Breadcrumbs3, ThemeFromUrlPane, TextArea, Icon2, AlgoliaSearchBox, CommandPalette, useSidebar, EmptyState, Navbar, withRouter, Menu as Menu$1 } from '@trops/dash-react';
|
|
4
6
|
export * from '@trops/dash-react';
|
|
5
7
|
export { ThemeContext } from '@trops/dash-react';
|
|
6
|
-
import _typeof from '@babel/runtime/helpers/typeof';
|
|
7
8
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
8
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
import React__default, { createContext, useContext, useState, useEffect, useMemo, useCallback, useRef, Fragment as Fragment$1, useReducer, Component, memo, Profiler } from 'react';
|
|
11
11
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
@@ -106,12 +106,47 @@ var event = {
|
|
|
106
106
|
};
|
|
107
107
|
var ipcBridgeListener = null;
|
|
108
108
|
var monitorCallbacks = new Set();
|
|
109
|
+
|
|
110
|
+
// Cache of last-seen event payloads by eventType. Used to replay the most
|
|
111
|
+
// recent value to late subscribers in popout windows — so a widget rendered
|
|
112
|
+
// in a popout can hydrate from current state without requiring the event to
|
|
113
|
+
// re-fire. Populated on-demand by enableIpcBridge({ replay: true }) and kept
|
|
114
|
+
// current via pub() and the broadcast listener.
|
|
115
|
+
var lastEventCache = new Map();
|
|
116
|
+
// Replay is opt-in per window to avoid resurrecting stale or command-style
|
|
117
|
+
// events when the main dashboard is reopened. Popout windows set this true;
|
|
118
|
+
// the main window leaves it false.
|
|
119
|
+
var replayEnabled = false;
|
|
109
120
|
var DashboardPublisher = {
|
|
110
121
|
sub: function sub(eventType, action, uuid) {
|
|
111
122
|
event.on(eventType, action, uuid);
|
|
123
|
+
|
|
124
|
+
// Replay last known payload to this subscriber so popouts can hydrate
|
|
125
|
+
// from current state without needing the event to re-fire. Only active
|
|
126
|
+
// in windows that opted in via enableIpcBridge({ replay: true }).
|
|
127
|
+
if (replayEnabled && lastEventCache.has(eventType) && typeof action === "function") {
|
|
128
|
+
var cached = lastEventCache.get(eventType);
|
|
129
|
+
// Defer so the caller finishes wiring up before the handler runs.
|
|
130
|
+
setTimeout(function () {
|
|
131
|
+
try {
|
|
132
|
+
action({
|
|
133
|
+
message: cached.content,
|
|
134
|
+
event: eventType,
|
|
135
|
+
uuid: uuid,
|
|
136
|
+
replay: true
|
|
137
|
+
});
|
|
138
|
+
} catch (_) {
|
|
139
|
+
// Replay must not break subscription
|
|
140
|
+
}
|
|
141
|
+
}, 0);
|
|
142
|
+
}
|
|
112
143
|
},
|
|
113
144
|
pub: function pub(eventType, content) {
|
|
114
145
|
var _window$mainApi;
|
|
146
|
+
lastEventCache.set(eventType, {
|
|
147
|
+
content: content,
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
});
|
|
115
150
|
event.emit(eventType, content);
|
|
116
151
|
|
|
117
152
|
// Notify monitor callbacks (debugger)
|
|
@@ -144,21 +179,51 @@ var DashboardPublisher = {
|
|
|
144
179
|
};
|
|
145
180
|
},
|
|
146
181
|
enableIpcBridge: function enableIpcBridge() {
|
|
147
|
-
var _window$mainApi2;
|
|
182
|
+
var _window$mainApi2, _window$mainApi3;
|
|
183
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
148
184
|
if (ipcBridgeListener) return;
|
|
149
185
|
if (!((_window$mainApi2 = window.mainApi) !== null && _window$mainApi2 !== void 0 && _window$mainApi2.on)) return;
|
|
186
|
+
var _options$replay = options.replay,
|
|
187
|
+
replay = _options$replay === void 0 ? false : _options$replay;
|
|
188
|
+
replayEnabled = replay;
|
|
150
189
|
ipcBridgeListener = function ipcBridgeListener(_e, message) {
|
|
190
|
+
if (replayEnabled && message && message.eventType) {
|
|
191
|
+
lastEventCache.set(message.eventType, {
|
|
192
|
+
content: message.content,
|
|
193
|
+
timestamp: Date.now()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
151
196
|
event.emit(message.eventType, message.content);
|
|
152
197
|
};
|
|
153
198
|
window.mainApi.on("widget-event:broadcast", ipcBridgeListener);
|
|
199
|
+
|
|
200
|
+
// Hydrate this window's cache from the main-process cache so that
|
|
201
|
+
// widgets mounted in a fresh window (popout) can replay events that
|
|
202
|
+
// fired before this window existed. Only for windows that opted in.
|
|
203
|
+
if (replayEnabled && (_window$mainApi3 = window.mainApi) !== null && _window$mainApi3 !== void 0 && (_window$mainApi3 = _window$mainApi3.widgetEvent) !== null && _window$mainApi3 !== void 0 && _window$mainApi3.getLastEvents) {
|
|
204
|
+
window.mainApi.widgetEvent.getLastEvents().then(function (events) {
|
|
205
|
+
if (events && _typeof(events) === "object") {
|
|
206
|
+
for (var _i = 0, _Object$entries = Object.entries(events); _i < _Object$entries.length; _i++) {
|
|
207
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
208
|
+
eventType = _Object$entries$_i[0],
|
|
209
|
+
entry = _Object$entries$_i[1];
|
|
210
|
+
var existing = lastEventCache.get(eventType);
|
|
211
|
+
if (!existing || existing.timestamp < (entry.timestamp || 0)) {
|
|
212
|
+
lastEventCache.set(eventType, entry);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
})["catch"](function () {});
|
|
217
|
+
}
|
|
154
218
|
},
|
|
155
219
|
disableIpcBridge: function disableIpcBridge() {
|
|
156
|
-
var _window$
|
|
220
|
+
var _window$mainApi4;
|
|
157
221
|
if (!ipcBridgeListener) return;
|
|
158
|
-
if ((_window$
|
|
222
|
+
if ((_window$mainApi4 = window.mainApi) !== null && _window$mainApi4 !== void 0 && _window$mainApi4.removeListener) {
|
|
159
223
|
window.mainApi.removeListener("widget-event:broadcast", ipcBridgeListener);
|
|
160
224
|
}
|
|
161
225
|
ipcBridgeListener = null;
|
|
226
|
+
replayEnabled = false;
|
|
162
227
|
},
|
|
163
228
|
listeners: function listeners() {
|
|
164
229
|
return event.list;
|
|
@@ -2746,7 +2811,16 @@ var DashboardWrapper = function DashboardWrapper(_ref) {
|
|
|
2746
2811
|
return w;
|
|
2747
2812
|
}, [dashApi]);
|
|
2748
2813
|
useEffect(function () {
|
|
2749
|
-
|
|
2814
|
+
var _window$location, _window$location2;
|
|
2815
|
+
// Only popout windows replay cached events on subscribe — keeps the
|
|
2816
|
+
// main dashboard from resurrecting stale state when reopened while
|
|
2817
|
+
// still letting popped-out widgets hydrate from current state.
|
|
2818
|
+
// Electron uses hash routing, so the popout path lives in
|
|
2819
|
+
// window.location.hash (e.g. "#/popout-widget/..."), not pathname.
|
|
2820
|
+
var isPopout = typeof window !== "undefined" && (typeof ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hash) === "string" && window.location.hash.includes("/popout") || typeof ((_window$location2 = window.location) === null || _window$location2 === void 0 ? void 0 : _window$location2.pathname) === "string" && window.location.pathname.includes("/popout"));
|
|
2821
|
+
DashboardPublisher.enableIpcBridge({
|
|
2822
|
+
replay: isPopout
|
|
2823
|
+
});
|
|
2750
2824
|
return function () {
|
|
2751
2825
|
return DashboardPublisher.disableIpcBridge();
|
|
2752
2826
|
};
|