@ecsplico/editor 3.1.1 → 3.3.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.
Files changed (267) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/adapters/direct-ai.d.ts +36 -0
  3. package/dist/adapters/direct-ai.js +169 -0
  4. package/dist/adapters/direct-ai.js.map +1 -0
  5. package/dist/adapters/memory.js.map +1 -1
  6. package/dist/code/CodeSurface.vue.d.ts +1 -1
  7. package/dist/core/block-drag.js +3 -0
  8. package/dist/core/block-drag.js.map +1 -1
  9. package/dist/core/block-transfer.d.ts +44 -0
  10. package/dist/core/block-transfer.js +68 -0
  11. package/dist/core/block-transfer.js.map +1 -0
  12. package/dist/core/commands.js +5 -0
  13. package/dist/core/commands.js.map +1 -1
  14. package/dist/core/core-feature.d.ts +4 -1
  15. package/dist/core/core-feature.js +8 -3
  16. package/dist/core/core-feature.js.map +1 -1
  17. package/dist/core/editor-ui.d.ts +3 -1
  18. package/dist/core/editor-ui.js.map +1 -1
  19. package/dist/core/extension-points.d.ts +17 -1
  20. package/dist/core/feature.d.ts +6 -1
  21. package/dist/core/feature.js.map +1 -1
  22. package/dist/core/index.d.ts +4 -2
  23. package/dist/core/index.js +3 -2
  24. package/dist/core/schema/index.d.ts +24 -3
  25. package/dist/core/schema/index.js +21 -4
  26. package/dist/core/schema/index.js.map +1 -1
  27. package/dist/core/surface-session.js +3 -1
  28. package/dist/core/surface-session.js.map +1 -1
  29. package/dist/core/toolbar-items.js +1 -1
  30. package/dist/core/toolbar-items.js.map +1 -1
  31. package/dist/document/DocumentSurface.vue.d.ts +1 -1
  32. package/dist/features/ai/agent-op-review.js +1 -1
  33. package/dist/features/ai/agent-ops.js +2 -2
  34. package/dist/features/ai/ai-apply.js +1 -1
  35. package/dist/features/ai/assistant.js +1 -1
  36. package/dist/features/ai/components/AiSelectionMenu.js +2 -2
  37. package/dist/features/ai/components/AiSidebar.js +2 -2
  38. package/dist/features/ai/components/SettingsAiTab.js +1 -1
  39. package/dist/features/ai/components/SettingsModelProfiles.js +1 -1
  40. package/dist/features/ai/document-chat-model.js +1 -1
  41. package/dist/features/ai/document-chat.js +2 -2
  42. package/dist/features/ai/ghost-autocomplete.js +1 -1
  43. package/dist/features/ai/index.d.ts +4 -3
  44. package/dist/features/ai/index.js +6 -5
  45. package/dist/features/ai/protocol/complete.d.ts +19 -0
  46. package/dist/features/ai/protocol/complete.js +27 -1
  47. package/dist/features/ai/protocol/complete.js.map +1 -1
  48. package/dist/features/ai/protocol/generate.d.ts +95 -0
  49. package/dist/features/ai/protocol/generate.js +58 -0
  50. package/dist/features/ai/protocol/generate.js.map +1 -0
  51. package/dist/features/ai/protocol/index.d.ts +4 -3
  52. package/dist/features/ai/protocol/index.js +6 -5
  53. package/dist/features/ai/protocol/tasks.d.ts +3 -1
  54. package/dist/features/ai/protocol/tasks.js +74 -2
  55. package/dist/features/ai/protocol/tasks.js.map +1 -1
  56. package/dist/features/ai/react/AiSelectionMenu.js +2 -2
  57. package/dist/features/ai/react/AiSidebar.js +2 -2
  58. package/dist/features/ai/react/SettingsAiTab.js +1 -1
  59. package/dist/features/ai/react/SettingsModelProfiles.js +1 -1
  60. package/dist/features/ai/selection-flow.js +1 -1
  61. package/dist/features/ai/sidebar-flow.js +1 -1
  62. package/dist/features/block-ui/block-actions.d.ts +19 -3
  63. package/dist/features/block-ui/block-actions.js +49 -3
  64. package/dist/features/block-ui/block-actions.js.map +1 -1
  65. package/dist/features/block-ui/components/BlockActionsOverlay.js +24 -13
  66. package/dist/features/block-ui/components/BlockActionsOverlay.js.map +1 -1
  67. package/dist/features/block-ui/components/BlockActionsOverlay.vue.d.ts +12 -5
  68. package/dist/features/block-ui/components/BlockUi.js +52 -20
  69. package/dist/features/block-ui/components/BlockUi.js.map +1 -1
  70. package/dist/features/block-ui/components/BlockUi.vue.d.ts +6 -4
  71. package/dist/features/block-ui/feature.d.ts +8 -2
  72. package/dist/features/block-ui/feature.js +7 -2
  73. package/dist/features/block-ui/feature.js.map +1 -1
  74. package/dist/features/block-ui/index.d.ts +3 -2
  75. package/dist/features/block-ui/index.js +2 -2
  76. package/dist/features/block-ui/react/BlockActionsOverlay.d.ts +14 -7
  77. package/dist/features/block-ui/react/BlockActionsOverlay.js +25 -13
  78. package/dist/features/block-ui/react/BlockActionsOverlay.js.map +1 -1
  79. package/dist/features/block-ui/react/BlockUi.d.ts +6 -4
  80. package/dist/features/block-ui/react/BlockUi.js +43 -15
  81. package/dist/features/block-ui/react/BlockUi.js.map +1 -1
  82. package/dist/features/block-ui/react.d.ts +4 -2
  83. package/dist/features/block-ui/react.js +3 -3
  84. package/dist/features/block-ui/react.js.map +1 -1
  85. package/dist/features/block-ui/vue.d.ts +4 -2
  86. package/dist/features/block-ui/vue.js +3 -3
  87. package/dist/features/block-ui/vue.js.map +1 -1
  88. package/dist/features/composites/baskets.d.ts +27 -0
  89. package/dist/features/composites/baskets.js +46 -0
  90. package/dist/features/composites/baskets.js.map +1 -0
  91. package/dist/features/composites/components/CompositeBasketMenu.js +97 -0
  92. package/dist/features/composites/components/CompositeBasketMenu.js.map +1 -0
  93. package/dist/features/composites/components/CompositeChrome.js +79 -23
  94. package/dist/features/composites/components/CompositeChrome.js.map +1 -1
  95. package/dist/features/composites/components/CompositeView.js +21 -2
  96. package/dist/features/composites/components/CompositeView.js.map +1 -1
  97. package/dist/features/composites/components/DerivationBadge.js +12 -3
  98. package/dist/features/composites/components/DerivationBadge.js.map +1 -1
  99. package/dist/features/composites/components/FocusChip.js +53 -0
  100. package/dist/features/composites/components/FocusChip.js.map +1 -0
  101. package/dist/features/composites/components/FocusChip.vue.d.ts +14 -0
  102. package/dist/features/composites/components/SettingsEditingTab.js +40 -4
  103. package/dist/features/composites/components/SettingsEditingTab.js.map +1 -1
  104. package/dist/features/composites/derivation.d.ts +2 -1
  105. package/dist/features/composites/derivation.js +5 -1
  106. package/dist/features/composites/derivation.js.map +1 -1
  107. package/dist/features/composites/derived-chrome.js +13 -3
  108. package/dist/features/composites/derived-chrome.js.map +1 -1
  109. package/dist/features/composites/feature.d.ts +7 -1
  110. package/dist/features/composites/feature.js +107 -23
  111. package/dist/features/composites/feature.js.map +1 -1
  112. package/dist/features/composites/focus.d.ts +38 -0
  113. package/dist/features/composites/focus.js +86 -0
  114. package/dist/features/composites/focus.js.map +1 -0
  115. package/dist/features/composites/index.d.ts +7 -3
  116. package/dist/features/composites/index.js +7 -3
  117. package/dist/features/composites/kinds.d.ts +6 -1
  118. package/dist/features/composites/kinds.js.map +1 -1
  119. package/dist/features/composites/merge.d.ts +24 -0
  120. package/dist/features/composites/merge.js +47 -0
  121. package/dist/features/composites/merge.js.map +1 -0
  122. package/dist/features/composites/meta-keys.d.ts +4 -0
  123. package/dist/features/composites/meta-keys.js +8 -4
  124. package/dist/features/composites/meta-keys.js.map +1 -1
  125. package/dist/features/composites/nodes.d.ts +15 -2
  126. package/dist/features/composites/nodes.js +61 -5
  127. package/dist/features/composites/nodes.js.map +1 -1
  128. package/dist/features/composites/outline.d.ts +4 -0
  129. package/dist/features/composites/outline.js +3 -0
  130. package/dist/features/composites/outline.js.map +1 -1
  131. package/dist/features/composites/react/CompositeBasketMenu.js +88 -0
  132. package/dist/features/composites/react/CompositeBasketMenu.js.map +1 -0
  133. package/dist/features/composites/react/CompositeChrome.js +52 -4
  134. package/dist/features/composites/react/CompositeChrome.js.map +1 -1
  135. package/dist/features/composites/react/CompositeView.js +15 -2
  136. package/dist/features/composites/react/CompositeView.js.map +1 -1
  137. package/dist/features/composites/react/DerivationBadge.js +10 -1
  138. package/dist/features/composites/react/DerivationBadge.js.map +1 -1
  139. package/dist/features/composites/react/FocusChip.d.ts +11 -0
  140. package/dist/features/composites/react/FocusChip.js +50 -0
  141. package/dist/features/composites/react/FocusChip.js.map +1 -0
  142. package/dist/features/composites/react/SettingsEditingTab.js +36 -1
  143. package/dist/features/composites/react/SettingsEditingTab.js.map +1 -1
  144. package/dist/features/composites/react.d.ts +2 -1
  145. package/dist/features/composites/react.js +3 -1
  146. package/dist/features/composites/react.js.map +1 -1
  147. package/dist/features/composites/schema.d.ts +5 -3
  148. package/dist/features/composites/schema.js +8 -4
  149. package/dist/features/composites/schema.js.map +1 -1
  150. package/dist/features/composites/split.d.ts +62 -0
  151. package/dist/features/composites/split.js +172 -0
  152. package/dist/features/composites/split.js.map +1 -0
  153. package/dist/features/composites/vue.d.ts +4 -3
  154. package/dist/features/composites/vue.js +7 -5
  155. package/dist/features/composites/vue.js.map +1 -1
  156. package/dist/features/transfer/components/TransferMenu.js +93 -0
  157. package/dist/features/transfer/components/TransferMenu.js.map +1 -0
  158. package/dist/features/transfer/components/TransferMenu.vue.d.ts +15 -0
  159. package/dist/features/transfer/feature.d.ts +76 -0
  160. package/dist/features/transfer/feature.js +169 -0
  161. package/dist/features/transfer/feature.js.map +1 -0
  162. package/dist/features/transfer/index.d.ts +3 -0
  163. package/dist/features/transfer/index.js +3 -0
  164. package/dist/features/transfer/react/TransferMenu.d.ts +12 -0
  165. package/dist/features/transfer/react/TransferMenu.js +71 -0
  166. package/dist/features/transfer/react/TransferMenu.js.map +1 -0
  167. package/dist/features/transfer/react.d.ts +10 -0
  168. package/dist/features/transfer/react.js +11 -0
  169. package/dist/features/transfer/react.js.map +1 -0
  170. package/dist/features/transfer/transforms.d.ts +83 -0
  171. package/dist/features/transfer/transforms.js +137 -0
  172. package/dist/features/transfer/transforms.js.map +1 -0
  173. package/dist/features/transfer/vue.d.ts +9 -0
  174. package/dist/features/transfer/vue.js +11 -0
  175. package/dist/features/transfer/vue.js.map +1 -0
  176. package/dist/i18n/de/ai.js +4 -0
  177. package/dist/i18n/de/ai.js.map +1 -1
  178. package/dist/i18n/de/composites.js +21 -1
  179. package/dist/i18n/de/composites.js.map +1 -1
  180. package/dist/i18n/de/integrations.js +16 -0
  181. package/dist/i18n/de/integrations.js.map +1 -1
  182. package/dist/i18n/de/transfer.js +17 -0
  183. package/dist/i18n/de/transfer.js.map +1 -0
  184. package/dist/i18n/de/tree.js +7 -0
  185. package/dist/i18n/de/tree.js.map +1 -1
  186. package/dist/i18n/de.d.ts +57 -0
  187. package/dist/i18n/de.js +3 -1
  188. package/dist/i18n/de.js.map +1 -1
  189. package/dist/i18n/en/ai.js +4 -0
  190. package/dist/i18n/en/ai.js.map +1 -1
  191. package/dist/i18n/en/composites.js +21 -1
  192. package/dist/i18n/en/composites.js.map +1 -1
  193. package/dist/i18n/en/integrations.js +16 -0
  194. package/dist/i18n/en/integrations.js.map +1 -1
  195. package/dist/i18n/en/transfer.js +17 -0
  196. package/dist/i18n/en/transfer.js.map +1 -0
  197. package/dist/i18n/en/tree.js +7 -0
  198. package/dist/i18n/en/tree.js.map +1 -1
  199. package/dist/i18n/en.js +3 -1
  200. package/dist/i18n/en.js.map +1 -1
  201. package/dist/integrations/composite-ai/composite-fill.js +1 -1
  202. package/dist/integrations/composite-ai/composite-summary.js +1 -1
  203. package/dist/integrations/composite-ai/derive.d.ts +21 -0
  204. package/dist/integrations/composite-ai/derive.js +69 -47
  205. package/dist/integrations/composite-ai/derive.js.map +1 -1
  206. package/dist/integrations/composite-ai/index.d.ts +8 -3
  207. package/dist/integrations/composite-ai/index.js +50 -4
  208. package/dist/integrations/composite-ai/index.js.map +1 -1
  209. package/dist/integrations/composite-ai/outline-sanitize.d.ts +48 -0
  210. package/dist/integrations/composite-ai/outline-sanitize.js +175 -0
  211. package/dist/integrations/composite-ai/outline-sanitize.js.map +1 -0
  212. package/dist/integrations/composite-ai/split.d.ts +44 -0
  213. package/dist/integrations/composite-ai/split.js +187 -0
  214. package/dist/integrations/composite-ai/split.js.map +1 -0
  215. package/dist/integrations/composite-ai/transfer-transforms.d.ts +27 -0
  216. package/dist/integrations/composite-ai/transfer-transforms.js +153 -0
  217. package/dist/integrations/composite-ai/transfer-transforms.js.map +1 -0
  218. package/dist/integrations/transcript-ai/protocol.d.ts +13 -0
  219. package/dist/integrations/transcript-ai/protocol.js +49 -1
  220. package/dist/integrations/transcript-ai/protocol.js.map +1 -1
  221. package/dist/integrations/transcript-ai/transcript-cleanup.js +1 -1
  222. package/dist/markdown/MarkdownSurface.vue.d.ts +1 -1
  223. package/dist/nuxt/module.d.ts +114 -0
  224. package/dist/presets/compose.d.ts +24 -8
  225. package/dist/presets/compose.js +117 -58
  226. package/dist/presets/compose.js.map +1 -1
  227. package/dist/react/compose.js +5 -1
  228. package/dist/react/compose.js.map +1 -1
  229. package/dist/react/composed-surface.d.ts +9 -0
  230. package/dist/react/composed-surface.js +4 -1
  231. package/dist/react/composed-surface.js.map +1 -1
  232. package/dist/server/ai.d.ts +2 -5
  233. package/dist/server/ai.js.map +1 -1
  234. package/dist/server/handlers/ai.d.ts +4 -75
  235. package/dist/server/handlers/ai.js +30 -94
  236. package/dist/server/handlers/ai.js.map +1 -1
  237. package/dist/server/handlers/editor.d.ts +1 -0
  238. package/dist/server/handlers/index.d.ts +3 -1
  239. package/dist/server/handlers/index.js +3 -1
  240. package/dist/server/index.d.ts +2 -1
  241. package/dist/settings/index.d.ts +8 -0
  242. package/dist/settings/index.js +16 -4
  243. package/dist/settings/index.js.map +1 -1
  244. package/dist/styles/composites.css +41 -0
  245. package/dist/tree/DocumentTree.js +246 -80
  246. package/dist/tree/DocumentTree.js.map +1 -1
  247. package/dist/tree/drop-rules.js +8 -0
  248. package/dist/tree/drop-rules.js.map +1 -1
  249. package/dist/tree/react/DocumentTree.js +164 -32
  250. package/dist/tree/react/DocumentTree.js.map +1 -1
  251. package/dist/tree/tree-host.js +41 -2
  252. package/dist/tree/tree-host.js.map +1 -1
  253. package/dist/tree/tree-items.js +53 -5
  254. package/dist/tree/tree-items.js.map +1 -1
  255. package/dist/tree/tree-model.js +122 -10
  256. package/dist/tree/tree-model.js.map +1 -1
  257. package/dist/tree/tree-rows.js +20 -7
  258. package/dist/tree/tree-rows.js.map +1 -1
  259. package/dist/tree/tree-view-model.d.ts +5 -0
  260. package/dist/tree/tree-view-model.js +13 -0
  261. package/dist/tree/tree-view-model.js.map +1 -1
  262. package/dist/vue/AdvancedEditor.js +6 -0
  263. package/dist/vue/AdvancedEditor.js.map +1 -1
  264. package/dist/vue/AdvancedEditor.vue.d.ts +9 -1
  265. package/dist/vue/compose.js +5 -1
  266. package/dist/vue/compose.js.map +1 -1
  267. package/package.json +21 -1
@@ -1,5 +1,6 @@
1
1
  import { createStore } from "../core/store.js";
2
2
  import { kindAccepts } from "../features/composites/kinds.js";
3
+ import { basketById } from "../features/composites/baskets.js";
3
4
  import { remapFolderPath } from "./folder-paths.js";
4
5
  import { EMPTY_OUTLINE, VIRTUAL_ROOT, ancestorKeys, collectFolderPaths, creatableBelow, dragPayloadOf, filterKinds, folderNamesIn, isDraggable, joinPath, parentPath } from "./tree-items.js";
5
6
  import { dropVerdict } from "./drop-rules.js";
@@ -7,9 +8,15 @@ import { deriveTree, filterQuery } from "./tree-rows.js";
7
8
  //#region src/tree/tree-model.ts
8
9
  const NO_DOCUMENTS = [];
9
10
  const NO_KINDS = [];
11
+ const NO_BASKETS = [];
10
12
  const NO_FILTERS = {};
11
13
  const UNSET = Symbol("unset");
12
14
  const isOutlineKey = (key) => key.startsWith("outline:");
15
+ const withView = (c, view) => ({
16
+ ...c,
17
+ view,
18
+ focusPath: view.focusPath
19
+ });
13
20
  function sameVerdict(a, b) {
14
21
  if (a === b) return true;
15
22
  if (!a || !b) return false;
@@ -45,6 +52,8 @@ function createTreeModel(options) {
45
52
  let structure = options.context.structure;
46
53
  let treeRoot = options.context.treeRoot;
47
54
  let unwatchEditor = editor?.onChange(onEditorChange);
55
+ /** The focus the editor last showed that the tree took over (or already had); a change of the editor's focus is told apart from the tree's own by comparing against it. */
56
+ let seenFocus = null;
48
57
  let outlineTimer;
49
58
  /** A folder move the host is running: until it is done, a selected folder at the old path follows to the new one. */
50
59
  let pendingMove;
@@ -57,9 +66,12 @@ function createTreeModel(options) {
57
66
  virtual: isVirtual(),
58
67
  structure,
59
68
  kinds: editor?.kinds ?? NO_KINDS,
69
+ baskets: editor?.baskets ?? NO_BASKETS,
60
70
  hasEditor: !!editor,
61
71
  outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,
62
72
  nodeFilters: shared.nodeFilters.get(),
73
+ basketFilter: shared.basketFilter.get(),
74
+ focusKey: null,
63
75
  expanded: shared.expanded.get(),
64
76
  collapsedOutline: [],
65
77
  filterText: "",
@@ -79,6 +91,7 @@ function createTreeModel(options) {
79
91
  const dropEnv = () => ({
80
92
  virtual: core.virtual,
81
93
  moveVerdict: editor?.moveVerdict,
94
+ canTransfer: editor?.canTransfer() ?? false,
82
95
  t
83
96
  });
84
97
  function viewOf(c) {
@@ -90,14 +103,19 @@ function createTreeModel(options) {
90
103
  c.outline,
91
104
  c.kinds,
92
105
  c.nodeFilters,
106
+ c.basketFilter,
107
+ c.baskets,
108
+ c.focusKey,
93
109
  c.expanded,
94
110
  c.collapsedOutline,
95
111
  c.filterText,
96
112
  c.filterOverrides
97
113
  ];
98
114
  if (lastView && deps.every((dep, i) => Object.is(dep, lastView.deps[i]))) return lastView.view;
115
+ const basketFilter = c.basketFilter.filter((id) => basketById(c.baskets, id) !== void 0);
99
116
  const view = deriveTree({
100
117
  ...c,
118
+ basketFilter,
101
119
  t,
102
120
  select: selectItem
103
121
  });
@@ -128,6 +146,10 @@ function createTreeModel(options) {
128
146
  ...next,
129
147
  virtualTarget: null
130
148
  };
149
+ if (next.focusKey !== null && !view.keys.has(next.focusKey)) next = {
150
+ ...next,
151
+ focusKey: null
152
+ };
131
153
  if (next.renaming) {
132
154
  const r = next.renaming;
133
155
  if (!view.keys.has(r.key)) next = {
@@ -164,7 +186,7 @@ function createTreeModel(options) {
164
186
  }
165
187
  if (next.drag) {
166
188
  const d = next.drag;
167
- if (!view.keys.has(d.sourceKey) || d.hover !== null && !view.keys.has(d.hover)) next = {
189
+ if (d.source.type !== "foreign-block" && !view.keys.has(d.sourceKey) || d.hover !== null && !view.keys.has(d.hover)) next = {
168
190
  ...next,
169
191
  drag: null
170
192
  };
@@ -182,18 +204,12 @@ function createTreeModel(options) {
182
204
  }
183
205
  return next;
184
206
  }
185
- const state = createStore({
186
- ...core,
187
- view: viewOf(core)
188
- });
207
+ const state = createStore(withView(core, viewOf(core)));
189
208
  function publish(c) {
190
209
  if (disposed) return;
191
210
  const view = viewOf(c);
192
211
  core = reconcile(c, view);
193
- const next = {
194
- ...core,
195
- view
196
- };
212
+ const next = withView(core, view);
197
213
  const current = state.get();
198
214
  if (Object.keys(next).every((key) => Object.is(next[key], current[key]))) return;
199
215
  state.set(next);
@@ -213,6 +229,7 @@ function createTreeModel(options) {
213
229
  documents,
214
230
  activeId,
215
231
  nodeFilters: shared.nodeFilters.get(),
232
+ basketFilter: shared.basketFilter.get(),
216
233
  expanded: shared.expanded.get()
217
234
  });
218
235
  const activeFolder = documents.find((d) => d.id === activeId)?.folder;
@@ -231,15 +248,37 @@ function createTreeModel(options) {
231
248
  store.documents.subscribe(sync),
232
249
  store.activeId.subscribe(sync),
233
250
  shared.nodeFilters.subscribe(sync),
251
+ shared.basketFilter.subscribe(sync),
234
252
  shared.expanded.subscribe(sync)
235
253
  ];
236
254
  function readOutline() {
237
255
  patch({ outline: editor ? editor.outline(structure) : EMPTY_OUTLINE });
256
+ mirrorFocus();
257
+ }
258
+ /**
259
+ * The editor's focus mode changed on its own (the focus chip, a block's „Fokussieren“, the focused Baustein vanished):
260
+ * the tree follows without a command. A Baustein the outline does not know yet is retried after the next outline read.
261
+ */
262
+ function mirrorFocus() {
263
+ const id = editor?.focusedId() ?? null;
264
+ if (id === seenFocus) return;
265
+ if (id === null) {
266
+ seenFocus = null;
267
+ if (core.focusKey !== null) patch({ focusKey: null });
268
+ return;
269
+ }
270
+ const key = `outline:${id}`;
271
+ if (core.focusKey !== key) {
272
+ if ((state.get().view.index.get(key)?.item)?.type !== "composite") return;
273
+ patch({ focusKey: key });
274
+ }
275
+ seenFocus = id;
238
276
  }
239
277
  function onEditorChange() {
240
278
  clearTimeout(outlineTimer);
241
279
  outlineTimer = setTimeout(readOutline, debounceMs);
242
280
  if (core.drag) publish(core);
281
+ mirrorFocus();
243
282
  }
244
283
  function setContext(context) {
245
284
  if (context.editor === editor && context.structure === structure && context.treeRoot === treeRoot) return;
@@ -250,6 +289,7 @@ function createTreeModel(options) {
250
289
  treeRoot = context.treeRoot;
251
290
  clearTimeout(outlineTimer);
252
291
  if (editorChanged) {
292
+ seenFocus = null;
253
293
  unwatchEditor?.();
254
294
  unwatchEditor = editor?.onChange(onEditorChange);
255
295
  }
@@ -257,10 +297,13 @@ function createTreeModel(options) {
257
297
  virtual: isVirtual(),
258
298
  structure,
259
299
  kinds: editor?.kinds ?? NO_KINDS,
300
+ baskets: editor?.baskets ?? NO_BASKETS,
301
+ ...editorChanged ? { focusKey: null } : {},
260
302
  hasEditor: !!editor,
261
303
  outline: editor ? editor.outline(structure) : EMPTY_OUTLINE
262
304
  });
263
305
  if (core.virtual && !wasVirtual) expand([VIRTUAL_ROOT]);
306
+ mirrorFocus();
264
307
  }
265
308
  const filtering = () => filterQuery(core.filterText) !== "";
266
309
  function setOpen(key, open) {
@@ -288,6 +331,31 @@ function createTreeModel(options) {
288
331
  filterOverrides: filterQuery(text) ? core.filterOverrides : NO_FILTERS
289
332
  });
290
333
  }
334
+ /** Only a Baustein the editor can address (it has a block ID) can be focused. */
335
+ function focus(key) {
336
+ const item = state.get().view.index.get(key)?.item;
337
+ if (item?.type !== "composite" || !item.blockId) return;
338
+ patch({ focusKey: key });
339
+ execute({
340
+ type: "focusBlock",
341
+ id: item.blockId
342
+ });
343
+ }
344
+ function defocus() {
345
+ if (core.focusKey === null) return;
346
+ patch({ focusKey: null });
347
+ execute({
348
+ type: "focusBlock",
349
+ id: null
350
+ });
351
+ }
352
+ const canMerge = (item) => item.type === "composite" && !!item.blockId && !!editor?.canMerge(item.blockId);
353
+ function merge(item) {
354
+ if (canMerge(item)) execute({
355
+ type: "mergeBlock",
356
+ id: item.blockId
357
+ });
358
+ }
291
359
  function setSelectedFolder(path) {
292
360
  patch({ selectedFolder: path });
293
361
  }
@@ -357,6 +425,39 @@ function createTreeModel(options) {
357
425
  } });
358
426
  return verdict;
359
427
  }
428
+ function foreignDragOver(item) {
429
+ const drag = core.drag;
430
+ if (drag && drag.source.type !== "foreign-block") return null;
431
+ const source = { type: "foreign-block" };
432
+ const verdict = dropVerdict(source, item, dropEnv());
433
+ if (!drag || drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: {
434
+ source,
435
+ sourceKey: "",
436
+ hover: item.key,
437
+ verdict
438
+ } });
439
+ return verdict;
440
+ }
441
+ async function dropForeign(item, payload, menu, x, y) {
442
+ if (core.drag && core.drag.source.type !== "foreign-block") return;
443
+ patch({ drag: null });
444
+ if (!dropVerdict({ type: "foreign-block" }, item, dropEnv()).ok) return;
445
+ const targetId = item.key === "vroot" ? null : item.blockId;
446
+ let done = false;
447
+ try {
448
+ done = await execute({
449
+ type: "transferBlock",
450
+ payload,
451
+ targetId,
452
+ menu,
453
+ x,
454
+ y
455
+ });
456
+ } catch {
457
+ return;
458
+ }
459
+ if (done && targetId && !menu) expand([`outline:${targetId}`]);
460
+ }
360
461
  async function drop(item) {
361
462
  const drag = core.drag;
362
463
  patch({ drag: null });
@@ -371,6 +472,7 @@ function createTreeModel(options) {
371
472
  }) && targetId) expand([`outline:${targetId}`]);
372
473
  return;
373
474
  }
475
+ if (source.type === "foreign-block") return;
374
476
  const targetPath = item.path;
375
477
  if (source.type === "document") {
376
478
  if (await execute({
@@ -513,6 +615,7 @@ function createTreeModel(options) {
513
615
  }
514
616
  }
515
617
  sync();
618
+ mirrorFocus();
516
619
  return {
517
620
  state,
518
621
  setContext,
@@ -524,6 +627,12 @@ function createTreeModel(options) {
524
627
  setKindHidden: (key, kind, hidden) => shared.setKindHidden(key, kind, hidden),
525
628
  clearFilter: (key) => shared.clearFilter(key),
526
629
  clearAllFilters: () => shared.clearAllFilters(),
630
+ setBasketShown: (id, shown) => shared.setBasketShown(id, shown),
631
+ clearBasketFilter: () => shared.clearBasketFilter(),
632
+ focus,
633
+ defocus,
634
+ canMerge,
635
+ merge,
527
636
  select: selectItem,
528
637
  activate(item) {
529
638
  selectItem(item);
@@ -535,7 +644,8 @@ function createTreeModel(options) {
535
644
  dragStart,
536
645
  dragOver,
537
646
  dragLeave(item) {
538
- if (core.drag?.hover === item.key) patch({ drag: {
647
+ if (core.drag?.source.type === "foreign-block") patch({ drag: null });
648
+ else if (core.drag?.hover === item.key) patch({ drag: {
539
649
  ...core.drag,
540
650
  hover: null,
541
651
  verdict: null
@@ -543,6 +653,8 @@ function createTreeModel(options) {
543
653
  },
544
654
  dragEnd: () => patch({ drag: null }),
545
655
  drop,
656
+ foreignDragOver,
657
+ dropForeign,
546
658
  startRename,
547
659
  setRenameDraft(text) {
548
660
  const r = core.renaming;
@@ -1 +1 @@
1
- {"version":3,"file":"tree-model.js","names":[],"sources":["../../src/tree/tree-model.ts"],"sourcesContent":["import { createStore, type ReadonlyStore } from '../core/store'\nimport { type CompositeKind, kindAccepts } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport { type DropEnv, dropVerdict, type DropVerdict } from './drop-rules'\nimport { remapFolderPath } from './folder-paths'\nimport type { DocumentStore } from './store'\nimport {\n ancestorKeys,\n collectFolderPaths,\n creatableBelow,\n type DragPayload,\n dragPayloadOf,\n EMPTY_OUTLINE,\n filterKinds,\n folderNamesIn,\n isDraggable,\n joinPath,\n type Outline,\n parentPath,\n type TreeItem,\n VIRTUAL_ROOT,\n} from './tree-items'\nimport { deriveTree, filterQuery, type TreeRow, type TreeView } from './tree-rows'\nimport type { NodeFilters, TreeViewModel } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// One framework-free model per `DocumentTree`, rendered by the Vue and the React component alike. It owns what the\n// tree remembers (open rows, kind filters, the title filter, the selection, a drag, a folder being renamed or created)\n// and checks all of it against the tree after every change of the store, the outline or the view state, so a key of\n// something that moved or vanished never lingers. It never calls the store or the editor to change something: it emits\n// `TreeCommand`s to the `execute` it was given and follows their result.\n\n/** What the model asks its host to do; the host reports whether it happened. */\nexport type TreeCommand\n = | { type: 'openDocument', id: string }\n | { type: 'createDocument', folder: string }\n | { type: 'moveDocument', id: string, folder: string }\n | { type: 'removeDocument', id: string, folder: string }\n | { type: 'createFolder', path: string }\n | { type: 'moveFolder', from: string, to: string }\n | { type: 'removeFolder', path: string }\n /** Moves the block into the Baustein `targetId` (`null` = the end of the document). */\n | { type: 'moveBlock', id: string, targetId: string | null }\n | { type: 'revealBlock', id: string | null, pos: number }\n /** Adds an Ordner-Baustein to the Baustein `targetId` (`null` = the end of the document). */\n | { type: 'createBausteinFolder', targetId: string | null }\n /** Lets the user pick files and imports them into the Baustein `targetId` (`null` = the end of the document); `false` when none were imported. */\n | { type: 'importFiles', targetId: string | null }\n | { type: 'warn', title: string, description: string }\n\n/** Runs a command and resolves whether it happened. Never rejects: the host reports its own failures. */\nexport type TreeExecutor = (command: TreeCommand) => boolean | Promise<boolean>\n\n/** What the model needs from the open document's editor. */\nexport interface TreeEditor {\n kinds: readonly CompositeKind[]\n /** The outline in `structure`: Bausteine in `'composite'` structure, else the headings. Empty once the editor is gone. */\n outline: (structure: string) => Outline\n /** Whether a block may move into a Baustein, judged on the live document. */\n moveVerdict: NonNullable<DropEnv['moveVerdict']>\n /** `listener` runs after the document changed; returns the unsubscribe function. */\n onChange: (listener: () => void) => () => void\n}\n\n/** What the surrounding app decides: the open editor and the `blocks.structure` / `blocks.treeRoot` settings. */\nexport interface TreeContext {\n editor: TreeEditor | undefined\n structure: string\n treeRoot: string\n}\n\nexport interface TreeModelOptions {\n /** Words the menus, the drop refusals and the label of an untitled open document; the framework layer passes the context's `t`. */\n t: Translate\n store: DocumentStore\n /** The view state shared by the trees of one app: open store items and kind filters (persisted). */\n view: TreeViewModel\n execute: TreeExecutor\n context: TreeContext\n /** The folder new documents and folders go to; default the root. */\n selectedFolder?: string\n /** How long the outline waits for the document to settle before it is read again; default 150 ms. */\n outlineDebounceMs?: number\n}\n\n/** A drag in progress. */\nexport interface TreeDrag {\n source: DragPayload\n /** Key of the dragged row */\n sourceKey: string\n /** Key of the row under the pointer */\n hover: string | null\n /** What dropping on `hover` would do; `null` without a `hover` */\n verdict: DropVerdict | null\n}\n\n/** A folder being renamed. */\nexport interface TreeRename {\n /** Key of the folder's row */\n key: string\n path: string\n /** Its name when renaming started */\n base: string\n draft: string\n error: string | null\n}\n\n/** A folder being named. */\nexport interface TreeCreateFolder {\n /** Folder path the folder is created in */\n parent: string\n draft: string\n error: string | null\n}\n\n/** Everything a renderer needs. Fields below `view` are what the derived `view` was computed from and what `rowOf` reads. */\nexport interface TreeState {\n /** The loaded folder tree: `undefined` = not loaded yet, `null` = loading failed. */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n structure: string\n kinds: readonly CompositeKind[]\n hasEditor: boolean\n outline: Outline\n nodeFilters: NodeFilters\n expanded: readonly string[]\n collapsedOutline: readonly string[]\n /** What the title filter input holds. */\n filterText: string\n filterOverrides: Readonly<Record<string, boolean>>\n /** The folder new documents, folders and host imports go to. */\n selectedFolder: string\n /** Virtual mode: block ID of the selected Baustein that takes Bausteine; `null` = the document itself. */\n virtualTarget: string | null\n drag: TreeDrag | null\n renaming: TreeRename | null\n creatingFolder: TreeCreateFolder | null\n /** Key of the row whose deletion is running. */\n removing: string | null\n view: TreeView\n}\n\n/** One row of a row's menu. */\nexport interface TreeMenuEntry {\n label: string\n icon: string\n run: () => void\n}\n\n/** How a renderer draws one row. */\nexport interface TreeRowState extends TreeRow {\n /** The row's document is the open one. */\n active: boolean\n /** The row is the selected folder, or (virtual mode) the selected Baustein. */\n selected: boolean\n /** What dropping the drag on this row would do, while the pointer is over it. */\n drop: DropVerdict | null\n renaming: TreeRename | null\n removing: boolean\n /** The kinds the row's kind filter can hide below it, and the ones it hides. */\n filterKinds: readonly CompositeKind[]\n hiddenKinds: readonly string[]\n /** The row offers a kind filter. */\n showFilter: boolean\n}\n\nexport interface TreeModel {\n readonly state: ReadonlyStore<TreeState>\n /** The open editor or a setting changed. */\n setContext: (context: TreeContext) => void\n /** The host selected another folder (it controls the value). */\n setSelectedFolder: (path: string) => void\n\n // --- what is open, filtered, typed\n /** Opens or closes a row; while the title filter is set the choice is discarded when it is cleared. */\n setOpen: (key: string, open: boolean) => void\n toggle: (key: string) => void\n /** Opens the rows (also during a title filter); closed rows are left alone otherwise. */\n expand: (keys: readonly string[]) => void\n /** Filters the rows by title (case-insensitive substring); `''` clears it and restores the opened rows from before. */\n setFilterText: (text: string) => void\n setKindHidden: (key: string, kind: string, hidden: boolean) => void\n clearFilter: (key: string) => void\n clearAllFilters: () => void\n\n // --- rows\n /** A row was chosen (click, Enter). */\n select: (item: TreeItem) => void\n /** `select`, and a folder or the root toggles. */\n activate: (item: TreeItem) => void\n addMenu: (item: TreeItem) => TreeMenuEntry[][]\n remove: (item: TreeItem) => Promise<void>\n\n // --- drag and drop\n isDraggable: (item: TreeItem) => boolean\n /** Starts dragging `item`; returns what the drag carries, `null` when `item` cannot be dragged. */\n dragStart: (item: TreeItem) => DragPayload | null\n /** The pointer is over `item`; returns the verdict (`null` without a drag). Only an `ok` one is a drop target. */\n dragOver: (item: TreeItem) => DropVerdict | null\n /** The pointer left `item` for good (not into one of its parts). */\n dragLeave: (item: TreeItem) => void\n dragEnd: () => void\n drop: (item: TreeItem) => Promise<void>\n\n // --- renaming and creating folders\n startRename: (item: TreeItem) => void\n setRenameDraft: (text: string) => void\n cancelRename: () => void\n commitRename: () => Promise<void>\n /** The rename field lost focus: commit, or give up with a warning when the name is invalid. */\n blurRename: () => Promise<void>\n startCreateFolder: (parent: string) => void\n setFolderDraft: (text: string) => void\n cancelCreateFolder: () => void\n commitCreateFolder: () => Promise<void>\n\n dispose: () => void\n}\n\nconst NO_DOCUMENTS: readonly DocumentSummary[] = []\nconst NO_KINDS: readonly CompositeKind[] = []\nconst NO_FILTERS: Readonly<Record<string, boolean>> = {}\nconst UNSET = Symbol('unset')\n\nconst isOutlineKey = (key: string) => key.startsWith('outline:')\n\n/** The state `core` holds: everything of `TreeState` but the derived `view`. */\ntype TreeCore = Omit<TreeState, 'view'>\n\nfunction sameVerdict(a: DropVerdict | null, b: DropVerdict | null): boolean {\n if (a === b) return true\n if (!a || !b) return false\n return a.ok ? b.ok : !b.ok && a.reason === b.reason\n}\n\n/** A row's state in `state` (`item` is one of `state.view.items`). */\nexport function rowOf(state: TreeState, item: TreeItem, t: Translate): TreeRowState {\n const hidden = state.nodeFilters[item.key] ?? []\n const kinds = filterKinds(item, { structure: state.structure, activeId: state.activeId, kinds: state.kinds, t })\n const virtualTarget = state.virtual && (item.key === VIRTUAL_ROOT ? state.virtualTarget === null : !!item.blockId && item.blockId === state.virtualTarget)\n return {\n ...state.view.rows.get(item.key)!,\n active: item.id !== undefined && item.id === state.activeId,\n selected: (item.type !== 'document' && item.path === state.selectedFolder) || virtualTarget,\n drop: state.drag?.hover === item.key ? state.drag.verdict : null,\n renaming: state.renaming?.key === item.key ? state.renaming : null,\n removing: state.removing === item.key,\n filterKinds: kinds,\n hiddenKinds: hidden,\n showFilter: kinds.length > 0 && (item.type === 'root' || item.type === 'folder' || !!item.children?.length || hidden.length > 0),\n }\n}\n\n/** A tree model over `options.store`; call `dispose` when its tree goes away. */\nexport function createTreeModel(options: TreeModelOptions): TreeModel {\n const { store, view: shared, execute, t } = options\n const debounceMs = options.outlineDebounceMs ?? 150\n\n let editor = options.context.editor\n let structure = options.context.structure\n let treeRoot = options.context.treeRoot\n let unwatchEditor = editor?.onChange(onEditorChange)\n let outlineTimer: ReturnType<typeof setTimeout> | undefined\n /** A folder move the host is running: until it is done, a selected folder at the old path follows to the new one. */\n let pendingMove: { from: string, to: string } | undefined\n let disposed = false\n\n const isVirtual = () => treeRoot === 'file' && structure === 'composite' && !!editor\n\n let core: TreeCore = {\n tree: store.tree.get(),\n documents: store.documents.get() ?? NO_DOCUMENTS,\n activeId: store.activeId.get(),\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n nodeFilters: shared.nodeFilters.get(),\n expanded: shared.expanded.get(),\n collapsedOutline: [],\n filterText: '',\n filterOverrides: NO_FILTERS,\n selectedFolder: options.selectedFolder ?? '',\n virtualTarget: null,\n drag: null,\n renaming: null,\n creatingFolder: null,\n removing: null,\n }\n let lastView: { deps: readonly unknown[], view: TreeView } | undefined\n let lastTree: TreeFolder | null | undefined | typeof UNSET = UNSET\n let folderPaths = new Set<string>()\n let lastActiveFolder: string | undefined | typeof UNSET = UNSET\n let lastActiveId: string | undefined | typeof UNSET = UNSET\n\n const dropEnv = (): DropEnv => ({ virtual: core.virtual, moveVerdict: editor?.moveVerdict, t })\n\n function viewOf(c: TreeCore): TreeView {\n const deps = [c.tree, c.documents, c.activeId, c.virtual, c.outline, c.kinds, c.nodeFilters, c.expanded, c.collapsedOutline, c.filterText, c.filterOverrides]\n if (lastView && deps.every((dep, i) => Object.is(dep, lastView!.deps[i]))) return lastView.view\n const view = deriveTree({ ...c, t, select: selectItem })\n lastView = { deps, view }\n return view\n }\n\n const renameError = (draft: string, path: string, base: string, tree: TreeFolder | null | undefined) =>\n draft.trim() === base ? null : store.validateName(draft, folderNamesIn(tree, parentPath(path), path))\n const folderError = (draft: string, parent: string, tree: TreeFolder | null | undefined) =>\n draft.trim() ? store.validateName(draft, folderNamesIn(tree, parent)) : null\n\n /** Measures everything the tree remembers against the current tree: what is gone is dropped, what depends on the tree is recomputed. */\n function reconcile(c: TreeCore, view: TreeView): TreeCore {\n let next = c\n if (c.tree !== lastTree) {\n lastTree = c.tree\n folderPaths = new Set<string>()\n if (c.tree) collectFolderPaths(c.tree, folderPaths)\n if (c.tree && !folderPaths.has(next.selectedFolder)) {\n const followed = pendingMove ? remapFolderPath(next.selectedFolder, pendingMove.from, pendingMove.to) : ''\n next = { ...next, selectedFolder: folderPaths.has(followed) ? followed : '' }\n }\n }\n if (next.virtualTarget !== null && (!next.virtual || !view.keys.has(`outline:${next.virtualTarget}`))) next = { ...next, virtualTarget: null }\n if (next.renaming) {\n const r = next.renaming\n if (!view.keys.has(r.key)) next = { ...next, renaming: null }\n else {\n const error = renameError(r.draft, r.path, r.base, next.tree)\n if (error !== r.error) next = { ...next, renaming: { ...r, error } }\n }\n }\n if (next.creatingFolder) {\n const f = next.creatingFolder\n if (next.tree && !folderPaths.has(f.parent)) next = { ...next, creatingFolder: null }\n else {\n const error = folderError(f.draft, f.parent, next.tree)\n if (error !== f.error) next = { ...next, creatingFolder: { ...f, error } }\n }\n }\n if (next.drag) {\n const d = next.drag\n if (!view.keys.has(d.sourceKey) || (d.hover !== null && !view.keys.has(d.hover))) next = { ...next, drag: null }\n else if (d.hover !== null) {\n const target = view.rows.get(d.hover)?.item\n const verdict = target ? dropVerdict(d.source, target, dropEnv()) : d.verdict\n if (!sameVerdict(verdict, d.verdict)) next = { ...next, drag: { ...d, verdict } }\n }\n }\n return next\n }\n\n const state = createStore<TreeState>({ ...core, view: viewOf(core) })\n\n function publish(c: TreeCore) {\n if (disposed) return\n const view = viewOf(c)\n core = reconcile(c, view)\n const next: TreeState = { ...core, view }\n const current = state.get()\n if ((Object.keys(next) as (keyof TreeState)[]).every(key => Object.is(next[key], current[key]))) return\n state.set(next)\n }\n\n const patch = (changes: Partial<TreeCore>) => publish({ ...core, ...changes })\n\n // --- sources ---------------------------------------------------------------------------------------------------\n\n /** Reads the store and the shared view state; what opening a document shows is opened. */\n function sync() {\n if (disposed) return\n const documents = store.documents.get() ?? NO_DOCUMENTS\n const activeId = store.activeId.get()\n publish({ ...core, tree: store.tree.get(), documents, activeId, nodeFilters: shared.nodeFilters.get(), expanded: shared.expanded.get() })\n // Opening a document (also by URL, or after a move) shows it: its folders open and its folder becomes the selected one.\n const activeFolder = documents.find(d => d.id === activeId)?.folder\n if (activeFolder !== lastActiveFolder) {\n lastActiveFolder = activeFolder\n expand(ancestorKeys(activeFolder ?? ''))\n if (activeFolder !== undefined) setSelectedFolder(activeFolder)\n }\n if (activeId !== lastActiveId) {\n lastActiveId = activeId\n if (activeId) expand([`doc:${activeId}`])\n }\n }\n\n const unsubscribe = [\n store.tree.subscribe(sync),\n store.documents.subscribe(sync),\n store.activeId.subscribe(sync),\n shared.nodeFilters.subscribe(sync),\n shared.expanded.subscribe(sync),\n ]\n\n function readOutline() {\n patch({ outline: editor ? editor.outline(structure) : EMPTY_OUTLINE })\n }\n\n // The outline is read when the document changed and has been quiet for a moment; a drag in progress is checked at once.\n function onEditorChange() {\n clearTimeout(outlineTimer)\n outlineTimer = setTimeout(readOutline, debounceMs)\n if (core.drag) publish(core)\n }\n\n function setContext(context: TreeContext) {\n if (context.editor === editor && context.structure === structure && context.treeRoot === treeRoot) return\n const editorChanged = context.editor !== editor\n const wasVirtual = core.virtual\n editor = context.editor\n structure = context.structure\n treeRoot = context.treeRoot\n clearTimeout(outlineTimer)\n if (editorChanged) {\n unwatchEditor?.()\n unwatchEditor = editor?.onChange(onEditorChange)\n }\n patch({\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n })\n if (core.virtual && !wasVirtual) expand([VIRTUAL_ROOT])\n }\n\n // --- open, filtered, typed -------------------------------------------------------------------------------------\n\n const filtering = () => filterQuery(core.filterText) !== ''\n\n function setOpen(key: string, open: boolean) {\n if (filtering()) patch({ filterOverrides: { ...core.filterOverrides, [key]: open } })\n else if (isOutlineKey(key)) patch({ collapsedOutline: open ? core.collapsedOutline.filter(k => k !== key) : [...core.collapsedOutline.filter(k => k !== key), key] })\n else if (open) shared.expand([key])\n else shared.expanded.set(shared.expanded.get().filter(k => k !== key))\n }\n\n function expand(keys: readonly string[]) {\n const outlineKeys = keys.filter(isOutlineKey)\n const { filterOverrides } = core\n const overridden = keys.some(key => key in filterOverrides)\n if (overridden || outlineKeys.some(key => core.collapsedOutline.includes(key))) {\n patch({\n collapsedOutline: core.collapsedOutline.filter(key => !outlineKeys.includes(key)),\n filterOverrides: overridden ? Object.fromEntries(Object.entries(filterOverrides).filter(([key]) => !keys.includes(key))) : filterOverrides,\n })\n }\n shared.expand(keys.filter(key => !isOutlineKey(key)))\n }\n\n function setFilterText(text: string) {\n patch({ filterText: text, filterOverrides: filterQuery(text) ? core.filterOverrides : NO_FILTERS })\n }\n\n // --- selection -------------------------------------------------------------------------------------------------\n\n function setSelectedFolder(path: string) {\n patch({ selectedFolder: path })\n }\n\n function selectItem(item: TreeItem) {\n if (core.renaming?.key === item.key) return\n if (item.key === VIRTUAL_ROOT) return patch({ virtualTarget: null })\n if (item.type === 'document') {\n setSelectedFolder(item.folder ?? '')\n void execute({ type: 'openDocument', id: item.id! })\n }\n else if (item.type === 'composite' || item.type === 'heading') {\n void execute({ type: 'revealBlock', id: item.blockId ?? null, pos: item.pos! })\n const takesBausteine = !!item.kind && core.kinds.some(kind => kindAccepts(core.kinds, item.kind!, kind.id))\n if (core.virtual && item.blockId && takesBausteine) patch({ virtualTarget: item.blockId })\n }\n else {\n setSelectedFolder(item.path ?? '')\n }\n }\n\n function toggle(key: string) {\n setOpen(key, !state.get().view.rows.get(key)?.open)\n }\n\n /** A folder moved from `from` to `to`: its open/selected state follows it. */\n function followFolderMove(from: string, to: string) {\n shared.followFolderMove(from, to)\n patch({\n selectedFolder: remapFolderPath(core.selectedFolder, from, to),\n filterOverrides: Object.fromEntries(Object.entries(core.filterOverrides).map(([key, open]) => [key.startsWith('folder:') ? `folder:${remapFolderPath(key.slice(7), from, to)}` : key, open])),\n })\n expand(ancestorKeys(parentPath(to)))\n }\n\n async function moveFolder(from: string, to: string) {\n pendingMove = { from, to }\n const moved = await execute({ type: 'moveFolder', from, to })\n pendingMove = undefined\n if (moved) followFolderMove(from, to)\n }\n\n // --- drag and drop ---------------------------------------------------------------------------------------------\n\n function dragStart(item: TreeItem) {\n if (core.renaming?.key === item.key || !isDraggable(item, core.virtual)) return null\n const source = dragPayloadOf(item)\n patch({ drag: { source, sourceKey: item.key, hover: null, verdict: null } })\n return source\n }\n\n function dragOver(item: TreeItem) {\n const drag = core.drag\n if (!drag) return null\n const verdict = dropVerdict(drag.source, item, dropEnv())\n if (drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { ...drag, hover: item.key, verdict } })\n return verdict\n }\n\n async function drop(item: TreeItem) {\n const drag = core.drag\n patch({ drag: null })\n if (!drag || !dropVerdict(drag.source, item, dropEnv()).ok) return\n const { source } = drag\n if (source.type === 'composite') {\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n if (await execute({ type: 'moveBlock', id: source.blockId, targetId }) && targetId) expand([`outline:${targetId}`])\n return\n }\n const targetPath = item.path!\n if (source.type === 'document') {\n if (await execute({ type: 'moveDocument', id: source.id!, folder: targetPath })) expand(ancestorKeys(targetPath))\n return\n }\n await moveFolder(source.path, joinPath(targetPath, source.path.slice(source.path.lastIndexOf('/') + 1)))\n }\n\n // --- renaming, creating ----------------------------------------------------------------------------------------\n\n function startRename(item: TreeItem) {\n if (item.type !== 'folder') return\n patch({ renaming: { key: item.key, path: item.path!, base: item.label, draft: item.label, error: null } })\n }\n\n async function commitRename() {\n const r = core.renaming\n // An invalid name keeps the field open with its inline error.\n if (!r || r.error) return\n const name = r.draft.trim()\n patch({ renaming: null })\n if (name !== r.base) await moveFolder(r.path, joinPath(parentPath(r.path), name))\n }\n\n async function blurRename() {\n const r = core.renaming\n if (!r) return\n if (r.error) {\n void execute({ type: 'warn', title: t('tree.folder.renameFailed'), description: r.error })\n patch({ renaming: null })\n return\n }\n await commitRename()\n }\n\n function startCreateFolder(parent: string) {\n patch({ selectedFolder: parent, creatingFolder: { parent, draft: '', error: null } })\n }\n\n async function commitCreateFolder() {\n const f = core.creatingFolder\n if (!f) return\n if (!f.draft.trim()) return patch({ creatingFolder: null })\n if (f.error) return\n patch({ creatingFolder: null })\n if (await execute({ type: 'createFolder', path: joinPath(f.parent, f.draft.trim()) })) expand(ancestorKeys(f.parent))\n }\n\n // --- menus, deleting -------------------------------------------------------------------------------------------\n\n async function createDocumentIn(folder: string) {\n setSelectedFolder(folder)\n if (await execute({ type: 'createDocument', folder })) expand(ancestorKeys(folder))\n }\n\n /** Runs `command` for the Baustein of `item` (the file itself when it has none) and shows the result. */\n async function inComposite(item: TreeItem, command: TreeCommand) {\n if (await execute(command)) expand([item.blockId ? `outline:${item.blockId}` : item.key])\n }\n\n /**\n * What can be created below `item`: folders of the store take documents and sub-folders, the open file (as the root or\n * as a document row) and its Bausteine take what their kind accepts. Other rows take nothing. Folders also list\n * „Umbenennen“ here: renaming a document happens in the editor's title field.\n */\n function addMenu(item: TreeItem): TreeMenuEntry[][] {\n const groups: TreeMenuEntry[][] = []\n if (item.key !== VIRTUAL_ROOT && (item.type === 'root' || item.type === 'folder')) {\n const path = item.path!\n groups.push([\n { label: t('tree.menu.newDocument'), icon: 'i-lucide-file-plus', run: () => void createDocumentIn(path) },\n { label: item.type === 'root' ? t('tree.menu.newFolder') : t('tree.menu.newSubfolder'), icon: 'i-lucide-folder-plus', run: () => startCreateFolder(path) },\n ])\n }\n else {\n const can = creatableBelow(item, { structure: core.structure, hasEditor: core.hasEditor, activeId: core.activeId, kinds: core.kinds })\n const targetId = item.blockId ?? null\n const entries: TreeMenuEntry[] = []\n if (can.folder) entries.push({ label: t('tree.menu.newCompositeFolder'), icon: 'i-lucide-folder-plus', run: () => void inComposite(item, { type: 'createBausteinFolder', targetId }) })\n if (can.document) entries.push({ label: t('tree.menu.importFile'), icon: 'i-lucide-file-up', run: () => void inComposite(item, { type: 'importFiles', targetId }) })\n if (entries.length) groups.push(entries)\n }\n if (item.type === 'folder') groups.push([{ label: t('tree.menu.rename'), icon: 'i-lucide-pencil', run: () => startRename(item) }])\n return groups\n }\n\n async function remove(item: TreeItem) {\n patch({ removing: item.key })\n try {\n await execute(item.type === 'document' ? { type: 'removeDocument', id: item.id!, folder: item.folder ?? '' } : { type: 'removeFolder', path: item.path! })\n }\n finally {\n patch({ removing: null })\n }\n }\n\n sync()\n\n return {\n state,\n setContext,\n setSelectedFolder,\n setOpen,\n toggle,\n expand,\n setFilterText,\n setKindHidden: (key, kind, hidden) => shared.setKindHidden(key, kind, hidden),\n clearFilter: key => shared.clearFilter(key),\n clearAllFilters: () => shared.clearAllFilters(),\n select: selectItem,\n activate(item) {\n selectItem(item)\n if (item.type === 'root' || item.type === 'folder') toggle(item.key)\n },\n addMenu,\n remove,\n isDraggable: item => core.renaming?.key !== item.key && isDraggable(item, core.virtual),\n dragStart,\n dragOver,\n dragLeave(item) {\n if (core.drag?.hover === item.key) patch({ drag: { ...core.drag, hover: null, verdict: null } })\n },\n dragEnd: () => patch({ drag: null }),\n drop,\n startRename,\n setRenameDraft(text) {\n const r = core.renaming\n if (r) patch({ renaming: { ...r, draft: text, error: renameError(text, r.path, r.base, core.tree) } })\n },\n cancelRename: () => patch({ renaming: null }),\n commitRename,\n blurRename,\n startCreateFolder,\n setFolderDraft(text) {\n const f = core.creatingFolder\n if (f) patch({ creatingFolder: { ...f, draft: text, error: folderError(text, f.parent, core.tree) } })\n },\n cancelCreateFolder: () => patch({ creatingFolder: null }),\n commitCreateFolder,\n dispose() {\n disposed = true\n clearTimeout(outlineTimer)\n unwatchEditor?.()\n for (const stop of unsubscribe) stop()\n },\n }\n}\n"],"mappings":";;;;;;;AA8NA,MAAM,eAA2C,CAAC;AAClD,MAAM,WAAqC,CAAC;AAC5C,MAAM,aAAgD,CAAC;AACvD,MAAM,QAAQ,OAAO,OAAO;AAE5B,MAAM,gBAAgB,QAAgB,IAAI,WAAW,UAAU;AAK/D,SAAS,YAAY,GAAuB,GAAgC;CAC1E,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO;CACrB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE;AAC/C;;AAGA,SAAgB,M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xD;EACA,UAAU;GACR,WAAW;GACX,aAAa,YAAY;GACzB,gBAAgB;GAChB,KAAK,MAAM,QAAQ,aAAa,KAAK;EACvC;CACF;AACF"}
1
+ {"version":3,"file":"tree-model.js","names":[],"sources":["../../src/tree/tree-model.ts"],"sourcesContent":["import type { BlockTransfer } from '../core/block-transfer'\nimport { createStore, type ReadonlyStore } from '../core/store'\nimport { type Basket, basketById, type CompositeKind, kindAccepts } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport { type DropEnv, dropVerdict, type DropVerdict } from './drop-rules'\nimport { remapFolderPath } from './folder-paths'\nimport type { DocumentStore } from './store'\nimport {\n ancestorKeys,\n collectFolderPaths,\n creatableBelow,\n type DragPayload,\n dragPayloadOf,\n EMPTY_OUTLINE,\n filterKinds,\n folderNamesIn,\n isDraggable,\n joinPath,\n type Outline,\n parentPath,\n type TreeItem,\n VIRTUAL_ROOT,\n} from './tree-items'\nimport { deriveTree, filterQuery, type TreeRow, type TreeView } from './tree-rows'\nimport type { NodeFilters, TreeViewModel } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// One framework-free model per `DocumentTree`, rendered by the Vue and the React component alike. It owns what the\n// tree remembers (open rows, kind filters, the title filter, the selection, a drag, a folder being renamed or created)\n// and checks all of it against the tree after every change of the store, the outline or the view state, so a key of\n// something that moved or vanished never lingers. It never calls the store or the editor to change something: it emits\n// `TreeCommand`s to the `execute` it was given and follows their result.\n\n/** What the model asks its host to do; the host reports whether it happened. */\nexport type TreeCommand\n = | { type: 'openDocument', id: string }\n | { type: 'createDocument', folder: string }\n | { type: 'moveDocument', id: string, folder: string }\n | { type: 'removeDocument', id: string, folder: string }\n | { type: 'createFolder', path: string }\n | { type: 'moveFolder', from: string, to: string }\n | { type: 'removeFolder', path: string }\n /** Moves the block into the Baustein `targetId` (`null` = the end of the document). */\n | { type: 'moveBlock', id: string, targetId: string | null }\n | { type: 'revealBlock', id: string | null, pos: number }\n /** Adds an Ordner-Baustein to the Baustein `targetId` (`null` = the end of the document). */\n | { type: 'createBausteinFolder', targetId: string | null }\n /** Lets the user pick files and imports them into the Baustein `targetId` (`null` = the end of the document); `false` when none were imported. */\n | { type: 'importFiles', targetId: string | null }\n | { type: 'warn', title: string, description: string }\n /** Inserts a Baustein dragged in from another surface or tree at the end of the Baustein `targetId` (`null` = the end of the document); `menu`: offer the transforms at `x`, `y` first. */\n | { type: 'transferBlock', payload: BlockTransfer, targetId: string | null, menu: boolean, x: number, y: number }\n /** Puts the editor into focus mode on the Baustein `id` (`null` = leaves focus mode); sent after the tree's own focus changed. */\n | { type: 'focusBlock', id: string | null }\n /** The Baustein `id` absorbs the Baustein that follows it (`mergeCompositeWithNext`); `false` when the editor refuses. */\n | { type: 'mergeBlock', id: string }\n\n/** Runs a command and resolves whether it happened. Never rejects: the host reports its own failures. */\nexport type TreeExecutor = (command: TreeCommand) => boolean | Promise<boolean>\n\n/** What the model needs from the open document's editor. */\nexport interface TreeEditor {\n kinds: readonly CompositeKind[]\n /** The baskets a Baustein can be put into (colour dots on the rows). */\n baskets: readonly Basket[]\n /** The outline in `structure`: Bausteine in `'composite'` structure, else the headings. Empty once the editor is gone. */\n outline: (structure: string) => Outline\n /** Whether a block may move into a Baustein, judged on the live document. */\n moveVerdict: NonNullable<DropEnv['moveVerdict']>\n /** Whether the editor takes blocks from outside: it has the transfer feature's drop target and its `transferBlock` command. */\n canTransfer: () => boolean\n /** The block id of the Baustein the editor is focused on (focus mode), `null` without focus. The model mirrors it into the tree. */\n focusedId: () => string | null\n /** Whether the Baustein `id` can absorb the Baustein that follows it, judged on the live document. */\n canMerge: (id: string) => boolean\n /** `listener` runs after the document or the editor's focus changed; returns the unsubscribe function. */\n onChange: (listener: () => void) => () => void\n}\n\n/** What the surrounding app decides: the open editor and the `blocks.structure` / `blocks.treeRoot` settings. */\nexport interface TreeContext {\n editor: TreeEditor | undefined\n structure: string\n treeRoot: string\n}\n\nexport interface TreeModelOptions {\n /** Words the menus, the drop refusals and the label of an untitled open document; the framework layer passes the context's `t`. */\n t: Translate\n store: DocumentStore\n /** The view state shared by the trees of one app: open store items and kind filters (persisted). */\n view: TreeViewModel\n execute: TreeExecutor\n context: TreeContext\n /** The folder new documents and folders go to; default the root. */\n selectedFolder?: string\n /** How long the outline waits for the document to settle before it is read again; default 150 ms. */\n outlineDebounceMs?: number\n}\n\n/** A drag in progress. */\nexport interface TreeDrag {\n source: DragPayload\n /** Key of the dragged row (`''` for a `foreign-block`, which has no row here) */\n sourceKey: string\n /** Key of the row under the pointer */\n hover: string | null\n /** What dropping on `hover` would do; `null` without a `hover` */\n verdict: DropVerdict | null\n}\n\n/** A folder being renamed. */\nexport interface TreeRename {\n /** Key of the folder's row */\n key: string\n path: string\n /** Its name when renaming started */\n base: string\n draft: string\n error: string | null\n}\n\n/** A folder being named. */\nexport interface TreeCreateFolder {\n /** Folder path the folder is created in */\n parent: string\n draft: string\n error: string | null\n}\n\n/** Everything a renderer needs. Fields below `view` are what the derived `view` was computed from and what `rowOf` reads. */\nexport interface TreeState {\n /** The loaded folder tree: `undefined` = not loaded yet, `null` = loading failed. */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n structure: string\n kinds: readonly CompositeKind[]\n /** The open editor's baskets (colours of the row dots). */\n baskets: readonly Basket[]\n hasEditor: boolean\n outline: Outline\n nodeFilters: NodeFilters\n /** The basket ids the tree shows (`[]` = all). */\n basketFilter: readonly string[]\n /** Key of the focused row: the tree lists only its children. `null` = no focus. */\n focusKey: string | null\n expanded: readonly string[]\n collapsedOutline: readonly string[]\n /** What the title filter input holds. */\n filterText: string\n filterOverrides: Readonly<Record<string, boolean>>\n /** The folder new documents, folders and host imports go to. */\n selectedFolder: string\n /** Virtual mode: block ID of the selected Baustein that takes Bausteine; `null` = the document itself. */\n virtualTarget: string | null\n drag: TreeDrag | null\n renaming: TreeRename | null\n creatingFolder: TreeCreateFolder | null\n /** Key of the row whose deletion is running. */\n removing: string | null\n view: TreeView\n /** The unfiltered items from the top down to the focused one (the breadcrumb); empty without a focus. Derived with `view`. */\n focusPath: readonly TreeItem[]\n}\n\n/** One row of a row's menu. */\nexport interface TreeMenuEntry {\n label: string\n icon: string\n run: () => void\n}\n\n/** How a renderer draws one row. */\nexport interface TreeRowState extends TreeRow {\n /** The row's document is the open one. */\n active: boolean\n /** The row is the selected folder, or (virtual mode) the selected Baustein. */\n selected: boolean\n /** What dropping the drag on this row would do, while the pointer is over it. */\n drop: DropVerdict | null\n renaming: TreeRename | null\n removing: boolean\n /** The kinds the row's kind filter can hide below it, and the ones it hides. */\n filterKinds: readonly CompositeKind[]\n hiddenKinds: readonly string[]\n /** The row offers a kind filter. */\n showFilter: boolean\n}\n\nexport interface TreeModel {\n readonly state: ReadonlyStore<TreeState>\n /** The open editor or a setting changed. */\n setContext: (context: TreeContext) => void\n /** The host selected another folder (it controls the value). */\n setSelectedFolder: (path: string) => void\n\n // --- what is open, filtered, typed\n /** Opens or closes a row; while the title filter is set the choice is discarded when it is cleared. */\n setOpen: (key: string, open: boolean) => void\n toggle: (key: string) => void\n /** Opens the rows (also during a title filter); closed rows are left alone otherwise. */\n expand: (keys: readonly string[]) => void\n /** Filters the rows by title (case-insensitive substring); `''` clears it and restores the opened rows from before. */\n setFilterText: (text: string) => void\n setKindHidden: (key: string, kind: string, hidden: boolean) => void\n clearFilter: (key: string) => void\n clearAllFilters: () => void\n /** Shows (`shown`) or stops showing the Bausteine of the basket; no basket shown = no filter. */\n setBasketShown: (id: string, shown: boolean) => void\n clearBasketFilter: () => void\n /** Focuses a Baustein row: the tree lists only its children and the editor hides everything else. */\n focus: (key: string) => void\n /** Leaves focus mode (tree and editor). */\n defocus: () => void\n /** Whether the Baustein row can be merged with the Baustein after it (it has a block ID and the editor accepts the merge). */\n canMerge: (item: TreeItem) => boolean\n /** Merges the Baustein row with the Baustein after it: the row keeps its title, id and meta and takes over the other one's body and sub-Bausteine. */\n merge: (item: TreeItem) => void\n\n // --- rows\n /** A row was chosen (click, Enter). */\n select: (item: TreeItem) => void\n /** `select`, and a folder or the root toggles. */\n activate: (item: TreeItem) => void\n addMenu: (item: TreeItem) => TreeMenuEntry[][]\n remove: (item: TreeItem) => Promise<void>\n\n // --- drag and drop\n isDraggable: (item: TreeItem) => boolean\n /** Starts dragging `item`; returns what the drag carries, `null` when `item` cannot be dragged. */\n dragStart: (item: TreeItem) => DragPayload | null\n /** The pointer is over `item`; returns the verdict (`null` without a drag). Only an `ok` one is a drop target. */\n dragOver: (item: TreeItem) => DropVerdict | null\n /** The pointer left `item` for good (not into one of its parts). */\n dragLeave: (item: TreeItem) => void\n dragEnd: () => void\n drop: (item: TreeItem) => Promise<void>\n /**\n * A Baustein from another surface or tree (`BLOCK_MIME`) is over `item`; returns the verdict, `null` while this\n * tree's own drag is running. Only an `ok` one is a drop target.\n */\n foreignDragOver: (item: TreeItem) => DropVerdict | null\n /** Drops the foreign Baustein `payload` on `item`: inserts a copy at the end of that Baustein (`menu`: offers the transforms at `x`, `y` instead). */\n dropForeign: (item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) => Promise<void>\n\n // --- renaming and creating folders\n startRename: (item: TreeItem) => void\n setRenameDraft: (text: string) => void\n cancelRename: () => void\n commitRename: () => Promise<void>\n /** The rename field lost focus: commit, or give up with a warning when the name is invalid. */\n blurRename: () => Promise<void>\n startCreateFolder: (parent: string) => void\n setFolderDraft: (text: string) => void\n cancelCreateFolder: () => void\n commitCreateFolder: () => Promise<void>\n\n dispose: () => void\n}\n\nconst NO_DOCUMENTS: readonly DocumentSummary[] = []\nconst NO_KINDS: readonly CompositeKind[] = []\nconst NO_BASKETS: readonly Basket[] = []\nconst NO_FILTERS: Readonly<Record<string, boolean>> = {}\nconst UNSET = Symbol('unset')\n\nconst isOutlineKey = (key: string) => key.startsWith('outline:')\n\n/** The state `core` holds: everything of `TreeState` but what is derived from the view. */\ntype TreeCore = Omit<TreeState, 'view' | 'focusPath'>\n\nconst withView = (c: TreeCore, view: TreeView): TreeState => ({ ...c, view, focusPath: view.focusPath })\n\nfunction sameVerdict(a: DropVerdict | null, b: DropVerdict | null): boolean {\n if (a === b) return true\n if (!a || !b) return false\n return a.ok ? b.ok : !b.ok && a.reason === b.reason\n}\n\n/** A row's state in `state` (`item` is one of `state.view.items`). */\nexport function rowOf(state: TreeState, item: TreeItem, t: Translate): TreeRowState {\n const hidden = state.nodeFilters[item.key] ?? []\n const kinds = filterKinds(item, { structure: state.structure, activeId: state.activeId, kinds: state.kinds, t })\n const virtualTarget = state.virtual && (item.key === VIRTUAL_ROOT ? state.virtualTarget === null : !!item.blockId && item.blockId === state.virtualTarget)\n return {\n ...state.view.rows.get(item.key)!,\n active: item.id !== undefined && item.id === state.activeId,\n selected: (item.type !== 'document' && item.path === state.selectedFolder) || virtualTarget,\n drop: state.drag?.hover === item.key ? state.drag.verdict : null,\n renaming: state.renaming?.key === item.key ? state.renaming : null,\n removing: state.removing === item.key,\n filterKinds: kinds,\n hiddenKinds: hidden,\n showFilter: kinds.length > 0 && (item.type === 'root' || item.type === 'folder' || !!item.children?.length || hidden.length > 0),\n }\n}\n\n/** A tree model over `options.store`; call `dispose` when its tree goes away. */\nexport function createTreeModel(options: TreeModelOptions): TreeModel {\n const { store, view: shared, execute, t } = options\n const debounceMs = options.outlineDebounceMs ?? 150\n\n let editor = options.context.editor\n let structure = options.context.structure\n let treeRoot = options.context.treeRoot\n let unwatchEditor = editor?.onChange(onEditorChange)\n /** The focus the editor last showed that the tree took over (or already had); a change of the editor's focus is told apart from the tree's own by comparing against it. */\n let seenFocus: string | null = null\n let outlineTimer: ReturnType<typeof setTimeout> | undefined\n /** A folder move the host is running: until it is done, a selected folder at the old path follows to the new one. */\n let pendingMove: { from: string, to: string } | undefined\n let disposed = false\n\n const isVirtual = () => treeRoot === 'file' && structure === 'composite' && !!editor\n\n let core: TreeCore = {\n tree: store.tree.get(),\n documents: store.documents.get() ?? NO_DOCUMENTS,\n activeId: store.activeId.get(),\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n nodeFilters: shared.nodeFilters.get(),\n basketFilter: shared.basketFilter.get(),\n focusKey: null,\n expanded: shared.expanded.get(),\n collapsedOutline: [],\n filterText: '',\n filterOverrides: NO_FILTERS,\n selectedFolder: options.selectedFolder ?? '',\n virtualTarget: null,\n drag: null,\n renaming: null,\n creatingFolder: null,\n removing: null,\n }\n let lastView: { deps: readonly unknown[], view: TreeView } | undefined\n let lastTree: TreeFolder | null | undefined | typeof UNSET = UNSET\n let folderPaths = new Set<string>()\n let lastActiveFolder: string | undefined | typeof UNSET = UNSET\n let lastActiveId: string | undefined | typeof UNSET = UNSET\n\n const dropEnv = (): DropEnv => ({ virtual: core.virtual, moveVerdict: editor?.moveVerdict, canTransfer: editor?.canTransfer() ?? false, t })\n\n function viewOf(c: TreeCore): TreeView {\n const deps = [c.tree, c.documents, c.activeId, c.virtual, c.outline, c.kinds, c.nodeFilters, c.basketFilter, c.baskets, c.focusKey, c.expanded, c.collapsedOutline, c.filterText, c.filterOverrides]\n if (lastView && deps.every((dep, i) => Object.is(dep, lastView!.deps[i]))) return lastView.view\n // A basket the open editor does not offer cannot be unchecked in the filter menu, so it never filters.\n const basketFilter = c.basketFilter.filter(id => basketById(c.baskets, id) !== undefined)\n const view = deriveTree({ ...c, basketFilter, t, select: selectItem })\n lastView = { deps, view }\n return view\n }\n\n const renameError = (draft: string, path: string, base: string, tree: TreeFolder | null | undefined) =>\n draft.trim() === base ? null : store.validateName(draft, folderNamesIn(tree, parentPath(path), path))\n const folderError = (draft: string, parent: string, tree: TreeFolder | null | undefined) =>\n draft.trim() ? store.validateName(draft, folderNamesIn(tree, parent)) : null\n\n /** Measures everything the tree remembers against the current tree: what is gone is dropped, what depends on the tree is recomputed. */\n function reconcile(c: TreeCore, view: TreeView): TreeCore {\n let next = c\n if (c.tree !== lastTree) {\n lastTree = c.tree\n folderPaths = new Set<string>()\n if (c.tree) collectFolderPaths(c.tree, folderPaths)\n if (c.tree && !folderPaths.has(next.selectedFolder)) {\n const followed = pendingMove ? remapFolderPath(next.selectedFolder, pendingMove.from, pendingMove.to) : ''\n next = { ...next, selectedFolder: folderPaths.has(followed) ? followed : '' }\n }\n }\n if (next.virtualTarget !== null && (!next.virtual || !view.keys.has(`outline:${next.virtualTarget}`))) next = { ...next, virtualTarget: null }\n if (next.focusKey !== null && !view.keys.has(next.focusKey)) next = { ...next, focusKey: null }\n if (next.renaming) {\n const r = next.renaming\n if (!view.keys.has(r.key)) next = { ...next, renaming: null }\n else {\n const error = renameError(r.draft, r.path, r.base, next.tree)\n if (error !== r.error) next = { ...next, renaming: { ...r, error } }\n }\n }\n if (next.creatingFolder) {\n const f = next.creatingFolder\n if (next.tree && !folderPaths.has(f.parent)) next = { ...next, creatingFolder: null }\n else {\n const error = folderError(f.draft, f.parent, next.tree)\n if (error !== f.error) next = { ...next, creatingFolder: { ...f, error } }\n }\n }\n if (next.drag) {\n const d = next.drag\n if ((d.source.type !== 'foreign-block' && !view.keys.has(d.sourceKey)) || (d.hover !== null && !view.keys.has(d.hover))) next = { ...next, drag: null }\n else if (d.hover !== null) {\n const target = view.rows.get(d.hover)?.item\n const verdict = target ? dropVerdict(d.source, target, dropEnv()) : d.verdict\n if (!sameVerdict(verdict, d.verdict)) next = { ...next, drag: { ...d, verdict } }\n }\n }\n return next\n }\n\n const state = createStore<TreeState>(withView(core, viewOf(core)))\n\n function publish(c: TreeCore) {\n if (disposed) return\n const view = viewOf(c)\n core = reconcile(c, view)\n const next = withView(core, view)\n const current = state.get()\n if ((Object.keys(next) as (keyof TreeState)[]).every(key => Object.is(next[key], current[key]))) return\n state.set(next)\n }\n\n const patch = (changes: Partial<TreeCore>) => publish({ ...core, ...changes })\n\n // --- sources ---------------------------------------------------------------------------------------------------\n\n /** Reads the store and the shared view state; what opening a document shows is opened. */\n function sync() {\n if (disposed) return\n const documents = store.documents.get() ?? NO_DOCUMENTS\n const activeId = store.activeId.get()\n publish({ ...core, tree: store.tree.get(), documents, activeId, nodeFilters: shared.nodeFilters.get(), basketFilter: shared.basketFilter.get(), expanded: shared.expanded.get() })\n // Opening a document (also by URL, or after a move) shows it: its folders open and its folder becomes the selected one.\n const activeFolder = documents.find(d => d.id === activeId)?.folder\n if (activeFolder !== lastActiveFolder) {\n lastActiveFolder = activeFolder\n expand(ancestorKeys(activeFolder ?? ''))\n if (activeFolder !== undefined) setSelectedFolder(activeFolder)\n }\n if (activeId !== lastActiveId) {\n lastActiveId = activeId\n if (activeId) expand([`doc:${activeId}`])\n }\n }\n\n const unsubscribe = [\n store.tree.subscribe(sync),\n store.documents.subscribe(sync),\n store.activeId.subscribe(sync),\n shared.nodeFilters.subscribe(sync),\n shared.basketFilter.subscribe(sync),\n shared.expanded.subscribe(sync),\n ]\n\n function readOutline() {\n patch({ outline: editor ? editor.outline(structure) : EMPTY_OUTLINE })\n mirrorFocus()\n }\n\n /**\n * The editor's focus mode changed on its own (the focus chip, a block's „Fokussieren“, the focused Baustein vanished):\n * the tree follows without a command. A Baustein the outline does not know yet is retried after the next outline read.\n */\n function mirrorFocus() {\n const id = editor?.focusedId() ?? null\n if (id === seenFocus) return\n if (id === null) {\n seenFocus = null\n if (core.focusKey !== null) patch({ focusKey: null })\n return\n }\n const key = `outline:${id}`\n if (core.focusKey !== key) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'composite') return\n patch({ focusKey: key })\n }\n seenFocus = id\n }\n\n // The outline is read when the document changed and has been quiet for a moment; a drag in progress is checked at once, and so is the editor's focus.\n function onEditorChange() {\n clearTimeout(outlineTimer)\n outlineTimer = setTimeout(readOutline, debounceMs)\n if (core.drag) publish(core)\n mirrorFocus()\n }\n\n function setContext(context: TreeContext) {\n if (context.editor === editor && context.structure === structure && context.treeRoot === treeRoot) return\n const editorChanged = context.editor !== editor\n const wasVirtual = core.virtual\n editor = context.editor\n structure = context.structure\n treeRoot = context.treeRoot\n clearTimeout(outlineTimer)\n if (editorChanged) {\n seenFocus = null\n unwatchEditor?.()\n unwatchEditor = editor?.onChange(onEditorChange)\n }\n patch({\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n ...(editorChanged ? { focusKey: null } : {}),\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n })\n if (core.virtual && !wasVirtual) expand([VIRTUAL_ROOT])\n mirrorFocus()\n }\n\n // --- open, filtered, typed -------------------------------------------------------------------------------------\n\n const filtering = () => filterQuery(core.filterText) !== ''\n\n function setOpen(key: string, open: boolean) {\n if (filtering()) patch({ filterOverrides: { ...core.filterOverrides, [key]: open } })\n else if (isOutlineKey(key)) patch({ collapsedOutline: open ? core.collapsedOutline.filter(k => k !== key) : [...core.collapsedOutline.filter(k => k !== key), key] })\n else if (open) shared.expand([key])\n else shared.expanded.set(shared.expanded.get().filter(k => k !== key))\n }\n\n function expand(keys: readonly string[]) {\n const outlineKeys = keys.filter(isOutlineKey)\n const { filterOverrides } = core\n const overridden = keys.some(key => key in filterOverrides)\n if (overridden || outlineKeys.some(key => core.collapsedOutline.includes(key))) {\n patch({\n collapsedOutline: core.collapsedOutline.filter(key => !outlineKeys.includes(key)),\n filterOverrides: overridden ? Object.fromEntries(Object.entries(filterOverrides).filter(([key]) => !keys.includes(key))) : filterOverrides,\n })\n }\n shared.expand(keys.filter(key => !isOutlineKey(key)))\n }\n\n function setFilterText(text: string) {\n patch({ filterText: text, filterOverrides: filterQuery(text) ? core.filterOverrides : NO_FILTERS })\n }\n\n // --- focus -----------------------------------------------------------------------------------------------------\n\n /** Only a Baustein the editor can address (it has a block ID) can be focused. */\n function focus(key: string) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'composite' || !item.blockId) return\n patch({ focusKey: key })\n void execute({ type: 'focusBlock', id: item.blockId })\n }\n\n function defocus() {\n if (core.focusKey === null) return\n patch({ focusKey: null })\n void execute({ type: 'focusBlock', id: null })\n }\n\n // --- merge -----------------------------------------------------------------------------------------------------\n\n const canMerge = (item: TreeItem) => item.type === 'composite' && !!item.blockId && !!editor?.canMerge(item.blockId)\n\n function merge(item: TreeItem) {\n if (canMerge(item)) void execute({ type: 'mergeBlock', id: item.blockId! })\n }\n\n // --- selection -------------------------------------------------------------------------------------------------\n\n function setSelectedFolder(path: string) {\n patch({ selectedFolder: path })\n }\n\n function selectItem(item: TreeItem) {\n if (core.renaming?.key === item.key) return\n if (item.key === VIRTUAL_ROOT) return patch({ virtualTarget: null })\n if (item.type === 'document') {\n setSelectedFolder(item.folder ?? '')\n void execute({ type: 'openDocument', id: item.id! })\n }\n else if (item.type === 'composite' || item.type === 'heading') {\n void execute({ type: 'revealBlock', id: item.blockId ?? null, pos: item.pos! })\n const takesBausteine = !!item.kind && core.kinds.some(kind => kindAccepts(core.kinds, item.kind!, kind.id))\n if (core.virtual && item.blockId && takesBausteine) patch({ virtualTarget: item.blockId })\n }\n else {\n setSelectedFolder(item.path ?? '')\n }\n }\n\n function toggle(key: string) {\n setOpen(key, !state.get().view.rows.get(key)?.open)\n }\n\n /** A folder moved from `from` to `to`: its open/selected state follows it. */\n function followFolderMove(from: string, to: string) {\n shared.followFolderMove(from, to)\n patch({\n selectedFolder: remapFolderPath(core.selectedFolder, from, to),\n filterOverrides: Object.fromEntries(Object.entries(core.filterOverrides).map(([key, open]) => [key.startsWith('folder:') ? `folder:${remapFolderPath(key.slice(7), from, to)}` : key, open])),\n })\n expand(ancestorKeys(parentPath(to)))\n }\n\n async function moveFolder(from: string, to: string) {\n pendingMove = { from, to }\n const moved = await execute({ type: 'moveFolder', from, to })\n pendingMove = undefined\n if (moved) followFolderMove(from, to)\n }\n\n // --- drag and drop ---------------------------------------------------------------------------------------------\n\n function dragStart(item: TreeItem) {\n if (core.renaming?.key === item.key || !isDraggable(item, core.virtual)) return null\n const source = dragPayloadOf(item)\n patch({ drag: { source, sourceKey: item.key, hover: null, verdict: null } })\n return source\n }\n\n function dragOver(item: TreeItem) {\n const drag = core.drag\n if (!drag) return null\n const verdict = dropVerdict(drag.source, item, dropEnv())\n if (drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { ...drag, hover: item.key, verdict } })\n return verdict\n }\n\n function foreignDragOver(item: TreeItem) {\n const drag = core.drag\n if (drag && drag.source.type !== 'foreign-block') return null\n const source: DragPayload = { type: 'foreign-block' }\n const verdict = dropVerdict(source, item, dropEnv())\n if (!drag || drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { source, sourceKey: '', hover: item.key, verdict } })\n return verdict\n }\n\n async function dropForeign(item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) {\n // This tree's own drag (a row also writes the block payload) is a move, not a transfer.\n if (core.drag && core.drag.source.type !== 'foreign-block') return\n patch({ drag: null })\n if (!dropVerdict({ type: 'foreign-block' }, item, dropEnv()).ok) return\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n // A throwing executor (the contract says it never does) must not leave the drop handler with an unhandled rejection.\n let done = false\n try {\n done = await execute({ type: 'transferBlock', payload, targetId, menu, x, y })\n }\n catch {\n return\n }\n if (done && targetId && !menu) expand([`outline:${targetId}`])\n }\n\n async function drop(item: TreeItem) {\n const drag = core.drag\n patch({ drag: null })\n if (!drag || !dropVerdict(drag.source, item, dropEnv()).ok) return\n const { source } = drag\n if (source.type === 'composite') {\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n if (await execute({ type: 'moveBlock', id: source.blockId, targetId }) && targetId) expand([`outline:${targetId}`])\n return\n }\n // A foreign Baustein is dropped through `dropForeign`, which reads its payload; it is no move of this tree.\n if (source.type === 'foreign-block') return\n const targetPath = item.path!\n if (source.type === 'document') {\n if (await execute({ type: 'moveDocument', id: source.id!, folder: targetPath })) expand(ancestorKeys(targetPath))\n return\n }\n await moveFolder(source.path, joinPath(targetPath, source.path.slice(source.path.lastIndexOf('/') + 1)))\n }\n\n // --- renaming, creating ----------------------------------------------------------------------------------------\n\n function startRename(item: TreeItem) {\n if (item.type !== 'folder') return\n patch({ renaming: { key: item.key, path: item.path!, base: item.label, draft: item.label, error: null } })\n }\n\n async function commitRename() {\n const r = core.renaming\n // An invalid name keeps the field open with its inline error.\n if (!r || r.error) return\n const name = r.draft.trim()\n patch({ renaming: null })\n if (name !== r.base) await moveFolder(r.path, joinPath(parentPath(r.path), name))\n }\n\n async function blurRename() {\n const r = core.renaming\n if (!r) return\n if (r.error) {\n void execute({ type: 'warn', title: t('tree.folder.renameFailed'), description: r.error })\n patch({ renaming: null })\n return\n }\n await commitRename()\n }\n\n function startCreateFolder(parent: string) {\n patch({ selectedFolder: parent, creatingFolder: { parent, draft: '', error: null } })\n }\n\n async function commitCreateFolder() {\n const f = core.creatingFolder\n if (!f) return\n if (!f.draft.trim()) return patch({ creatingFolder: null })\n if (f.error) return\n patch({ creatingFolder: null })\n if (await execute({ type: 'createFolder', path: joinPath(f.parent, f.draft.trim()) })) expand(ancestorKeys(f.parent))\n }\n\n // --- menus, deleting -------------------------------------------------------------------------------------------\n\n async function createDocumentIn(folder: string) {\n setSelectedFolder(folder)\n if (await execute({ type: 'createDocument', folder })) expand(ancestorKeys(folder))\n }\n\n /** Runs `command` for the Baustein of `item` (the file itself when it has none) and shows the result. */\n async function inComposite(item: TreeItem, command: TreeCommand) {\n if (await execute(command)) expand([item.blockId ? `outline:${item.blockId}` : item.key])\n }\n\n /**\n * What can be created below `item`: folders of the store take documents and sub-folders, the open file (as the root or\n * as a document row) and its Bausteine take what their kind accepts. Other rows take nothing. Folders also list\n * „Umbenennen“ here: renaming a document happens in the editor's title field.\n */\n function addMenu(item: TreeItem): TreeMenuEntry[][] {\n const groups: TreeMenuEntry[][] = []\n if (item.key !== VIRTUAL_ROOT && (item.type === 'root' || item.type === 'folder')) {\n const path = item.path!\n groups.push([\n { label: t('tree.menu.newDocument'), icon: 'i-lucide-file-plus', run: () => void createDocumentIn(path) },\n { label: item.type === 'root' ? t('tree.menu.newFolder') : t('tree.menu.newSubfolder'), icon: 'i-lucide-folder-plus', run: () => startCreateFolder(path) },\n ])\n }\n else {\n const can = creatableBelow(item, { structure: core.structure, hasEditor: core.hasEditor, activeId: core.activeId, kinds: core.kinds })\n const targetId = item.blockId ?? null\n const entries: TreeMenuEntry[] = []\n if (can.folder) entries.push({ label: t('tree.menu.newCompositeFolder'), icon: 'i-lucide-folder-plus', run: () => void inComposite(item, { type: 'createBausteinFolder', targetId }) })\n if (can.document) entries.push({ label: t('tree.menu.importFile'), icon: 'i-lucide-file-up', run: () => void inComposite(item, { type: 'importFiles', targetId }) })\n if (entries.length) groups.push(entries)\n }\n if (item.type === 'folder') groups.push([{ label: t('tree.menu.rename'), icon: 'i-lucide-pencil', run: () => startRename(item) }])\n return groups\n }\n\n async function remove(item: TreeItem) {\n patch({ removing: item.key })\n try {\n await execute(item.type === 'document' ? { type: 'removeDocument', id: item.id!, folder: item.folder ?? '' } : { type: 'removeFolder', path: item.path! })\n }\n finally {\n patch({ removing: null })\n }\n }\n\n sync()\n mirrorFocus()\n\n return {\n state,\n setContext,\n setSelectedFolder,\n setOpen,\n toggle,\n expand,\n setFilterText,\n setKindHidden: (key, kind, hidden) => shared.setKindHidden(key, kind, hidden),\n clearFilter: key => shared.clearFilter(key),\n clearAllFilters: () => shared.clearAllFilters(),\n setBasketShown: (id, shown) => shared.setBasketShown(id, shown),\n clearBasketFilter: () => shared.clearBasketFilter(),\n focus,\n defocus,\n canMerge,\n merge,\n select: selectItem,\n activate(item) {\n selectItem(item)\n if (item.type === 'root' || item.type === 'folder') toggle(item.key)\n },\n addMenu,\n remove,\n isDraggable: item => core.renaming?.key !== item.key && isDraggable(item, core.virtual),\n dragStart,\n dragOver,\n dragLeave(item) {\n // A foreign drag only exists while it is over this tree (no `dragend` reaches here), so leaving a row ends it; the next row's `foreignDragOver` starts it again.\n if (core.drag?.source.type === 'foreign-block') patch({ drag: null })\n else if (core.drag?.hover === item.key) patch({ drag: { ...core.drag, hover: null, verdict: null } })\n },\n dragEnd: () => patch({ drag: null }),\n drop,\n foreignDragOver,\n dropForeign,\n startRename,\n setRenameDraft(text) {\n const r = core.renaming\n if (r) patch({ renaming: { ...r, draft: text, error: renameError(text, r.path, r.base, core.tree) } })\n },\n cancelRename: () => patch({ renaming: null }),\n commitRename,\n blurRename,\n startCreateFolder,\n setFolderDraft(text) {\n const f = core.creatingFolder\n if (f) patch({ creatingFolder: { ...f, draft: text, error: folderError(text, f.parent, core.tree) } })\n },\n cancelCreateFolder: () => patch({ creatingFolder: null }),\n commitCreateFolder,\n dispose() {\n disposed = true\n clearTimeout(outlineTimer)\n unwatchEditor?.()\n for (const stop of unsubscribe) stop()\n },\n }\n}\n"],"mappings":";;;;;;;;AAuQA,MAAM,eAA2C,CAAC;AAClD,MAAM,WAAqC,CAAC;AAC5C,MAAM,aAAgC,CAAC;AACvC,MAAM,aAAgD,CAAC;AACvD,MAAM,QAAQ,OAAO,OAAO;AAE5B,MAAM,gBAAgB,QAAgB,IAAI,WAAW,UAAU;AAK/D,MAAM,YAAY,GAAa,UAA+B;CAAE,GAAG;CAAG;CAAM,WAAW,KAAK;AAAU;AAEtG,SAAS,YAAY,GAAuB,GAAgC;CAC1E,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO;CACrB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE;AAC/C;;AAGA,SAAgB,MAAM,OAAkB,MAAgB,GAA4B;CAClF,MAAM,SAAS,MAAM,YAAY,KAAK,QAAQ,CAAC;CAC/C,MAAM,QAAQ,YAAY,MAAM;EAAE,WAAW,MAAM;EAAW,UAAU,MAAM;EAAU,OAAO,MAAM;EAAO;CAAE,CAAC;CAC/G,MAAM,gBAAgB,MAAM,YAAY,KAAK,QAAA,UAAuB,MAAM,kBA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AAgB;GAChB,KAAK,MAAM,QAAQ,aAAa,KAAK;EACvC;CACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { applyNodeFilters, collectKeys, folderItem, outlineItems, virtualRootItem } from "./tree-items.js";
1
+ import { applyBasketFilter, applyNodeFilters, folderItem, indexItems, outlineItems, pathTo, virtualRootItem } from "./tree-items.js";
2
2
  //#region src/tree/tree-rows.ts
3
3
  const isOutlineItem = (item) => item.type === "composite" || item.type === "heading";
4
4
  /** The normalized filter text: trimmed and lower-cased; empty = no filter. */
@@ -23,16 +23,26 @@ function pruneByText(list, query, matched, below) {
23
23
  /**
24
24
  * The tree to show. In the store's folders: the `Dokumente` root with folders and documents, the open document listing
25
25
  * its outline; in virtual mode: the open document as the root with its Bausteine. The kind filters (hidden kinds per
26
- * item) apply first, then the filter text: only matching rows and their ancestors stay, and the ancestors of a match
27
- * show open (without being written to `expanded`) until the filter text is cleared. A choice to open or close a row
28
- * made meanwhile lives in `filterOverrides`.
26
+ * item) apply first (on the children of the focused item while a focus is set), then the basket filter (composites of
27
+ * other baskets go unless a descendant stays; those ancestors are `dimmed`), then the filter text: only matching rows and
28
+ * their ancestors stay, and the ancestors of a match show open (without being written to `expanded`) until the filter
29
+ * text is cleared. A choice to open or close a row made meanwhile lives in `filterOverrides`.
29
30
  */
30
31
  function deriveTree(input) {
31
32
  const { tree, virtual, activeId, nodeFilters, select } = input;
32
33
  const outline = outlineItems(input.outline.nodes, input.kinds, select);
33
34
  const unfiltered = virtual ? [virtualRootItem(input.documents.find((d) => d.id === activeId)?.title ?? input.t("tree.rootFallback"), outline, select)] : tree ? [folderItem(tree, activeId, outline, select)] : [];
34
- const keys = collectKeys(unfiltered, /* @__PURE__ */ new Set());
35
- let items = applyNodeFilters(unfiltered, nodeFilters);
35
+ const index = indexItems(unfiltered, /* @__PURE__ */ new Map());
36
+ const keys = new Set(index.keys());
37
+ const focusPath = input.focusKey !== null ? pathTo(index, input.focusKey) : [];
38
+ const focused = focusPath.at(-1);
39
+ let items;
40
+ if (focused) {
41
+ const inherited = new Set(focusPath.flatMap((item) => nodeFilters[item.key] ?? []));
42
+ items = applyNodeFilters(focused.children ?? [], nodeFilters, inherited);
43
+ } else items = applyNodeFilters(unfiltered, nodeFilters);
44
+ const dimmed = /* @__PURE__ */ new Set();
45
+ if (input.basketFilter.length) items = applyBasketFilter(items, new Set(input.basketFilter), dimmed);
36
46
  const query = filterQuery(input.filterText);
37
47
  const matched = /* @__PURE__ */ new Set();
38
48
  const below = /* @__PURE__ */ new Set();
@@ -54,7 +64,8 @@ function deriveTree(input) {
54
64
  expandable,
55
65
  open: isOpen,
56
66
  forcedOpen: isOpen && forced && !stored,
57
- match: at >= 0 ? [at, query.length] : null
67
+ match: at >= 0 ? [at, query.length] : null,
68
+ dimmed: dimmed.has(item.key)
58
69
  });
59
70
  if (isOpen) open.push(item.key);
60
71
  if (item.children) walk(item.children, depth + 1);
@@ -66,6 +77,8 @@ function deriveTree(input) {
66
77
  rows,
67
78
  open,
68
79
  keys,
80
+ index,
81
+ focusPath,
69
82
  hasKindFilters: Object.entries(nodeFilters).some(([key, hidden]) => hidden.length > 0 && keys.has(key)),
70
83
  isEmpty: !virtual && !!tree && !tree.folders.length && !tree.documents.length,
71
84
  noMatches: !!query && items.length === 0 && (virtual || !!tree)
@@ -1 +1 @@
1
- {"version":3,"file":"tree-rows.js","names":[],"sources":["../../src/tree/tree-rows.ts"],"sourcesContent":["import type { CompositeKind } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport {\n applyNodeFilters,\n collectKeys,\n folderItem,\n type Outline,\n outlineItems,\n type TreeItem,\n virtualRootItem,\n} from './tree-items'\nimport type { NodeFilters } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// The visible rows of the document tree as one pure function of what the tree has loaded and what the user opened,\n// filtered and typed. No framework, no editor, no store.\n\n/** Everything `deriveTree` reads. */\nexport interface TreeInput {\n /** Words the root's label while the open document has no title in `documents`. */\n t: Translate\n /** `null` = loading failed, `undefined` = not loaded yet */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n outline: Outline\n kinds: readonly CompositeKind[]\n /** Hidden kinds per item key */\n nodeFilters: NodeFilters\n /** Keys of the open store items (folders, documents, the roots) */\n expanded: readonly string[]\n /** Outline entries start open: only the closed ones are listed. */\n collapsedOutline: readonly string[]\n /** What the title filter shows; blank = no filter */\n filterText: string\n /** While a filter text is set: open (`true`) or closed (`false`) choices made meanwhile, by item key. Ignored without a filter text. */\n filterOverrides: Readonly<Record<string, boolean>>\n /** Chosen on an item (a row click, Enter). */\n select: (item: TreeItem) => void\n}\n\n/** What the tree knows about one visible row. */\nexport interface TreeRow {\n /** The (filtered) item of the row. */\n item: TreeItem\n depth: number\n /** The item has (or may get) children and shows a chevron. */\n expandable: boolean\n open: boolean\n /** Open only because the filter text matches below it. */\n forcedOpen: boolean\n /** `[start, length]` of the filter text in the label when this row's title matches. */\n match: readonly [number, number] | null\n}\n\nexport interface TreeView {\n /** The items to render: the kind filters and the filter text applied. */\n items: TreeItem[]\n /** Per key of the items in `items`. */\n rows: ReadonlyMap<string, TreeRow>\n /** Keys of the open rows, for a host tree that wants a list. */\n open: string[]\n /** Every key the unfiltered tree has: what a stale key is measured against. */\n keys: ReadonlySet<string>\n /** A kind filter of an existing item hides something. */\n hasKindFilters: boolean\n /** The store has no folder and no document. */\n isEmpty: boolean\n /** A filter text is set and nothing matches it. */\n noMatches: boolean\n}\n\nconst isOutlineItem = (item: TreeItem) => item.type === 'composite' || item.type === 'heading'\n\n/** The normalized filter text: trimmed and lower-cased; empty = no filter. */\nexport const filterQuery = (filterText: string) => filterText.trim().toLowerCase()\n\n/**\n * Keeps the items whose label contains `query` and the ancestors of such items; everything else goes, also below a\n * match. `matched` collects the keys of the matches, `below` those that have a match among their descendants.\n */\nfunction pruneByText(list: readonly TreeItem[], query: string, matched: Set<string>, below: Set<string>): TreeItem[] {\n return list.flatMap((item) => {\n const hit = item.label.toLowerCase().includes(query)\n const children = item.children ? pruneByText(item.children, query, matched, below) : []\n if (hit) matched.add(item.key)\n if (children.length) below.add(item.key)\n if (!hit && !children.length) return []\n return [{ ...item, children: children.length ? children : undefined }]\n })\n}\n\n/**\n * The tree to show. In the store's folders: the `Dokumente` root with folders and documents, the open document listing\n * its outline; in virtual mode: the open document as the root with its Bausteine. The kind filters (hidden kinds per\n * item) apply first, then the filter text: only matching rows and their ancestors stay, and the ancestors of a match\n * show open (without being written to `expanded`) until the filter text is cleared. A choice to open or close a row\n * made meanwhile lives in `filterOverrides`.\n */\nexport function deriveTree(input: TreeInput): TreeView {\n const { tree, virtual, activeId, nodeFilters, select } = input\n const outline = outlineItems(input.outline.nodes, input.kinds, select)\n const unfiltered: TreeItem[] = virtual\n ? [virtualRootItem(input.documents.find(d => d.id === activeId)?.title ?? input.t('tree.rootFallback'), outline, select)]\n : tree ? [folderItem(tree, activeId, outline, select)] : []\n const keys = collectKeys(unfiltered, new Set())\n\n let items = applyNodeFilters(unfiltered, nodeFilters)\n const query = filterQuery(input.filterText)\n const matched = new Set<string>()\n const below = new Set<string>()\n if (query) items = pruneByText(items, query, matched, below)\n\n const expanded = new Set(input.expanded)\n const collapsed = new Set(input.collapsedOutline)\n const rows = new Map<string, TreeRow>()\n const open: string[] = []\n const walk = (list: readonly TreeItem[], depth: number) => {\n for (const item of list) {\n const expandable = item.type === 'root' || item.type === 'folder' || !!item.children?.length\n const stored = isOutlineItem(item) ? !collapsed.has(item.key) : expanded.has(item.key)\n const forced = below.has(item.key)\n const isOpen = expandable && ((query ? input.filterOverrides[item.key] : undefined) ?? (forced || stored))\n const at = matched.has(item.key) ? item.label.toLowerCase().indexOf(query) : -1\n rows.set(item.key, { item, depth, expandable, open: isOpen, forcedOpen: isOpen && forced && !stored, match: at >= 0 ? [at, query.length] : null })\n if (isOpen) open.push(item.key)\n if (item.children) walk(item.children, depth + 1)\n }\n }\n walk(items, 0)\n\n return {\n items,\n rows,\n open,\n keys,\n hasKindFilters: Object.entries(nodeFilters).some(([key, hidden]) => hidden.length > 0 && keys.has(key)),\n isEmpty: !virtual && !!tree && !tree.folders.length && !tree.documents.length,\n noMatches: !!query && items.length === 0 && (virtual || !!tree),\n }\n}\n"],"mappings":";;AA0EA,MAAM,iBAAiB,SAAmB,KAAK,SAAS,eAAe,KAAK,SAAS;;AAGrF,MAAa,eAAe,eAAuB,WAAW,KAAK,CAAC,CAAC,YAAY;;;;;AAMjF,SAAS,YAAY,MAA2B,OAAe,SAAsB,OAAgC;CACnH,OAAO,KAAK,SAAS,SAAS;EAC5B,MAAM,MAAM,KAAK,MAAM,YAAY,CAAC,CAAC,SAAS,KAAK;EACnD,MAAM,WAAW,KAAK,WAAW,YAAY,KAAK,UAAU,OAAO,SAAS,KAAK,IAAI,CAAC;EACtF,IAAI,KAAK,QAAQ,IAAI,KAAK,GAAG;EAC7B,IAAI,SAAS,QAAQ,MAAM,IAAI,KAAK,GAAG;EACvC,IAAI,CAAC,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC;EACtC,OAAO,CAAC;GAAE,GAAG;GAAM,UAAU,SAAS,SAAS,WAAW,KAAA;EAAU,CAAC;CACvE,CAAC;AACH;;;;;;;;AASA,SAAgB,WAAW,OAA4B;CACrD,MAAM,EAAE,MAAM,SAAS,UAAU,aAAa,WAAW;CACzD,MAAM,UAAU,aAAa,MAAM,QAAQ,OAAO,MAAM,OAAO,MAAM;CACrE,MAAM,aAAyB,UAC3B,CAAC,gBAAgB,MAAM,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,mBAAmB,GAAG,SAAS,MAAM,CAAC,IACtH,OAAO,CAAC,WAAW,MAAM,UAAU,SAAS,MAAM,CAAC,IAAI,CAAC;CAC5D,MAAM,OAAO,YAAY,4BAAY,IAAI,IAAI,CAAC;CAE9C,IAAI,QAAQ,iBAAiB,YAAY,WAAW;CACpD,MAAM,Q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AAC,KAAK,QAAQ,UAAU,CAAC,KAAK,UAAU;EACvE,WAAW,CAAC,CAAC,SAAS,MAAM,WAAW,MAAM,WAAW,CAAC,CAAC;CAC5D;AACF"}
1
+ {"version":3,"file":"tree-rows.js","names":[],"sources":["../../src/tree/tree-rows.ts"],"sourcesContent":["import type { CompositeKind } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport {\n applyBasketFilter,\n applyNodeFilters,\n folderItem,\n type IndexedItem,\n indexItems,\n type Outline,\n outlineItems,\n pathTo,\n type TreeItem,\n virtualRootItem,\n} from './tree-items'\nimport type { NodeFilters } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// The visible rows of the document tree as one pure function of what the tree has loaded and what the user opened,\n// filtered and typed. No framework, no editor, no store.\n\n/** Everything `deriveTree` reads. */\nexport interface TreeInput {\n /** Words the root's label while the open document has no title in `documents`. */\n t: Translate\n /** `null` = loading failed, `undefined` = not loaded yet */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n outline: Outline\n kinds: readonly CompositeKind[]\n /** Hidden kinds per item key */\n nodeFilters: NodeFilters\n /** The basket ids to show (`[]` = no basket filter): composites of other baskets without a visible descendant are hidden. */\n basketFilter: readonly string[]\n /** Key of the focused item: the tree then lists only its children. A key the tree no longer has is ignored. */\n focusKey: string | null\n /** Keys of the open store items (folders, documents, the roots) */\n expanded: readonly string[]\n /** Outline entries start open: only the closed ones are listed. */\n collapsedOutline: readonly string[]\n /** What the title filter shows; blank = no filter */\n filterText: string\n /** While a filter text is set: open (`true`) or closed (`false`) choices made meanwhile, by item key. Ignored without a filter text. */\n filterOverrides: Readonly<Record<string, boolean>>\n /** Chosen on an item (a row click, Enter). */\n select: (item: TreeItem) => void\n}\n\n/** What the tree knows about one visible row. */\nexport interface TreeRow {\n /** The (filtered) item of the row. */\n item: TreeItem\n depth: number\n /** The item has (or may get) children and shows a chevron. */\n expandable: boolean\n open: boolean\n /** Open only because the filter text matches below it. */\n forcedOpen: boolean\n /** `[start, length]` of the filter text in the label when this row's title matches. */\n match: readonly [number, number] | null\n /** A composite kept only because a descendant is shown by the basket filter. */\n dimmed: boolean\n}\n\nexport interface TreeView {\n /** The items to render: the focus, the kind filters, the basket filter and the filter text applied. */\n items: TreeItem[]\n /** Per key of the items in `items`. */\n rows: ReadonlyMap<string, TreeRow>\n /** Keys of the open rows, for a host tree that wants a list. */\n open: string[]\n /** Every key the unfiltered tree has: what a stale key is measured against. */\n keys: ReadonlySet<string>\n /** Every item of the unfiltered tree by key, with its parent's key. */\n index: ReadonlyMap<string, IndexedItem>\n /** The unfiltered items from the top down to the focused one; empty without a (known) focus. */\n focusPath: TreeItem[]\n /** A kind filter of an existing item hides something. */\n hasKindFilters: boolean\n /** The store has no folder and no document. */\n isEmpty: boolean\n /** A filter text is set and nothing matches it. */\n noMatches: boolean\n}\n\nconst isOutlineItem = (item: TreeItem) => item.type === 'composite' || item.type === 'heading'\n\n/** The normalized filter text: trimmed and lower-cased; empty = no filter. */\nexport const filterQuery = (filterText: string) => filterText.trim().toLowerCase()\n\n/**\n * Keeps the items whose label contains `query` and the ancestors of such items; everything else goes, also below a\n * match. `matched` collects the keys of the matches, `below` those that have a match among their descendants.\n */\nfunction pruneByText(list: readonly TreeItem[], query: string, matched: Set<string>, below: Set<string>): TreeItem[] {\n return list.flatMap((item) => {\n const hit = item.label.toLowerCase().includes(query)\n const children = item.children ? pruneByText(item.children, query, matched, below) : []\n if (hit) matched.add(item.key)\n if (children.length) below.add(item.key)\n if (!hit && !children.length) return []\n return [{ ...item, children: children.length ? children : undefined }]\n })\n}\n\n/**\n * The tree to show. In the store's folders: the `Dokumente` root with folders and documents, the open document listing\n * its outline; in virtual mode: the open document as the root with its Bausteine. The kind filters (hidden kinds per\n * item) apply first (on the children of the focused item while a focus is set), then the basket filter (composites of\n * other baskets go unless a descendant stays; those ancestors are `dimmed`), then the filter text: only matching rows and\n * their ancestors stay, and the ancestors of a match show open (without being written to `expanded`) until the filter\n * text is cleared. A choice to open or close a row made meanwhile lives in `filterOverrides`.\n */\nexport function deriveTree(input: TreeInput): TreeView {\n const { tree, virtual, activeId, nodeFilters, select } = input\n const outline = outlineItems(input.outline.nodes, input.kinds, select)\n const unfiltered: TreeItem[] = virtual\n ? [virtualRootItem(input.documents.find(d => d.id === activeId)?.title ?? input.t('tree.rootFallback'), outline, select)]\n : tree ? [folderItem(tree, activeId, outline, select)] : []\n const index = indexItems(unfiltered, new Map())\n const keys = new Set(index.keys())\n\n // A focus lists the children of the focused item; the filters of the items on the way down still apply to them.\n const focusPath = input.focusKey !== null ? pathTo(index, input.focusKey) : []\n const focused = focusPath.at(-1)\n let items: TreeItem[]\n if (focused) {\n const inherited = new Set(focusPath.flatMap(item => nodeFilters[item.key] ?? []))\n items = applyNodeFilters(focused.children ?? [], nodeFilters, inherited)\n }\n else {\n items = applyNodeFilters(unfiltered, nodeFilters)\n }\n const dimmed = new Set<string>()\n if (input.basketFilter.length) items = applyBasketFilter(items, new Set(input.basketFilter), dimmed)\n const query = filterQuery(input.filterText)\n const matched = new Set<string>()\n const below = new Set<string>()\n if (query) items = pruneByText(items, query, matched, below)\n\n const expanded = new Set(input.expanded)\n const collapsed = new Set(input.collapsedOutline)\n const rows = new Map<string, TreeRow>()\n const open: string[] = []\n const walk = (list: readonly TreeItem[], depth: number) => {\n for (const item of list) {\n const expandable = item.type === 'root' || item.type === 'folder' || !!item.children?.length\n const stored = isOutlineItem(item) ? !collapsed.has(item.key) : expanded.has(item.key)\n const forced = below.has(item.key)\n const isOpen = expandable && ((query ? input.filterOverrides[item.key] : undefined) ?? (forced || stored))\n const at = matched.has(item.key) ? item.label.toLowerCase().indexOf(query) : -1\n rows.set(item.key, { item, depth, expandable, open: isOpen, forcedOpen: isOpen && forced && !stored, match: at >= 0 ? [at, query.length] : null, dimmed: dimmed.has(item.key) })\n if (isOpen) open.push(item.key)\n if (item.children) walk(item.children, depth + 1)\n }\n }\n walk(items, 0)\n\n return {\n items,\n rows,\n open,\n keys,\n index,\n focusPath,\n hasKindFilters: Object.entries(nodeFilters).some(([key, hidden]) => hidden.length > 0 && keys.has(key)),\n isEmpty: !virtual && !!tree && !tree.folders.length && !tree.documents.length,\n noMatches: !!query && items.length === 0 && (virtual || !!tree),\n }\n}\n"],"mappings":";;AAuFA,MAAM,iBAAiB,SAAmB,KAAK,SAAS,eAAe,KAAK,SAAS;;AAGrF,MAAa,eAAe,eAAuB,WAAW,KAAK,CAAC,CAAC,YAAY;;;;;AAMjF,SAAS,YAAY,MAA2B,OAAe,SAAsB,OAAgC;CACnH,OAAO,KAAK,SAAS,SAAS;EAC5B,MAAM,MAAM,KAAK,MAAM,YAAY,CAAC,CAAC,SAAS,KAAK;EACnD,MAAM,WAAW,KAAK,WAAW,YAAY,KAAK,UAAU,OAAO,SAAS,KAAK,IAAI,CAAC;EACtF,IAAI,KAAK,QAAQ,IAAI,KAAK,GAAG;EAC7B,IAAI,SAAS,QAAQ,MAAM,IAAI,KAAK,GAAG;EACvC,IAAI,CAAC,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC;EACtC,OAAO,CAAC;GAAE,GAAG;GAAM,UAAU,SAAS,SAAS,WAAW,KAAA;EAAU,CAAC;CACvE,CAAC;AACH;;;;;;;;;AAUA,SAAgB,WAAW,OAA4B;CACrD,MAAM,EAAE,MAAM,SAAS,UAAU,aAAa,WAAW;CACzD,MAAM,UAAU,aAAa,MAAM,QAAQ,OAAO,MAAM,OAAO,MAAM;CACrE,MAAM,aAAyB,UAC3B,CAAC,gBAAgB,MAAM,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,mBAAmB,GAAG,SAAS,MAAM,CAAC,IACtH,OAAO,CAAC,WAAW,MAAM,UAAU,SAAS,MAAM,CAAC,IAAI,CAAC;CAC5D,MAAM,QAAQ,WAAW,4BAAY,IAAI,IAAI,CAAC;CAC9C,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AAC,QAAQ,KAAK,IAAI;GAC7E,KAAK,IAAI,KAAK,KAAK;IAAE;IAAM;IAAO;IAAY,MAAM;IAAQ,YAAY,UAAU,UAAU,CAAC;IAAQ,OAAO,MAAM,IAAI,CAAC,IAAI,MAAM,MAAM,IAAI;IAAM,QAAQ,OAAO,IAAI,KAAK,GAAG;GAAE,CAAC;GAC/K,IAAI,QAAQ,KAAK,KAAK,KAAK,GAAG;GAC9B,IAAI,KAAK,UAAU,KAAK,KAAK,UAAU,QAAQ,CAAC;EAClD;CACF;CACA,KAAK,OAAO,CAAC;CAEb,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,gBAAgB,OAAO,QAAQ,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,YAAY,OAAO,SAAS,KAAK,KAAK,IAAI,GAAG,CAAC;EACtG,SAAS,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,QAAQ,UAAU,CAAC,KAAK,UAAU;EACvE,WAAW,CAAC,CAAC,SAAS,MAAM,WAAW,MAAM,WAAW,CAAC,CAAC;CAC5D;AACF"}
@@ -7,6 +7,8 @@ export type NodeFilters = Record<string, string[]>;
7
7
  export interface TreeViewModel {
8
8
  /** The kinds hidden below each tree item, by item key. Persists in localStorage. Replace, never mutate. */
9
9
  nodeFilters: Store<NodeFilters>;
10
+ /** The basket ids whose Bausteine the tree shows; `[]` = all of them. Persists in localStorage. Replace, never mutate. */
11
+ basketFilter: Store<string[]>;
10
12
  /** Keys of the open tree items; lasts for the session. Replace, never mutate. */
11
13
  expanded: Store<string[]>;
12
14
  /** Opens the items (already open ones are left alone). */
@@ -15,6 +17,9 @@ export interface TreeViewModel {
15
17
  setKindHidden(key: string, kind: string, hidden: boolean): void;
16
18
  clearFilter(key: string): void;
17
19
  clearAllFilters(): void;
20
+ /** Shows (`shown`) or stops showing the Bausteine of the basket. */
21
+ setBasketShown(id: string, shown: boolean): void;
22
+ clearBasketFilter(): void;
18
23
  /** Follows a folder moved from `from` to `to`: open folder items of it and below it get the new path. */
19
24
  followFolderMove(from: string, to: string): void;
20
25
  }