Skip to content

feat(gallery): Add interactive playground to Component Gallery - #265

Merged
ktu22 merged 12 commits into
a2ui-project:mainfrom
ktu22:feature/gallery-updates
Oct 21, 2026
Merged

ktu22 merged 12 commits into
a2ui-project:mainfrom
ktu22:feature/gallery-updates

Conversation

@ktu22

@ktu22 ktu22 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Description

Note: This PR builds off of #129.

Adds interactive playground to Component Gallery where users can now inspect and edit component properties via schema-driven UI controls or live Monaco JSON editor, preview updates in real time, reset drafts to their original state, and launch their edited draft directly into the main Composer workspace.

Demo

InteractivePlaygroundDemo.mov

Changes by Functionality

1. Interactive Gallery Playground & Unit Tests & UI (4 files)

  • shell/src/app/gallery/gallery.ts: Manages local draft state via linkedSignal, synchronizes edits between the schema-driven property controls and the JSON editor, preserves the last valid preview payload when invalid edits occur, and supports resetting or copying payloads.

    • shell/src/app/gallery/gallery.spec.ts: Adds unit test coverage for live property editing, two-way JSON synchronization, invalid draft recovery, common vs. component-specific property grouping, and workspace handoff.
  • shell/src/app/gallery/gallery.ng.html: Adds the interactive playground layout, including dynamic property controls (selects, slide toggles, inputs, nested object fields, dynamic array item lists, and JSON textareas), inline validation errors, status announcements, and action buttons (Reset example, Open in Composer).

  • shell/src/app/gallery/gallery.scss: Styles the expandable playground panel, property editor rows, nested object/array controls, inline error states, and responsive layout adjustments.

2. Schema-Driven Parsing of Types for UI Control Elements & Unit Tests (2 file)

  • shell/src/app/gallery/gallery-example.ts: Implements parseGalleryExample, galleryPropertyControl, createDefaultGalleryValue, and describeUneditableValue to validate {components, data} drafts against the active catalog schema, infer control kinds (enum, boolean, number, string, array, object, json), and distinguish literal values from read-only data bindings/function calls.
    • shell/src/app/gallery/gallery-example.spec.ts: Tests schema control inference, default value generation, and draft validation edge cases.

3. Composer Workspace Handoff ("Open in Composer" button) & Unit Tests (2 file)

  • shell/src/app/gallery/gallery-launcher.ts: Introduces the GalleryLauncher service to compress the active gallery payload via QueryParser.encodeSharedPayload and navigate to the Composer workspace with #renderer, #rendererId, and #a2ui hash parameters.
    • shell/src/app/gallery/gallery-launcher.spec.ts: Tests URL generation and compressed payload handoff to the Composer workspace.

4. Monaco Editor Gallery Schema Mode & Unit Tests (2 file)

  • shell/src/app/shared/monaco-editor/monaco-editor.ts: Adds schemaMode ('layout' | 'gallery-example') and dynamic ariaLabel inputs to MonacoEditor, registering a2ui-gallery-example-schema (inmemory://model/gallery-draft-*.json) to validate {components, data} drafts against the active catalog's component schemas.
    • shell/src/app/shared/monaco-editor/monaco-editor.spec.ts: Verifies gallery-example schema registration, inmemory://model/gallery-draft-* URI prefixing, and dynamic ariaLabel updates.

5. Sample Catalog Usage Updates from v0.8 to v0.9 (3 files)

  • samples/lit-basic-catalog/src/usages.ts
  • samples/ng-basic-catalog/src/assets/usages.ts
  • samples/react-basic-catalog/src/usages.ts
    • Aligns sample component usage presets with current catalog schemas (e.g., migrating usageHint/primary/textFieldType to variant, ChoicePicker.selections to value, Slider.minValue/maxValue to min/max, Icon name 'check_circle' to 'check', and Button action context to an object).

6. Harness & E2E Coverage (3 files)

  • shell/src/app/gallery/test/gallery.harness.ts: Extends GalleryHarness with helper methods for editing draft JSON, interacting with typed/nested/array property controls, reading validation errors/notes, resetting drafts, and triggering Open in Composer.
  • shell/e2e/gallery.e2e.ts: Adds Playwright E2E user journeys covering interactive playground editing, validation error states, resetting examples, and opening drafts in Composer.
  • shell/e2e/helpers.ts: Updates waitForMonacoEditor to support both the Workspace Dockview tab and the Component Gallery's Edit JSON card. Prevents E2E timeouts when no Dockview tab is present by waiting on editorTab.or(editorLocator).

Pre-launch Checklist

If you need help, consider asking for advice on the discussion board.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an interactive playground to the Components Gallery, enabling users to edit component examples directly using either an 'Edit JSON' Monaco editor or an interactive 'Usage' property form. It updates component usage samples across Lit, Angular, and React catalogs to align with schema changes, adds a GalleryLauncher service to open drafts in the Composer, and implements comprehensive unit and E2E tests. The reviewer feedback identifies a potential runtime TypeError in matchesSimpleSchema when a sub-schema is a boolean, and suggests adding a defensive type guard to handle boolean schemas robustly.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

⚡ A2UI Composer PR Preview

Your automated preview is successfully live (commit fa58af3):
👉 Launch PR Preview

Note: This environment will be wiped automatically when the PR is merged or closed.

…e-assist suggestion

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Kelly Tu <[email protected]>
@jgindin

jgindin commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I kinda think the "Interactive Playground" collapsable group takes up extra space that would be better used to show the actual content. WDYT?

@jgindin

jgindin commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

To save more space, what do you think about putting the "Preview" and "Edit JSON" into tab components (like the default layout of the workspace page)?

@jgindin

jgindin commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

What if the property name was above the property editor? It would prevent squished editors and wrapping property names:
image

Comment thread shell/src/app/gallery/gallery.ts Outdated
});

/** Memoized schema resolver and shared property names, computed once per active catalog. */
private readonly activeCatalogResolver = computed(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our code is a bit hit-and-miss on this, but I find adding the type on fields where it's not immediately obvious is really helpful for reading the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Added the type for some of the functions

Comment thread shell/src/app/gallery/gallery.ts Outdated
});

/**
* linkedSignal owns the local draft without propagating component state through effects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"linkedSignal owns ..." this was confusing to me, since I know linkedSignal can't be a class field name.

Especially since there are multiple fields of type linkedSignal, I'd suggest specifying the name of the field "that owns..." instead of the type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the comments those functions

Comment thread shell/src/app/gallery/gallery.ts Outdated
return new Set([...first].filter(prop => rest.every(set => set.has(prop))));
}

/** Property Editor form reads and writes to. Prioritize 'target'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Start the comment with the /** on its own line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Fixed for other files too

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to undo anything you've done, but our TS style says that if the comment fits on a single line, then using /** the comment */ is fine. Using something like:

/** here
 * is the comment
 */

is what's not right.

Comment thread shell/src/app/gallery/gallery.ts Outdated
);
}

protected describeUneditable(value: unknown, control: GalleryPropertyControl): string | null {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method just calls the describeUneditableValue without doing anything else, can we remove this and update callers to just use the describeUneditableValue method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the function is used in gallery.ng.html for checking whether nested objects/array properties are uneditable, it needs to be in gallery.ts so that gallery.ng.html can use it. So instead of having the wrapper, we can expose the function as a protected readonly field

}

protected asArray(value: unknown): unknown[] {
return Array.isArray(value) ? value : [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? I would have expected:

return Array.isArray(value)  ? value : [value];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the function is used to help render the items of an array property. So if a component that has an optional array property that isn't set in the sample yet, it should have an empty array (e.g. without it, Button's checks property would have an entry when it's not supposed to cause its not set in the samples). I changed the name asArray to ensureArray so its not confusing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest leaving a comment in the code to explain this for future readers.

Comment thread shell/src/app/gallery/gallery.ts Outdated
}

protected formatJsonValue(value: unknown): string {
return value === undefined ? '' : formatJson(value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just update the formatJson function to handle an undefined input?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I changed formatJson so it handles undefined inputs and added the test for it.

Similar to describeUneditable, formatJson as needs to be exposed as protected readonly field to be used in gallery.ng.html

return null;
}
if (
control.kind !== 'enum' &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above, we have more specialized checks (e.g., if control.kind === 'array' *and* Array.isArray`.

But, both here and there, we're just going to return null, so it seems like this check is sufficient?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is meant for the remaining editable controls types, which are the primitive types. i updated it so its more clear that its checking for primitive types (string/boolean/number)

@ktu22

ktu22 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Updates

  • Addressed comments from Jay
  • Updated the interactive playground UI & test cases for it
    • Removed toggle ability of interactive playground
    • Added back tabbed view of Preview and Edit Json
    • Property names are now on top of their property UI editor
    • Usage section with property UI editors are now on left hand side

Comment thread shell/src/app/gallery/gallery.ts Outdated
control: GalleryPropertyControl;
kind: GalleryPropertyControl['kind'];
options: GalleryPropertyControl['options'];
// The current value, or undefined when the example omits the property.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use JSDoc for commenting class or interface members.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

/**
* Memoized schema resolver and shared property names, computed once per active catalog.
*/
private readonly activeCatalogResolver: Signal<{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the return type is going to be used more than once (I'm not sure in the cases here and below), I'd suggest creating an interface for more clarity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged, activeCatalogResolver and draftSource return types are only used once but will add interfaces for next time!

}

protected asArray(value: unknown): unknown[] {
return Array.isArray(value) ? value : [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest leaving a comment in the code to explain this for future readers.

Comment thread shell/src/app/gallery/gallery.ts Outdated
return new Set([...first].filter(prop => rest.every(set => set.has(prop))));
}

/** Property Editor form reads and writes to. Prioritize 'target'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to undo anything you've done, but our TS style says that if the comment fits on a single line, then using /** the comment */ is fine. Using something like:

/** here
 * is the comment
 */

is what's not right.

private readonly location = inject(Location);

/**
* Snapshots the selected example ands renderer before compressing the workspace handoff.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "...ands..." --> "...and..."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@ktu22
ktu22 force-pushed the feature/gallery-updates branch from d1715be to fa58af3 Compare October 20, 2026 22:19
@ktu22
ktu22 merged commit 461845f into a2ui-project:main Oct 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants