@marimo-team/frontend 0.23.14-dev25 → 0.23.14-dev30

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 (25) hide show
  1. package/dist/assets/{cell-editor-3PkTaSur.js → cell-editor-DeAW5cIb.js} +1 -1
  2. package/dist/assets/{command-palette-D2gzhCzl.js → command-palette-DuB4v96S.js} +1 -1
  3. package/dist/assets/{edit-page-BU3ek7Rt.js → edit-page-C2hff1e_.js} +4 -4
  4. package/dist/assets/{hooks-Q3y983ON.js → hooks-BtDf7O9d.js} +1 -1
  5. package/dist/assets/{index-Co7t4LPQ.js → index-C9lIEelG.js} +15 -15
  6. package/dist/assets/layout-CIuQ8Vb3.js +9 -0
  7. package/dist/assets/{panels-ClMIloyA.js → panels-ntqecwQW.js} +1 -1
  8. package/dist/assets/{reveal-component-BMfGxbyk.js → reveal-component-CSNvXKBK.js} +54 -54
  9. package/dist/assets/{run-page-D_AovSqt.js → run-page-DSYUUqE5.js} +1 -1
  10. package/dist/assets/{scratchpad-panel-BpvYuSq5.js → scratchpad-panel-r1Y1r0ML.js} +1 -1
  11. package/dist/assets/{useNotebookActions-C2TVewtT.js → useNotebookActions-C4iWpqNG.js} +1 -1
  12. package/dist/index.html +1 -1
  13. package/package.json +1 -1
  14. package/src/components/data-table/charts/__tests__/merge-index-fields.test.ts +33 -0
  15. package/src/components/data-table/charts/charts.tsx +24 -1
  16. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +7 -2
  17. package/src/components/slides/__tests__/slide.test.tsx +33 -0
  18. package/src/components/slides/minimap.tsx +7 -1
  19. package/src/components/slides/reveal-component.tsx +3 -0
  20. package/src/components/slides/slide-cell-view.tsx +3 -0
  21. package/src/components/slides/slide.tsx +16 -13
  22. package/src/plugins/impl/DataTablePlugin.tsx +1 -0
  23. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +53 -2
  24. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +52 -2
  25. package/dist/assets/layout-CoL1gz3N.js +0 -9
@@ -140,7 +140,8 @@ const AnyWidgetSlot = (props: IPluginProps<ModelIdRef, Data>) => {
140
140
  return null;
141
141
  }
142
142
 
143
- if (!isAnyWidgetModule(jsModule)) {
143
+ const widget = resolveAnyWidget(jsModule, jsUrl);
144
+ if (!widget) {
144
145
  return (
145
146
  <ErrorBanner error={getInvalidAnyWidgetModuleError(jsModule, jsUrl)} />
146
147
  );
@@ -150,7 +151,7 @@ const AnyWidgetSlot = (props: IPluginProps<ModelIdRef, Data>) => {
150
151
  <LoadedSlot
151
152
  // Force remount when the widget module or model changes (cell re-run).
152
153
  key={`${jsHash}:${modelId}`}
153
- widget={jsModule.default}
154
+ widget={widget}
154
155
  modelId={modelId}
155
156
  host={host}
156
157
  />
@@ -200,6 +201,55 @@ function isAnyWidgetModule(mod: any): mod is { default: AnyWidget } {
200
201
  );
201
202
  }
202
203
 
204
+ const warnedLegacyNamedExportUrls = new Set<string>();
205
+ // Cache the synthesized widget per module namespace so its identity stays
206
+ // stable across re-renders (like a default export), avoiding needless
207
+ // WidgetBinding re-initialization.
208
+ const legacyWidgetCache = new WeakMap<object, AnyWidget>();
209
+
210
+ /**
211
+ * Resolve the AnyWidget from a loaded module: prefer the AFM-spec default
212
+ * export, otherwise synthesize one from legacy named `render`/`initialize`
213
+ * exports. Returns null if neither is present.
214
+ */
215
+ function resolveAnyWidget(mod: any, jsUrl: string): AnyWidget | null {
216
+ if (isAnyWidgetModule(mod)) {
217
+ return mod.default;
218
+ }
219
+
220
+ // Only fall back to legacy (pre-AFM) named exports when there is no default
221
+ // export at all; a present-but-invalid default should surface an error
222
+ // rather than be masked.
223
+ if (mod?.default != null) {
224
+ return null;
225
+ }
226
+
227
+ const hasNamedRender = typeof mod?.render === "function";
228
+ const hasNamedInitialize = typeof mod?.initialize === "function";
229
+ if (!hasNamedRender && !hasNamedInitialize) {
230
+ return null;
231
+ }
232
+
233
+ const cached = legacyWidgetCache.get(mod);
234
+ if (cached) {
235
+ return cached;
236
+ }
237
+
238
+ if (!warnedLegacyNamedExportUrls.has(jsUrl)) {
239
+ warnedLegacyNamedExportUrls.add(jsUrl);
240
+ Logger.warn(
241
+ `Anywidget module at ${jsUrl} uses deprecated top-level named ` +
242
+ "exports (`render`/`initialize`). Per the AFM spec, use a default " +
243
+ "export instead: `export default { render }`. " +
244
+ "See https://anywidget.dev/en/afm/",
245
+ );
246
+ }
247
+
248
+ const widget: AnyWidget = { render: mod.render, initialize: mod.initialize };
249
+ legacyWidgetCache.set(mod, widget);
250
+ return widget;
251
+ }
252
+
203
253
  function getInvalidAnyWidgetModuleError(mod: unknown, jsUrl: string): Error {
204
254
  const afmDocs = "https://anywidget.dev/en/afm/";
205
255
  const hasNamedRender = isRecord(mod) && hasFunctionProperty(mod, "render");
@@ -296,5 +346,6 @@ export const visibleForTesting = {
296
346
  LoadedSlot,
297
347
  runAnyWidgetModule,
298
348
  isAnyWidgetModule,
349
+ resolveAnyWidget,
299
350
  getInvalidAnyWidgetModuleError,
300
351
  };
@@ -9,8 +9,12 @@ import { MODEL_MANAGER, Model } from "../model";
9
9
  import type { WidgetModelId } from "../types";
10
10
  import { BINDING_MANAGER } from "../widget-binding";
11
11
 
12
- const { LoadedSlot, isAnyWidgetModule, getInvalidAnyWidgetModuleError } =
13
- visibleForTesting;
12
+ const {
13
+ LoadedSlot,
14
+ isAnyWidgetModule,
15
+ resolveAnyWidget,
16
+ getInvalidAnyWidgetModuleError,
17
+ } = visibleForTesting;
14
18
 
15
19
  // Helper to create typed model IDs for tests
16
20
  const asModelId = (id: string): WidgetModelId => id as WidgetModelId;
@@ -170,6 +174,52 @@ describe("isAnyWidgetModule", () => {
170
174
  });
171
175
  });
172
176
 
177
+ describe("resolveAnyWidget", () => {
178
+ const jsUrl = "./@file/widget.js";
179
+
180
+ it("should return the default export when present", () => {
181
+ const widget = { render: () => undefined };
182
+ expect(resolveAnyWidget({ default: widget }, jsUrl)).toBe(widget);
183
+ });
184
+
185
+ it("should return a default factory function", () => {
186
+ const factory = async () => ({ render: () => {} });
187
+ expect(resolveAnyWidget({ default: factory }, jsUrl)).toBe(factory);
188
+ });
189
+
190
+ it("should synthesize a widget from a legacy named render export", () => {
191
+ const render = vi.fn();
192
+ const resolved = resolveAnyWidget({ render }, jsUrl);
193
+ expect(resolved).not.toBeNull();
194
+ expect(resolved).toMatchObject({ render });
195
+ });
196
+
197
+ it("should synthesize a widget from a legacy named initialize export", () => {
198
+ const initialize = vi.fn();
199
+ const resolved = resolveAnyWidget({ initialize }, jsUrl);
200
+ expect(resolved).not.toBeNull();
201
+ expect(resolved).toMatchObject({ initialize });
202
+ });
203
+
204
+ it("should return null for a module with no valid exports", () => {
205
+ expect(resolveAnyWidget({}, jsUrl)).toBeNull();
206
+ expect(resolveAnyWidget({ default: {} }, jsUrl)).toBeNull();
207
+ expect(resolveAnyWidget({ render: "not a function" }, jsUrl)).toBeNull();
208
+ });
209
+
210
+ it("should return a stable widget identity across calls for one module", () => {
211
+ const mod = { render: vi.fn() };
212
+ expect(resolveAnyWidget(mod, jsUrl)).toBe(resolveAnyWidget(mod, jsUrl));
213
+ });
214
+
215
+ it("should not fall back to named exports when a default export is present", () => {
216
+ // A present-but-invalid default should surface an error, not be masked.
217
+ expect(
218
+ resolveAnyWidget({ default: {}, render: vi.fn() }, jsUrl),
219
+ ).toBeNull();
220
+ });
221
+ });
222
+
173
223
  describe("getInvalidAnyWidgetModuleError", () => {
174
224
  const jsUrl = "./@file/widget.js";
175
225