@marimo-team/frontend 0.23.6-dev13 → 0.23.6-dev16
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/assets/{CellStatus-DKMrz26-.js → CellStatus-BasmzQBh.js} +1 -1
- package/dist/assets/{JsonOutput-02ehjjSC.js → JsonOutput-vLKwARbP.js} +1 -1
- package/dist/assets/{MarimoErrorOutput-Dbk0HqOA.js → MarimoErrorOutput-BV73ko7W.js} +1 -1
- package/dist/assets/RenderHTML-Cv8cr_an.js +1 -0
- package/dist/assets/{add-cell-with-ai-DfniMbLM.js → add-cell-with-ai-BqApEAcB.js} +1 -1
- package/dist/assets/{add-connection-dialog-8ChtH4mo.js → add-connection-dialog-C3cn-x1B.js} +1 -1
- package/dist/assets/{agent-panel-jsnbrvBR.js → agent-panel-C-5MUkzV.js} +1 -1
- package/dist/assets/{ai-model-dropdown-BFTnsrTP.js → ai-model-dropdown-DQ9Z4-uL.js} +4 -4
- package/dist/assets/{app-config-button-c_2rVezv.js → app-config-button-F1PfzgiC.js} +1 -1
- package/dist/assets/{cell-editor-WSoKgacR.js → cell-editor-C33HDTDM.js} +1 -1
- package/dist/assets/{cell-link-BRdZl0OJ.js → cell-link-8o8mCUzE.js} +1 -1
- package/dist/assets/{cells-CcBfzJ1Z.js → cells-Jdt48eTG.js} +47 -47
- package/dist/assets/{chat-display-NiFkPnNN.js → chat-display-YfE-PieK.js} +1 -1
- package/dist/assets/{chat-panel-C6V6gxrr.js → chat-panel-CGR5FQXH.js} +1 -1
- package/dist/assets/{chat-ui-BLiRBYhk.js → chat-ui-CzB2bGbZ.js} +1 -1
- package/dist/assets/{column-preview-rDM8Q-wn.js → column-preview-z4x0_KlJ.js} +1 -1
- package/dist/assets/{command-palette-CUYBVGPU.js → command-palette-Ft577HZi.js} +1 -1
- package/dist/assets/{common-CHmdPmWi.js → common-C6ZHulDM.js} +1 -1
- package/dist/assets/{components-HCInimq-.js → components-BiZUhizd.js} +1 -1
- package/dist/assets/{components-DVKf_7RU.js → components-Du9BBcZY.js} +1 -1
- package/dist/assets/{datasource-Czm_KBfK.js → datasource-BGCJgHn8.js} +1 -1
- package/dist/assets/{dependency-graph-panel-DPKylrlr.js → dependency-graph-panel-BFoJRcHv.js} +1 -1
- package/dist/assets/{documentation-panel-DZkIKuPv.js → documentation-panel-CL6z2pC-.js} +1 -1
- package/dist/assets/{download-YUQiaxS9.js → download-q17GDjRk.js} +1 -1
- package/dist/assets/{edit-page-BiwFohnL.js → edit-page-DTof11Ql.js} +3 -3
- package/dist/assets/{error-panel-C4UQHEjp.js → error-panel-CrL_-c65.js} +1 -1
- package/dist/assets/{file-explorer-panel-DEJtGGUp.js → file-explorer-panel-DxWjS8x0.js} +1 -1
- package/dist/assets/{file-icons-CMxkj_kV.js → file-icons-D1lzcliR.js} +1 -1
- package/dist/assets/{floating-outline-BtNnv2IX.js → floating-outline-DVqXePmL.js} +1 -1
- package/dist/assets/{focus-CXQpR65O.js → focus-Bz1PGBQ2.js} +1 -1
- package/dist/assets/{form-EgPmt17c.js → form-BeWsuyiN.js} +1 -1
- package/dist/assets/{home-page-CaIONOO0.js → home-page-B-NywDCP.js} +1 -1
- package/dist/assets/{hooks-CZcajTLZ.js → hooks-CenNRyn0.js} +1 -1
- package/dist/assets/{html-to-image-BHdf1t5J.js → html-to-image-BJDxFKbb.js} +1 -1
- package/dist/assets/{index-CL4WR8q8.js → index-CMy5rqL5.js} +4 -4
- package/dist/assets/{kiosk-mode-vHMq9vr1.js → kiosk-mode-DlJLa7MP.js} +1 -1
- package/dist/assets/layout-C0mYexWg.js +9 -0
- package/dist/assets/{logs-panel-DL9WeQsv.js → logs-panel--5x174b0.js} +1 -1
- package/dist/assets/{markdown-renderer-DmnGXdCp.js → markdown-renderer-9gIJjISB.js} +1 -1
- package/dist/assets/{name-cell-input-CHuLB3H7.js → name-cell-input-DUUJ7fdG.js} +1 -1
- package/dist/assets/{outline-panel-JaSUHnmD.js → outline-panel-B6y7CdzK.js} +1 -1
- package/dist/assets/{packages-panel-BB5_Iu2c.js → packages-panel-C973lbUg.js} +1 -1
- package/dist/assets/{panels-D4g3bUpO.js → panels-C-FuTmb5.js} +1 -1
- package/dist/assets/{process-output-hJso9ugZ.js → process-output-TR8koJYc.js} +1 -1
- package/dist/assets/{radio-group-6t7ozlnG.js → radio-group-B0jYgGRE.js} +1 -1
- package/dist/assets/{readonly-python-code-JBCsN3-9.js → readonly-python-code-BNCBnJYH.js} +1 -1
- package/dist/assets/{reveal-component-BKMB17JT.js → reveal-component-Dm1r-VqB.js} +1 -1
- package/dist/assets/{run-page-BPM6GfJo.js → run-page-Bg9tp_B4.js} +1 -1
- package/dist/assets/{scratchpad-panel-Cabu2odx.js → scratchpad-panel-BTCY4gJu.js} +1 -1
- package/dist/assets/{session-panel-BAiIHm0d.js → session-panel-CQ0WCDPM.js} +1 -1
- package/dist/assets/{snippets-panel-CQKr-OMs.js → snippets-panel-CYRWuEqZ.js} +1 -1
- package/dist/assets/{state-DGoUR-mM.js → state-B1sEnd95.js} +1 -1
- package/dist/assets/{state-DCT6JLba.js → state-Bhut5iLD.js} +1 -1
- package/dist/assets/{textarea-BI_mXP9w.js → textarea-DapfQSws.js} +1 -1
- package/dist/assets/{tracing-BF-ca60a.js → tracing-D3nIh6vh.js} +1 -1
- package/dist/assets/{tracing-panel-D1j7Fbvr.js → tracing-panel-B23uvwYc.js} +2 -2
- package/dist/assets/{useCellActionButton-CcXV09GQ.js → useCellActionButton-DrzG-_Bd.js} +1 -1
- package/dist/assets/{useDeleteCell-BVX9aH-t.js → useDeleteCell-CcnkgOq-.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-CewdyAAy.js → useDependencyPanelTab-Dv04JzMr.js} +1 -1
- package/dist/assets/useNotebookActions-C0IbJuzO.js +1 -0
- package/dist/assets/{useRunCells-CgXnbA14.js → useRunCells-BeRcytF8.js} +1 -1
- package/dist/assets/{useSplitCell-_Q2wQXsQ.js → useSplitCell-DSLPh_8D.js} +1 -1
- package/dist/index.html +22 -22
- package/package.json +5 -5
- package/src/components/slides/slide-form.tsx +43 -0
- package/src/core/cells/__tests__/apply-transaction.test.ts +193 -27
- package/src/core/cells/__tests__/cells.test.ts +99 -0
- package/src/core/cells/__tests__/document-changes.test.ts +14 -0
- package/src/core/cells/cells.ts +14 -1
- package/src/core/cells/document-changes.ts +17 -14
- package/src/plugins/core/RenderHTML.tsx +49 -3
- package/src/plugins/core/__test__/RenderHTML.test.ts +54 -0
- package/dist/assets/RenderHTML-8cI8zL5y.js +0 -1
- package/dist/assets/layout-DNOqvNbP.js +0 -9
- package/dist/assets/useNotebookActions-CWpi-dx_.js +0 -1
|
@@ -203,6 +203,8 @@ describe("toDocumentChanges", () => {
|
|
|
203
203
|
[
|
|
204
204
|
{
|
|
205
205
|
"cellId": "0",
|
|
206
|
+
"column": null,
|
|
207
|
+
"disabled": false,
|
|
206
208
|
"hideCode": true,
|
|
207
209
|
"type": "set-config",
|
|
208
210
|
},
|
|
@@ -246,6 +248,8 @@ describe("toDocumentChanges", () => {
|
|
|
246
248
|
{
|
|
247
249
|
"cellId": "1",
|
|
248
250
|
"column": 1,
|
|
251
|
+
"disabled": false,
|
|
252
|
+
"hideCode": false,
|
|
249
253
|
"type": "set-config",
|
|
250
254
|
},
|
|
251
255
|
{
|
|
@@ -273,11 +277,15 @@ describe("toDocumentChanges", () => {
|
|
|
273
277
|
{
|
|
274
278
|
"cellId": "1",
|
|
275
279
|
"column": 1,
|
|
280
|
+
"disabled": false,
|
|
281
|
+
"hideCode": false,
|
|
276
282
|
"type": "set-config",
|
|
277
283
|
},
|
|
278
284
|
{
|
|
279
285
|
"cellId": "2",
|
|
280
286
|
"column": 1,
|
|
287
|
+
"disabled": false,
|
|
288
|
+
"hideCode": false,
|
|
281
289
|
"type": "set-config",
|
|
282
290
|
},
|
|
283
291
|
{
|
|
@@ -310,11 +318,15 @@ describe("toDocumentChanges", () => {
|
|
|
310
318
|
{
|
|
311
319
|
"cellId": "1",
|
|
312
320
|
"column": 0,
|
|
321
|
+
"disabled": false,
|
|
322
|
+
"hideCode": false,
|
|
313
323
|
"type": "set-config",
|
|
314
324
|
},
|
|
315
325
|
{
|
|
316
326
|
"cellId": "2",
|
|
317
327
|
"column": 0,
|
|
328
|
+
"disabled": false,
|
|
329
|
+
"hideCode": false,
|
|
318
330
|
"type": "set-config",
|
|
319
331
|
},
|
|
320
332
|
{
|
|
@@ -358,6 +370,8 @@ describe("toDocumentChanges", () => {
|
|
|
358
370
|
{
|
|
359
371
|
"cellId": "1",
|
|
360
372
|
"column": 1,
|
|
373
|
+
"disabled": false,
|
|
374
|
+
"hideCode": false,
|
|
361
375
|
"type": "set-config",
|
|
362
376
|
},
|
|
363
377
|
{
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { isErrorMime } from "../mime";
|
|
|
29
29
|
import type { CellConfig } from "../network/types";
|
|
30
30
|
import { isRtcEnabled } from "../rtc/state";
|
|
31
31
|
import { createDeepEqualAtom, store } from "../state/jotai";
|
|
32
|
+
import { isWasm } from "../wasm/utils";
|
|
32
33
|
import { prepareCellForExecution, transitionCell } from "./cell";
|
|
33
34
|
import { documentTransactionMiddleware } from "./document-changes";
|
|
34
35
|
import { CellId, SCRATCH_CELL_ID, SETUP_CELL_ID } from "./ids";
|
|
@@ -1032,8 +1033,20 @@ const {
|
|
|
1032
1033
|
setCells: (state, cells: CellData[]) => {
|
|
1033
1034
|
const cellData = Object.fromEntries(cells.map((cell) => [cell.id, cell]));
|
|
1034
1035
|
|
|
1036
|
+
// WASM has no server-side SessionView to replay outputs, so the
|
|
1037
|
+
// snapshot hydrated by notebookStateFromSession is the only source.
|
|
1038
|
+
const preserveSnapshot = isWasm();
|
|
1039
|
+
const runtimeFor = (cellId: CellId): CellRuntimeState => {
|
|
1040
|
+
if (!preserveSnapshot) {
|
|
1041
|
+
return createCellRuntimeState();
|
|
1042
|
+
}
|
|
1043
|
+
const prev = state.cellRuntime[cellId];
|
|
1044
|
+
const hasSnapshot =
|
|
1045
|
+
prev && (prev.output != null || prev.consoleOutputs.length > 0);
|
|
1046
|
+
return hasSnapshot ? prev : createCellRuntimeState();
|
|
1047
|
+
};
|
|
1035
1048
|
const cellRuntime = Object.fromEntries(
|
|
1036
|
-
cells.map((cell) => [cell.id,
|
|
1049
|
+
cells.map((cell) => [cell.id, runtimeFor(cell.id)]),
|
|
1037
1050
|
);
|
|
1038
1051
|
|
|
1039
1052
|
return withScratchCell({
|
|
@@ -156,10 +156,13 @@ function columnChanges(
|
|
|
156
156
|
for (const [cellId, newCol] of newColumns) {
|
|
157
157
|
const prevCol = prevColumns.get(cellId);
|
|
158
158
|
if (prevCol !== newCol) {
|
|
159
|
+
const cell = getCell(cellId, newState);
|
|
159
160
|
changes.push({
|
|
160
161
|
type: "set-config",
|
|
161
162
|
cellId: cellId,
|
|
162
163
|
column: newCol,
|
|
164
|
+
disabled: cell?.config.disabled ?? false,
|
|
165
|
+
hideCode: cell?.config.hide_code ?? false,
|
|
163
166
|
});
|
|
164
167
|
}
|
|
165
168
|
}
|
|
@@ -257,18 +260,21 @@ export function toDocumentChanges(
|
|
|
257
260
|
}
|
|
258
261
|
|
|
259
262
|
// updateCellConfig → set-config
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
// (from the action payload, not the full cell config).
|
|
263
|
+
// SetConfig is full-replacement: emit the cell's complete config from
|
|
264
|
+
// newState (which already merged the action's partial payload).
|
|
263
265
|
case "updateCellConfig": {
|
|
264
|
-
const { cellId
|
|
266
|
+
const { cellId } = action.payload;
|
|
267
|
+
const cell = getCell(cellId, newState);
|
|
268
|
+
if (!cell) {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
265
271
|
return [
|
|
266
272
|
{
|
|
267
273
|
type: "set-config",
|
|
268
274
|
cellId: cellId,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
column: cell.config.column ?? null,
|
|
276
|
+
disabled: cell.config.disabled ?? false,
|
|
277
|
+
hideCode: cell.config.hide_code ?? false,
|
|
272
278
|
},
|
|
273
279
|
];
|
|
274
280
|
}
|
|
@@ -538,18 +544,15 @@ export function fromDocumentChanges(
|
|
|
538
544
|
break;
|
|
539
545
|
|
|
540
546
|
// set-config → updateCellConfig
|
|
541
|
-
// Maps the change's camelCase hideCode back to CellConfig's snake_case
|
|
542
|
-
// hide_code. Only includes fields that are non-null (null means
|
|
543
|
-
// "not specified" on the wire, not "clear the value").
|
|
544
547
|
case "set-config":
|
|
545
548
|
actions.push({
|
|
546
549
|
type: "updateCellConfig",
|
|
547
550
|
payload: {
|
|
548
551
|
cellId: change.cellId,
|
|
549
552
|
config: {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
+
column: change.column,
|
|
554
|
+
disabled: change.disabled,
|
|
555
|
+
hide_code: change.hideCode,
|
|
553
556
|
},
|
|
554
557
|
},
|
|
555
558
|
});
|
|
@@ -650,7 +653,7 @@ export function applyTransactionChanges(
|
|
|
650
653
|
) {
|
|
651
654
|
continue;
|
|
652
655
|
}
|
|
653
|
-
if (change.type === "set-config"
|
|
656
|
+
if (change.type === "set-config") {
|
|
654
657
|
hasColumnChange = true;
|
|
655
658
|
}
|
|
656
659
|
if (change.type === "create-cell" && change.config?.column != null) {
|
|
@@ -6,6 +6,7 @@ import parse, {
|
|
|
6
6
|
type HTMLReactParserOptions,
|
|
7
7
|
} from "html-react-parser";
|
|
8
8
|
import React, {
|
|
9
|
+
cloneElement,
|
|
9
10
|
isValidElement,
|
|
10
11
|
type JSX,
|
|
11
12
|
type ReactNode,
|
|
@@ -169,6 +170,35 @@ const addCopyButtonToCodehilite: TransformFn = (
|
|
|
169
170
|
}
|
|
170
171
|
};
|
|
171
172
|
|
|
173
|
+
// Decorator (not a match-and-replace transform): applies a src-based key
|
|
174
|
+
// to <img> elements so they remount on src change. Reusing an <img> across
|
|
175
|
+
// src changes can leave the previous image painted (e.g. when the new
|
|
176
|
+
// request is slow/blocked, served stale by a CDN, or fails CORS), so the
|
|
177
|
+
// user sees the old image even though the HTML source is up to date.
|
|
178
|
+
//
|
|
179
|
+
// Runs unconditionally after the match-and-replace transforms so it still
|
|
180
|
+
// applies when an <img> was already wrapped by, say, wrapTooltipTargets.
|
|
181
|
+
const keyImagesBySrc: TransformFn = (
|
|
182
|
+
reactNode: ReactNode,
|
|
183
|
+
domNode: DOMNode,
|
|
184
|
+
index: number,
|
|
185
|
+
): JSX.Element | undefined => {
|
|
186
|
+
if (!(domNode instanceof Element) || domNode.name !== "img") {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const src = domNode.attribs?.src;
|
|
190
|
+
if (!src || !isValidElement(reactNode)) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
// data: URIs are inline — no network fetch — so they can't go stale.
|
|
194
|
+
// Skip to avoid bloating the React key with a megabyte base64 payload.
|
|
195
|
+
// URI schemes are case-insensitive per RFC 3986.
|
|
196
|
+
if (/^data:/i.test(src)) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
return cloneElement(reactNode, { key: `${src}-${index}` });
|
|
200
|
+
};
|
|
201
|
+
|
|
172
202
|
// Wrap elements with data-marimo-doc attribute in a DocHoverTarget
|
|
173
203
|
const wrapDocHoverTargets: TransformFn = (
|
|
174
204
|
reactNode: ReactNode,
|
|
@@ -281,6 +311,8 @@ function parseHtml({
|
|
|
281
311
|
...additionalReplacements,
|
|
282
312
|
];
|
|
283
313
|
|
|
314
|
+
// Match-and-replace transforms: the first one that returns a value wins
|
|
315
|
+
// (short-circuits the rest).
|
|
284
316
|
const transformFunctions: TransformFn[] = [
|
|
285
317
|
addCopyButtonToCodehilite,
|
|
286
318
|
preserveQueryParamsInAnchorLinks,
|
|
@@ -290,6 +322,12 @@ function parseHtml({
|
|
|
290
322
|
removeWrappingHtmlTags,
|
|
291
323
|
];
|
|
292
324
|
|
|
325
|
+
// Decorators: run unconditionally on the result of the transform pipeline
|
|
326
|
+
// and may further wrap/clone it. Used for cross-cutting concerns that
|
|
327
|
+
// should apply regardless of which (if any) match-and-replace transform
|
|
328
|
+
// ran above.
|
|
329
|
+
const decoratorFunctions: TransformFn[] = [keyImagesBySrc];
|
|
330
|
+
|
|
293
331
|
return parse(html, {
|
|
294
332
|
replace: (domNode: DOMNode, index: number) => {
|
|
295
333
|
for (const renderFunction of renderFunctions) {
|
|
@@ -301,13 +339,21 @@ function parseHtml({
|
|
|
301
339
|
return domNode;
|
|
302
340
|
},
|
|
303
341
|
transform: (reactNode: ReactNode, domNode: DOMNode, index: number) => {
|
|
342
|
+
let result: ReactNode = reactNode as JSX.Element;
|
|
304
343
|
for (const transformFunction of transformFunctions) {
|
|
305
|
-
const transformed = transformFunction(
|
|
344
|
+
const transformed = transformFunction(result, domNode, index);
|
|
306
345
|
if (transformed) {
|
|
307
|
-
|
|
346
|
+
result = transformed;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
for (const decorate of decoratorFunctions) {
|
|
351
|
+
const decorated = decorate(result, domNode, index);
|
|
352
|
+
if (decorated) {
|
|
353
|
+
result = decorated;
|
|
308
354
|
}
|
|
309
355
|
}
|
|
310
|
-
return
|
|
356
|
+
return result as JSX.Element;
|
|
311
357
|
},
|
|
312
358
|
});
|
|
313
359
|
}
|
|
@@ -60,6 +60,60 @@ describe("parseHtml", () => {
|
|
|
60
60
|
`);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
+
test("img has key derived from src so React remounts on src change", () => {
|
|
64
|
+
const html = '<img src="https://cdn.example.com/a.png" alt="a">';
|
|
65
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
66
|
+
expect(result.key).toBe("https://cdn.example.com/a.png-0");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("multiple imgs each get distinct keys", () => {
|
|
70
|
+
const html =
|
|
71
|
+
'<div><img src="https://cdn.example.com/a.png"><img src="https://cdn.example.com/b.png"></div>';
|
|
72
|
+
const result = parseHtml({ html }) as React.ReactElement<{
|
|
73
|
+
children: React.ReactElement[];
|
|
74
|
+
}>;
|
|
75
|
+
const children = result.props.children;
|
|
76
|
+
expect(children[0].key).toBe("https://cdn.example.com/a.png-0");
|
|
77
|
+
expect(children[1].key).toBe("https://cdn.example.com/b.png-1");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("img without src is left alone", () => {
|
|
81
|
+
const html = "<img>";
|
|
82
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
83
|
+
expect(result.key).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("img with data: URI is not keyed (inline, no network fetch)", () => {
|
|
87
|
+
const longPayload = "A".repeat(10_000);
|
|
88
|
+
const html = `<img src="data:image/png;base64,${longPayload}">`;
|
|
89
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
90
|
+
// No remount-on-src needed for inline images, so we leave the key
|
|
91
|
+
// unset rather than bloat it with the base64 payload.
|
|
92
|
+
expect(result.key).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("img with uppercase DATA: URI is also skipped (scheme is case-insensitive)", () => {
|
|
96
|
+
const html = `<img src="DATA:image/png;base64,${"A".repeat(100)}">`;
|
|
97
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
98
|
+
expect(result.key).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("img wrapped by data-tooltip is still keyed by src", () => {
|
|
102
|
+
const html =
|
|
103
|
+
'<img src="https://cdn.example.com/a.png" data-tooltip="hi" alt="a">';
|
|
104
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
105
|
+
// Outer Tooltip carries the src-based key so it remounts on src change,
|
|
106
|
+
// forcing the inner <img> to remount as well.
|
|
107
|
+
expect(result.key).toBe("https://cdn.example.com/a.png-0");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("img wrapped by data-marimo-doc is still keyed by src", () => {
|
|
111
|
+
const html =
|
|
112
|
+
'<img src="https://cdn.example.com/b.png" data-marimo-doc="foo.bar">';
|
|
113
|
+
const result = parseHtml({ html }) as React.ReactElement;
|
|
114
|
+
expect(result.key).toBe("https://cdn.example.com/b.png-0");
|
|
115
|
+
});
|
|
116
|
+
|
|
63
117
|
test("codehilite with copy button", () => {
|
|
64
118
|
const html =
|
|
65
119
|
'<div class="codehilite"><pre><code>console.log("Hello");</code></pre></div>';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as x}from"./chunk-LvLJmgfZ.js";import{i as g,p as T,u as C}from"./useEvent-D91BmmQi.js";import{t as M}from"./react-Bj1aDYRI.js";import{Sn as H,ci as I,it as j,li as c,m as L,vn as N,yt as k}from"./cells-CcBfzJ1Z.js";import{t as E}from"./compiler-runtime-B3qBwwSJ.js";import{_ as w}from"./useEventListener-BR0C1MaI.js";import{o as _}from"./utils-DIGrmLDO.js";import{t as A}from"./jsx-runtime-BqBOg78p.js";import{t as F}from"./tooltip-Gcwqb_SK.js";import{t as O}from"./copy-icon-BYNydU7b.js";import{t as W}from"./usePress-CfcdTqJM.js";import{n as q}from"./useDebounce-CLMpJfhX.js";import{t as R}from"./useRunCells-CgXnbA14.js";var z=E(),m=x(M(),1),l=x(A(),1);const V=e=>{let t=(0,z.c)(16),r,n,i;t[0]===e?(r=t[1],n=t[2],i=t[3]):({href:n,children:r,...i}=e,t[0]=e,t[1]=r,t[2]=n,t[3]=i);let a=(0,m.useRef)(null),o;t[4]===n?o=t[5]:(o=()=>{let p=new URL(globalThis.location.href);p.hash=n,globalThis.history.pushState({},"",p.toString()),globalThis.dispatchEvent(new HashChangeEvent("hashchange"));let S=n.slice(1),y=document.getElementById(S);y&&y.scrollIntoView({behavior:"smooth",block:"start"})},t[4]=n,t[5]=o);let s=o,f;t[6]===s?f=t[7]:(f={onPress:()=>{s()}},t[6]=s,t[7]=f);let{pressProps:h}=W(f),u;t[8]===s?u=t[9]:(u=p=>{p.preventDefault(),s()},t[8]=s,t[9]=u);let b=u,d;return t[10]!==r||t[11]!==b||t[12]!==n||t[13]!==h||t[14]!==i?(d=(0,l.jsx)("a",{ref:a,href:n,...h,onClick:b,...i,children:r}),t[10]=r,t[11]=b,t[12]=n,t[13]=h,t[14]=i,t[15]=d):d=t[15],d};async function P(e){let t=L().inOrderIds.at(0);if(t)try{let r=await N.request({document:e,cellId:t});if(!r||r.options.length===0)return;let n=e.split(".").pop()??e,i=r.options[0],a=r.options.find(o=>o.name===n)??i;a!=null&&a.completion_info&&g.set(H,{documentation:a.completion_info})}catch(r){w.debug(`Doc lookup failed for "${e}"`,r)}}var D=E();const $=e=>{let t=(0,D.c)(8),{qualifiedName:r,children:n}=e,i;t[0]===r?i=t[1]:(i=()=>{P(r)},t[0]=r,t[1]=i);let a=q(i,100),o;t[2]===a?o=t[3]:(o=()=>a.cancel(),t[2]=a,t[3]=o);let s;return t[4]!==n||t[5]!==a||t[6]!==o?(s=(0,l.jsx)("span",{onMouseEnter:a,onMouseLeave:o,children:n}),t[4]=n,t[5]=a,t[6]=o,t[7]=s):s=t[7],s};function B(e){if(typeof e!="object"||!e)return!1;let t=e;return!(t.trusted!==!0||t.notebookCode!==void 0&&typeof t.notebookCode!="string")}function U(){let e=window==null?void 0:window.__MARIMO_EXPORT_CONTEXT__;return B(e)?e:void 0}function v(){var e;return((e=U())==null?void 0:e.trusted)===!0}function X(){if(g.get(R)||v()||g.get(_))return!0;try{if(j()==="read")return!0}catch{}return!1}var G=T(e=>{let t=e(R),r=e(_);if(t||r||v())return!1;let n=!0;try{n=j()==="read"}catch{return!0}return!n});function K(){return C(G)}var Z=E(),J=e=>{if(e instanceof c.Element&&!/^[A-Za-z][\w-]*$/.test(e.name))return m.createElement(m.Fragment)},Q=(e,t)=>{if(t instanceof c.Element&&t.name==="body"){if((0,m.isValidElement)(e)&&"props"in e){let r=e.props.children;return(0,l.jsx)(l.Fragment,{children:r})}return}},Y=(e,t)=>{if(t instanceof c.Element&&t.name==="html"){if((0,m.isValidElement)(e)&&"props"in e){let r=e.props.children;return(0,l.jsx)(l.Fragment,{children:r})}return}},tt=e=>{if(e instanceof c.Element&&e.attribs&&e.name==="iframe"){let t=document.createElement("iframe");return Object.entries(e.attribs).forEach(([r,n])=>{r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)),t.setAttribute(r,n)}),(0,l.jsx)("div",{dangerouslySetInnerHTML:{__html:t.outerHTML}})}},et=e=>{if(e instanceof c.Element&&e.name==="script"){let t=e.attribs.src;if(!t)return;if(!X())return w.warn(`[RenderHTML] refusing <script src> in untrusted context: ${t}`),(0,l.jsx)(l.Fragment,{});if(![...document.querySelectorAll("script[src]")].some(r=>r.getAttribute("src")===t)){let r=document.createElement("script");r.src=t,document.head.append(r)}return(0,l.jsx)(l.Fragment,{})}},rt=(e,t)=>{if(t instanceof c.Element&&t.name==="a"){let r=t.attribs.href;if(r!=null&&r.startsWith("#")&&!r.startsWith("#code/")){let n=null;return(0,m.isValidElement)(e)&&"props"in e&&(n=e.props.children),(0,l.jsx)(V,{href:r,...t.attribs,children:n})}}},nt=(e,t,r)=>{var n,i;if(t instanceof c.Element&&t.name==="div"&&((i=(n=t.attribs)==null?void 0:n.class)!=null&&i.includes("codehilite")))return(0,l.jsx)(ot,{children:e},r)},it=(e,t)=>{var r;if(t instanceof c.Element&&((r=t.attribs)!=null&&r["data-marimo-doc"])){let n=t.attribs["data-marimo-doc"];return(0,l.jsx)($,{qualifiedName:n,children:e})}},at=(e,t)=>{var r,n;if(t instanceof c.Element&&((r=t.attribs)!=null&&r["data-tooltip"])){if((((n=t.name)==null?void 0:n.toLowerCase())??"").startsWith("marimo-"))return;let i=t.attribs["data-tooltip"];return(0,l.jsx)(F,{content:i,children:e})}},ot=e=>{let t=(0,Z.c)(3),{children:r}=e,n=(0,m.useRef)(null),i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=(0,l.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,l.jsx)(O,{tooltip:!1,className:"p-1",value:()=>{var s;let o=(s=n.current)==null?void 0:s.firstChild;return o&&o.textContent||""}})}),t[0]=i):i=t[0];let a;return t[1]===r?a=t[2]:(a=(0,l.jsxs)("div",{className:"relative group codehilite-wrapper",ref:n,children:[r,i]}),t[1]=r,t[2]=a),a};const st=({html:e,additionalReplacements:t=[],alwaysSanitizeHtml:r=!0})=>(0,l.jsx)(lt,{html:e,alwaysSanitizeHtml:r,additionalReplacements:t});var lt=({html:e,additionalReplacements:t=[],alwaysSanitizeHtml:r})=>{let n=K();return ct({html:(0,m.useMemo)(()=>r||n?k(e):e,[e,r,n]),additionalReplacements:t})};function ct({html:e,additionalReplacements:t=[]}){let r=[J,tt,et,...t],n=[nt,rt,it,at,Q,Y];return I(e,{replace:(i,a)=>{for(let o of r){let s=o(i,a);if(s)return s}return i},transform:(i,a,o)=>{for(let s of n){let f=s(i,a,o);if(f)return f}return i}})}export{v as n,st as t};
|