@trops/dash-core 0.1.730 → 0.1.731

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
@@ -50333,6 +50333,21 @@ function noAiOptions(type) {
50333
50333
  return [].concat(_toConsumableArray(NO_AI_BY_TYPE[type] || []), NO_AI_COMMON);
50334
50334
  }
50335
50335
 
50336
+ /** How many recent widget drafts the start screen offers to continue. */
50337
+ var RECENT_DRAFTS = 3;
50338
+
50339
+ /** "just now" · "5m ago" · "3h ago" · "2d ago" for a draft's updatedAt. */
50340
+ function draftAge(updatedAt) {
50341
+ var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
50342
+ var ms = Math.max(0, now - Number(updatedAt || 0));
50343
+ var min = Math.floor(ms / 60000);
50344
+ if (min < 1) return "just now";
50345
+ if (min < 60) return "".concat(min, "m ago");
50346
+ var hours = Math.floor(min / 60);
50347
+ if (hours < 24) return "".concat(hours, "h ago");
50348
+ return "".concat(Math.floor(hours / 24), "d ago");
50349
+ }
50350
+
50336
50351
  /** Whether Send can run: a prompt, and an AI for types that need one. */
50337
50352
  function canSend(_ref) {
50338
50353
  var type = _ref.type,
@@ -50443,6 +50458,11 @@ var CreateModal = function CreateModal(_ref) {
50443
50458
  _useState8 = _slicedToArray(_useState7, 2),
50444
50459
  bots = _useState8[0],
50445
50460
  setBots = _useState8[1];
50461
+ // Recent Widget Builder drafts (newest first) — "Continue a draft".
50462
+ var _useState9 = useState(EMPTY$6),
50463
+ _useState0 = _slicedToArray(_useState9, 2),
50464
+ drafts = _useState0[0],
50465
+ setDrafts = _useState0[1];
50446
50466
 
50447
50467
  // Each open starts fresh on the requested type.
50448
50468
  useEffect(function () {
@@ -50465,6 +50485,22 @@ var CreateModal = function CreateModal(_ref) {
50465
50485
  };
50466
50486
  }, [open, botForm]);
50467
50487
 
50488
+ // Widget drafts to continue (the host's drafts store; none outside the
50489
+ // app).
50490
+ useEffect(function () {
50491
+ var _api$drafts;
50492
+ if (!open || type !== "widget") return undefined;
50493
+ var alive = true;
50494
+ var api = typeof window !== "undefined" ? window.mainApi : null;
50495
+ if (!(api !== null && api !== void 0 && (_api$drafts = api.drafts) !== null && _api$drafts !== void 0 && _api$drafts.list)) return undefined;
50496
+ Promise.resolve(api.drafts.list()).then(function (list) {
50497
+ if (alive && Array.isArray(list)) setDrafts(list);
50498
+ })["catch"](function () {});
50499
+ return function () {
50500
+ alive = false;
50501
+ };
50502
+ }, [open, type]);
50503
+
50468
50504
  // Other bots → "Another bot" events in the bot form's picker.
50469
50505
  useEffect(function () {
50470
50506
  var _api$bots;
@@ -50510,6 +50546,17 @@ var CreateModal = function CreateModal(_ref) {
50510
50546
  });
50511
50547
  }
50512
50548
  };
50549
+ var continueDraft = function continueDraft(draft) {
50550
+ close();
50551
+ window.dispatchEvent(new CustomEvent("dash:open-widget-builder", {
50552
+ detail: {
50553
+ resumeDraftId: draft.id
50554
+ }
50555
+ }));
50556
+ };
50557
+ var recentDrafts = type === "widget" ? _toConsumableArray(drafts).sort(function (a, b) {
50558
+ return (b.updatedAt || 0) - (a.updatedAt || 0);
50559
+ }).slice(0, RECENT_DRAFTS) : EMPTY$6;
50513
50560
  var startWithoutAi = function startWithoutAi(key) {
50514
50561
  if (key === "blank-bot") {
50515
50562
  setBotForm({
@@ -50620,6 +50667,37 @@ var CreateModal = function CreateModal(_ref) {
50620
50667
  onOpenAiSettings();
50621
50668
  }
50622
50669
  })]
50670
+ }), recentDrafts.length > 0 && /*#__PURE__*/jsxs("div", {
50671
+ className: "flex flex-col gap-2",
50672
+ children: [/*#__PURE__*/jsx(SectionLabel, {
50673
+ children: "Continue a draft"
50674
+ }), /*#__PURE__*/jsxs("div", {
50675
+ className: "flex flex-row flex-wrap gap-2",
50676
+ children: [recentDrafts.map(function (d) {
50677
+ return /*#__PURE__*/jsx(Button3, {
50678
+ size: "sm",
50679
+ onClick: function onClick() {
50680
+ return continueDraft(d);
50681
+ },
50682
+ children: /*#__PURE__*/jsxs("span", {
50683
+ className: "inline-flex items-center gap-2",
50684
+ children: [/*#__PURE__*/jsx(FontAwesomeIcon, {
50685
+ icon: "pen-to-square",
50686
+ className: "h-3.5 w-3.5"
50687
+ }), d.name || "Untitled draft", /*#__PURE__*/jsxs("span", {
50688
+ className: muted,
50689
+ children: ["\xB7 ", draftAge(d.updatedAt)]
50690
+ })]
50691
+ })
50692
+ }, d.id);
50693
+ }), drafts.length > RECENT_DRAFTS && /*#__PURE__*/jsx(Button3, {
50694
+ size: "sm",
50695
+ title: "All ".concat(drafts.length, " drafts"),
50696
+ onClick: function onClick() {
50697
+ return startWithoutAi("widget-drafts");
50698
+ }
50699
+ })]
50700
+ })]
50623
50701
  }), /*#__PURE__*/jsxs("div", {
50624
50702
  className: "flex flex-col gap-2",
50625
50703
  children: [/*#__PURE__*/jsx(SectionLabel, {
@@ -77914,6 +77992,9 @@ var DashboardStageInner = function DashboardStageInner(_ref3) {
77914
77992
  setThemeEditorKey(null);
77915
77993
  setThemeStartInCreate(true);
77916
77994
  setIsThemeManagerOpen(true);
77995
+ } else if (key === "widget-drafts") {
77996
+ // Drafts are listed (with Resume) on the Widgets page.
77997
+ handleOpenPageGuarded("widgets");
77917
77998
  } else if (WIDGET_INSTALL_ACTIONS[key]) {
77918
77999
  handleOpenPageGuarded("widgets", {
77919
78000
  widgetLink: {