@operad-io/tui 0.3.1 → 0.4.0
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/package.json +2 -2
- package/src/state.ts +49 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@opentui/core": "0.6.8",
|
|
11
|
-
"@operad-io/engine": "0.
|
|
11
|
+
"@operad-io/engine": "0.4.0"
|
|
12
12
|
},
|
|
13
13
|
"description": "operad: the terminal client",
|
|
14
14
|
"repository": {
|
package/src/state.ts
CHANGED
|
@@ -438,7 +438,15 @@ export interface TuiState {
|
|
|
438
438
|
* can start on it; the page's answer starts it. `noteFirst` starts at the
|
|
439
439
|
* first message, leaving the action's arguments at their defaults.
|
|
440
440
|
*/
|
|
441
|
-
readonly creating?:
|
|
441
|
+
readonly creating?:
|
|
442
|
+
| {
|
|
443
|
+
readonly parent: string;
|
|
444
|
+
readonly type: string;
|
|
445
|
+
readonly noteFirst?: boolean | undefined;
|
|
446
|
+
/** Go to the parent's main chat, named by its page, when it has one; else create. */
|
|
447
|
+
readonly mainFirst?: boolean | undefined;
|
|
448
|
+
}
|
|
449
|
+
| undefined;
|
|
442
450
|
/** Set when a section must be fetched. */
|
|
443
451
|
readonly sectionRequest?: TuiSectionRequest | undefined;
|
|
444
452
|
/** Grows each time a list cursor moves; the shell opens what it lands on. */
|
|
@@ -1603,19 +1611,33 @@ function applyObject(
|
|
|
1603
1611
|
updated = requestSection(updated, active);
|
|
1604
1612
|
}
|
|
1605
1613
|
const creating = updated.creating;
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
return creating.
|
|
1613
|
-
? startNote(updated, make.name)
|
|
1614
|
-
: startAction(updated, make.name);
|
|
1614
|
+
// A parent entered by start-chat waits for its page's section, which names its main chat.
|
|
1615
|
+
if (
|
|
1616
|
+
creating !== undefined &&
|
|
1617
|
+
previous.id === creating.parent &&
|
|
1618
|
+
(creating.mainFirst !== true || sections.length === 0)
|
|
1619
|
+
) {
|
|
1620
|
+
return startCreating(updated, creating, view.actions);
|
|
1615
1621
|
}
|
|
1616
1622
|
return updated;
|
|
1617
1623
|
}
|
|
1618
1624
|
|
|
1625
|
+
/** Ends a pending create on its parent: the first message, or the action's own input. */
|
|
1626
|
+
function startCreating(
|
|
1627
|
+
state: TuiState,
|
|
1628
|
+
creating: NonNullable<TuiState["creating"]>,
|
|
1629
|
+
actions: readonly ViewAction[],
|
|
1630
|
+
): TuiState {
|
|
1631
|
+
const updated: TuiState = { ...state, creating: undefined };
|
|
1632
|
+
const make = actions.find((action) => action.creates === creating.type);
|
|
1633
|
+
if (make === undefined) {
|
|
1634
|
+
return withNotice(updated, `${creating.parent} has no way to create a ${creating.type}`);
|
|
1635
|
+
}
|
|
1636
|
+
return creating.noteFirst === true
|
|
1637
|
+
? startNote(updated, make.name)
|
|
1638
|
+
: startAction(updated, make.name);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1619
1641
|
/** `c` on a tab of one object type: the palette, listing where a new one can be made. */
|
|
1620
1642
|
function createHere(state: TuiState): TuiState {
|
|
1621
1643
|
const info = state.tabs[state.active]?.types?.find((one) => one.parents !== undefined);
|
|
@@ -1753,11 +1775,20 @@ function applySection(
|
|
|
1753
1775
|
scroll: next.following ? bottom : Math.min(value.scroll, bottom),
|
|
1754
1776
|
};
|
|
1755
1777
|
});
|
|
1756
|
-
|
|
1778
|
+
const settled: TuiState = {
|
|
1757
1779
|
...updated,
|
|
1758
1780
|
sectionRequest:
|
|
1759
1781
|
state.sectionRequest?.sectionId === sectionId ? undefined : state.sectionRequest,
|
|
1760
1782
|
};
|
|
1783
|
+
const creating = settled.creating;
|
|
1784
|
+
if (creating?.mainFirst === true && creating.parent === objectId) {
|
|
1785
|
+
const main = content.data?.mainChat;
|
|
1786
|
+
if (typeof main === "string" && parseObjectId(main) !== undefined) {
|
|
1787
|
+
return openNamed({ ...settled, creating: undefined }, main);
|
|
1788
|
+
}
|
|
1789
|
+
return startCreating(settled, creating, object.actions);
|
|
1790
|
+
}
|
|
1791
|
+
return settled;
|
|
1761
1792
|
}
|
|
1762
1793
|
|
|
1763
1794
|
function applySectionError(
|
|
@@ -1780,11 +1811,16 @@ function applySectionError(
|
|
|
1780
1811
|
loading: false,
|
|
1781
1812
|
error: sanitize(message),
|
|
1782
1813
|
}));
|
|
1783
|
-
|
|
1814
|
+
const settled: TuiState = {
|
|
1784
1815
|
...updated,
|
|
1785
1816
|
sectionRequest:
|
|
1786
1817
|
state.sectionRequest?.sectionId === sectionId ? undefined : state.sectionRequest,
|
|
1787
1818
|
};
|
|
1819
|
+
const creating = settled.creating;
|
|
1820
|
+
// A page that cannot say its main chat starts a new one, as before.
|
|
1821
|
+
return creating?.mainFirst === true && creating.parent === objectId
|
|
1822
|
+
? startCreating(settled, creating, object?.actions ?? [])
|
|
1823
|
+
: settled;
|
|
1788
1824
|
}
|
|
1789
1825
|
|
|
1790
1826
|
/** Scrolls the open section; a page can ask for the section's next page. */
|
|
@@ -2962,7 +2998,7 @@ export function reduce(state: TuiState, event: TuiStateEvent): TuiState {
|
|
|
2962
2998
|
const opened = openNamed({ ...state, followPending: false }, event.parent);
|
|
2963
2999
|
return opened === state
|
|
2964
3000
|
? state
|
|
2965
|
-
: { ...opened, creating: { parent: event.parent, type: "chat", noteFirst: true } };
|
|
3001
|
+
: { ...opened, creating: { parent: event.parent, type: "chat", noteFirst: true, mainFirst: true } };
|
|
2966
3002
|
}
|
|
2967
3003
|
case "status":
|
|
2968
3004
|
if (stale(state, event.generation)) return state;
|