@dxos/plugin-deck 0.7.2 → 0.7.3-staging.0905f03

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.
@@ -12,9 +12,10 @@ import {
12
12
  import { batch } from "@preact/signals-core";
13
13
  import { setAutoFreeze } from "immer";
14
14
  import React16 from "react";
15
- import { IntentAction, LayoutAction as LayoutAction2, NavigationAction as NavigationAction3, parseGraphPlugin, parseIntentPlugin, resolvePlugin, Toast as ToastSchema, SLUG_PATH_SEPARATOR as SLUG_PATH_SEPARATOR4, isLayoutParts, isLayoutAdjustment, isLayoutMode, openIds as openIds2, filterPlugins } from "@dxos/app-framework";
16
- import { create, getTypename, isReactiveObject } from "@dxos/echo-schema";
15
+ import { filterPlugins, IntentAction, isLayoutAdjustment, isLayoutMode, isLayoutParts, LayoutAction as LayoutAction3, NavigationAction as NavigationAction3, openIds as openIds2, parseGraphPlugin, parseIntentPlugin, resolvePlugin, SLUG_PATH_SEPARATOR as SLUG_PATH_SEPARATOR4, Toast as ToastSchema } from "@dxos/app-framework";
16
+ import { getTypename } from "@dxos/echo-schema";
17
17
  import { scheduledEffect } from "@dxos/echo-signals/core";
18
+ import { create, isReactiveObject } from "@dxos/live-object";
18
19
  import { LocalStorageStore } from "@dxos/local-storage";
19
20
  import { log } from "@dxos/log";
20
21
  import { parseAttentionPlugin } from "@dxos/plugin-attention";
@@ -32,7 +33,7 @@ import { Sidebar as MenuIcon } from "@phosphor-icons/react";
32
33
  import { untracked } from "@preact/signals-core";
33
34
  import React14, { useCallback as useCallback2, useEffect as useEffect5, useMemo as useMemo5, useRef as useRef2, Fragment as Fragment2 } from "react";
34
35
  import { Surface as Surface9, firstIdInPart, usePlugin } from "@dxos/app-framework";
35
- import { Button as Button3, Dialog, Main as Main3, Popover as Popover2, useOnTransition, useTranslation as useTranslation5 } from "@dxos/react-ui";
36
+ import { AlertDialog, Button as Button3, Dialog as NaturalDialog, Main as Main3, Popover as Popover2, useOnTransition, useTranslation as useTranslation5 } from "@dxos/react-ui";
36
37
  import { Stack, StackContext as StackContext2, DEFAULT_HORIZONTAL_SIZE } from "@dxos/react-ui-stack";
37
38
  import { getSize, mainPaddingTransitions as mainPaddingTransitions2 } from "@dxos/react-ui-theme";
38
39
 
@@ -360,15 +361,11 @@ import { descriptionText, mx } from "@dxos/react-ui-theme";
360
361
 
361
362
  // packages/plugins/plugin-deck/src/components/DeckLayout/PlankLoading.tsx
362
363
  import React4 from "react";
363
- import { Status } from "@dxos/react-ui";
364
364
  var PlankLoading = () => {
365
365
  return /* @__PURE__ */ React4.createElement("div", {
366
366
  role: "none",
367
367
  className: "grid place-items-center attention-surface"
368
- }, /* @__PURE__ */ React4.createElement(Status, {
369
- indeterminate: true,
370
- "aria-label": "Initializing"
371
- }));
368
+ });
372
369
  };
373
370
 
374
371
  // packages/plugins/plugin-deck/src/components/DeckLayout/PlankError.tsx
@@ -522,7 +519,7 @@ var Fullscreen = ({ id }) => {
522
519
 
523
520
  // packages/plugins/plugin-deck/src/components/DeckLayout/Plank.tsx
524
521
  import React10, { memo as memo2, useCallback, useLayoutEffect, useMemo as useMemo3, useRef } from "react";
525
- import { Surface as Surface6, useIntentDispatcher as useIntentDispatcher3, indexInPart, partLength } from "@dxos/app-framework";
522
+ import { Surface as Surface6, useIntentDispatcher as useIntentDispatcher3, indexInPart, partLength, LayoutAction as LayoutAction2 } from "@dxos/app-framework";
526
523
  import { debounce } from "@dxos/async";
527
524
  import { useGraph as useGraph5 } from "@dxos/plugin-graph";
528
525
  import { useAttendableAttributes } from "@dxos/react-ui-attention";
@@ -537,7 +534,7 @@ var useDeckContext = () => useContext2(DeckContext) ?? raise2(new Error("Missing
537
534
 
538
535
  // packages/plugins/plugin-deck/src/components/DeckLayout/Plank.tsx
539
536
  var UNKNOWN_ID = "unknown_id";
540
- var Plank = /* @__PURE__ */ memo2(({ entry, layoutParts, part, layoutMode, order, last }) => {
537
+ var Plank = /* @__PURE__ */ memo2(({ entry, layoutParts, part, layoutMode, order }) => {
541
538
  const dispatch = useIntentDispatcher3();
542
539
  const coordinate = useMemo3(() => ({
543
540
  part,
@@ -578,13 +575,20 @@ var Plank = /* @__PURE__ */ memo2(({ entry, layoutParts, part, layoutMode, order
578
575
  }, []);
579
576
  useLayoutEffect(() => {
580
577
  if (scrollIntoView === coordinate.entryId) {
581
- rootElement.current?.focus({
578
+ const focusable = rootElement.current?.querySelector("button") || rootElement.current;
579
+ focusable?.focus({
582
580
  preventScroll: true
583
581
  });
584
- layoutMode === "deck" && rootElement.current?.scrollIntoView({
582
+ layoutMode === "deck" && focusable?.scrollIntoView({
585
583
  behavior: "smooth",
586
584
  inline: "center"
587
585
  });
586
+ void dispatch({
587
+ action: LayoutAction2.SCROLL_INTO_VIEW,
588
+ data: {
589
+ id: void 0
590
+ }
591
+ });
588
592
  }
589
593
  }, [
590
594
  coordinate.entryId,
@@ -782,7 +786,7 @@ var PlankSeparator = ({ index }) => index > 0 ? /* @__PURE__ */ React14.createEl
782
786
  }) : null;
783
787
  var DeckLayout = ({ layoutParts, toasts, overscroll, showHints, panels, onDismissToast }) => {
784
788
  const context = useLayout();
785
- const { layoutMode, sidebarOpen, complementarySidebarOpen, dialogOpen, dialogContent, dialogBlockAlign, popoverOpen, popoverContent, popoverAnchorId } = context;
789
+ const { layoutMode, sidebarOpen, complementarySidebarOpen, dialogOpen, dialogContent, dialogBlockAlign, dialogType, popoverOpen, popoverContent, popoverAnchorId } = context;
786
790
  const { t } = useTranslation5(DECK_PLUGIN);
787
791
  const { plankSizing } = useDeckContext();
788
792
  const attentionPlugin = usePlugin("dxos.org/plugin/attention");
@@ -832,6 +836,7 @@ var DeckLayout = ({ layoutParts, toasts, overscroll, showHints, panels, onDismis
832
836
  overscroll,
833
837
  layoutParts.main
834
838
  ]);
839
+ const Dialog = dialogType === "alert" ? AlertDialog : NaturalDialog;
835
840
  return /* @__PURE__ */ React14.createElement(Popover2.Root, {
836
841
  modal: true,
837
842
  open: !!(popoverAnchorId && popoverOpen),
@@ -909,8 +914,7 @@ var DeckLayout = ({ layoutParts, toasts, overscroll, showHints, panels, onDismis
909
914
  layoutParts,
910
915
  part: "main",
911
916
  layoutMode,
912
- order: index * 2 + 1,
913
- last: index === layoutParts.main.length - 1
917
+ order: index * 2 + 1
914
918
  }))))), /* @__PURE__ */ React14.createElement("div", {
915
919
  role: "none",
916
920
  className: isSoloModeLoaded ? "relative bg-deck overflow-hidden" : "sr-only",
@@ -1238,6 +1242,7 @@ var DeckPlugin = ({ observability } = {}) => {
1238
1242
  dialogContent: null,
1239
1243
  dialogOpen: false,
1240
1244
  dialogBlockAlign: void 0,
1245
+ dialogType: void 0,
1241
1246
  popoverContent: null,
1242
1247
  popoverAnchorId: void 0,
1243
1248
  popoverOpen: false,
@@ -1259,7 +1264,7 @@ var DeckPlugin = ({ observability } = {}) => {
1259
1264
  const layoutModeHistory = create({
1260
1265
  values: []
1261
1266
  });
1262
- const handleSetLayout = ({ element, state, component, subject, anchorId, dialogBlockAlign }) => {
1267
+ const handleSetLayout = ({ element, state, component, subject, anchorId, dialogBlockAlign, dialogType }) => {
1263
1268
  switch (element) {
1264
1269
  case "sidebar": {
1265
1270
  layout.values.sidebarOpen = state ?? !layout.values.sidebarOpen;
@@ -1280,6 +1285,7 @@ var DeckPlugin = ({ observability } = {}) => {
1280
1285
  subject
1281
1286
  } : null;
1282
1287
  layout.values.dialogBlockAlign = dialogBlockAlign ?? "center";
1288
+ layout.values.dialogType = dialogType;
1283
1289
  return {
1284
1290
  data: true
1285
1291
  };
@@ -1309,19 +1315,36 @@ var DeckPlugin = ({ observability } = {}) => {
1309
1315
  }
1310
1316
  };
1311
1317
  const handleSetLocation = (next) => {
1318
+ const part = layout.values.layoutMode === "solo" ? "solo" : "main";
1319
+ const ids = openIds2(next, [
1320
+ part
1321
+ ]);
1312
1322
  if (attentionPlugin) {
1313
1323
  const attended = attentionPlugin.provides.attention.attended;
1314
1324
  const [attendedId] = Array.from(attended);
1315
- const ids = (layout.values.layoutMode === "deck" ? next.main : next.solo)?.map(({ id }) => id) ?? [];
1316
1325
  const isAttendedAvailable = !!attendedId && ids.includes(attendedId);
1317
1326
  if (!isAttendedAvailable) {
1318
- requestAnimationFrame(() => {
1319
- const nextAttended = layout.values.layoutMode === "solo" ? next.solo?.[0].id : next.main?.[0]?.id;
1320
- const article = document.querySelector(`article[data-attendable-id="${nextAttended}"]`);
1321
- article?.focus();
1327
+ const currentIds = location.values.active[part]?.map(({ id }) => id) ?? [];
1328
+ const attendedIndex = currentIds.indexOf(attendedId);
1329
+ const index = attendedIndex === -1 ? 0 : attendedIndex >= ids.length ? ids.length - 1 : attendedIndex;
1330
+ const nextAttended = next[part]?.[index].id;
1331
+ void intentPlugin?.provides.intent.dispatch({
1332
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1333
+ data: {
1334
+ id: nextAttended
1335
+ }
1322
1336
  });
1323
1337
  }
1324
1338
  }
1339
+ const current = openIds2(location.values.active, [
1340
+ part
1341
+ ]);
1342
+ const removed = current.filter((id) => !ids.includes(id));
1343
+ const closed = Array.from(/* @__PURE__ */ new Set([
1344
+ ...location.values.closed.filter((id) => !ids.includes(id)),
1345
+ ...removed
1346
+ ]));
1347
+ location.values.closed = closed;
1325
1348
  location.values.active = next;
1326
1349
  };
1327
1350
  return {
@@ -1434,11 +1457,11 @@ var DeckPlugin = ({ observability } = {}) => {
1434
1457
  filter: (node) => false,
1435
1458
  actions: () => [
1436
1459
  {
1437
- id: `${LayoutAction2.SET_LAYOUT_MODE}/fullscreen`,
1460
+ id: `${LayoutAction3.SET_LAYOUT_MODE}/fullscreen`,
1438
1461
  data: async () => {
1439
1462
  await intentPlugin?.provides.intent.dispatch({
1440
1463
  plugin: DECK_PLUGIN,
1441
- action: LayoutAction2.SET_LAYOUT_MODE,
1464
+ action: LayoutAction3.SET_LAYOUT_MODE,
1442
1465
  data: {
1443
1466
  layoutMode: "fullscreen"
1444
1467
  }
@@ -1501,27 +1524,47 @@ var DeckPlugin = ({ observability } = {}) => {
1501
1524
  intent: {
1502
1525
  resolver: (intent) => {
1503
1526
  switch (intent.action) {
1504
- case LayoutAction2.SET_LAYOUT: {
1527
+ case LayoutAction3.SET_LAYOUT: {
1505
1528
  return intent.data && handleSetLayout(intent.data);
1506
1529
  }
1507
- case LayoutAction2.SET_LAYOUT_MODE: {
1530
+ case LayoutAction3.SET_LAYOUT_MODE: {
1531
+ const setMode = (mode) => {
1532
+ const main = openIds2(location.values.active, [
1533
+ "main"
1534
+ ]);
1535
+ const solo = openIds2(location.values.active, [
1536
+ "solo"
1537
+ ]);
1538
+ const current = layout.values.layoutMode === "solo" ? solo : main;
1539
+ const next = mode === "solo" ? solo : [
1540
+ ...main,
1541
+ ...solo
1542
+ ];
1543
+ const removed = current.filter((id) => !next.includes(id));
1544
+ const closed = Array.from(/* @__PURE__ */ new Set([
1545
+ ...location.values.closed.filter((id) => !next.includes(id)),
1546
+ ...removed
1547
+ ]));
1548
+ location.values.closed = closed;
1549
+ layout.values.layoutMode = mode;
1550
+ };
1508
1551
  return batch(() => {
1509
1552
  if (!intent.data) {
1510
1553
  return;
1511
1554
  }
1512
1555
  if (intent.data?.revert) {
1513
- layout.values.layoutMode = layoutModeHistory.values.pop() ?? "solo";
1556
+ setMode(layoutModeHistory.values.pop() ?? "solo");
1514
1557
  return {
1515
1558
  data: true
1516
1559
  };
1517
1560
  }
1518
1561
  if (isLayoutMode(intent?.data?.layoutMode)) {
1519
1562
  layoutModeHistory.values.push(layout.values.layoutMode);
1520
- layout.values.layoutMode = intent.data.layoutMode;
1563
+ setMode(intent.data.layoutMode);
1521
1564
  } else {
1522
1565
  log.warn("Invalid layout mode", intent?.data?.layoutMode, {
1523
1566
  F: __dxlog_file,
1524
- L: 379,
1567
+ L: 412,
1525
1568
  S: void 0,
1526
1569
  C: (f, a) => f(...a)
1527
1570
  });
@@ -1531,9 +1574,11 @@ var DeckPlugin = ({ observability } = {}) => {
1531
1574
  };
1532
1575
  });
1533
1576
  }
1534
- case LayoutAction2.SCROLL_INTO_VIEW: {
1577
+ case LayoutAction3.SCROLL_INTO_VIEW: {
1535
1578
  layout.values.scrollIntoView = intent.data?.id ?? void 0;
1536
- return void 0;
1579
+ return {
1580
+ data: true
1581
+ };
1537
1582
  }
1538
1583
  case DeckAction.UPDATE_PLANK_SIZE: {
1539
1584
  const { id, size } = intent.data;
@@ -1575,7 +1620,7 @@ var DeckPlugin = ({ observability } = {}) => {
1575
1620
  return;
1576
1621
  }
1577
1622
  const processLayoutEntry = (partName, entryString, currentLayout) => {
1578
- const toggle = true;
1623
+ const toggle = false;
1579
1624
  const [id, path] = entryString.split(SLUG_PATH_SEPARATOR4);
1580
1625
  const layoutEntry = {
1581
1626
  id,
@@ -1616,7 +1661,7 @@ var DeckPlugin = ({ observability } = {}) => {
1616
1661
  intents: [
1617
1662
  newlyOpen.length > 0 ? [
1618
1663
  {
1619
- action: LayoutAction2.SCROLL_INTO_VIEW,
1664
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1620
1665
  data: {
1621
1666
  id: newlyOpen[0]
1622
1667
  }
@@ -1661,7 +1706,7 @@ var DeckPlugin = ({ observability } = {}) => {
1661
1706
  if (data.scrollIntoView && layout.values.layoutMode === "deck") {
1662
1707
  intents.push([
1663
1708
  {
1664
- action: LayoutAction2.SCROLL_INTO_VIEW,
1709
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1665
1710
  data: {
1666
1711
  id: data.id
1667
1712
  }
@@ -1731,13 +1776,8 @@ var DeckPlugin = ({ observability } = {}) => {
1731
1776
  return {
1732
1777
  data: true,
1733
1778
  intents: [
1779
+ // NOTE: The order of these is important.
1734
1780
  [
1735
- {
1736
- action: LayoutAction2.SET_LAYOUT_MODE,
1737
- data: {
1738
- layoutMode: "solo"
1739
- }
1740
- },
1741
1781
  {
1742
1782
  action: NavigationAction3.OPEN,
1743
1783
  data: {
@@ -1747,6 +1787,12 @@ var DeckPlugin = ({ observability } = {}) => {
1747
1787
  ]
1748
1788
  }
1749
1789
  }
1790
+ },
1791
+ {
1792
+ action: LayoutAction3.SET_LAYOUT_MODE,
1793
+ data: {
1794
+ layoutMode: "solo"
1795
+ }
1750
1796
  }
1751
1797
  ]
1752
1798
  ]
@@ -1755,9 +1801,10 @@ var DeckPlugin = ({ observability } = {}) => {
1755
1801
  return {
1756
1802
  data: true,
1757
1803
  intents: [
1804
+ // NOTE: The order of these is important.
1758
1805
  [
1759
1806
  {
1760
- action: LayoutAction2.SET_LAYOUT_MODE,
1807
+ action: LayoutAction3.SET_LAYOUT_MODE,
1761
1808
  data: {
1762
1809
  layoutMode: "deck"
1763
1810
  }
@@ -1784,7 +1831,7 @@ var DeckPlugin = ({ observability } = {}) => {
1784
1831
  }
1785
1832
  },
1786
1833
  {
1787
- action: LayoutAction2.SCROLL_INTO_VIEW,
1834
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1788
1835
  data: {
1789
1836
  id: entryId
1790
1837
  }