@trops/dash-core 0.1.333 → 0.1.335

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
@@ -27298,6 +27298,34 @@ var SettingsModel = function SettingsModel() {
27298
27298
  return obj;
27299
27299
  };
27300
27300
 
27301
+ /**
27302
+ * Default layout for a brand-new workspace: a single 1x1 grid container
27303
+ * with one empty cell. Mirrors DashboardModel._initializeLayout().
27304
+ */
27305
+ function defaultGridLayout() {
27306
+ return [LayoutModel({
27307
+ id: 1,
27308
+ order: 1,
27309
+ type: "grid",
27310
+ component: "LayoutGridContainer",
27311
+ hasChildren: 1,
27312
+ scrollable: false,
27313
+ parent: 0,
27314
+ menuId: 1,
27315
+ width: "w-full",
27316
+ height: "h-full",
27317
+ grid: {
27318
+ rows: 1,
27319
+ cols: 1,
27320
+ gap: "gap-2",
27321
+ 1.1: {
27322
+ component: null,
27323
+ hide: false
27324
+ }
27325
+ }
27326
+ }, [])];
27327
+ }
27328
+
27301
27329
  /**
27302
27330
  * A Model for a Workspace (Dashboard)
27303
27331
  * The Workspace in this instance is the entire Dashboard Layout inclusive of the workspaces and widgets
@@ -27330,9 +27358,26 @@ var WorkspaceModel = function WorkspaceModel(workspaceItem) {
27330
27358
  workspace.type = "type" in obj ? sanitizeType(obj["type"]) : "workspace";
27331
27359
  workspace.label = "label" in obj ? obj["label"] : "New Dashboard";
27332
27360
  workspace.version = "version" in obj ? obj["version"] : 1;
27333
- workspace.layout = "layout" in obj ? obj["layout"] : [];
27361
+ workspace.layout = "layout" in obj && Array.isArray(obj["layout"]) && obj["layout"].length > 0 ? obj["layout"] : defaultGridLayout();
27334
27362
  workspace.pages = "pages" in obj ? obj["pages"] : [];
27335
27363
  workspace.activePageId = "activePageId" in obj ? obj["activePageId"] : null;
27364
+
27365
+ // Always-pages model: every workspace must have at least one page.
27366
+ // If the source data is single-page (empty pages array), wrap the
27367
+ // layout into pages[0] so renderers always have a page to display.
27368
+ // The page is named "Page 1" — when only one page exists, the
27369
+ // PageTabBar hides it; when the user adds a second page, both
27370
+ // "Page 1" and the new page become visible. Idempotent.
27371
+ if (!Array.isArray(workspace.pages) || workspace.pages.length === 0) {
27372
+ var page = {
27373
+ id: "page-".concat(workspace.id || Date.now()),
27374
+ name: "Page 1",
27375
+ order: 0,
27376
+ layout: workspace.layout
27377
+ };
27378
+ workspace.pages = [page];
27379
+ workspace.activePageId = page.id;
27380
+ }
27336
27381
  workspace.sidebarEnabled = "sidebarEnabled" in obj ? obj["sidebarEnabled"] : false;
27337
27382
  workspace.sidebarLayout = "sidebarLayout" in obj ? obj["sidebarLayout"] : [];
27338
27383
  workspace.sidebarWidth = "sidebarWidth" in obj ? obj["sidebarWidth"] : 280;
@@ -49031,7 +49076,7 @@ var PageTabBar = function PageTabBar(_ref) {
49031
49076
  };
49032
49077
  return /*#__PURE__*/jsxs("div", {
49033
49078
  className: "flex flex-row items-center shrink-0 overflow-x-auto gap-1 px-2 py-1.5 border-b ".concat(currentTheme["border-primary-dark"] || "border-gray-700", " ").concat(currentTheme["bg-primary-medium"] || "bg-gray-800/50", " scrollbar-none"),
49034
- children: [sortedPages.map(function (page) {
49079
+ children: [pages.length > 1 && sortedPages.map(function (page) {
49035
49080
  var isActive = page.id === activePageId;
49036
49081
  var isDragOver = page.id === dragOverId;
49037
49082
  return /*#__PURE__*/jsxs("button", {
@@ -49103,7 +49148,7 @@ var PageTabBar = function PageTabBar(_ref) {
49103
49148
  }), /*#__PURE__*/jsx("span", {
49104
49149
  children: "Add Page"
49105
49150
  })]
49106
- }), editMode && onScrollableChange && /*#__PURE__*/jsx("div", {
49151
+ }), editMode && pages.length > 1 && onScrollableChange && /*#__PURE__*/jsx("div", {
49107
49152
  className: "ml-auto flex items-center shrink-0",
49108
49153
  children: /*#__PURE__*/jsx(Toggle, {
49109
49154
  text: "Scrollable",
@@ -51795,7 +51840,18 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
51795
51840
  }, [currentActivePageId, workspacePages, workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.id, workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.name]);
51796
51841
  function handleAddPage() {
51797
51842
  if (!workspaceSelected) return;
51798
- var existingPages = _toConsumableArray(workspacePages);
51843
+ // Sync existing pages with their live layouts from refs so any
51844
+ // unsaved user edits to the current page are preserved when
51845
+ // adding a new page (especially relevant when going from 1 → 2
51846
+ // pages where the lone page's tab is hidden but its grid is live).
51847
+ var existingPages = workspacePages.map(function (p) {
51848
+ var _pageRef$current;
51849
+ var pageRef = pageRefsMap.current[p.id];
51850
+ var liveLayout = pageRef === null || pageRef === void 0 || (_pageRef$current = pageRef.current) === null || _pageRef$current === void 0 ? void 0 : _pageRef$current.layout;
51851
+ return liveLayout ? _objectSpread$5(_objectSpread$5({}, p), {}, {
51852
+ layout: liveLayout
51853
+ }) : p;
51854
+ });
51799
51855
  var newPage = DashboardModel.createPage("Page ".concat(existingPages.length + 1));
51800
51856
  newPage.order = existingPages.length;
51801
51857
  var updatedWorkspace = _objectSpread$5(_objectSpread$5({}, workspaceSelected), {}, {
@@ -52028,11 +52084,11 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52028
52084
 
52029
52085
  // Derive scrollable state from the active page's root layout item
52030
52086
  function getRootScrollable() {
52031
- var _pageRef$current, _ws$pages;
52087
+ var _pageRef$current2, _ws$pages;
52032
52088
  var ws = currentWorkspaceRef.current || workspaceSelected;
52033
52089
  if (!ws) return false;
52034
52090
  var pageRef = pageRefsMap.current[currentActivePageId];
52035
- var layout = (pageRef === null || pageRef === void 0 || (_pageRef$current = pageRef.current) === null || _pageRef$current === void 0 ? void 0 : _pageRef$current.layout) || ((_ws$pages = ws.pages) === null || _ws$pages === void 0 || (_ws$pages = _ws$pages.find(function (p) {
52091
+ var layout = (pageRef === null || pageRef === void 0 || (_pageRef$current2 = pageRef.current) === null || _pageRef$current2 === void 0 ? void 0 : _pageRef$current2.layout) || ((_ws$pages = ws.pages) === null || _ws$pages === void 0 || (_ws$pages = _ws$pages.find(function (p) {
52036
52092
  return p.id === currentActivePageId;
52037
52093
  })) === null || _ws$pages === void 0 ? void 0 : _ws$pages.layout);
52038
52094
  if (!layout) return false;
@@ -52049,9 +52105,9 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52049
52105
  // Gather latest layout from each page's LayoutBuilder ref
52050
52106
  var workspaceToSave = deepCopy(workspaceSelected);
52051
52107
  workspaceToSave.pages = (workspaceToSave.pages || []).map(function (page) {
52052
- var _pageRef$current2;
52108
+ var _pageRef$current3;
52053
52109
  var pageRef = pageRefsMap.current[page.id];
52054
- var latestLayout = (pageRef === null || pageRef === void 0 || (_pageRef$current2 = pageRef.current) === null || _pageRef$current2 === void 0 ? void 0 : _pageRef$current2.layout) || page.layout || [];
52110
+ var latestLayout = (pageRef === null || pageRef === void 0 || (_pageRef$current3 = pageRef.current) === null || _pageRef$current3 === void 0 ? void 0 : _pageRef$current3.layout) || page.layout || [];
52055
52111
  return _objectSpread$5(_objectSpread$5({}, page), {}, {
52056
52112
  layout: latestLayout.map(function (item) {
52057
52113
  var copy = _objectSpread$5({}, item);
@@ -52336,7 +52392,9 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52336
52392
  onFolderChange: popout ? null : handleWorkspaceFolderChange,
52337
52393
  onThemeChange: popout ? null : handleWorkspaceThemeChange,
52338
52394
  sidebarEnabled: sidebarEnabled,
52339
- onSidebarChange: popout ? null : handleSidebarToggle
52395
+ onSidebarChange: popout ? null : handleSidebarToggle,
52396
+ scrollableEnabled: workspacePages.length <= 1 ? getRootScrollable() : undefined,
52397
+ onScrollableChange: workspacePages.length <= 1 && !popout ? handleScrollableChange : null
52340
52398
  }), /*#__PURE__*/jsxs(DashboardThemeProvider, {
52341
52399
  themeKey: workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.themeKey,
52342
52400
  children: [hasMissing && missingComponents.length >= 2 && !dismissedMissingForWorkspace.has(workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.id) && /*#__PURE__*/jsxs("div", {