@trops/dash-core 0.1.119 → 0.1.121

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.
@@ -595,7 +595,7 @@ const DASHBOARD_CONFIG_PREVIEW$1 = "dashboard-config-preview";
595
595
  const DASHBOARD_CONFIG_CHECK_UPDATES$1 = "dashboard-config-check-updates";
596
596
  const DASHBOARD_CONFIG_PROVIDER_SETUP$1 = "dashboard-config-provider-setup";
597
597
  const DASHBOARD_CONFIG_PUBLISH_PREVIEW$1 = "dashboard-config-publish-preview";
598
- const DASHBOARD_CONFIG_SELECT_FILE = "dashboard-config-select-file";
598
+ const DASHBOARD_CONFIG_SELECT_FILE$1 = "dashboard-config-select-file";
599
599
 
600
600
  var dashboardConfigEvents$1 = {
601
601
  DASHBOARD_CONFIG_EXPORT: DASHBOARD_CONFIG_EXPORT$1,
@@ -607,7 +607,7 @@ var dashboardConfigEvents$1 = {
607
607
  DASHBOARD_CONFIG_CHECK_UPDATES: DASHBOARD_CONFIG_CHECK_UPDATES$1,
608
608
  DASHBOARD_CONFIG_PROVIDER_SETUP: DASHBOARD_CONFIG_PROVIDER_SETUP$1,
609
609
  DASHBOARD_CONFIG_PUBLISH_PREVIEW: DASHBOARD_CONFIG_PUBLISH_PREVIEW$1,
610
- DASHBOARD_CONFIG_SELECT_FILE,
610
+ DASHBOARD_CONFIG_SELECT_FILE: DASHBOARD_CONFIG_SELECT_FILE$1,
611
611
  };
612
612
 
613
613
  /**
@@ -10848,11 +10848,93 @@ async function exportDashboardConfig$1(
10848
10848
  }
10849
10849
  }
10850
10850
 
10851
+ /**
10852
+ * Select and preview a dashboard ZIP file without importing it.
10853
+ * Opens the file picker, extracts and validates the .dashboard.json,
10854
+ * and returns a preview of the config + the file path for later import.
10855
+ *
10856
+ * @param {BrowserWindow} win - The main window (for dialog)
10857
+ * @returns {Promise<Object>} Result with success, filePath, and dashboardConfig preview
10858
+ */
10859
+ async function selectDashboardFile$1(win) {
10860
+ try {
10861
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
10862
+ title: "Import Dashboard Configuration",
10863
+ filters: [{ name: "ZIP Archive", extensions: ["zip"] }],
10864
+ properties: ["openFile"],
10865
+ });
10866
+
10867
+ if (canceled || !filePaths || !filePaths.length) {
10868
+ return { success: false, canceled: true };
10869
+ }
10870
+
10871
+ const zipPath = filePaths[0];
10872
+
10873
+ // Extract and validate
10874
+ const zip = new AdmZip(zipPath);
10875
+ const tempDir = path$1.join(app$1.getPath("temp"), "dash-import");
10876
+ const { validateZipEntries } = widgetRegistryExports;
10877
+ validateZipEntries(zip, tempDir);
10878
+
10879
+ const entries = zip.getEntries();
10880
+ const configEntry = entries.find((e) =>
10881
+ e.entryName.endsWith(".dashboard.json"),
10882
+ );
10883
+
10884
+ if (!configEntry) {
10885
+ return {
10886
+ success: false,
10887
+ error: "No .dashboard.json file found in ZIP archive",
10888
+ };
10889
+ }
10890
+
10891
+ const configJson = configEntry.getData().toString("utf-8");
10892
+ let dashboardConfig;
10893
+ try {
10894
+ dashboardConfig = JSON.parse(configJson);
10895
+ } catch (parseError) {
10896
+ return {
10897
+ success: false,
10898
+ error: `Invalid JSON: ${parseError.message}`,
10899
+ };
10900
+ }
10901
+
10902
+ const validation = validateDashboardConfig(dashboardConfig);
10903
+ if (!validation.valid) {
10904
+ return {
10905
+ success: false,
10906
+ error: `Invalid config: ${validation.errors.join(", ")}`,
10907
+ };
10908
+ }
10909
+
10910
+ dashboardConfig = applyDefaults(dashboardConfig);
10911
+
10912
+ return {
10913
+ success: true,
10914
+ filePath: zipPath,
10915
+ dashboardConfig: {
10916
+ name: dashboardConfig.name,
10917
+ description: dashboardConfig.description,
10918
+ author: dashboardConfig.author,
10919
+ workspace: dashboardConfig.workspace,
10920
+ widgets: dashboardConfig.widgets || [],
10921
+ providers: dashboardConfig.providers || [],
10922
+ },
10923
+ };
10924
+ } catch (error) {
10925
+ console.error(
10926
+ "[DashboardConfigController] Error selecting dashboard file:",
10927
+ error,
10928
+ );
10929
+ return { success: false, error: error.message };
10930
+ }
10931
+ }
10932
+
10851
10933
  /**
10852
10934
  * Import a dashboard from a ZIP file containing a .dashboard.json config.
10853
10935
  *
10854
10936
  * Steps:
10855
- * 1. Show native file picker for .zip selection
10937
+ * 1. Show native file picker for .zip selection (or use options.filePath)
10856
10938
  * 2. Extract and validate .dashboard.json
10857
10939
  * 3. Auto-install missing widgets from registry
10858
10940
  * 4. Create workspace in workspaces.json
@@ -10862,22 +10944,39 @@ async function exportDashboardConfig$1(
10862
10944
  * @param {BrowserWindow} win - The main window (for dialog)
10863
10945
  * @param {string} appId - Application identifier
10864
10946
  * @param {Object} widgetRegistry - WidgetRegistry instance (needs getWidgets(), downloadWidget())
10947
+ * @param {Object} options - Import options
10948
+ * @param {string} options.filePath - Skip file picker, use this path directly
10949
+ * @param {string} options.name - Override workspace name
10950
+ * @param {number} options.menuId - Override workspace menuId (folder)
10951
+ * @param {string} options.themeKey - Override workspace themeKey
10865
10952
  * @returns {Promise<Object>} Result with success, workspace, and import summary
10866
10953
  */
10867
- async function importDashboardConfig$1(win, appId, widgetRegistry = null) {
10954
+ async function importDashboardConfig$1(
10955
+ win,
10956
+ appId,
10957
+ widgetRegistry = null,
10958
+ options = {},
10959
+ ) {
10868
10960
  try {
10869
- // 1. Show file picker
10870
- const { canceled, filePaths } = await dialog.showOpenDialog(win, {
10871
- title: "Import Dashboard Configuration",
10872
- filters: [{ name: "ZIP Archive", extensions: ["zip"] }],
10873
- properties: ["openFile"],
10874
- });
10961
+ let zipPath;
10875
10962
 
10876
- if (canceled || !filePaths || !filePaths.length) {
10877
- return { success: false, canceled: true };
10878
- }
10963
+ if (options.filePath) {
10964
+ // Use the provided file path (from selectDashboardFile)
10965
+ zipPath = options.filePath;
10966
+ } else {
10967
+ // Show file picker
10968
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
10969
+ title: "Import Dashboard Configuration",
10970
+ filters: [{ name: "ZIP Archive", extensions: ["zip"] }],
10971
+ properties: ["openFile"],
10972
+ });
10879
10973
 
10880
- const zipPath = filePaths[0];
10974
+ if (canceled || !filePaths || !filePaths.length) {
10975
+ return { success: false, canceled: true };
10976
+ }
10977
+
10978
+ zipPath = filePaths[0];
10979
+ }
10881
10980
 
10882
10981
  // 2. Extract and validate .dashboard.json from ZIP
10883
10982
  const zip = new AdmZip(zipPath);
@@ -10923,12 +11022,17 @@ async function importDashboardConfig$1(win, appId, widgetRegistry = null) {
10923
11022
  // Apply defaults to fill in optional fields
10924
11023
  dashboardConfig = applyDefaults(dashboardConfig);
10925
11024
 
10926
- // Delegate to shared import pipeline
11025
+ // Delegate to shared import pipeline with overrides
10927
11026
  return await processDashboardConfig(
10928
11027
  win,
10929
11028
  appId,
10930
11029
  dashboardConfig,
10931
11030
  widgetRegistry,
11031
+ {
11032
+ name: options.name,
11033
+ menuId: options.menuId,
11034
+ themeKey: options.themeKey,
11035
+ },
10932
11036
  );
10933
11037
  } catch (error) {
10934
11038
  console.error(
@@ -11025,6 +11129,11 @@ async function processDashboardConfig(
11025
11129
  // Generate a unique ID for the imported workspace
11026
11130
  workspace.id = Date.now();
11027
11131
 
11132
+ // Apply name/menuId/themeKey overrides if provided
11133
+ if (options.name) workspace.name = options.name;
11134
+ if (options.menuId !== undefined) workspace.menuId = options.menuId;
11135
+ if (options.themeKey !== undefined) workspace.themeKey = options.themeKey;
11136
+
11028
11137
  // 3. Apply event wiring to layout
11029
11138
  const eventWiringSummary = [];
11030
11139
  if (
@@ -11653,6 +11762,7 @@ function getDashboardPublishPreview$1(appId, workspaceId, widgetRegistry = null)
11653
11762
 
11654
11763
  var dashboardConfigController$1 = {
11655
11764
  exportDashboardConfig: exportDashboardConfig$1,
11765
+ selectDashboardFile: selectDashboardFile$1,
11656
11766
  importDashboardConfig: importDashboardConfig$1,
11657
11767
  installDashboardFromRegistry: installDashboardFromRegistry$1,
11658
11768
  checkCompatibility: checkCompatibility$1,
@@ -12287,6 +12397,7 @@ const {
12287
12397
  const { install: pluginInstall } = pluginController_1;
12288
12398
  const {
12289
12399
  exportDashboardConfig,
12400
+ selectDashboardFile,
12290
12401
  importDashboardConfig,
12291
12402
  installDashboardFromRegistry,
12292
12403
  checkCompatibility,
@@ -12370,6 +12481,7 @@ var controller = {
12370
12481
  pluginInstall,
12371
12482
  searchIndex,
12372
12483
  exportDashboardConfig,
12484
+ selectDashboardFile,
12373
12485
  importDashboardConfig,
12374
12486
  installDashboardFromRegistry,
12375
12487
  checkCompatibility,
@@ -13778,6 +13890,7 @@ var clientCacheApi_1 = clientCacheApi$2;
13778
13890
  const { ipcRenderer: ipcRenderer$5 } = require$$0$1;
13779
13891
  const {
13780
13892
  DASHBOARD_CONFIG_EXPORT,
13893
+ DASHBOARD_CONFIG_SELECT_FILE,
13781
13894
  DASHBOARD_CONFIG_IMPORT,
13782
13895
  DASHBOARD_CONFIG_INSTALL,
13783
13896
  DASHBOARD_CONFIG_COMPATIBILITY,
@@ -13804,16 +13917,27 @@ const dashboardConfigApi$2 = {
13804
13917
  options,
13805
13918
  }),
13806
13919
 
13920
+ /**
13921
+ * Select and preview a dashboard ZIP file without importing it.
13922
+ * Opens the file picker, validates the config, and returns a preview
13923
+ * with the file path for later import.
13924
+ *
13925
+ * @returns {Promise<Object>} Result with success, filePath, and dashboardConfig preview
13926
+ */
13927
+ selectDashboardFile: () =>
13928
+ ipcRenderer$5.invoke(DASHBOARD_CONFIG_SELECT_FILE),
13929
+
13807
13930
  /**
13808
13931
  * Import a dashboard config from a ZIP file.
13809
- * Shows a file picker, validates the config, installs missing widgets,
13810
- * creates the workspace, and applies event wiring.
13932
+ * Shows a file picker (or uses options.filePath), validates the config,
13933
+ * installs missing widgets, creates the workspace, and applies event wiring.
13811
13934
  *
13812
13935
  * @param {string} appId - Application identifier
13936
+ * @param {Object} options - Import options (filePath, name, menuId, themeKey)
13813
13937
  * @returns {Promise<Object>} Result with success, workspace, and summary
13814
13938
  */
13815
- importDashboardConfig: (appId) =>
13816
- ipcRenderer$5.invoke(DASHBOARD_CONFIG_IMPORT, { appId }),
13939
+ importDashboardConfig: (appId, options = {}) =>
13940
+ ipcRenderer$5.invoke(DASHBOARD_CONFIG_IMPORT, { appId, ...options }),
13817
13941
 
13818
13942
  /**
13819
13943
  * Install a dashboard from the registry by package name.