dirvi-lib 0.11.0-beta.5 → 0.11.0-beta.7

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.
Files changed (159) hide show
  1. package/dist/app/app-api.d.ts +7 -25
  2. package/dist/app/app-api.d.ts.map +1 -1
  3. package/dist/app/app-api.js +1 -11
  4. package/dist/app/index.d.ts +1 -0
  5. package/dist/app/index.d.ts.map +1 -1
  6. package/dist/app/index.js +1 -0
  7. package/dist/app/node-presentation.d.ts +13 -0
  8. package/dist/app/node-presentation.d.ts.map +1 -0
  9. package/dist/app/reducer/effect-to-action.d.ts +2 -2
  10. package/dist/app/reducer/effect-to-action.d.ts.map +1 -1
  11. package/dist/app/reducer/effect-to-action.js +87 -32
  12. package/dist/app/reducer/reducer-action.d.ts +12 -6
  13. package/dist/app/reducer/reducer-action.d.ts.map +1 -1
  14. package/dist/app/reducer/reducer.d.ts +4 -2
  15. package/dist/app/reducer/reducer.d.ts.map +1 -1
  16. package/dist/app/reducer/reducer.js +102 -68
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/input/application/intent-to-effect.d.ts +2 -2
  21. package/dist/input/application/intent-to-effect.d.ts.map +1 -1
  22. package/dist/input/application/intent-to-effect.js +9 -10
  23. package/dist/input/application/parse-ex-command.d.ts +22 -12
  24. package/dist/input/application/parse-ex-command.d.ts.map +1 -1
  25. package/dist/input/application/parse-ex-command.js +61 -65
  26. package/dist/input/application/parse-normal-command.d.ts +1 -1
  27. package/dist/input/application/parse-normal-command.d.ts.map +1 -1
  28. package/dist/input/domain/effect.d.ts +9 -5
  29. package/dist/input/domain/effect.d.ts.map +1 -1
  30. package/dist/state-and-nav/cursor.d.ts +89 -0
  31. package/dist/state-and-nav/cursor.d.ts.map +1 -0
  32. package/dist/state-and-nav/cursor.js +84 -0
  33. package/dist/{trees → state-and-nav}/fold-node/deprecated/fold-node.impl.d.ts +1 -1
  34. package/dist/state-and-nav/fold-node/deprecated/fold-node.impl.d.ts.map +1 -0
  35. package/dist/state-and-nav/fold-node/deprecated/fold-node.test.d.ts.map +1 -0
  36. package/dist/{trees → state-and-nav}/fold-node/deprecated/fold-node.test.js +2 -2
  37. package/dist/{trees → state-and-nav}/fold-node/deprecated/fold-node.types.d.ts +2 -2
  38. package/dist/state-and-nav/fold-node/deprecated/fold-node.types.d.ts.map +1 -0
  39. package/dist/{trees → state-and-nav}/fold-node/fold-node.impl.d.ts +3 -3
  40. package/dist/state-and-nav/fold-node/fold-node.impl.d.ts.map +1 -0
  41. package/dist/{trees → state-and-nav}/fold-node/fold-node.impl.js +1 -1
  42. package/dist/{trees → state-and-nav}/fold-node/fold-node.model.d.ts +1 -1
  43. package/dist/state-and-nav/fold-node/fold-node.model.d.ts.map +1 -0
  44. package/dist/{trees → state-and-nav}/fold-node/fold-node.types.d.ts +2 -2
  45. package/dist/state-and-nav/fold-node/fold-node.types.d.ts.map +1 -0
  46. package/dist/state-and-nav/fold-node/index.d.ts.map +1 -0
  47. package/dist/state-and-nav/index.d.ts +16 -0
  48. package/dist/state-and-nav/index.d.ts.map +1 -0
  49. package/dist/state-and-nav/index.js +6 -0
  50. package/dist/state-and-nav/nav/nav.ordered.impl.d.ts +12 -0
  51. package/dist/state-and-nav/nav/nav.ordered.impl.d.ts.map +1 -0
  52. package/dist/state-and-nav/nav/nav.ordered.impl.js +77 -0
  53. package/dist/state-and-nav/nav/nav.traversal.d.ts +11 -0
  54. package/dist/state-and-nav/nav/nav.traversal.d.ts.map +1 -0
  55. package/dist/state-and-nav/nav/nav.traversal.js +207 -0
  56. package/dist/{trees/nav-node/nav-node.types.d.ts → state-and-nav/nav/nav.types.d.ts} +32 -22
  57. package/dist/state-and-nav/nav/nav.types.d.ts.map +1 -0
  58. package/dist/state-and-nav/nav/nav.unordered.impl.d.ts +13 -0
  59. package/dist/state-and-nav/nav/nav.unordered.impl.d.ts.map +1 -0
  60. package/dist/state-and-nav/nav/nav.unordered.impl.js +77 -0
  61. package/dist/state-and-nav/state/state.impl.d.ts +9 -0
  62. package/dist/state-and-nav/state/state.impl.d.ts.map +1 -0
  63. package/dist/{trees → state-and-nav}/state/state.impl.js +62 -9
  64. package/dist/state-and-nav/state/state.schemas.d.ts +2 -0
  65. package/dist/state-and-nav/state/state.schemas.d.ts.map +1 -0
  66. package/dist/state-and-nav/state/state.schemas.js +39 -0
  67. package/dist/state-and-nav/state/state.types.d.ts +72 -0
  68. package/dist/state-and-nav/state/state.types.d.ts.map +1 -0
  69. package/dist/state-and-nav/tree/deprecated/tree-node.arb.d.ts.map +1 -0
  70. package/dist/state-and-nav/tree/deprecated/tree-node.arb.debug.test.d.ts.map +1 -0
  71. package/dist/state-and-nav/tree/deprecated/tree-node.impl.d.ts.map +1 -0
  72. package/dist/state-and-nav/tree/deprecated/tree-node.schemas.d.ts.map +1 -0
  73. package/dist/state-and-nav/tree/deprecated/tree-node.test.d.ts.map +1 -0
  74. package/dist/state-and-nav/tree/deprecated/tree-node.types.d.ts.map +1 -0
  75. package/dist/state-and-nav/tree/index.d.ts +7 -0
  76. package/dist/state-and-nav/tree/index.d.ts.map +1 -0
  77. package/dist/state-and-nav/tree/index.js +1 -0
  78. package/dist/state-and-nav/tree/tree-node.arb.d.ts +94 -0
  79. package/dist/state-and-nav/tree/tree-node.arb.d.ts.map +1 -0
  80. package/dist/state-and-nav/tree/tree-node.arb.debug.test.d.ts +2 -0
  81. package/dist/state-and-nav/tree/tree-node.arb.debug.test.d.ts.map +1 -0
  82. package/dist/state-and-nav/tree/tree-node.arb.debug.test.js +54 -0
  83. package/dist/state-and-nav/tree/tree-node.arb.js +188 -0
  84. package/dist/state-and-nav/tree/tree-node.model.d.ts +193 -0
  85. package/dist/state-and-nav/tree/tree-node.model.d.ts.map +1 -0
  86. package/dist/state-and-nav/tree/tree-node.model.js +110 -0
  87. package/dist/state-and-nav/tree/tree-node.test.d.ts +2 -0
  88. package/dist/state-and-nav/tree/tree-node.test.d.ts.map +1 -0
  89. package/dist/state-and-nav/tree/tree-node.test.js +234 -0
  90. package/dist/{trees/tree-node/tree-node.impl.d.ts → state-and-nav/tree/tree.impl.d.ts} +3 -3
  91. package/dist/state-and-nav/tree/tree.impl.d.ts.map +1 -0
  92. package/dist/{trees/tree-node/tree-node.impl.js → state-and-nav/tree/tree.impl.js} +19 -16
  93. package/dist/{trees/tree-node/tree-node.types.d.ts → state-and-nav/tree/tree.types.d.ts} +64 -44
  94. package/dist/state-and-nav/tree/tree.types.d.ts.map +1 -0
  95. package/dist/state-and-nav/tree/tree.types.js +1 -0
  96. package/package.json +1 -1
  97. package/dist/trees/cursor.d.ts +0 -59
  98. package/dist/trees/cursor.d.ts.map +0 -1
  99. package/dist/trees/cursor.js +0 -55
  100. package/dist/trees/fold-node/deprecated/fold-node.impl.d.ts.map +0 -1
  101. package/dist/trees/fold-node/deprecated/fold-node.test.d.ts.map +0 -1
  102. package/dist/trees/fold-node/deprecated/fold-node.types.d.ts.map +0 -1
  103. package/dist/trees/fold-node/fold-node.impl.d.ts.map +0 -1
  104. package/dist/trees/fold-node/fold-node.model.d.ts.map +0 -1
  105. package/dist/trees/fold-node/fold-node.types.d.ts.map +0 -1
  106. package/dist/trees/fold-node/index.d.ts.map +0 -1
  107. package/dist/trees/index.d.ts +0 -9
  108. package/dist/trees/index.d.ts.map +0 -1
  109. package/dist/trees/index.js +0 -8
  110. package/dist/trees/nav-node/nav-node.impl.d.ts +0 -29
  111. package/dist/trees/nav-node/nav-node.impl.d.ts.map +0 -1
  112. package/dist/trees/nav-node/nav-node.impl.js +0 -223
  113. package/dist/trees/nav-node/nav-node.types.d.ts.map +0 -1
  114. package/dist/trees/state/state.impl.d.ts +0 -8
  115. package/dist/trees/state/state.impl.d.ts.map +0 -1
  116. package/dist/trees/state/state.schemas.d.ts +0 -25
  117. package/dist/trees/state/state.schemas.d.ts.map +0 -1
  118. package/dist/trees/state/state.schemas.js +0 -17
  119. package/dist/trees/state/state.types.d.ts +0 -36
  120. package/dist/trees/state/state.types.d.ts.map +0 -1
  121. package/dist/trees/tree-node/deprecated/tree-node.arb.d.ts.map +0 -1
  122. package/dist/trees/tree-node/deprecated/tree-node.arb.debug.test.d.ts.map +0 -1
  123. package/dist/trees/tree-node/deprecated/tree-node.impl.d.ts.map +0 -1
  124. package/dist/trees/tree-node/deprecated/tree-node.schemas.d.ts.map +0 -1
  125. package/dist/trees/tree-node/deprecated/tree-node.test.d.ts.map +0 -1
  126. package/dist/trees/tree-node/deprecated/tree-node.types.d.ts.map +0 -1
  127. package/dist/trees/tree-node/index.d.ts +0 -5
  128. package/dist/trees/tree-node/index.d.ts.map +0 -1
  129. package/dist/trees/tree-node/index.js +0 -2
  130. package/dist/trees/tree-node/tree-node.arb.d.ts +0 -104
  131. package/dist/trees/tree-node/tree-node.arb.d.ts.map +0 -1
  132. package/dist/trees/tree-node/tree-node.arb.js +0 -188
  133. package/dist/trees/tree-node/tree-node.impl.d.ts.map +0 -1
  134. package/dist/trees/tree-node/tree-node.model.d.ts +0 -78
  135. package/dist/trees/tree-node/tree-node.model.d.ts.map +0 -1
  136. package/dist/trees/tree-node/tree-node.model.js +0 -37
  137. package/dist/trees/tree-node/tree-node.types.d.ts.map +0 -1
  138. /package/dist/{trees/fold-node/deprecated/fold-node.types.js → app/node-presentation.js} +0 -0
  139. /package/dist/{trees → state-and-nav}/fold-node/deprecated/fold-node.impl.js +0 -0
  140. /package/dist/{trees → state-and-nav}/fold-node/deprecated/fold-node.test.d.ts +0 -0
  141. /package/dist/{trees/fold-node → state-and-nav/fold-node/deprecated}/fold-node.types.js +0 -0
  142. /package/dist/{trees → state-and-nav}/fold-node/fold-node.model.js +0 -0
  143. /package/dist/{trees/nav-node/nav-node.types.js → state-and-nav/fold-node/fold-node.types.js} +0 -0
  144. /package/dist/{trees → state-and-nav}/fold-node/index.d.ts +0 -0
  145. /package/dist/{trees → state-and-nav}/fold-node/index.js +0 -0
  146. /package/dist/{trees/state/state.types.js → state-and-nav/nav/nav.types.js} +0 -0
  147. /package/dist/{trees/tree-node/deprecated/tree-node.types.js → state-and-nav/state/state.types.js} +0 -0
  148. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.arb.d.ts +0 -0
  149. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.arb.debug.test.d.ts +0 -0
  150. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.arb.debug.test.js +0 -0
  151. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.arb.js +0 -0
  152. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.impl.d.ts +0 -0
  153. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.impl.js +0 -0
  154. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.schemas.d.ts +0 -0
  155. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.schemas.js +0 -0
  156. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.test.d.ts +0 -0
  157. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.test.js +0 -0
  158. /package/dist/{trees/tree-node → state-and-nav/tree}/deprecated/tree-node.types.d.ts +0 -0
  159. /package/dist/{trees/tree-node → state-and-nav/tree/deprecated}/tree-node.types.js +0 -0
@@ -1,24 +1,76 @@
1
- function firstAvailableAdditionalFoldIndex(foldsApi, state) {
1
+ function firstAvailableAdditionalFoldIndex(foldsApi, folds) {
2
2
  let index = 1;
3
- while (foldsApi.hasAtIndex(state.folds, index)) {
3
+ while (foldsApi.hasAtIndex(folds, index)) {
4
4
  index += 1;
5
5
  }
6
6
  return index;
7
7
  }
8
- export function createReducer(treeNodeApi, foldsApi) {
8
+ export function createReducer(stateApi, navNodeApi) {
9
+ const { treeNodeApi, foldsApi, cursorApi } = stateApi;
10
+ /**
11
+ * Preserve the cursor if its position remains navigable. Otherwise, move it
12
+ * to a fold marker containing its representative entry, or to the nearest
13
+ * visible ancestor.
14
+ */
15
+ function reconcileCursor(state) {
16
+ const navigation = navNodeApi.from(stateApi.getRoot(state), stateApi.getFolds(state));
17
+ if (navigation === undefined || navigation.children === null) {
18
+ // StateApi guarantees that the root is a loaded branch.
19
+ throw new Error('Cannot navigate state: root is not a loaded branch.');
20
+ }
21
+ const cursor = stateApi.getCursor(state);
22
+ const positions = [
23
+ { path: [] },
24
+ ...navNodeApi.cursors(navigation.children),
25
+ ];
26
+ if (positions.some((position) => cursorApi.equal(position, cursor))) {
27
+ return state;
28
+ }
29
+ const path = cursorApi.getPath(cursor);
30
+ while (path.length > 0) {
31
+ const entryId = path.at(-1);
32
+ if (entryId !== undefined) {
33
+ const parentPath = path.slice(0, -1);
34
+ const parent = navNodeApi.getNodeAtPath(navigation.children, parentPath);
35
+ const foldEntry = parent?.entries.find((entry) => navNodeApi.entryIsFold(entry) &&
36
+ entry.folded.some((foldedEntry) => !navNodeApi.entryIsFold(foldedEntry) &&
37
+ foldedEntry.id === entryId));
38
+ if (foldEntry !== undefined && navNodeApi.entryIsFold(foldEntry)) {
39
+ const firstEntry = foldEntry.folded.find((entry) => !navNodeApi.entryIsFold(entry));
40
+ if (firstEntry !== undefined && !navNodeApi.entryIsFold(firstEntry)) {
41
+ const foldCursor = {
42
+ parentPath,
43
+ firstId: firstEntry.id,
44
+ };
45
+ if (positions.some((position) => cursorApi.equal(position, foldCursor))) {
46
+ return stateApi.update(state, { cursor: foldCursor }) ?? state;
47
+ }
48
+ }
49
+ }
50
+ const nodeCursor = { path: [...path] };
51
+ if (positions.some((position) => cursorApi.equal(position, nodeCursor))) {
52
+ return stateApi.update(state, { cursor: nodeCursor }) ?? state;
53
+ }
54
+ }
55
+ path.pop();
56
+ }
57
+ // The root cursor is always included in `positions`.
58
+ return stateApi.update(state, { cursor: { path: [] } }) ?? state;
59
+ }
60
+ function update(state, changes) {
61
+ const nextState = stateApi.update(state, changes);
62
+ return nextState === undefined ? state : reconcileCursor(nextState);
63
+ }
9
64
  return (state, action) => {
10
65
  switch (action.kind) {
11
66
  case 'changeCursor':
12
- return {
13
- ...state,
14
- cursor: action.cursor,
15
- };
67
+ return update(state, { cursor: action.cursor });
16
68
  case 'updateBranch': {
17
- const root = treeNodeApi.updateAtPath(state.root, action.path, (node) => {
69
+ const root = treeNodeApi.updateAtPath(stateApi.getRoot(state), action.path, (node) => {
18
70
  /*
19
- * Loading/unloading is a branch-only operation. TreeNodeApi can
20
- * structurally convert any node, but the application reducer must
21
- * not turn a leaf into a branch.
71
+ * Loading/unloading is a branch-only operation. TreeMethods can
72
+ * structurally convert any node, but the reducer must not turn a
73
+ * leaf into a branch.
22
74
  */
23
75
  if (treeNodeApi.kind(node) === 'leaf') {
24
76
  return undefined;
@@ -35,19 +87,14 @@ export function createReducer(treeNodeApi, foldsApi) {
35
87
  if (root === undefined || treeNodeApi.kind(root) !== 'loaded-branch') {
36
88
  return state;
37
89
  }
38
- return {
39
- ...state,
40
- root,
41
- };
90
+ return update(state, { root });
42
91
  }
43
92
  case 'setState': {
44
93
  // A newer update has already been applied.
45
94
  if (state !== action.oldState) {
46
95
  return state;
47
96
  }
48
- return {
49
- ...action.newState,
50
- };
97
+ return reconcileCursor(action.newState);
51
98
  }
52
99
  case 'addToFoldTree': {
53
100
  const entryId = action.path.at(-1);
@@ -55,82 +102,69 @@ export function createReducer(treeNodeApi, foldsApi) {
55
102
  return state;
56
103
  }
57
104
  const parentPath = action.path.slice(0, -1);
58
- const folds = foldsApi.hideEntryAtPath(state.folds, action.foldTreeIndex, parentPath, entryId);
105
+ const folds = foldsApi.hideEntryAtPath(stateApi.getFolds(state), action.foldTreeIndex, parentPath, entryId);
59
106
  if (folds === undefined) {
60
107
  return state;
61
108
  }
62
- return {
63
- ...state,
109
+ return update(state, {
64
110
  folds,
65
111
  cursor: action.cursor,
66
- };
112
+ });
67
113
  }
68
114
  case 'removeFromFoldTree': {
69
- // TODO: Change to show only entry at cursor. mirroring addToFoldTree
70
- const folds = foldsApi.showAllHiddenEntriesAtPath(state.folds, action.foldTreeIndex, action.path);
71
- if (folds === undefined) {
72
- return state;
115
+ let folds = stateApi.getFolds(state);
116
+ if (action.entryIds === null) {
117
+ const nextFolds = foldsApi.showAllHiddenEntriesAtPath(folds, action.foldTreeIndex, action.path);
118
+ if (nextFolds === undefined) {
119
+ return state;
120
+ }
121
+ folds = nextFolds;
122
+ }
123
+ else {
124
+ for (const entryId of action.entryIds) {
125
+ const nextFolds = foldsApi.showEntryAtPath(folds, action.foldTreeIndex, action.path, entryId);
126
+ if (nextFolds === undefined) {
127
+ return state;
128
+ }
129
+ folds = nextFolds;
130
+ }
73
131
  }
74
- return {
75
- ...state,
132
+ return update(state, {
76
133
  folds,
77
134
  cursor: action.cursor,
78
- };
135
+ });
79
136
  }
80
137
  case 'fold': {
81
- const folds = foldsApi.activateAtIndex(state.folds, action.foldTreeIndex);
82
- return folds === undefined
83
- ? state
84
- : {
85
- ...state,
86
- folds,
87
- };
138
+ const folds = foldsApi.activateAtIndex(stateApi.getFolds(state), action.foldTreeIndex);
139
+ return folds === undefined ? state : update(state, { folds });
88
140
  }
89
141
  case 'unfold': {
90
- const folds = foldsApi.deactivateAtIndex(state.folds, action.foldTreeIndex);
91
- return folds === undefined
92
- ? state
93
- : {
94
- ...state,
95
- folds,
96
- };
142
+ const folds = foldsApi.deactivateAtIndex(stateApi.getFolds(state), action.foldTreeIndex);
143
+ return folds === undefined ? state : update(state, { folds });
97
144
  }
98
145
  case 'toggleFold': {
99
- const folds = foldsApi.toggleActiveAtIndex(state.folds, action.foldTreeIndex);
100
- return folds === undefined
101
- ? state
102
- : {
103
- ...state,
104
- folds,
105
- };
146
+ const folds = foldsApi.toggleActiveAtIndex(stateApi.getFolds(state), action.foldTreeIndex);
147
+ return folds === undefined ? state : update(state, { folds });
106
148
  }
107
149
  case 'createFoldTree': {
108
- const index = firstAvailableAdditionalFoldIndex(foldsApi, state);
109
- const folds = foldsApi.setAdditionalFoldAtIndex(state.folds, index,
110
- // Obtain this through the actual TreeNodeApi root-ID operation.
111
- treeNodeApi.id(state.root), {
150
+ const currentFolds = stateApi.getFolds(state);
151
+ const index = firstAvailableAdditionalFoldIndex(foldsApi, currentFolds);
152
+ const folds = foldsApi.setAdditionalFoldAtIndex(currentFolds, index,
153
+ // Obtain this through the actual TreeMethods root-ID operation.
154
+ treeNodeApi.id(stateApi.getRoot(state)), {
112
155
  name: action.name,
113
156
  description: null,
114
157
  });
115
- return folds === undefined
116
- ? state
117
- : {
118
- ...state,
119
- folds,
120
- };
158
+ return folds === undefined ? state : update(state, { folds });
121
159
  }
122
160
  case 'deleteFoldTree': {
123
- const index = foldsApi.getIndexByName(state.folds, action.name);
161
+ const currentFolds = stateApi.getFolds(state);
162
+ const index = foldsApi.getIndexByName(currentFolds, action.name);
124
163
  if (index === undefined || index === 0) {
125
164
  return state;
126
165
  }
127
- const folds = foldsApi.removeAdditionalFoldAtIndex(state.folds, index);
128
- return folds === undefined
129
- ? state
130
- : {
131
- ...state,
132
- folds,
133
- };
166
+ const folds = foldsApi.removeAdditionalFoldAtIndex(currentFolds, index);
167
+ return folds === undefined ? state : update(state, { folds });
134
168
  }
135
169
  default: {
136
170
  const _exhaustive = action;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './trees/index.js';
1
+ export * from './state-and-nav/index.js';
2
2
  export * from './feedback/index.js';
3
3
  export * from './app/index.js';
4
4
  export * from './input/application/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,8BAA8B,CAAC;AAE7C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AAEzC,cAAc,qBAAqB,CAAC;AAEpC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,8BAA8B,CAAC;AAE7C,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './trees/index.js';
1
+ export * from './state-and-nav/index.js';
2
2
  export * from './feedback/index.js';
3
3
  export * from './app/index.js';
4
4
  export * from './input/application/index.js';
@@ -1,4 +1,4 @@
1
- import type { CursorApi, SerializableKey, State, StateApi, TreeNodeApi } from '../../trees/index.js';
1
+ import type { SerializableKey, State, StateApi } from '../../state-and-nav/index.js';
2
2
  import type { Effect, Intent } from '../domain/index.js';
3
3
  /**
4
4
  * Converts a user intent and the current tree state into an effect.
@@ -10,5 +10,5 @@ import type { Effect, Intent } from '../domain/index.js';
10
10
  * @typeParam Value - Application-owned data stored in each tree node.
11
11
  */
12
12
  export type IntentToEffect<Id extends SerializableKey, Value> = (intent: Intent, state: State<Id, Value>) => Effect<Id, Value> | undefined;
13
- export declare function createIntentToEffect<Id extends SerializableKey, Value>(stateApi: StateApi<Id, Value>, cursorApi: CursorApi<Id>, treeNodeApi: TreeNodeApi<Id, Value>): IntentToEffect<Id, Value>;
13
+ export declare function createIntentToEffect<Id extends SerializableKey, Value>(registeredCommands: ReadonlySet<string>, stateApi: StateApi<Id, Value>): IntentToEffect<Id, Value>;
14
14
  //# sourceMappingURL=intent-to-effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"intent-to-effect.d.ts","sourceRoot":"","sources":["../../../src/input/application/intent-to-effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,KAAK,EACL,QAAQ,EACR,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAKvE;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAAI,CAC9D,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KACpB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;AAEnC,wBAAgB,oBAAoB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EACpE,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,EAC7B,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,GAClC,cAAc,CAAC,EAAE,EAAE,KAAK,CAAC,CAkE3B"}
1
+ {"version":3,"file":"intent-to-effect.d.ts","sourceRoot":"","sources":["../../../src/input/application/intent-to-effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,KAAK,EACL,QAAQ,EACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAKvE;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAAI,CAC9D,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KACpB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;AAEnC,wBAAgB,oBAAoB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EACpE,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAC,EACvC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,GAC5B,cAAc,CAAC,EAAE,EAAE,KAAK,CAAC,CAgE3B"}
@@ -1,14 +1,14 @@
1
1
  import { parseExCommand } from './parse-ex-command.js';
2
2
  import { parseNormalCommand } from './parse-normal-command.js';
3
- export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
3
+ export function createIntentToEffect(registeredCommands, stateApi) {
4
4
  return (intent, state) => {
5
5
  switch (intent.intentType) {
6
6
  case 'setNormalBuffer':
7
7
  return normalBufferToEffectResult(intent.normalBuffer);
8
8
  case 'normalRight':
9
- return normalInteractRightToEffect(state, stateApi, cursorApi, treeNodeApi);
9
+ return normalInteractRightToEffect(state, stateApi);
10
10
  case 'normalLeft':
11
- return normalInteractLeftToEffect(state, cursorApi);
11
+ return normalInteractLeftToEffect(state, stateApi);
12
12
  case 'normalDown':
13
13
  return dispatchAction({
14
14
  effectActionType: 'nextEntry',
@@ -42,7 +42,7 @@ export function createIntentToEffect(stateApi, cursorApi, treeNodeApi) {
42
42
  },
43
43
  };
44
44
  case 'executeCommandLine':
45
- return (parseExCommand(intent.commandLine) ?? {
45
+ return (parseExCommand(intent.commandLine, registeredCommands) ?? {
46
46
  effectType: 'setInputState',
47
47
  inputState: {
48
48
  inputMode: 'normal',
@@ -106,16 +106,16 @@ function normalBufferToEffectResult(updatedNormalBuffer) {
106
106
  * - An open branch dispatches an action that closes/unloads its children.
107
107
  * - A leaf has no right-interaction effect.
108
108
  */
109
- function normalInteractRightToEffect(state, stateApi, cursorApi, treeNodeApi) {
109
+ function normalInteractRightToEffect(state, stateApi) {
110
110
  const currentEntry = stateApi.getNodeAtCursor(state);
111
111
  if (currentEntry === undefined) {
112
112
  return undefined;
113
113
  }
114
- const path = cursorApi.getPath(state.cursor);
114
+ const path = stateApi.cursorPath(state);
115
115
  if (path === undefined) {
116
116
  return undefined;
117
117
  }
118
- switch (treeNodeApi.kind(currentEntry)) {
118
+ switch (stateApi.treeNodeApi.kind(currentEntry)) {
119
119
  case 'unloaded-branch':
120
120
  return {
121
121
  effectType: 'loadBranchEntries',
@@ -137,9 +137,8 @@ function normalInteractRightToEffect(state, stateApi, cursorApi, treeNodeApi) {
137
137
  * Left from the root has no effect. Otherwise dispatch navigation to the
138
138
  * parent entry.
139
139
  */
140
- function normalInteractLeftToEffect(state, cursorApi) {
141
- const path = cursorApi.getPath(state.cursor);
142
- if (path === undefined || path.length === 0) {
140
+ function normalInteractLeftToEffect(state, stateApi) {
141
+ if (stateApi.isCursorRoot(state)) {
143
142
  return undefined;
144
143
  }
145
144
  return dispatchAction({
@@ -1,22 +1,30 @@
1
- import type { SerializableKey } from '../../trees/index.js';
1
+ import type { SerializableKey } from '../../state-and-nav/index.js';
2
2
  import type { Effect } from '../domain/index.js';
3
3
  /**
4
4
  * Parses a Vim-style Ex command line into an application effect.
5
5
  *
6
- * Leading and trailing whitespace is removed, and all consecutive leading `:`
7
- * characters are removed before parsing. The remaining text is split on one or
8
- * more whitespace characters:
6
+ * Leading and trailing whitespace is removed, followed by all consecutive
7
+ * leading `:` characters. The remaining text is split on one or more
8
+ * whitespace characters:
9
9
  *
10
10
  * - The first token is treated as the command name.
11
- * - All remaining tokens are passed to the command-specific parser as
12
- * `commandArgs`.
11
+ * - All remaining tokens are treated as command arguments.
12
+ *
13
+ * Registered user commands are matched by exact name before built-in commands,
14
+ * allowing them to override built-ins. A match produces a `userExCommand`
15
+ * effect containing the registered name and argument tokens. This function
16
+ * neither looks up nor executes the registered callback.
17
+ *
18
+ * Otherwise, the command is interpreted as a built-in, with its arguments
19
+ * passed to the command-specific parser where applicable.
13
20
  *
14
21
  * Parsing is token-based and does not support quoted or escaped arguments.
15
22
  * Consequently, whitespace within an argument cannot currently be preserved.
16
- * Command-specific parsers are responsible for validating their arguments.
23
+ * Built-in argument validation is handled by the command-specific parsers;
24
+ * registered user-command arguments are forwarded without validation.
17
25
  *
18
- * An empty command line produces `undefined`. An unknown command produces an
19
- * `unrecognizedCommand` effect containing the original `commandLine`.
26
+ * An empty command produces `undefined`. An unknown command produces an
27
+ * `emitError` effect whose message includes the original `commandLine`.
20
28
  *
21
29
  * Command parsing is independent of the concrete tree-node value type, but the
22
30
  * generic parameters allow its result to compose with the application's
@@ -24,9 +32,11 @@ import type { Effect } from '../domain/index.js';
24
32
  *
25
33
  * @typeParam Id - The sibling-unique tree-node ID type.
26
34
  * @typeParam Value - Application-owned data stored in each tree node.
27
- * @param commandLine - The raw Ex command line, optionally prefixed with one
28
- * or more `:` characters.
35
+ * @param commandLine - The raw Ex command line, whitespace before or after,
36
+ * optionally prefixed with one or more `:` characters.
37
+ * @param registeredCommands - Registered user-command names that take
38
+ * precedence over built-in commands.
29
39
  * @returns The parsed application effect, or `undefined` for an empty command.
30
40
  */
31
- export declare function parseExCommand<Id extends SerializableKey, Value>(commandLine: string): Effect<Id, Value> | undefined;
41
+ export declare function parseExCommand<Id extends SerializableKey, Value>(commandLine: string, registeredCommands: ReadonlySet<string>): Effect<Id, Value> | undefined;
32
42
  //# sourceMappingURL=parse-ex-command.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-ex-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-ex-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmKjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAC9D,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CA4D/B"}
1
+ {"version":3,"file":"parse-ex-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-ex-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA6IjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,cAAc,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAC9D,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAC,GACtC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAoE/B"}
@@ -1,25 +1,23 @@
1
- const DEFAULT_VIEW_NAME = 'default';
1
+ // const DEFAULT_VIEW_NAME = 'default';
2
2
  const DEFAULT_FOLD_TREE_NAME = 'default';
3
3
  function parseAppCommand(commandArgs) {
4
4
  const [firstArgument, ...remainingArguments] = commandArgs;
5
+ const badArgs = {
6
+ effectType: 'emitError',
7
+ message: `Unrecognized command arguments: app ${commandArgs.join(' ')}`,
8
+ };
5
9
  switch (firstArgument) {
6
10
  case 'list':
7
11
  return commandArgs.length === 1
8
12
  ? {
9
13
  effectType: 'listApps',
10
14
  }
11
- : {
12
- effectType: 'unrecognizedCommand',
13
- commandLine: `app ${commandArgs.join(' ')}`,
14
- };
15
+ : badArgs;
15
16
  case 'open':
16
17
  case 'switch': {
17
18
  const [appId, input] = remainingArguments;
18
19
  if (appId === undefined || remainingArguments.length > 2) {
19
- return {
20
- effectType: 'unrecognizedCommand',
21
- commandLine: `app ${commandArgs.join(' ')}`,
22
- };
20
+ return badArgs;
23
21
  }
24
22
  return {
25
23
  effectType: 'switchApp',
@@ -29,10 +27,7 @@ function parseAppCommand(commandArgs) {
29
27
  }
30
28
  default: {
31
29
  if (firstArgument === undefined || remainingArguments.length > 1) {
32
- return {
33
- effectType: 'unrecognizedCommand',
34
- commandLine: `app ${commandArgs.join(' ')}`,
35
- };
30
+ return badArgs;
36
31
  }
37
32
  const input = remainingArguments[0];
38
33
  return {
@@ -45,22 +40,20 @@ function parseAppCommand(commandArgs) {
45
40
  }
46
41
  function parseFoldCommand(commandArgs) {
47
42
  const [subcommand, name] = commandArgs;
43
+ const badArgs = {
44
+ effectType: 'emitError',
45
+ message: `Unrecognized command arguments: fold ${commandArgs.join(' ')}`,
46
+ };
48
47
  switch (subcommand) {
49
48
  case 'list':
50
49
  return commandArgs.length === 1
51
50
  ? {
52
51
  effectType: 'listFolds',
53
52
  }
54
- : {
55
- effectType: 'unrecognizedCommand',
56
- commandLine: `fold ${commandArgs.join(' ')}`,
57
- };
53
+ : badArgs;
58
54
  case 'create':
59
55
  return name === undefined || commandArgs.length !== 2
60
- ? {
61
- effectType: 'unrecognizedCommand',
62
- commandLine: `fold ${commandArgs.join(' ')}`,
63
- }
56
+ ? badArgs
64
57
  : {
65
58
  effectType: 'dispatchEffectAction',
66
59
  action: {
@@ -70,10 +63,7 @@ function parseFoldCommand(commandArgs) {
70
63
  };
71
64
  case 'delete':
72
65
  return name === undefined || commandArgs.length !== 2
73
- ? {
74
- effectType: 'unrecognizedCommand',
75
- commandLine: `fold ${commandArgs.join(' ')}`,
76
- }
66
+ ? badArgs
77
67
  : {
78
68
  effectType: 'dispatchEffectAction',
79
69
  action: {
@@ -84,10 +74,7 @@ function parseFoldCommand(commandArgs) {
84
74
  case 'enable':
85
75
  case 'close':
86
76
  return commandArgs.length > 2
87
- ? {
88
- effectType: 'unrecognizedCommand',
89
- commandLine: `fold ${commandArgs.join(' ')}`,
90
- }
77
+ ? badArgs
91
78
  : {
92
79
  effectType: 'dispatchEffectAction',
93
80
  action: {
@@ -101,10 +88,7 @@ function parseFoldCommand(commandArgs) {
101
88
  case 'disable':
102
89
  case 'open':
103
90
  return commandArgs.length > 2
104
- ? {
105
- effectType: 'unrecognizedCommand',
106
- commandLine: `fold ${commandArgs.join(' ')}`,
107
- }
91
+ ? badArgs
108
92
  : {
109
93
  effectType: 'dispatchEffectAction',
110
94
  action: {
@@ -117,10 +101,7 @@ function parseFoldCommand(commandArgs) {
117
101
  };
118
102
  case 'toggle':
119
103
  return commandArgs.length > 2
120
- ? {
121
- effectType: 'unrecognizedCommand',
122
- commandLine: `fold ${commandArgs.join(' ')}`,
123
- }
104
+ ? badArgs
124
105
  : {
125
106
  effectType: 'dispatchEffectAction',
126
107
  action: {
@@ -132,29 +113,34 @@ function parseFoldCommand(commandArgs) {
132
113
  },
133
114
  };
134
115
  default:
135
- return {
136
- effectType: 'unrecognizedCommand',
137
- commandLine: `fold ${commandArgs.join(' ')}`,
138
- };
116
+ return badArgs;
139
117
  }
140
118
  }
141
119
  /**
142
120
  * Parses a Vim-style Ex command line into an application effect.
143
121
  *
144
- * Leading and trailing whitespace is removed, and all consecutive leading `:`
145
- * characters are removed before parsing. The remaining text is split on one or
146
- * more whitespace characters:
122
+ * Leading and trailing whitespace is removed, followed by all consecutive
123
+ * leading `:` characters. The remaining text is split on one or more
124
+ * whitespace characters:
147
125
  *
148
126
  * - The first token is treated as the command name.
149
- * - All remaining tokens are passed to the command-specific parser as
150
- * `commandArgs`.
127
+ * - All remaining tokens are treated as command arguments.
128
+ *
129
+ * Registered user commands are matched by exact name before built-in commands,
130
+ * allowing them to override built-ins. A match produces a `userExCommand`
131
+ * effect containing the registered name and argument tokens. This function
132
+ * neither looks up nor executes the registered callback.
133
+ *
134
+ * Otherwise, the command is interpreted as a built-in, with its arguments
135
+ * passed to the command-specific parser where applicable.
151
136
  *
152
137
  * Parsing is token-based and does not support quoted or escaped arguments.
153
138
  * Consequently, whitespace within an argument cannot currently be preserved.
154
- * Command-specific parsers are responsible for validating their arguments.
139
+ * Built-in argument validation is handled by the command-specific parsers;
140
+ * registered user-command arguments are forwarded without validation.
155
141
  *
156
- * An empty command line produces `undefined`. An unknown command produces an
157
- * `unrecognizedCommand` effect containing the original `commandLine`.
142
+ * An empty command produces `undefined`. An unknown command produces an
143
+ * `emitError` effect whose message includes the original `commandLine`.
158
144
  *
159
145
  * Command parsing is independent of the concrete tree-node value type, but the
160
146
  * generic parameters allow its result to compose with the application's
@@ -162,16 +148,25 @@ function parseFoldCommand(commandArgs) {
162
148
  *
163
149
  * @typeParam Id - The sibling-unique tree-node ID type.
164
150
  * @typeParam Value - Application-owned data stored in each tree node.
165
- * @param commandLine - The raw Ex command line, optionally prefixed with one
166
- * or more `:` characters.
151
+ * @param commandLine - The raw Ex command line, whitespace before or after,
152
+ * optionally prefixed with one or more `:` characters.
153
+ * @param registeredCommands - Registered user-command names that take
154
+ * precedence over built-in commands.
167
155
  * @returns The parsed application effect, or `undefined` for an empty command.
168
156
  */
169
- export function parseExCommand(commandLine) {
157
+ export function parseExCommand(commandLine, registeredCommands) {
170
158
  const command = commandLine.trim().replace(/^:+/, '');
171
159
  if (command === '') {
172
160
  return undefined;
173
161
  }
174
162
  const [commandName, ...commandArgs] = command.split(/\s+/);
163
+ if (commandName !== undefined && registeredCommands.has(commandName)) {
164
+ return {
165
+ effectType: 'userExCommand',
166
+ name: commandName,
167
+ args: commandArgs,
168
+ };
169
+ }
175
170
  switch (commandName) {
176
171
  case 'q':
177
172
  return {
@@ -186,21 +181,22 @@ export function parseExCommand(commandLine) {
186
181
  return {
187
182
  effectType: 'emitVisibleLeavesPaths',
188
183
  };
189
- case 'mkview!':
190
- return {
191
- effectType: 'saveView',
192
- name: commandArgs[0] || DEFAULT_VIEW_NAME,
193
- overwrite: true,
194
- };
195
- case 'loadview':
196
- return {
197
- effectType: 'loadView',
198
- name: commandArgs[0] || DEFAULT_VIEW_NAME,
199
- };
184
+ // case 'mkview!':
185
+ // return {
186
+ // effectType: 'saveView',
187
+ // name: commandArgs[0] || DEFAULT_VIEW_NAME,
188
+ // overwrite: true,
189
+ // };
190
+ //
191
+ // case 'loadview':
192
+ // return {
193
+ // effectType: 'loadView',
194
+ // name: commandArgs[0] || DEFAULT_VIEW_NAME,
195
+ // };
200
196
  default:
201
197
  return {
202
- effectType: 'unrecognizedCommand',
203
- commandLine,
198
+ effectType: 'emitError',
199
+ message: `Unrecognized command: "${commandLine}"`,
204
200
  };
205
201
  }
206
202
  /*
@@ -1,4 +1,4 @@
1
- import type { SerializableKey } from '../../trees/index.js';
1
+ import type { SerializableKey } from '../../state-and-nav/index.js';
2
2
  import type { EffectAction } from '../domain/index.js';
3
3
  export type ParseNormalCommandResult<Id extends SerializableKey, Value> = {
4
4
  kind: 'incomplete';
@@ -1 +1 @@
1
- {"version":3,"file":"parse-normal-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-normal-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOvD,MAAM,MAAM,wBAAwB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAClE;IACE,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;CACjC,GACD;IACE,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AAEN,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAClE,YAAY,EAAE,MAAM,GACnB,wBAAwB,CAAC,EAAE,EAAE,KAAK,CAAC,CAwCrC"}
1
+ {"version":3,"file":"parse-normal-command.d.ts","sourceRoot":"","sources":["../../../src/input/application/parse-normal-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAOvD,MAAM,MAAM,wBAAwB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,IAClE;IACE,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;CACjC,GACD;IACE,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AAEN,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,eAAe,EAAE,KAAK,EAClE,YAAY,EAAE,MAAM,GACnB,wBAAwB,CAAC,EAAE,EAAE,KAAK,CAAC,CAwCrC"}