@trops/dash-core 0.1.334 → 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,20 +27358,22 @@ 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;
27336
27364
 
27337
27365
  // Always-pages model: every workspace must have at least one page.
27338
- // If the source data is single-page (empty pages array but populated
27339
- // layout), wrap the layout into pages[0] now so renderers always have
27340
- // a page to display. Idempotent: a no-op if pages is already populated.
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.
27341
27371
  if (!Array.isArray(workspace.pages) || workspace.pages.length === 0) {
27342
27372
  var page = {
27343
27373
  id: "page-".concat(workspace.id || Date.now()),
27344
- name: workspace.name || "Page 1",
27374
+ name: "Page 1",
27345
27375
  order: 0,
27346
- layout: workspace.layout || []
27376
+ layout: workspace.layout
27347
27377
  };
27348
27378
  workspace.pages = [page];
27349
27379
  workspace.activePageId = page.id;
@@ -49046,7 +49076,7 @@ var PageTabBar = function PageTabBar(_ref) {
49046
49076
  };
49047
49077
  return /*#__PURE__*/jsxs("div", {
49048
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"),
49049
- children: [sortedPages.map(function (page) {
49079
+ children: [pages.length > 1 && sortedPages.map(function (page) {
49050
49080
  var isActive = page.id === activePageId;
49051
49081
  var isDragOver = page.id === dragOverId;
49052
49082
  return /*#__PURE__*/jsxs("button", {
@@ -49118,7 +49148,7 @@ var PageTabBar = function PageTabBar(_ref) {
49118
49148
  }), /*#__PURE__*/jsx("span", {
49119
49149
  children: "Add Page"
49120
49150
  })]
49121
- }), editMode && onScrollableChange && /*#__PURE__*/jsx("div", {
49151
+ }), editMode && pages.length > 1 && onScrollableChange && /*#__PURE__*/jsx("div", {
49122
49152
  className: "ml-auto flex items-center shrink-0",
49123
49153
  children: /*#__PURE__*/jsx(Toggle, {
49124
49154
  text: "Scrollable",
@@ -51810,7 +51840,18 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
51810
51840
  }, [currentActivePageId, workspacePages, workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.id, workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.name]);
51811
51841
  function handleAddPage() {
51812
51842
  if (!workspaceSelected) return;
51813
- 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
+ });
51814
51855
  var newPage = DashboardModel.createPage("Page ".concat(existingPages.length + 1));
51815
51856
  newPage.order = existingPages.length;
51816
51857
  var updatedWorkspace = _objectSpread$5(_objectSpread$5({}, workspaceSelected), {}, {
@@ -52043,11 +52084,11 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52043
52084
 
52044
52085
  // Derive scrollable state from the active page's root layout item
52045
52086
  function getRootScrollable() {
52046
- var _pageRef$current, _ws$pages;
52087
+ var _pageRef$current2, _ws$pages;
52047
52088
  var ws = currentWorkspaceRef.current || workspaceSelected;
52048
52089
  if (!ws) return false;
52049
52090
  var pageRef = pageRefsMap.current[currentActivePageId];
52050
- 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) {
52051
52092
  return p.id === currentActivePageId;
52052
52093
  })) === null || _ws$pages === void 0 ? void 0 : _ws$pages.layout);
52053
52094
  if (!layout) return false;
@@ -52064,9 +52105,9 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52064
52105
  // Gather latest layout from each page's LayoutBuilder ref
52065
52106
  var workspaceToSave = deepCopy(workspaceSelected);
52066
52107
  workspaceToSave.pages = (workspaceToSave.pages || []).map(function (page) {
52067
- var _pageRef$current2;
52108
+ var _pageRef$current3;
52068
52109
  var pageRef = pageRefsMap.current[page.id];
52069
- 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 || [];
52070
52111
  return _objectSpread$5(_objectSpread$5({}, page), {}, {
52071
52112
  layout: latestLayout.map(function (item) {
52072
52113
  var copy = _objectSpread$5({}, item);
@@ -52351,7 +52392,9 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
52351
52392
  onFolderChange: popout ? null : handleWorkspaceFolderChange,
52352
52393
  onThemeChange: popout ? null : handleWorkspaceThemeChange,
52353
52394
  sidebarEnabled: sidebarEnabled,
52354
- onSidebarChange: popout ? null : handleSidebarToggle
52395
+ onSidebarChange: popout ? null : handleSidebarToggle,
52396
+ scrollableEnabled: workspacePages.length <= 1 ? getRootScrollable() : undefined,
52397
+ onScrollableChange: workspacePages.length <= 1 && !popout ? handleScrollableChange : null
52355
52398
  }), /*#__PURE__*/jsxs(DashboardThemeProvider, {
52356
52399
  themeKey: workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.themeKey,
52357
52400
  children: [hasMissing && missingComponents.length >= 2 && !dismissedMissingForWorkspace.has(workspaceSelected === null || workspaceSelected === void 0 ? void 0 : workspaceSelected.id) && /*#__PURE__*/jsxs("div", {