@dxos/plugin-deck 0.7.2 → 0.7.3-staging.971cd8d

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";
@@ -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,
@@ -909,8 +913,7 @@ var DeckLayout = ({ layoutParts, toasts, overscroll, showHints, panels, onDismis
909
913
  layoutParts,
910
914
  part: "main",
911
915
  layoutMode,
912
- order: index * 2 + 1,
913
- last: index === layoutParts.main.length - 1
916
+ order: index * 2 + 1
914
917
  }))))), /* @__PURE__ */ React14.createElement("div", {
915
918
  role: "none",
916
919
  className: isSoloModeLoaded ? "relative bg-deck overflow-hidden" : "sr-only",
@@ -1309,19 +1312,36 @@ var DeckPlugin = ({ observability } = {}) => {
1309
1312
  }
1310
1313
  };
1311
1314
  const handleSetLocation = (next) => {
1315
+ const part = layout.values.layoutMode === "solo" ? "solo" : "main";
1316
+ const ids = openIds2(next, [
1317
+ part
1318
+ ]);
1312
1319
  if (attentionPlugin) {
1313
1320
  const attended = attentionPlugin.provides.attention.attended;
1314
1321
  const [attendedId] = Array.from(attended);
1315
- const ids = (layout.values.layoutMode === "deck" ? next.main : next.solo)?.map(({ id }) => id) ?? [];
1316
1322
  const isAttendedAvailable = !!attendedId && ids.includes(attendedId);
1317
1323
  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();
1324
+ const currentIds = location.values.active[part]?.map(({ id }) => id) ?? [];
1325
+ const attendedIndex = currentIds.indexOf(attendedId);
1326
+ const index = attendedIndex === -1 ? 0 : attendedIndex >= ids.length ? ids.length - 1 : attendedIndex;
1327
+ const nextAttended = next[part]?.[index].id;
1328
+ void intentPlugin?.provides.intent.dispatch({
1329
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1330
+ data: {
1331
+ id: nextAttended
1332
+ }
1322
1333
  });
1323
1334
  }
1324
1335
  }
1336
+ const current = openIds2(location.values.active, [
1337
+ part
1338
+ ]);
1339
+ const removed = current.filter((id) => !ids.includes(id));
1340
+ const closed = Array.from(/* @__PURE__ */ new Set([
1341
+ ...location.values.closed.filter((id) => !ids.includes(id)),
1342
+ ...removed
1343
+ ]));
1344
+ location.values.closed = closed;
1325
1345
  location.values.active = next;
1326
1346
  };
1327
1347
  return {
@@ -1434,11 +1454,11 @@ var DeckPlugin = ({ observability } = {}) => {
1434
1454
  filter: (node) => false,
1435
1455
  actions: () => [
1436
1456
  {
1437
- id: `${LayoutAction2.SET_LAYOUT_MODE}/fullscreen`,
1457
+ id: `${LayoutAction3.SET_LAYOUT_MODE}/fullscreen`,
1438
1458
  data: async () => {
1439
1459
  await intentPlugin?.provides.intent.dispatch({
1440
1460
  plugin: DECK_PLUGIN,
1441
- action: LayoutAction2.SET_LAYOUT_MODE,
1461
+ action: LayoutAction3.SET_LAYOUT_MODE,
1442
1462
  data: {
1443
1463
  layoutMode: "fullscreen"
1444
1464
  }
@@ -1501,27 +1521,47 @@ var DeckPlugin = ({ observability } = {}) => {
1501
1521
  intent: {
1502
1522
  resolver: (intent) => {
1503
1523
  switch (intent.action) {
1504
- case LayoutAction2.SET_LAYOUT: {
1524
+ case LayoutAction3.SET_LAYOUT: {
1505
1525
  return intent.data && handleSetLayout(intent.data);
1506
1526
  }
1507
- case LayoutAction2.SET_LAYOUT_MODE: {
1527
+ case LayoutAction3.SET_LAYOUT_MODE: {
1528
+ const setMode = (mode) => {
1529
+ const main = openIds2(location.values.active, [
1530
+ "main"
1531
+ ]);
1532
+ const solo = openIds2(location.values.active, [
1533
+ "solo"
1534
+ ]);
1535
+ const current = layout.values.layoutMode === "solo" ? solo : main;
1536
+ const next = mode === "solo" ? solo : [
1537
+ ...main,
1538
+ ...solo
1539
+ ];
1540
+ const removed = current.filter((id) => !next.includes(id));
1541
+ const closed = Array.from(/* @__PURE__ */ new Set([
1542
+ ...location.values.closed.filter((id) => !next.includes(id)),
1543
+ ...removed
1544
+ ]));
1545
+ location.values.closed = closed;
1546
+ layout.values.layoutMode = mode;
1547
+ };
1508
1548
  return batch(() => {
1509
1549
  if (!intent.data) {
1510
1550
  return;
1511
1551
  }
1512
1552
  if (intent.data?.revert) {
1513
- layout.values.layoutMode = layoutModeHistory.values.pop() ?? "solo";
1553
+ setMode(layoutModeHistory.values.pop() ?? "solo");
1514
1554
  return {
1515
1555
  data: true
1516
1556
  };
1517
1557
  }
1518
1558
  if (isLayoutMode(intent?.data?.layoutMode)) {
1519
1559
  layoutModeHistory.values.push(layout.values.layoutMode);
1520
- layout.values.layoutMode = intent.data.layoutMode;
1560
+ setMode(intent.data.layoutMode);
1521
1561
  } else {
1522
1562
  log.warn("Invalid layout mode", intent?.data?.layoutMode, {
1523
1563
  F: __dxlog_file,
1524
- L: 379,
1564
+ L: 409,
1525
1565
  S: void 0,
1526
1566
  C: (f, a) => f(...a)
1527
1567
  });
@@ -1531,9 +1571,11 @@ var DeckPlugin = ({ observability } = {}) => {
1531
1571
  };
1532
1572
  });
1533
1573
  }
1534
- case LayoutAction2.SCROLL_INTO_VIEW: {
1574
+ case LayoutAction3.SCROLL_INTO_VIEW: {
1535
1575
  layout.values.scrollIntoView = intent.data?.id ?? void 0;
1536
- return void 0;
1576
+ return {
1577
+ data: true
1578
+ };
1537
1579
  }
1538
1580
  case DeckAction.UPDATE_PLANK_SIZE: {
1539
1581
  const { id, size } = intent.data;
@@ -1575,7 +1617,7 @@ var DeckPlugin = ({ observability } = {}) => {
1575
1617
  return;
1576
1618
  }
1577
1619
  const processLayoutEntry = (partName, entryString, currentLayout) => {
1578
- const toggle = true;
1620
+ const toggle = false;
1579
1621
  const [id, path] = entryString.split(SLUG_PATH_SEPARATOR4);
1580
1622
  const layoutEntry = {
1581
1623
  id,
@@ -1616,7 +1658,7 @@ var DeckPlugin = ({ observability } = {}) => {
1616
1658
  intents: [
1617
1659
  newlyOpen.length > 0 ? [
1618
1660
  {
1619
- action: LayoutAction2.SCROLL_INTO_VIEW,
1661
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1620
1662
  data: {
1621
1663
  id: newlyOpen[0]
1622
1664
  }
@@ -1661,7 +1703,7 @@ var DeckPlugin = ({ observability } = {}) => {
1661
1703
  if (data.scrollIntoView && layout.values.layoutMode === "deck") {
1662
1704
  intents.push([
1663
1705
  {
1664
- action: LayoutAction2.SCROLL_INTO_VIEW,
1706
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1665
1707
  data: {
1666
1708
  id: data.id
1667
1709
  }
@@ -1731,13 +1773,8 @@ var DeckPlugin = ({ observability } = {}) => {
1731
1773
  return {
1732
1774
  data: true,
1733
1775
  intents: [
1776
+ // NOTE: The order of these is important.
1734
1777
  [
1735
- {
1736
- action: LayoutAction2.SET_LAYOUT_MODE,
1737
- data: {
1738
- layoutMode: "solo"
1739
- }
1740
- },
1741
1778
  {
1742
1779
  action: NavigationAction3.OPEN,
1743
1780
  data: {
@@ -1747,6 +1784,12 @@ var DeckPlugin = ({ observability } = {}) => {
1747
1784
  ]
1748
1785
  }
1749
1786
  }
1787
+ },
1788
+ {
1789
+ action: LayoutAction3.SET_LAYOUT_MODE,
1790
+ data: {
1791
+ layoutMode: "solo"
1792
+ }
1750
1793
  }
1751
1794
  ]
1752
1795
  ]
@@ -1755,9 +1798,10 @@ var DeckPlugin = ({ observability } = {}) => {
1755
1798
  return {
1756
1799
  data: true,
1757
1800
  intents: [
1801
+ // NOTE: The order of these is important.
1758
1802
  [
1759
1803
  {
1760
- action: LayoutAction2.SET_LAYOUT_MODE,
1804
+ action: LayoutAction3.SET_LAYOUT_MODE,
1761
1805
  data: {
1762
1806
  layoutMode: "deck"
1763
1807
  }
@@ -1784,7 +1828,7 @@ var DeckPlugin = ({ observability } = {}) => {
1784
1828
  }
1785
1829
  },
1786
1830
  {
1787
- action: LayoutAction2.SCROLL_INTO_VIEW,
1831
+ action: LayoutAction3.SCROLL_INTO_VIEW,
1788
1832
  data: {
1789
1833
  id: entryId
1790
1834
  }