@connectorvol/tree 4.0.0 → 4.1.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.
@@ -37,33 +37,26 @@
37
37
  pieceSet,
38
38
  }: TMoveProps = $props();
39
39
 
40
- const {
41
- chessTree,
42
- onSelectNode,
43
- onDeleteVariant,
44
- onChessNodeSelected,
45
- selectable,
46
- setPreviewFen,
47
- previewHoverDelayMs,
48
- } = getGameContext();
40
+ /** Контекст игры без деструктуризации — иначе selectable и chessTree «замораживаются» при первом рендере TreeViewer. */
41
+ const game = getGameContext();
49
42
 
50
43
  /** Представляет обработчик выбора текущего узла по `mousedown`. */
51
44
  function handleMoveMouseDown() {
52
- if (!selectable || !moveNode) return;
53
- chessTree.currentNode = chessNode;
45
+ if (!game.selectable || !moveNode) return;
46
+ game.chessTree.currentNode = chessNode;
54
47
 
55
- onSelectNode();
56
- onChessNodeSelected?.(chessTree.currentNode);
48
+ game.onSelectNode();
49
+ game.onChessNodeSelected?.(game.chessTree.currentNode);
57
50
  }
58
51
 
59
52
  const moveNode = $derived(chessNode);
60
53
  const previewHover = createPreviewHover({
61
- setPreviewFen,
54
+ setPreviewFen: game.setPreviewFen,
62
55
  getFen: () => moveNode.data.fen,
63
56
  getLastMove: () => moveNode.data.lastMove ?? null,
64
- getDelayMs: () => previewHoverDelayMs,
57
+ getDelayMs: () => game.previewHoverDelayMs,
65
58
  });
66
- const isCurrentMove = $derived(chessNode.id === chessTree.currentNode.id);
59
+ const isCurrentMove = $derived(chessNode.id === game.chessTree.currentNode.id);
67
60
  /** Представляет текст первого PGN-комментария узла после разбора `comments[0]`, синхронно с правкой строки под деревом. */
68
61
  const firstCommentParsed = $derived(
69
62
  moveNode.data.comments?.[0] !== undefined
@@ -72,11 +65,11 @@
72
65
  );
73
66
  const firstCommentText = $derived(firstCommentParsed?.text);
74
67
  const childMoves = $derived(chessNode.children);
75
- const isForcedLineStart = $derived(chessNode.id === chessTree.forcedNodeId);
68
+ const isForcedLineStart = $derived(chessNode.id === game.chessTree.forcedNodeId);
76
69
 
77
70
  /** Представляет признак активного drill-down «варианты отдельно». */
78
71
  const variationDrillDownActive = $derived(
79
- chessTree.isVariationDrillDownActive(),
72
+ game.chessTree.isVariationDrillDownActive(),
80
73
  );
81
74
 
82
75
  /**
@@ -87,7 +80,7 @@
87
80
  shouldRenderSiblingVariations &&
88
81
  parentNode !== null &&
89
82
  (parentNode.children?.length ?? 0) > 1 &&
90
- chessTree.currentGuideHighlightForkParent?.id === parentNode.id,
83
+ game.chessTree.currentGuideHighlightForkParent?.id === parentNode.id,
91
84
  );
92
85
 
93
86
  const spaceBlockClass = "px-3 py-2 !bg-gray-50/95";
@@ -139,10 +132,10 @@
139
132
  function onVariationLinesHit(e: MouseEvent) {
140
133
  e.stopPropagation();
141
134
  if (parentNode === null) return;
142
- const selectFork = !chessTree.isCurrentNodeWithinForkSubtree(parentNode);
143
- chessTree.openVariationDrillDown(parentNode, { selectFork });
144
- onSelectNode();
145
- onChessNodeSelected?.(chessTree.currentNode);
135
+ const selectFork = !game.chessTree.isCurrentNodeWithinForkSubtree(parentNode);
136
+ game.chessTree.openVariationDrillDown(parentNode, { selectFork });
137
+ game.onSelectNode();
138
+ game.onChessNodeSelected?.(game.chessTree.currentNode);
146
139
  }
147
140
  </script>
148
141
 
@@ -192,7 +185,7 @@
192
185
  {@render fullMovesCounter()}
193
186
  {/if}
194
187
 
195
- {#if variationDrillDownActive && moveNode.data.ply % 2 === 0 && chessTree.drillForkParent !== null && chessTree.drillForkParent.children[0]?.id === chessNode.id && moveNode.parentId}
188
+ {#if variationDrillDownActive && moveNode.data.ply % 2 === 0 && game.chessTree.drillForkParent !== null && game.chessTree.drillForkParent.children[0]?.id === chessNode.id && moveNode.parentId}
196
189
  <span
197
190
  class={{
198
191
  "flex items-center justify-center text-center": isHighestLevel,
@@ -219,7 +212,7 @@
219
212
  {chessNode}
220
213
  {parentNode}
221
214
  {pieceSet}
222
- {selectable}
215
+ selectable={game.selectable}
223
216
  {isHighestLevel}
224
217
  {isCurrentMove}
225
218
  previewHover={{
@@ -229,9 +222,9 @@
229
222
  onMoveMouseDown={handleMoveMouseDown}
230
223
  {spaceInlineBlockClass}
231
224
  nags={moveNode.data.nags}
232
- {chessTree}
225
+ chessTree={game.chessTree}
233
226
  {showUpPriorityItem}
234
- {onDeleteVariant}
227
+ onDeleteVariant={game.onDeleteVariant}
235
228
  mainRowBottomEdge={addsEmptyMainLineBlackCell}
236
229
  />
237
230
  {/if}
@@ -257,7 +250,7 @@
257
250
  {/if}
258
251
  {/if}
259
252
  {:else}
260
- {#if moveNode.data.ply % 2 === 0 && chessTree.forcedNodeId === moveNode.parentId && parentNode?.children[0].id === moveNode.id}
253
+ {#if moveNode.data.ply % 2 === 0 && game.chessTree.forcedNodeId === moveNode.parentId && parentNode?.children[0].id === moveNode.id}
261
254
  {@render fullMovesCounter(1)}
262
255
  {/if}
263
256
 
@@ -266,7 +259,7 @@
266
259
  {chessNode}
267
260
  {parentNode}
268
261
  {pieceSet}
269
- {selectable}
262
+ selectable={game.selectable}
270
263
  {isHighestLevel}
271
264
  {isCurrentMove}
272
265
  previewHover={{
@@ -276,9 +269,9 @@
276
269
  onMoveMouseDown={handleMoveMouseDown}
277
270
  {spaceInlineBlockClass}
278
271
  nags={moveNode.data.nags}
279
- {chessTree}
272
+ chessTree={game.chessTree}
280
273
  {showUpPriorityItem}
281
- {onDeleteVariant}
274
+ onDeleteVariant={game.onDeleteVariant}
282
275
  />
283
276
  {/if}
284
277
  {#if firstCommentText}
@@ -296,7 +289,7 @@
296
289
  {/if}
297
290
 
298
291
  {#if parentNode && parentNode?.children.length > 1 && shouldRenderSiblingVariations}
299
- {@const showVariationDrillExpand = !chessTree.isNodeOnMainLine(chessNode)}
292
+ {@const showVariationDrillExpand = !game.chessTree.isNodeOnMainLine(chessNode)}
300
293
  <VariationGroup
301
294
  {parentNode}
302
295
  {isHighestLevel}
@@ -304,7 +297,7 @@
304
297
  {showVariationDrillExpand}
305
298
  {onVariationLinesHit}
306
299
  {variationMoveRow}
307
- isBranchOnCurrentPath={(n) => chessTree.isCurrentOnPathFromNode(n)}
300
+ isBranchOnCurrentPath={(n) => game.chessTree.isCurrentOnPathFromNode(n)}
308
301
  />
309
302
  {/if}
310
303
 
@@ -338,7 +331,7 @@
338
331
  {@render fullMovesCounter()}
339
332
  {@render emptyMove()}
340
333
  {/if}
341
- {#if variationDrillDownActive && isHighestLevel && moveNode.data.ply % 2 === 1 && !shouldReserveEmptyMoveCell && childMoves?.[0] && !isForcedLineStart && chessTree.drillForkParent !== null && chessTree.drillForkParent.children[0]?.id === chessNode.id}
334
+ {#if variationDrillDownActive && isHighestLevel && moveNode.data.ply % 2 === 1 && !shouldReserveEmptyMoveCell && childMoves?.[0] && !isForcedLineStart && game.chessTree.drillForkParent !== null && game.chessTree.drillForkParent.children[0]?.id === chessNode.id}
342
335
  <span
343
336
  class={{
344
337
  "flex items-center justify-center text-center": isHighestLevel,
@@ -117,18 +117,36 @@
117
117
  );
118
118
 
119
119
  setContext<GameContext>(CHESS_TREE_CONTEXT_KEY, {
120
- chessTree: (() => chessTree)(),
121
- onSelectNode: (() => onSelectNode)(),
122
- onDeleteVariant: (() => onDeleteVariant)(),
123
- onChessNodeSelected: (() => onChessNodeSelected)(),
124
- setChessFen: (() => setChessFen)(),
125
- setChessboardFen: (() => setChessboardFen)(),
126
- setPreviewFen: (() =>
127
- previewFenSetter
128
- ? (fen, lastMove) => previewFenSetter(fen, lastMove)
129
- : undefined)(),
130
- previewHoverDelayMs: (() => previewDelayMs)(),
131
- selectable: (() => selectable)(),
120
+ get chessTree() {
121
+ return chessTree;
122
+ },
123
+ get onSelectNode() {
124
+ return onSelectNode;
125
+ },
126
+ get onDeleteVariant() {
127
+ return onDeleteVariant;
128
+ },
129
+ get onChessNodeSelected() {
130
+ return onChessNodeSelected;
131
+ },
132
+ get setChessFen() {
133
+ return setChessFen;
134
+ },
135
+ get setChessboardFen() {
136
+ return setChessboardFen;
137
+ },
138
+ get setPreviewFen() {
139
+ const setter = previewFenSetter;
140
+ return setter
141
+ ? (fen: string | null, lastMove?: TSharedMove | null) => setter(fen, lastMove)
142
+ : undefined;
143
+ },
144
+ get previewHoverDelayMs() {
145
+ return previewDelayMs;
146
+ },
147
+ get selectable() {
148
+ return selectable;
149
+ },
132
150
  });
133
151
 
134
152
  const panelNav = $derived.by(() =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectorvol/tree",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -39,14 +39,14 @@
39
39
  "test:ui": "npx playwright test --ui"
40
40
  },
41
41
  "dependencies": {
42
- "@connectorvol/chessops": "2.0.3",
43
- "@connectorvol/shared": "2.1.2",
42
+ "@connectorvol/chessops": "3.0.0",
43
+ "@connectorvol/shared": "4.0.0",
44
44
  "clsx": "^2.1.1",
45
45
  "tailwind-merge": "3.3.1",
46
46
  "tailwind-variants": "3.1.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@connectorvol/chessboard": "2.2.0",
49
+ "@connectorvol/chessboard": "4.0.0",
50
50
  "@ianvs/prettier-plugin-sort-imports": "4.5.1",
51
51
  "@internationalized/date": "3.9.0",
52
52
  "@lucide/svelte": "^0.553.0",