Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .agents/rules/mendix-widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Mendix Widget Development Rules

## API Guards

- ALWAYS check `actionValue.canExecute` before calling `execute()`
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.

We have a utility function that does this, maybe we could refer that too.

- NEVER render widget content while value status is `"loading"` — show loading/placeholder state instead
- Use `editableValue.setValue()` for two-way binding, never mutate the value directly
- Handle all three `EditableValue` states: `"available"`, `"loading"`, `"unavailable"`

## XML ↔ TypeScript

- XML property keys MUST be lowerCamelCase and MUST match TypeScript prop names exactly
- When adding an XML property: update `<Widget>.xml`, rebuild to regenerate `typings/<Widget>Props.d.ts`, update `editorConfig.ts`, and `editorPreview.tsx`
- Each widget MUST have a unique widget ID in `package.xml` — never duplicate across widgets

## Versioning

- Any change to runtime behavior, XML schema, or public API REQUIRES:
- Semver bump in `package.json`
- CHANGELOG.md entry (Keep a Changelog format)
- Run `pnpm -w changelog` or update manually
- Refactor, test, or docs-only changes: no bump required

## Styling

- SCSS only — no inline styles for static design
- Prefer Atlas UI classes (`btn`, `btn-primary`, `badge`, etc.) for common elements
- Custom classes MUST use the widget-name prefix: `.widget-<name>-<element>`
- NEVER override core Atlas UI classes — wrap in a widget-specific selector if custom styling is needed

## Testing

- Run tests from the widget package dir: `cd packages/pluggableWidgets/<name>-web && pnpm test`
- Use `@mendix/widget-plugin-test-utils` builders for mocking Mendix API values:
```ts
import { dynamicValue, EditableValueBuilder } from "@mendix/widget-plugin-test-utils";
const mockAttr = new EditableValueBuilder<string>().withValue("test").build();
```
- New features require unit tests; bug fixes require regression tests
- User-visible behavior changes require E2E updates in `e2e/*.spec.js`
- E2E tests MUST include `test.afterEach` session logout to avoid Mendix license limit issues

## Constraints

- Never modify `dist/`, generated typings, or `pnpm-lock.yaml`
- No tree-shaking-hostile imports — use named imports for large dependencies
- No core Atlas class overrides
- `dangerouslySetInnerHTML` is forbidden unless the content is explicitly sanitized
58 changes: 58 additions & 0 deletions .agents/rules/react-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# React & MobX Patterns for Mendix Widgets

## Hooks

- `useEffect` deps array MUST include all referenced variables — no stale closures
- Async effects MUST guard against state updates after unmount:
```ts
useEffect(() => {
let active = true;
(async () => {
const data = await load();
if (active) setData(data);
})();
return () => {
active = false;
};
}, [load]);
```
- No side effects in render — use `useEffect` for side effects
- Cleanup subscriptions, timers, and event listeners on unmount

## State

- Use functional updates when reading previous state: `setCount(c => c + 1)`
- Do NOT store computed values in `useState` if they can be derived from props
- Source of truth priority: Mendix props → MobX store → React state
- Controlled vs. uncontrolled inputs: never mix `value` and `defaultValue` on the same element

## Keys & Lists

- Stable, unique `key` props on all list items — NEVER use array index for dynamic lists
- For large lists, consider virtualization

## MobX

- Stores: use `makeAutoObservable(this)` or explicit `makeObservable(this, { ... })` in the constructor
- State mutations: inside `action` or `runInAction` — never mutate observables outside an action
- Derived values: `computed` — no side effects allowed inside computed properties
- React integration: `observer()` HOC from `mobx-react-lite` + `useSubscribe()` from `@mendix/widget-plugin-mobx-kit`
- Use `reaction()` for side effects triggered by state changes, not `autorun()` in most cases

## Performance

- `useMemo`/`useCallback` only where re-render cost is measurable — incorrect deps are worse than no memoization
- Avoid creating new objects/arrays/functions inline in JSX props passed to child components (new reference on every render forces child re-render)

## Accessibility

- Semantic HTML first — ARIA only when native elements don't convey the right semantics
- WCAG 2.2 AA: 4.5:1 contrast for normal text, 3:1 for large text and UI elements
- Keyboard navigation: Arrow keys (menus/lists), Enter/Space (activation), Escape (dismiss), Tab (focus order)
- Use Floating UI accessibility hooks for floating elements: `useRole`, `useDismiss`, `useListNavigation`, `FloatingFocusManager`
- `dangerouslySetInnerHTML`: never — if unavoidable, sanitize with a trusted library

## Props

- Do NOT spread unknown props onto DOM nodes — filter non-HTML attributes before spreading
- Prefer composition over prop drilling; use React Context for cross-tree state when prop chains exceed 2-3 levels
21 changes: 14 additions & 7 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ Use this guide to review both code and workflow. Focus on Mendix pluggable widge
- If refactor/docs/tests-only: bump not required (ask author to confirm).
- Multiple changed packages: each needs its own bump and changelog entry.

### OpenSpec change proposals

- If the PR introduces a new feature, behavior change, or XML property change in a widget that has `openspec/` initialized:
- Check if `openspec/changes/<change-name>/` exists with a `proposal.md`.
- If no proposal exists: "No OpenSpec proposal found. For behavior/XML changes, consider `/opsx:propose` to document intent. This is optional for small changes."
- If a proposal **does** exist, verify:
- `proposal.md` clearly states the why and lists XML property impact.
- Delta specs in `specs/` use Given/When/Then scenarios and cover loading/empty/error states.
- `tasks.md` has a **Versioning** group with CHANGELOG and semver tasks.
- Generally ignore `openspec/changes/archive/` — that's completed history.

## Code quality – Mendix pluggable widgets and React

### Mendix-specific
Expand All @@ -48,7 +59,6 @@ Use this guide to review both code and workflow. Focus on Mendix pluggable widge
### React code-logic best practices

- **Hooks and effects**

- Correct `useEffect`/`useMemo`/`useCallback` dependencies; avoid stale closures.
- No side effects in render. Cleanup subscriptions/timers on unmount.
- Guard async effects to avoid setting state after unmount:
Expand All @@ -67,7 +77,6 @@ Use this guide to review both code and workflow. Focus on Mendix pluggable widge
- Avoid deriving state directly from props unless necessary; prefer computing from props or synchronize carefully (watch for loops).

- **State management**

- Use functional updates when reading previous state:
```ts
setCount(c => c + 1);
Expand All @@ -76,27 +85,22 @@ Use this guide to review both code and workflow. Focus on Mendix pluggable widge
- **MobX stores** for complex cross-component state; **React state** for simple UI state; **Mendix props** as source of truth for persistent data.

- **Rendering and lists**

- Use stable, unique `key`s (avoid array index unless list is static).
- Avoid heavy computations in render; memoize when there's proven benefit.
- For large lists/tables, consider virtualization.

- **Performance hygiene**

- Limit `useCallback`/`useMemo` to cases with measurable re-render cost; ensure dependency arrays are correct.
- Avoid creating new objects/arrays/styles inline when passed to children repeatedly; memoize where needed.

- **Composition and props**

- Prefer composition over prop drilling; consider Context when appropriate.
- Don't spread unknown props onto DOM nodes (avoid React unknown prop warnings). Validate/filter props before spreading.

- **Accessibility**

- Semantic elements, proper ARIA, focus management, and keyboard navigation.

- **Error handling and robustness**

- Handle null/undefined from Mendix props; safe optional chaining; avoid non-null assertions unless justified.
- Guard external data parsing; provide graceful fallbacks.
- Avoid `dangerouslySetInnerHTML`; if unavoidable, sanitize input.
Expand Down Expand Up @@ -320,6 +324,9 @@ This repository uses a comprehensive three-tier testing strategy:
- E2E (dev): `pnpm e2edev` (with GUI debugger)
- E2E (CI): `pnpm e2e` (headless)
- Prepare changelog/version (workspace): `pnpm -w changelog`, `pnpm -w version`
- OpenSpec propose (in widget dir): `/opsx:propose "<change-name>"`
- OpenSpec apply: `/opsx:apply`
- OpenSpec archive: `/opsx:archive`

## Tone and format for comments

Expand Down
37 changes: 37 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ Reference (consult on demand for specific tasks):
- docs/requirements/implementation-plan.md — New widget guide + PR template
- docs/requirements/widget-to-module.md — Widget-to-module conversion guide

## OpenSpec Workflow

We use [OpenSpec](https://github.com/Fission-AI/OpenSpec) for spec-driven development. Install globally: `npm install -g @fission-ai/openspec@latest`.

**When to use:** Before implementing new widget features, behavior changes, or XML property changes. Not required for bug fixes, refactors, or test-only changes.

**Per-widget structure (opt-in):** Each widget that has been initialized has:
```
packages/pluggableWidgets/<name>-web/
└── openspec/
├── specs/spec.md ← current behavior spec (source of truth)
├── changes/ ← active change proposals
└── config.yaml ← widget-specific context
```

**Starting a change:**
```
cd packages/pluggableWidgets/<widget>-web
/opsx:propose "<what-you-want-to-build>"
```
This creates `openspec/changes/<change-name>/` with `proposal.md`, `specs/`, `design.md`, `tasks.md`.

**The workflow:** `/opsx:propose` → `/opsx:apply` → `/opsx:archive`

**Schema:** `mendix-widget` (default in `openspec/config.yaml`). Provides Mendix-aware templates with XML impact tracking, Mendix API guidance, and versioning tasks.

**Monorepo conventions spec:** `openspec/specs/conventions/spec.md` — source of truth for shared widget development requirements.

**Initializing a new widget:**
```
cd packages/pluggableWidgets/<new-widget>-web
openspec init
# Then edit openspec/config.yaml with widget-specific context
```

**Agent rules:** `.agents/rules/mendix-widget.md` and `.agents/rules/react-patterns.md` contain concise, tool-agnostic coding rules for this repo.

## Agent-Specific Instructions

- **Claude Code** — See `CLAUDE.md` for hooks and auto-imported documentation
Expand Down
10 changes: 10 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@
@docs/requirements/app-flow.md
@docs/requirements/backend-structure.md
@docs/requirements/project-requirements-document.md
@openspec/specs/conventions/spec.md
@openspec/schemas/mendix-widget/schema.yaml

## OpenSpec

Per-widget `openspec/` directories exist inside widget packages that have been initialized
(e.g., `packages/pluggableWidgets/datagrid-web/openspec/`). When working inside a widget
directory, check for `openspec/specs/spec.md` as the source of truth for current behavior,
and `openspec/changes/` for any active change proposals. Use `/opsx:propose` before
implementing non-trivial behavior changes.
98 changes: 98 additions & 0 deletions openspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# OpenSpec in This Repository

Spec-driven development for Mendix pluggable widgets. We use
[OpenSpec](https://github.com/Fission-AI/OpenSpec) to align on what to build
before any code is written.

## Quick Start

```bash
# Install the CLI (one-time)
npm install -g @fission-ai/openspec@latest

# Navigate to a widget you want to change
cd packages/pluggableWidgets/<widget-name>-web

# Propose a change
/opsx:propose "<what-you-want-to-build>"

# Implement the generated tasks
/opsx:apply

# Archive when done (merges delta specs into source of truth)
/opsx:archive
```

## Structure
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably not final structure, so I would avoid this section for now.


```
openspec/ # Monorepo-level
├── specs/
│ └── conventions/spec.md # Shared widget dev conventions (source of truth)
├── schemas/
│ └── mendix-widget/ # Custom schema for widget development
│ ├── schema.yaml # Artifact definitions + instructions
│ └── templates/ # AI generation templates
│ ├── proposal.md
│ ├── spec.md
│ ├── design.md
│ └── tasks.md
└── config.yaml # Monorepo context + default schema

packages/pluggableWidgets/<name>-web/ # Per-widget (opt-in)
└── openspec/
├── specs/spec.md # Widget behavior source of truth
├── changes/ # Active proposals (one folder per change)
│ └── <change-name>/
│ ├── proposal.md
│ ├── specs/spec.md # Delta spec (ADDED/MODIFIED/REMOVED)
│ ├── design.md
│ └── tasks.md
└── config.yaml # Widget-specific context

.agents/rules/ # Tool-agnostic coding rules
├── mendix-widget.md # Mendix API guards, versioning, styling
└── react-patterns.md # React hooks, MobX, accessibility
```

## Pilot Widgets

These widgets have OpenSpec initialized and baseline specs:

| Widget | Spec | Status |
| -------------- | ------------------------------------------------------------------------------------------ | -------- |
| `datagrid-web` | [openspec/specs/spec.md](../packages/pluggableWidgets/datagrid-web/openspec/specs/spec.md) | baseline |
| `combobox-web` | [openspec/specs/spec.md](../packages/pluggableWidgets/combobox-web/openspec/specs/spec.md) | baseline |
| `gallery-web` | [openspec/specs/spec.md](../packages/pluggableWidgets/gallery-web/openspec/specs/spec.md) | baseline |

## Initializing a New Widget

```bash
cd packages/pluggableWidgets/<widget>-web
openspec init
```

Then edit `openspec/config.yaml` to add widget-specific context (architecture,
key XML properties, data dependencies). Use the pilot widgets as reference.

## When to Use OpenSpec

| Situation | Use OpenSpec? |
| ----------------------------------- | --------------------------- |
| New feature or behavior change | Yes — `/opsx:propose` first |
| XML property added/modified/removed | Yes — `/opsx:propose` first |
| Bug fix | No |
| Refactor (no behavior change) | No |
| Test-only change | No |
| Docs update | No |

## The `mendix-widget` Schema

The custom schema (`openspec/schemas/mendix-widget/`) generates four artifacts:

1. **`proposal.md`** — Intent, Mendix XML impact, scope, release checklist
2. **`specs/<domain>/spec.md`** — Delta specs (ADDED/MODIFIED/REMOVED) in Given/When/Then
3. **`design.md`** — Mendix API usage, component hierarchy, file changes
4. **`tasks.md`** — Grouped checklist: XML/Types → Implementation → Tests → Versioning

Dependency order: `proposal → specs + design → tasks → implement`
Loading
Loading