@marimo-team/islands 0.26.1-dev0 → 0.26.1-dev14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConnectedDataExplorerComponent-DtwVgVpX.js → ConnectedDataExplorerComponent-CR9WyiEc.js} +11 -11
- package/dist/{ErrorBoundary-BAPXZkp8.js → ErrorBoundary-BQoOxxn3.js} +7 -7
- package/dist/{abnfDiagram-VCTEODGH-BbZOIueZ.js → abnfDiagram-VCTEODGH-DGAbsdXT.js} +2 -2
- package/dist/{any-language-editor-yG-YmLaK.js → any-language-editor-DzGF1ll-.js} +5 -5
- package/dist/{architectureDiagram-5GKGNRK7-qjLjxapm.js → architectureDiagram-5GKGNRK7-D4DnIo7R.js} +1 -1
- package/dist/{assertNever-DywGMo-S.js → assertNever-CqwxSD_2.js} +3 -3
- package/dist/{button-qQhINE7z.js → button-Z2R2272J.js} +34 -31
- package/dist/{capabilities-DKqMqBzm.js → capabilities-ba3Dyv8n.js} +1 -1
- package/dist/{chat-ui-D5YPIONI.js → chat-ui-b1ERxzeA.js} +17 -17
- package/dist/{check-jchHMCfs.js → check-D9vf6LYF.js} +1 -1
- package/dist/{chunk-IMKFNOWR-BzDY1_I7.js → chunk-IMKFNOWR-Bc_i6jWx.js} +1 -1
- package/dist/{chunk-SHT3W25Y-DbHsMKdo.js → chunk-SHT3W25Y-CGML5pnF.js} +1 -1
- package/dist/{chunk-SVP7TREG-CtwnwAE6.js → chunk-SVP7TREG-ZpeFKfFT.js} +1 -1
- package/dist/{chunk-TICWLB2K-C5Z5QMbO.js → chunk-TICWLB2K-C6cLmcg8.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-B8E5Hn78.js → classDiagram-ZZMXUADV--q40NTXr.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-DeGsK9bT.js → classDiagram-v2-VYDZK3BY-Dt_Pp94L.js} +2 -2
- package/dist/{code-visibility-Ebrgx-u3.js → code-visibility-BYnPkZsj.js} +6 -6
- package/dist/{common-Capdc2h_.js → common-xIzCDB2e.js} +41 -41
- package/dist/{config-qTaTHnpE.js → config-B8JCQMby.js} +4 -4
- package/dist/{copy-icon-BI7vZHEW.js → copy-icon-BLig0ZKb.js} +3 -3
- package/dist/{createReducer-DdSLRfBT.js → createReducer-BIUQ3TbG.js} +2 -2
- package/dist/{cynefinDiagram-5FMLGOSQ-NDedRwsw.js → cynefinDiagram-5FMLGOSQ-2FtF_-cc.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-De0sSZO7.js → dagre-GXQ25YYZ-Cymu2SPS.js} +1 -1
- package/dist/{data-grid-overlay-editor-CErEC4xn.js → data-grid-overlay-editor-BtCJxGqi.js} +5 -5
- package/dist/{data-grid-types-DIX_pCco.js → data-grid-types-DBNnjiYJ.js} +2 -2
- package/dist/{diagram-S7CK7UJ4-wBtVl61y.js → diagram-S7CK7UJ4-OwDa8kAa.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-CKWE3c1T.js → diagram-UQ7AKVKN-CzRDwZwd.js} +1 -1
- package/dist/{diagram-VX7I27RA-D2Ac5198.js → diagram-VX7I27RA-XRIcgMDs.js} +1 -1
- package/dist/{diagram-Z3DM3KII-CYaFOQcI.js → diagram-Z3DM3KII-DdRDYAs6.js} +1 -1
- package/dist/{dialog-Ic6dh09m.js → dialog-DGh2HNAO.js} +3 -3
- package/dist/{dist-BvZpdAuG.js → dist-6B1_Ttbh.js} +1 -1
- package/dist/{dist-D1D56-GS.js → dist-B28poF32.js} +2 -2
- package/dist/{dist-BozTF_gH.js → dist-BBZ7lnMw.js} +2 -2
- package/dist/{dist-BfrgytDR.js → dist-BD8ZKF5t.js} +3 -3
- package/dist/{dist-DNkrY12t.js → dist-BG-7Qpaj.js} +3 -3
- package/dist/{dist-D92tYjLc.js → dist-BIaGGUbU.js} +13 -11
- package/dist/{dist-BagHbFqG.js → dist-BR5PU2Ph.js} +3 -3
- package/dist/{dist-DpYpG8Yc.js → dist-BidYR5m4.js} +3 -3
- package/dist/{dist-D95Cd4xm.js → dist-BkGYCvFX.js} +3 -3
- package/dist/{dist-DneeBk3K.js → dist-BmEyXT7K.js} +2 -2
- package/dist/{dist-BdUitvVW.js → dist-Bt0Wt6m9.js} +2 -2
- package/dist/{dist-CEomphG1.js → dist-CG2Sl0D4.js} +2 -2
- package/dist/{dist-BMz__bo5.js → dist-CQfpgadU.js} +3 -3
- package/dist/{dist-BreKIQqQ.js → dist-CVOPvfzN.js} +3 -3
- package/dist/{dist-BEcpQbZa.js → dist-Cm0iCeQQ.js} +3 -3
- package/dist/{dist-CDVvitRS.js → dist-Cnc14jEq.js} +2 -2
- package/dist/{dist-ChcBm3jk.js → dist-D3KPC38e.js} +4 -4
- package/dist/{dist-B1qu3Bez.js → dist-D7BXk27E.js} +3 -3
- package/dist/{dist-BsE4gQHj.js → dist-D9Qhvxvg.js} +1 -1
- package/dist/{dist-OmeAz0fR.js → dist-DJKajXDB.js} +3 -3
- package/dist/{dist-ObeTgSmf.js → dist-DYbNRTYG.js} +4 -4
- package/dist/{dist-Cshl6jBw.js → dist-DhtDWnzK.js} +2 -2
- package/dist/{dist-BunZKA_9.js → dist-_x2Jks2R.js} +2 -2
- package/dist/{dist-MggMo7OR.js → dist-m0MWV-aw.js} +1 -1
- package/dist/{dist-TGSwzj8a.js → dist-pPbYNVjd.js} +4 -4
- package/dist/{dropdown-menu-Dhv4fcNl.js → dropdown-menu-ChH3oiqI.js} +6 -6
- package/dist/{ebnfDiagram-PWID7BFC-Ds7f42dj.js → ebnfDiagram-PWID7BFC-CZMNMGNP.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-b58Sz2Mc.js → erDiagram-RLTQ6QDP-ByxHAN4b.js} +1 -1
- package/dist/{error-banner-CJVLr5_a.js → error-banner-BvRaQnGH.js} +22 -22
- package/dist/{error-entries-BKlEsuk4.js → error-entries-Bl8fzLQc.js} +11 -11
- package/dist/{esm-B9n0caHs.js → esm-DY8dGAjJ.js} +23 -23
- package/dist/{esm-Bwp_FHP0.js → esm-Dw2ZydG_.js} +3 -3
- package/dist/{feedback-button-Bxokl7c-.js → feedback-button-BBSDxjBA.js} +8 -8
- package/dist/{flowDiagram-HODETNUW-BH9U7VZK.js → flowDiagram-HODETNUW-BQpzWx5O.js} +2 -2
- package/dist/{formats-BLNFWWhV.js → formats-BxP8k8Un.js} +3 -3
- package/dist/{glide-data-editor-DkbmoSoO.js → glide-data-editor-8dFDW-2H.js} +59 -59
- package/dist/{glide-utils-Cn2_NadX.js → glide-utils-bKdvDwwo.js} +4 -4
- package/dist/{globals-BZH2TwVV.js → globals-BpKkNxJe.js} +3 -3
- package/dist/{html-to-image-CNM0ZSFD.js → html-to-image-D6A1lg0A.js} +3471 -3367
- package/dist/{infoDiagram-27XIBGKW-xbjwrcNi.js → infoDiagram-27XIBGKW-C9EWHkak.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-DKtukhGS.js → ishikawaDiagram-5VMMS53U-D67SGFvp.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-BEhlkZBb.js → kanban-definition-UXKFOSKX-CTMTiazR.js} +1 -1
- package/dist/{loader-Bin_dutt.js → loader-qPmiRXZd.js} +1 -1
- package/dist/main.js +5808 -5783
- package/dist/{mermaid-D1CZDNoB.js → mermaid-DE_tvTGF.js} +35 -35
- package/dist/{mindmap-definition-YA3MSWOX-DQcnJPcV.js → mindmap-definition-YA3MSWOX-LzNgDy8O.js} +1 -1
- package/dist/{number-overlay-editor-CkRxchEC.js → number-overlay-editor-Bp-Jnfbm.js} +3 -3
- package/dist/{pegDiagram-XKGWAZYB-BFQuPYfI.js → pegDiagram-XKGWAZYB-DFMS6feI.js} +2 -2
- package/dist/{pencil-DVYzq-iR.js → pencil-CHkdsX07.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-l7aqNrem.js → pieDiagram-E7YTZNPT-C0MSBop-.js} +1 -1
- package/dist/{process-output-DthYR2Te.js → process-output-w5omHedc.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-6R3C1lwQ.js → railroadDiagram-O6MQD6OU-mbdav2pV.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-DdWYu8fn.js → requirementDiagram-BXWQKSXE-C1HNBBO6.js} +1 -1
- package/dist/{reveal-component-YJ4y0XIg.js → reveal-component-N07U-Dy_.js} +20 -20
- package/dist/{select-CDUxhHZg.js → select-CvorIE3l.js} +35 -35
- package/dist/{sequenceDiagram-WJ2MYXX4-Dzp0dgRc.js → sequenceDiagram-WJ2MYXX4-D6gBHifq.js} +1 -1
- package/dist/{spec-ZAt4P01J.js → spec-ayzaXGVq.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-BGnTUhFJ.js → stateDiagram-D77RDMKH-Bx-fTtRZ.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-DsJbmDf1.js → stateDiagram-v2-MP3YSRHH-Cec8T2yO.js} +2 -2
- package/dist/{static-state-C4bAlKTU.js → static-state-CqwW3B_X.js} +1 -1
- package/dist/{swimlanes-42K2YHIH-Bd4Bzh9r.js → swimlanes-42K2YHIH-C2bAgnov.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-BlY12Jf6.js → swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js} +2 -2
- package/dist/{swiper-component-DTdNB9wg.js → swiper-component-B2O8hF7b.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-m0LanyCH.js → timeline-definition-24CTP7MA-DTJ0Rx8X.js} +1 -1
- package/dist/{toast-U3NpO2x3.js → toast-6V8Og7d5.js} +11 -11
- package/dist/{tooltip-UzJukb3F.js → tooltip-D0h-ZJ6j.js} +2 -2
- package/dist/{use-restore-focus-DaTVz6S6.js → use-restore-focus-BFvwj2Hj.js} +1884 -1861
- package/dist/{useDateFormatter-LQNtoXyh.js → useDateFormatter-D6o9PsWt.js} +2 -2
- package/dist/{useDeepCompareMemoize-CmNbQ9TT.js → useDeepCompareMemoize-D-Pbv7dN.js} +1 -1
- package/dist/{useIframeCapabilities-HTZiVlGV.js → useIframeCapabilities-_0KX0nu_.js} +1 -1
- package/dist/{useLifecycle-DTMczKkf.js → useLifecycle-CE0yGTMF.js} +2 -2
- package/dist/{vega-component-ZTdbCcwI.js → vega-component-DTf7GHQe.js} +8 -8
- package/dist/{vennDiagram-4TSXK5OY-BJ7vqDmn.js → vennDiagram-4TSXK5OY-lIM3SAjl.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-D5kWacsn.js → wardleyDiagram-VM6X3IG4-Bw_t7uvA.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-gr15Ws_z.js → xychartDiagram-S5SC5T6Z-BXwkLYKj.js} +1 -1
- package/package.json +3 -3
- package/src/components/editor/cell/CreateCellButton.tsx +69 -40
- package/src/components/editor/cell/__tests__/CreateCellButton.test.tsx +49 -0
- package/src/components/editor/cell/__tests__/cell-context-menu.test.tsx +126 -0
- package/src/components/editor/cell/cell-context-menu.tsx +202 -111
- package/src/components/editor/cell/code/cell-editor.tsx +5 -2
- package/src/components/editor/cell/code/code-placeholder.tsx +5 -3
- package/src/components/editor/output/console/ConsoleOutput.tsx +77 -50
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +28 -0
- package/src/components/editor/renderers/cells-renderer.tsx +3 -2
- package/src/components/ui/__tests__/button-shortcut.test.tsx +22 -0
- package/src/components/ui/__tests__/fullscreen.test.tsx +23 -1
- package/src/components/ui/button.tsx +5 -1
- package/src/components/ui/fullscreen.tsx +8 -39
- package/src/core/codemirror/__tests__/debounced-editor-update.test.ts +72 -0
- package/src/core/codemirror/__tests__/setup.test.ts +61 -1
- package/src/core/codemirror/cells/debugger-decorations.ts +22 -18
- package/src/core/codemirror/cells/line-timing-decorations.ts +13 -11
- package/src/core/codemirror/cells/traceback-decorations.ts +10 -11
- package/src/core/codemirror/code-lens/__tests__/extension.test.ts +31 -0
- package/src/core/codemirror/code-lens/extension.ts +21 -13
- package/src/core/codemirror/debounced-editor-update.ts +41 -0
- package/src/core/codemirror/go-to-definition/__tests__/underline.test.ts +58 -0
- package/src/core/codemirror/go-to-definition/extension.ts +9 -7
- package/src/core/codemirror/go-to-definition/underline.ts +39 -48
- package/src/core/codemirror/language/__tests__/sql.test.ts +36 -0
- package/src/core/codemirror/language/languages/sql/sql.ts +3 -0
- package/src/core/codemirror/placeholder/extensions.ts +26 -24
- package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +60 -0
- package/src/core/codemirror/reactive-references/extension.ts +30 -21
- package/src/core/islands/__tests__/bridge.test.ts +1 -1
- package/src/core/islands/bootstrap.ts +0 -3
- package/src/core/notebook/replica/__tests__/replica.test.ts +7 -7
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +2 -2
- package/src/core/session/useNotebookSession.tsx +0 -8
- package/src/utils/__tests__/shared-resource.test.ts +107 -0
- package/src/utils/shared-resource.ts +59 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ViewPlugin,
|
|
10
10
|
type ViewUpdate,
|
|
11
11
|
} from "@codemirror/view";
|
|
12
|
+
import { createSharedResource } from "@/utils/shared-resource";
|
|
12
13
|
import type { TreeCursor } from "@lezer/common";
|
|
13
14
|
import {
|
|
14
15
|
reactiveHoverDecoration,
|
|
@@ -50,23 +51,47 @@ export const underlineField = StateField.define<DecorationSet>({
|
|
|
50
51
|
provide: (f) => EditorView.decorations.from(f),
|
|
51
52
|
});
|
|
52
53
|
|
|
54
|
+
// Only editors with an underline need notification when a modifier is released.
|
|
55
|
+
const activeUnderlines = new Set<() => void>();
|
|
56
|
+
function resetModifier() {
|
|
57
|
+
for (const clear of activeUnderlines) {
|
|
58
|
+
clear();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function trackModifier(event: KeyboardEvent) {
|
|
62
|
+
if (!event.metaKey && !event.ctrlKey) {
|
|
63
|
+
resetModifier();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const subscribeToModifiers = createSharedResource(() => {
|
|
67
|
+
window.addEventListener("keydown", trackModifier);
|
|
68
|
+
window.addEventListener("keyup", trackModifier);
|
|
69
|
+
window.addEventListener("blur", resetModifier);
|
|
70
|
+
window.addEventListener("mouseleave", resetModifier);
|
|
71
|
+
return () => {
|
|
72
|
+
window.removeEventListener("keydown", trackModifier);
|
|
73
|
+
window.removeEventListener("keyup", trackModifier);
|
|
74
|
+
window.removeEventListener("blur", resetModifier);
|
|
75
|
+
window.removeEventListener("mouseleave", resetModifier);
|
|
76
|
+
resetModifier();
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
53
80
|
// When meta is pressed, underline the variable name under the cursor
|
|
54
81
|
class MetaUnderlineVariablePlugin {
|
|
55
82
|
private view: EditorView;
|
|
56
|
-
private
|
|
83
|
+
private unsubscribeModifiers: () => void;
|
|
57
84
|
private hoveredRange: { from: number; to: number; position: number } | null;
|
|
58
85
|
private onClick: (view: EditorView) => void;
|
|
59
86
|
|
|
60
87
|
public constructor(view: EditorView, onClick: (view: EditorView) => void) {
|
|
61
88
|
this.view = view;
|
|
62
|
-
this.commandClickMode = false;
|
|
63
89
|
this.hoveredRange = null;
|
|
64
90
|
this.onClick = onClick;
|
|
65
91
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
window.addEventListener("mouseleave", this.windowBlur);
|
|
92
|
+
this.unsubscribeModifiers = subscribeToModifiers();
|
|
93
|
+
this.view.dom.addEventListener("mousemove", this.mousemove);
|
|
94
|
+
this.view.dom.addEventListener("click", this.click);
|
|
70
95
|
}
|
|
71
96
|
|
|
72
97
|
public update(_update: ViewUpdate) {
|
|
@@ -76,42 +101,10 @@ class MetaUnderlineVariablePlugin {
|
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
public destroy() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
window.removeEventListener("blur", this.windowBlur);
|
|
82
|
-
window.removeEventListener("mouseleave", this.windowBlur);
|
|
83
|
-
this.view.dom.removeEventListener("mousemove", this.mousemove);
|
|
84
|
-
this.view.dom.removeEventListener("click", this.click);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Start the cmd+click mode
|
|
88
|
-
private keydown = (event: KeyboardEvent) => {
|
|
89
|
-
if (event.key === "Meta" || event.key === "Control") {
|
|
90
|
-
this.commandClickMode = true;
|
|
91
|
-
this.view.dom.addEventListener("mousemove", this.mousemove);
|
|
92
|
-
this.view.dom.addEventListener("click", this.click);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Exit the cmd+click mode
|
|
97
|
-
private keyup = (event: KeyboardEvent) => {
|
|
98
|
-
if (event.key === "Meta" || event.key === "Control") {
|
|
99
|
-
this.exitCommandClickMode();
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Handle window blur event to reset state
|
|
104
|
-
private windowBlur = () => {
|
|
105
|
-
if (this.commandClickMode) {
|
|
106
|
-
this.exitCommandClickMode();
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
private exitCommandClickMode() {
|
|
111
|
-
this.commandClickMode = false;
|
|
104
|
+
activeUnderlines.delete(this.clearUnderline);
|
|
105
|
+
this.unsubscribeModifiers();
|
|
112
106
|
this.view.dom.removeEventListener("mousemove", this.mousemove);
|
|
113
107
|
this.view.dom.removeEventListener("click", this.click);
|
|
114
|
-
this.clearUnderline();
|
|
115
108
|
}
|
|
116
109
|
|
|
117
110
|
// While moving the mouse in cmd+click mode,
|
|
@@ -119,11 +112,6 @@ class MetaUnderlineVariablePlugin {
|
|
|
119
112
|
private mousemove = (event: MouseEvent) => {
|
|
120
113
|
// Check if the key is still pressed
|
|
121
114
|
if (!event.metaKey && !event.ctrlKey) {
|
|
122
|
-
this.exitCommandClickMode();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!this.commandClickMode) {
|
|
127
115
|
this.clearUnderline();
|
|
128
116
|
return;
|
|
129
117
|
}
|
|
@@ -157,6 +145,7 @@ class MetaUnderlineVariablePlugin {
|
|
|
157
145
|
// Clear existing decorations
|
|
158
146
|
this.clearUnderline();
|
|
159
147
|
// Add subtle hover enhancement for reactive variables
|
|
148
|
+
activeUnderlines.add(this.clearUnderline);
|
|
160
149
|
this.hoveredRange = { from, to, position: pos };
|
|
161
150
|
this.view.dispatch({ effects: addReactiveHover.of(this.hoveredRange) });
|
|
162
151
|
return;
|
|
@@ -178,6 +167,7 @@ class MetaUnderlineVariablePlugin {
|
|
|
178
167
|
// Clear existing underlines
|
|
179
168
|
this.clearUnderline();
|
|
180
169
|
// Set the underline
|
|
170
|
+
activeUnderlines.add(this.clearUnderline);
|
|
181
171
|
this.hoveredRange = { from, to, position: pos };
|
|
182
172
|
this.view.dispatch({ effects: addUnderline.of(this.hoveredRange) });
|
|
183
173
|
} else {
|
|
@@ -187,7 +177,7 @@ class MetaUnderlineVariablePlugin {
|
|
|
187
177
|
|
|
188
178
|
// If we have a hovered range, go to it
|
|
189
179
|
private click = (event: MouseEvent) => {
|
|
190
|
-
if (this.hoveredRange) {
|
|
180
|
+
if (this.hoveredRange && (event.metaKey || event.ctrlKey)) {
|
|
191
181
|
event.preventDefault();
|
|
192
182
|
event.stopPropagation();
|
|
193
183
|
// Move the cursor before resolving so LSP uses the clicked position.
|
|
@@ -202,12 +192,13 @@ class MetaUnderlineVariablePlugin {
|
|
|
202
192
|
};
|
|
203
193
|
|
|
204
194
|
// Only clear the underline if we have some underline
|
|
205
|
-
private clearUnderline() {
|
|
195
|
+
private clearUnderline = () => {
|
|
196
|
+
activeUnderlines.delete(this.clearUnderline);
|
|
206
197
|
if (this.hoveredRange) {
|
|
207
198
|
this.view.dispatch({ effects: removeUnderlines.of(null) });
|
|
208
199
|
this.hoveredRange = null;
|
|
209
200
|
}
|
|
210
|
-
}
|
|
201
|
+
};
|
|
211
202
|
}
|
|
212
203
|
|
|
213
204
|
export const createUnderlinePlugin = (onClick: (view: EditorView) => void) =>
|
|
@@ -1011,6 +1011,42 @@ describe("SQL analysis features", () => {
|
|
|
1011
1011
|
view.destroy();
|
|
1012
1012
|
});
|
|
1013
1013
|
|
|
1014
|
+
it("updates gutter validity when the connection changes without an edit", async () => {
|
|
1015
|
+
const doc = "SELECT TOP 1 * FROM users";
|
|
1016
|
+
const extensions = adapter.getExtension({
|
|
1017
|
+
...TEST_EXTENSION_ARGS[0],
|
|
1018
|
+
lspConfig: {
|
|
1019
|
+
diagnostics: { sql_linter: true },
|
|
1020
|
+
} as LSPConfig & { diagnostics: DiagnosticsConfig },
|
|
1021
|
+
});
|
|
1022
|
+
const view = new EditorView({
|
|
1023
|
+
doc,
|
|
1024
|
+
extensions: [
|
|
1025
|
+
languageMetadataField.init(() => ({
|
|
1026
|
+
...metadata,
|
|
1027
|
+
engine: DUCKDB_ENGINE,
|
|
1028
|
+
})),
|
|
1029
|
+
...extensions,
|
|
1030
|
+
],
|
|
1031
|
+
});
|
|
1032
|
+
const markerColor = () =>
|
|
1033
|
+
view.dom.querySelector<HTMLElement>(".cm-sql-gutter-marker")?.style
|
|
1034
|
+
.backgroundColor;
|
|
1035
|
+
|
|
1036
|
+
try {
|
|
1037
|
+
await vi.waitFor(() => expect(markerColor()).toBe("rgb(59, 130, 246)"));
|
|
1038
|
+
|
|
1039
|
+
view.dispatch({
|
|
1040
|
+
effects: updateLanguageMetadata.of({ engine: TEST_ENGINE }),
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
await vi.waitFor(() => expect(markerColor()).toBe("rgb(239, 68, 68)"));
|
|
1044
|
+
expect(view.state.doc.toString()).toBe(doc);
|
|
1045
|
+
} finally {
|
|
1046
|
+
view.destroy();
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1014
1050
|
it("invalidates analysis caches when the engine changes", async () => {
|
|
1015
1051
|
const mssqlEngine = "mssql_engine" as ConnectionName;
|
|
1016
1052
|
const postgresEngine = "postgres_engine" as ConnectionName;
|
|
@@ -214,6 +214,9 @@ export class SQLLanguageAdapter implements LanguageAdapter<SQLLanguageAdapterMet
|
|
|
214
214
|
extensions.push(
|
|
215
215
|
sqlExtension({
|
|
216
216
|
schema: getSchema,
|
|
217
|
+
needsRefresh: (update) =>
|
|
218
|
+
getSQLMetadata(update.startState).engine !==
|
|
219
|
+
getSQLMetadata(update.state).engine,
|
|
217
220
|
enableLinting: true,
|
|
218
221
|
linterConfig: {
|
|
219
222
|
delay: 250, // Delay before running validation
|
|
@@ -55,6 +55,31 @@ function acceptPlaceholder(cm: EditorView, text: string) {
|
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
const placeholderTheme = EditorView.theme({
|
|
59
|
+
".cm-placeholder": {
|
|
60
|
+
color: "var(--slate-8)",
|
|
61
|
+
},
|
|
62
|
+
".cm-clickable-placeholder": {
|
|
63
|
+
cursor: "pointer !important",
|
|
64
|
+
font: "inherit",
|
|
65
|
+
background: "transparent",
|
|
66
|
+
border: "none",
|
|
67
|
+
padding: "0",
|
|
68
|
+
pointerEvents: "auto",
|
|
69
|
+
color: "var(--slate-9)",
|
|
70
|
+
textDecoration: "underline",
|
|
71
|
+
textUnderlineOffset: "0.2em",
|
|
72
|
+
},
|
|
73
|
+
".cm-clickable-placeholder:focus-visible": {
|
|
74
|
+
outline: "1px solid var(--muted-foreground)",
|
|
75
|
+
outlineOffset: "2px",
|
|
76
|
+
borderRadius: "2px",
|
|
77
|
+
},
|
|
78
|
+
".cm-clickable-placeholder:hover": {
|
|
79
|
+
color: "var(--sky-11)",
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
58
83
|
/**
|
|
59
84
|
* Create a placeholder with a clickable link.
|
|
60
85
|
*/
|
|
@@ -132,29 +157,6 @@ export function clickablePlaceholderExtension(opts: {
|
|
|
132
157
|
])
|
|
133
158
|
: Decoration.none,
|
|
134
159
|
),
|
|
135
|
-
|
|
136
|
-
".cm-placeholder": {
|
|
137
|
-
color: "var(--slate-8)",
|
|
138
|
-
},
|
|
139
|
-
".cm-clickable-placeholder": {
|
|
140
|
-
cursor: "pointer !important",
|
|
141
|
-
font: "inherit",
|
|
142
|
-
background: "transparent",
|
|
143
|
-
border: "none",
|
|
144
|
-
padding: "0",
|
|
145
|
-
pointerEvents: "auto",
|
|
146
|
-
color: "var(--slate-9)",
|
|
147
|
-
textDecoration: "underline",
|
|
148
|
-
textUnderlineOffset: "0.2em",
|
|
149
|
-
},
|
|
150
|
-
".cm-clickable-placeholder:focus-visible": {
|
|
151
|
-
outline: "1px solid var(--muted-foreground)",
|
|
152
|
-
outlineOffset: "2px",
|
|
153
|
-
borderRadius: "2px",
|
|
154
|
-
},
|
|
155
|
-
".cm-clickable-placeholder:hover": {
|
|
156
|
-
color: "var(--sky-11)",
|
|
157
|
-
},
|
|
158
|
-
}),
|
|
160
|
+
placeholderTheme,
|
|
159
161
|
];
|
|
160
162
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { python } from "@codemirror/lang-python";
|
|
3
|
+
import { EditorState } from "@codemirror/state";
|
|
4
|
+
import { EditorView } from "@codemirror/view";
|
|
5
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
+
import { cellId, variableName } from "@/__tests__/branded";
|
|
7
|
+
import { store } from "@/core/state/jotai";
|
|
8
|
+
import { variablesAtom } from "@/core/variables/state";
|
|
9
|
+
import {
|
|
10
|
+
reactiveReferencesBundle,
|
|
11
|
+
reactiveReferencesField,
|
|
12
|
+
} from "../extension";
|
|
13
|
+
|
|
14
|
+
let view: EditorView;
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
view?.destroy();
|
|
17
|
+
vi.useRealTimers();
|
|
18
|
+
store.set(variablesAtom, {});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("skips unchanged ranges, updates edited ranges, and clears removed references", async () => {
|
|
22
|
+
vi.useFakeTimers();
|
|
23
|
+
store.set(variablesAtom, {});
|
|
24
|
+
view = new EditorView({
|
|
25
|
+
state: EditorState.create({
|
|
26
|
+
doc: "value",
|
|
27
|
+
extensions: [python(), reactiveReferencesBundle(cellId("cell1"), true)],
|
|
28
|
+
}),
|
|
29
|
+
parent: document.body,
|
|
30
|
+
});
|
|
31
|
+
const dispatch = vi.spyOn(view, "dispatch");
|
|
32
|
+
const flush = async () => {
|
|
33
|
+
vi.advanceTimersByTime(300);
|
|
34
|
+
await Promise.resolve();
|
|
35
|
+
};
|
|
36
|
+
await flush();
|
|
37
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
38
|
+
const variables = {
|
|
39
|
+
[variableName("value")]: {
|
|
40
|
+
name: variableName("value"),
|
|
41
|
+
declaredBy: [cellId("cell2")],
|
|
42
|
+
usedBy: [cellId("cell1")],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
store.set(variablesAtom, variables);
|
|
46
|
+
await flush();
|
|
47
|
+
expect(view.state.field(reactiveReferencesField).ranges).toEqual([
|
|
48
|
+
{ from: 0, to: 5, variableName: "value" },
|
|
49
|
+
]);
|
|
50
|
+
dispatch.mockClear();
|
|
51
|
+
store.set(variablesAtom, { ...variables });
|
|
52
|
+
await flush();
|
|
53
|
+
expect(dispatch).not.toHaveBeenCalled();
|
|
54
|
+
view.dispatch({ changes: { from: 0, insert: " " } });
|
|
55
|
+
await flush();
|
|
56
|
+
expect(view.state.field(reactiveReferencesField).ranges[0].from).toBe(1);
|
|
57
|
+
store.set(variablesAtom, {});
|
|
58
|
+
await flush();
|
|
59
|
+
expect(view.state.field(reactiveReferencesField).ranges).toEqual([]);
|
|
60
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { StateEffect, StateField } from "@codemirror/state";
|
|
3
|
+
import { RangeSet, StateEffect, StateField } from "@codemirror/state";
|
|
4
4
|
import {
|
|
5
5
|
Decoration,
|
|
6
6
|
type DecorationSet,
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
ViewPlugin,
|
|
9
9
|
type ViewUpdate,
|
|
10
10
|
} from "@codemirror/view";
|
|
11
|
-
import {
|
|
11
|
+
import { dequal } from "dequal";
|
|
12
|
+
import { createDebouncedEditorUpdate } from "../debounced-editor-update";
|
|
12
13
|
|
|
13
14
|
import type { CellId } from "@/core/cells/ids";
|
|
14
15
|
import { store } from "@/core/state/jotai";
|
|
@@ -44,41 +45,38 @@ class ReactiveReferencesPlugin {
|
|
|
44
45
|
private cellId: CellId;
|
|
45
46
|
private variablesUnsubscribe: () => void;
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
private readonly highlightDebounceMs = 300;
|
|
49
|
-
|
|
50
|
-
// Debounced function to trigger highlighting
|
|
51
|
-
private readonly scheduleHighlighting: DebouncedFunc<() => void>;
|
|
48
|
+
private readonly highlighting: ReturnType<typeof createDebouncedEditorUpdate>;
|
|
52
49
|
|
|
53
50
|
public constructor(view: EditorView, cellId: CellId) {
|
|
54
51
|
this.view = view;
|
|
55
52
|
this.cellId = cellId;
|
|
56
53
|
|
|
57
|
-
this.
|
|
58
|
-
this.runHighlighting()
|
|
59
|
-
|
|
54
|
+
this.highlighting = createDebouncedEditorUpdate(view, () =>
|
|
55
|
+
this.runHighlighting(),
|
|
56
|
+
);
|
|
60
57
|
|
|
61
58
|
// React to variable store changes
|
|
62
59
|
this.variablesUnsubscribe = store.sub(variablesAtom, () => {
|
|
63
|
-
this.
|
|
60
|
+
this.highlighting.schedule();
|
|
64
61
|
});
|
|
65
62
|
|
|
66
63
|
// Initial run
|
|
67
|
-
this.
|
|
64
|
+
this.highlighting.schedule();
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
public update(update: ViewUpdate) {
|
|
71
|
-
if (update.docChanged || update.focusChanged) {
|
|
72
|
-
this.
|
|
68
|
+
if (update.docChanged || update.focusChanged || update.viewportChanged) {
|
|
69
|
+
this.highlighting.schedule();
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
public destroy() {
|
|
77
|
-
this.
|
|
74
|
+
this.highlighting.destroy();
|
|
78
75
|
this.variablesUnsubscribe();
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
private runHighlighting() {
|
|
79
|
+
const state = this.view.state;
|
|
82
80
|
const ranges = findReactiveVariables({
|
|
83
81
|
state: this.view.state,
|
|
84
82
|
cellId: this.cellId,
|
|
@@ -91,12 +89,23 @@ class ReactiveReferencesPlugin {
|
|
|
91
89
|
);
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
const current = state.field(reactiveReferencesField);
|
|
93
|
+
if (
|
|
94
|
+
dequal(current.ranges, ranges) &&
|
|
95
|
+
RangeSet.eq(
|
|
96
|
+
[current.decorations],
|
|
97
|
+
[
|
|
98
|
+
Decoration.set(
|
|
99
|
+
ranges.map((range) =>
|
|
100
|
+
reactiveVariableDecoration.range(range.from, range.to),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
],
|
|
104
|
+
)
|
|
105
|
+
) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
return { effects: updateReactiveVariables.of(ranges) };
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -183,7 +183,7 @@ describe("IslandsPyodideBridge", () => {
|
|
|
183
183
|
|
|
184
184
|
/** Send a notification and return the call the consumer should receive. */
|
|
185
185
|
function sendKernelMessage(sessionGeneration: number) {
|
|
186
|
-
const notification = { op: "
|
|
186
|
+
const notification = { op: "reload" };
|
|
187
187
|
sendNotebookEvent(sessionGeneration, {
|
|
188
188
|
event: "marimo",
|
|
189
189
|
data: { marimo: notification },
|
|
@@ -206,11 +206,8 @@ function handleNotification(
|
|
|
206
206
|
case "secret-keys-result":
|
|
207
207
|
case "startup-logs":
|
|
208
208
|
case "startup-progress":
|
|
209
|
-
case "interrupted":
|
|
210
|
-
case "cache-cleared":
|
|
211
209
|
case "cache-info":
|
|
212
210
|
case "kernel-startup-error":
|
|
213
|
-
case "notebook-document-transaction":
|
|
214
211
|
return;
|
|
215
212
|
|
|
216
213
|
case "completed-run":
|
|
@@ -283,7 +283,7 @@ describe("NotebookReplica lifetime", () => {
|
|
|
283
283
|
}
|
|
284
284
|
attempt.receive({
|
|
285
285
|
event: "marimo",
|
|
286
|
-
data: { marimo: { op: "
|
|
286
|
+
data: { marimo: { op: "reload" } },
|
|
287
287
|
});
|
|
288
288
|
await vi.waitFor(() =>
|
|
289
289
|
expect(store.get(client.connectionAtom).state).toBe(
|
|
@@ -506,10 +506,10 @@ describe("NotebookReplica lifetime", () => {
|
|
|
506
506
|
earlier.receive(kernelReady);
|
|
507
507
|
current.receive({
|
|
508
508
|
event: "marimo",
|
|
509
|
-
data: { marimo: { op: "
|
|
509
|
+
data: { marimo: { op: "reload" } },
|
|
510
510
|
});
|
|
511
511
|
expect(onNotification).toHaveBeenCalledExactlyOnceWith({
|
|
512
|
-
data: { op: "
|
|
512
|
+
data: { op: "reload" },
|
|
513
513
|
});
|
|
514
514
|
});
|
|
515
515
|
|
|
@@ -563,7 +563,7 @@ describe("NotebookReplica lifetime", () => {
|
|
|
563
563
|
const { receive } = await opened();
|
|
564
564
|
receive({ event: "notebook", data: { notebook } });
|
|
565
565
|
receive(kernelReady);
|
|
566
|
-
receive({ event: "marimo", data: { marimo: { op: "
|
|
566
|
+
receive({ event: "marimo", data: { marimo: { op: "reload" } } });
|
|
567
567
|
onNotification.mockImplementationOnce(() => current.abort());
|
|
568
568
|
|
|
569
569
|
receive({ event: "ready", id: "1", data: {} });
|
|
@@ -578,8 +578,8 @@ describe("NotebookReplica lifetime", () => {
|
|
|
578
578
|
const { receive } = await opened();
|
|
579
579
|
receive({ event: "notebook", data: { notebook } });
|
|
580
580
|
receive(kernelReady);
|
|
581
|
-
const
|
|
582
|
-
receive({ event: "marimo", data: { marimo:
|
|
581
|
+
const reload = { op: "reload" };
|
|
582
|
+
receive({ event: "marimo", data: { marimo: reload } });
|
|
583
583
|
const error = new Error("notification failed");
|
|
584
584
|
onNotification.mockImplementationOnce(() => {
|
|
585
585
|
throw error;
|
|
@@ -592,7 +592,7 @@ describe("NotebookReplica lifetime", () => {
|
|
|
592
592
|
receive({ event: "ready", id: "1", data: {} });
|
|
593
593
|
expect(onNotification.mock.calls).toEqual([
|
|
594
594
|
[{ data: kernelReady.data.marimo }],
|
|
595
|
-
[{ data:
|
|
595
|
+
[{ data: reload }],
|
|
596
596
|
]);
|
|
597
597
|
expect(report).toHaveBeenCalledOnce();
|
|
598
598
|
expect(report.mock.calls[0][0]).toThrow(error);
|
|
@@ -22,7 +22,7 @@ vi.mock("../backend", () => ({ createEditorBackend: vi.fn() }));
|
|
|
22
22
|
/** A host-framed native notification. */
|
|
23
23
|
const notification = {
|
|
24
24
|
event: "marimo",
|
|
25
|
-
data: { marimo: { op: "
|
|
25
|
+
data: { marimo: { op: "reload" } },
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/** A transport whose connections the test drives. */
|
|
@@ -154,7 +154,7 @@ describe("useNotebookReplica", () => {
|
|
|
154
154
|
act(() => fake.notify());
|
|
155
155
|
expect(options.onNotification).not.toHaveBeenCalled();
|
|
156
156
|
expect(onNotification).toHaveBeenCalledExactlyOnceWith({
|
|
157
|
-
data: { op: "
|
|
157
|
+
data: { op: "reload" },
|
|
158
158
|
});
|
|
159
159
|
const [{ url }] = vi.mocked(createEditorBackend).mock.calls[0];
|
|
160
160
|
expect(url()).toBe("ws://redirected/ws");
|
|
@@ -180,8 +180,6 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
180
180
|
case "completed-run":
|
|
181
181
|
setInitialRunCompleted(true);
|
|
182
182
|
return;
|
|
183
|
-
case "interrupted":
|
|
184
|
-
return;
|
|
185
183
|
|
|
186
184
|
case "kernel-startup-error":
|
|
187
185
|
// Full error received via message before websocket close
|
|
@@ -338,9 +336,6 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
338
336
|
case "cache-info":
|
|
339
337
|
setCacheInfo(msg.data);
|
|
340
338
|
return;
|
|
341
|
-
case "cache-cleared":
|
|
342
|
-
// Cache cleared, could refresh cache info if needed
|
|
343
|
-
return;
|
|
344
339
|
case "data-source-connections":
|
|
345
340
|
addDataSourceConnection({
|
|
346
341
|
connections: msg.data.connections.map((conn) => ({
|
|
@@ -379,9 +374,6 @@ export function useNotebookSession(opts: { sessionId: SessionId }) {
|
|
|
379
374
|
: { cellId: msg.data.cell_id, line: msg.data.line },
|
|
380
375
|
);
|
|
381
376
|
return;
|
|
382
|
-
case "notebook-document-transaction":
|
|
383
|
-
// Edits reach the notebook through the host document.
|
|
384
|
-
return;
|
|
385
377
|
case "consumer-capabilities":
|
|
386
378
|
setKioskMode(!msg.data.consumer_capabilities.edit);
|
|
387
379
|
if (!msg.data.consumer_capabilities.edit) {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
createSharedResource,
|
|
5
|
+
createSharedSubscription,
|
|
6
|
+
} from "../shared-resource";
|
|
7
|
+
|
|
8
|
+
describe("shared resources", () => {
|
|
9
|
+
it.each([1, 500])(
|
|
10
|
+
"keeps one resource for %i consumers and supports remounting",
|
|
11
|
+
(count) => {
|
|
12
|
+
const stop = vi.fn();
|
|
13
|
+
const start = vi.fn(() => stop);
|
|
14
|
+
const acquire = createSharedResource(start);
|
|
15
|
+
const releases = Array.from({ length: count }, acquire);
|
|
16
|
+
expect(start).toHaveBeenCalledTimes(1);
|
|
17
|
+
for (const release of releases.slice(1)) {
|
|
18
|
+
release();
|
|
19
|
+
release();
|
|
20
|
+
}
|
|
21
|
+
expect(stop).not.toHaveBeenCalled();
|
|
22
|
+
releases[0]();
|
|
23
|
+
releases[0]();
|
|
24
|
+
expect(stop).toHaveBeenCalledTimes(1);
|
|
25
|
+
const release = acquire();
|
|
26
|
+
expect(start).toHaveBeenCalledTimes(2);
|
|
27
|
+
release();
|
|
28
|
+
expect(stop).toHaveBeenCalledTimes(2);
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
it("can retry if starting the resource fails", () => {
|
|
33
|
+
const stop = vi.fn();
|
|
34
|
+
const acquire = createSharedResource(
|
|
35
|
+
vi
|
|
36
|
+
.fn()
|
|
37
|
+
.mockImplementationOnce(() => {
|
|
38
|
+
throw new Error("start failed");
|
|
39
|
+
})
|
|
40
|
+
.mockReturnValue(stop),
|
|
41
|
+
);
|
|
42
|
+
expect(acquire).toThrow("start failed");
|
|
43
|
+
acquire()();
|
|
44
|
+
expect(stop).toHaveBeenCalledOnce();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("keeps duplicate subscriptions independent", () => {
|
|
48
|
+
let notify: () => void = vi.fn();
|
|
49
|
+
const stop = vi.fn();
|
|
50
|
+
const subscribe = createSharedSubscription((onChange) => {
|
|
51
|
+
notify = onChange;
|
|
52
|
+
return stop;
|
|
53
|
+
});
|
|
54
|
+
const listener = vi.fn();
|
|
55
|
+
const first = subscribe(listener);
|
|
56
|
+
const second = subscribe(listener);
|
|
57
|
+
notify();
|
|
58
|
+
expect(listener).toHaveBeenCalledTimes(2);
|
|
59
|
+
first();
|
|
60
|
+
first();
|
|
61
|
+
notify();
|
|
62
|
+
expect(listener).toHaveBeenCalledTimes(3);
|
|
63
|
+
expect(stop).not.toHaveBeenCalled();
|
|
64
|
+
second();
|
|
65
|
+
notify();
|
|
66
|
+
expect(listener).toHaveBeenCalledTimes(3);
|
|
67
|
+
expect(stop).toHaveBeenCalledOnce();
|
|
68
|
+
});
|
|
69
|
+
it("does not notify subscribers added during the same notification", () => {
|
|
70
|
+
let notify: () => void = vi.fn();
|
|
71
|
+
const subscribe = createSharedSubscription((onChange) => {
|
|
72
|
+
notify = onChange;
|
|
73
|
+
return vi.fn();
|
|
74
|
+
});
|
|
75
|
+
const second = vi.fn();
|
|
76
|
+
let releaseSecond: () => void = vi.fn();
|
|
77
|
+
const releaseFirst = subscribe(() => {
|
|
78
|
+
releaseSecond = subscribe(second);
|
|
79
|
+
});
|
|
80
|
+
notify();
|
|
81
|
+
expect(second).not.toHaveBeenCalled();
|
|
82
|
+
releaseFirst();
|
|
83
|
+
notify();
|
|
84
|
+
expect(second).toHaveBeenCalledOnce();
|
|
85
|
+
releaseSecond();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("delivers synchronous notifications and rolls back failed subscriptions", () => {
|
|
89
|
+
const stop = vi.fn();
|
|
90
|
+
const start = vi.fn((notify: () => void) => {
|
|
91
|
+
notify();
|
|
92
|
+
return stop;
|
|
93
|
+
});
|
|
94
|
+
start.mockImplementationOnce(() => {
|
|
95
|
+
throw new Error("start failed");
|
|
96
|
+
});
|
|
97
|
+
const subscribe = createSharedSubscription(start);
|
|
98
|
+
const failed = vi.fn();
|
|
99
|
+
expect(() => subscribe(failed)).toThrow("start failed");
|
|
100
|
+
const listener = vi.fn();
|
|
101
|
+
const release = subscribe(listener);
|
|
102
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
103
|
+
expect(failed).not.toHaveBeenCalled();
|
|
104
|
+
release();
|
|
105
|
+
expect(stop).toHaveBeenCalledOnce();
|
|
106
|
+
});
|
|
107
|
+
});
|