mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 05:10:32 +00:00
📚 Organize frontend UI memories by task
Separate CLJS components, styles, the shared UI package, and the text editor so each guide has a direct entry point and current build details. AI-assisted-by: gpt-6.1-terra
This commit is contained in:
parent
7082d7bd61
commit
ef62f21bed
@ -4,8 +4,8 @@ Start at `app.main.ui` for Rumext components, `app.main.data` for Potok events,
|
||||
|
||||
## UI and integration
|
||||
|
||||
- CLJS components, Design System, SCSS modules, accessibility and render cost: `mem:frontend/ui-conventions-and-style-system`.
|
||||
- JS/TS packages, shared React UI, Storybook and text editor boundaries: `mem:frontend/ui-packages-text-editor-workflow`.
|
||||
- CLJS app components, accessibility and Design System: `mem:frontend/ui-cljs`. SCSS modules and Design System tokens: `mem:frontend/ui-styles`.
|
||||
- Shared `frontend/packages/ui` React library and Storybook: `mem:frontend/ui-package`. JS text editor and render-wasm artifacts: `mem:frontend/text-editor`.
|
||||
- PO files and locale conventions: `mem:frontend/translations`.
|
||||
- JS Plugin API bindings and proxies: `mem:frontend/plugin-api-to-cljs-binding`; plugin save waits and rollback events: `mem:frontend/plugin-save-events`. External SaaS hooks and script load order: `mem:frontend/host-integration`.
|
||||
|
||||
|
||||
6
.serena/memories/frontend/text-editor.md
Normal file
6
.serena/memories/frontend/text-editor.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Frontend text editor
|
||||
|
||||
- `frontend/text-editor` is the JS/Vite `@penpot/text-editor` package, with its own Vitest and browser-test setup. Its entry point is `src/editor/TextEditor.js`; shared text data rules are in `mem:common/text-subtleties`.
|
||||
- It copies render-wasm artifacts from `frontend/resources/public/js` to `src/wasm`. After rebuilding render-wasm, run `pnpm run wasm:update` from `frontend/text-editor` when local development or tests need updated artifacts.
|
||||
- From `frontend/text-editor`, `pnpm run dev` starts Vite, `pnpm run test` runs tests, `pnpm run coverage` collects coverage, and `pnpm run test:watch:e2e` starts browser tests. `pnpm run fmt:js` checks formatting. Frontend root JS formatting also covers text-editor sources, but does not replace package tests.
|
||||
- Text behavior can cross this package, render-wasm and CLJS integration; verify the runtime that owns the changed behavior. For the separate shared UI package see `mem:frontend/ui-package`.
|
||||
9
.serena/memories/frontend/ui-cljs.md
Normal file
9
.serena/memories/frontend/ui-cljs.md
Normal file
@ -0,0 +1,9 @@
|
||||
# CLJS application UI
|
||||
|
||||
- Start at `frontend/src/app/main/ui` and `docs/technical-guide/developer/ui.md`. Rumext components normally use `mf/defc`, a `*` var suffix and `[:> component* props]`; private components use `::mf/private true`.
|
||||
- Keep component ownership clear: use children for normal composition and slots for separately owned regions. Do not style or restructure child DOM the component does not own. When callers need layout customization, merge a `class` prop with `mf/spread-props` so Rumext transforms it to `className`.
|
||||
- Avoid boolean prop names ending in `?` at the JS boundary; use `^boolean` where JS semantics matter. Dynamic inline `:style` values on native elements must be JS objects: a CLJS map passed at runtime reaches React unconverted, even though static literals can be converted by the macro.
|
||||
- Resolve translations during render or render-time memoization so locale changes update labels; catalog and asset rules are in `mem:frontend/translations`.
|
||||
- Use semantic HTML and appropriate ARIA patterns. Give icon-only controls accessible names and hide decorative images from assistive technology.
|
||||
- Memoize expensive derived collections in hot render paths. `d/xf:add-index` attaches `:app.common.data/index` and requires associative items; it cannot index plain IDs or keywords. Avoid unnecessary callback and object allocation in hot renders.
|
||||
- CLJS Design System components live in `frontend/src/app/main/ui/ds`: follow the UI guide for implementation, CSS module, Storybook story and export from `ds.cljs`. For SCSS and Design System tokens see `mem:frontend/ui-styles`; for the separate React package see `mem:frontend/ui-package`. For tests and compile diagnosis see `mem:frontend/testing` and `mem:frontend/compile-diagnostics`.
|
||||
@ -1,55 +0,0 @@
|
||||
# Frontend UI Conventions and Style System
|
||||
|
||||
## CLJS app UI
|
||||
|
||||
- Main app components live under `frontend/src/app/main/ui*` and normally use Rumext `mf/defc` with a `*` suffix for component vars and `[:> component* props]` call sites.
|
||||
- Components should have clear ownership. Use `children` for normal composition; use slotted props only when separate owned regions are needed. Do not style or structurally manipulate child DOM that the component did not instantiate.
|
||||
- Accept and merge a `class` prop when callers reasonably need layout/positioning customization. Use `mf/spread-props` so Rumext prop transformations such as `:class` -> `className` still apply.
|
||||
- Avoid boolean prop names ending in `?`; they do not translate cleanly to JavaScript props. Use type hints such as `^boolean` where JS truthiness/semantics matter.
|
||||
- Split large components into smaller private components when useful; `::mf/private true` is the local convention for private Rumext components.
|
||||
|
||||
## Styling
|
||||
|
||||
- Co-located SCSS modules are preferred. Use `app.main.style/stl` helpers from CLJS and design-system SCSS tokens/mixins instead of legacy global selectors or high-specificity nesting.
|
||||
- Keep CSS specificity low. Avoid nested selectors unless they target elements the component owns; CSS Modules already prevent class-name collisions.
|
||||
- Prefer CSS logical properties for directional spacing/layout (`padding-inline-start`, etc.). Physical `width`/`height` are still acceptable where they are clearer. Never mix: a stylesheet logical property (`inline-size`) and an inline physical `width` on the same element cascade separately, and the logical mapping wins — a dynamically driven width must be `width` on both sides (import modal progress bar hit this). And an inline style passed from CLJS must be a JS object (`#js {:width …}`): for plain `[:div …]` elements the Rumext macro does not convert the `:style` map at runtime — a plain CLJS map reaches React raw and React never finds the keys (static style literals are converted at compile time, which is why `:style` maps seem to work elsewhere).
|
||||
- Use named design-system variables/tokens for spacing, borders, fixed dimensions, colors, and typography. Avoid hardcoded px/rem values and deprecated `resources/styles/common/refactor/spacing.scss` variables.
|
||||
- Use component-local CSS custom properties for variants and theming instead of one-off Sass variables when a component has multiple visual states.
|
||||
- Prefer DS typography components (`heading*`, `text*`) and typography mixins instead of plain text wrappers or deprecated typography mixins.
|
||||
|
||||
## Accessibility
|
||||
|
||||
- Prefer semantic HTML first: anchors for navigation/download/email links, buttons for actions, correct heading levels, and keyboard-focusable controls.
|
||||
- If native elements cannot be used, apply appropriate ARIA roles/patterns. Follow WAI-ARIA APG patterns for standard widgets.
|
||||
- Icon-only controls need an accessible name via surrounding text, `aria-label`, `alt`, or equivalent. Decorative images/icons should be hidden from assistive tech.
|
||||
|
||||
## I18n
|
||||
|
||||
- Translations must be resolved during render or render-time memoization, not at namespace load time. For static option lists, memoize inside render so locale changes still update labels.
|
||||
- For catalog edits, locale registration and generated translation assets see `mem:frontend/translations`.
|
||||
|
||||
## Performance
|
||||
|
||||
- Keep expensive derived data in refs, memoized selectors, or pure helpers. In hot render paths, prefer existing `app.common.data.macros` helpers where local code already uses them.
|
||||
- Derive index-aware or sorted/filtered sequences once: wrap the transformation in `mf/with-memo` keyed on the source collection instead of calling `d/enumerate` in the render body. Use the shared `d/xf:add-index`, which attaches `:app.common.data/index` to each item; the items must be associative (maps/records), so it does not work on keywords or plain ids.
|
||||
- Avoid creating new callback functions/objects inside hot renders when a named function, memoized callback, data attribute, or precomputed JS props object works.
|
||||
- Destructure props/state values used repeatedly. Avoid repeated deref/property access in render loops.
|
||||
|
||||
## Shared React UI package
|
||||
|
||||
- `frontend/packages/ui` is the shared React/Vite package. It should remain framework-neutral relative to the CLJS app store; reusable primitives belong here only when they do not depend on Potok/Rumext app state.
|
||||
- Package styles are emitted through the package build and copied into `frontend/resources/public/css/ui.css`; stale shared styles are often a build artifact issue.
|
||||
- Storybook is the primary visual harness for shared UI/package behavior. Use `mem:frontend/ui-packages-text-editor-workflow` for package build/test commands.
|
||||
|
||||
## Choosing a location
|
||||
|
||||
- Put editor/dashboard/viewer workflow logic in CLJS app namespaces close to the owning feature.
|
||||
- Put reusable presentational React primitives in `frontend/packages/ui` when they can be consumed without Penpot app state.
|
||||
- Put CLJS design-system components under `frontend/src/app/main/ui/ds`; new DS components need implementation, CSS module, Storybook story, optional MDX docs, and export from `frontend/src/app/main/ui/ds.cljs` with a JavaScript-friendly name.
|
||||
- Put text editing internals in `frontend/text-editor` when the behavior belongs to the JS editor package; use `mem:common/text-subtleties` for shared text data-model behavior.
|
||||
|
||||
## Validation
|
||||
|
||||
- For CLJS app UI, use `mem:frontend/testing`, `mem:frontend/compile-diagnostics`, and live browser/REPL checks when behavior depends on store or canvas state.
|
||||
- For shared UI package changes, run the package build plus Storybook/component tests when relevant.
|
||||
- For text editor changes, run `frontend/text-editor` tests and refresh/copy WASM artifacts if render-wasm output is involved.
|
||||
6
.serena/memories/frontend/ui-package.md
Normal file
6
.serena/memories/frontend/ui-package.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Shared UI package
|
||||
|
||||
- `frontend/packages/ui` builds `@penpot/ui`, a React/Vite library separate from the CLJS Design System. Keep reusable primitives independent of the Penpot app store. React and ReactDOM are peers and must remain external to the library build.
|
||||
- The Vite build emits ESM and type declarations and copies `dist/ui.css` to `frontend/resources/public/css/ui.css`. If shared styles are stale, check the package build and copy before debugging CLJS.
|
||||
- From `frontend/packages/ui`, use `pnpm run build`, `pnpm run watch` or `pnpm run test`. From `frontend/`, `pnpm run build:app:libs` builds app-side packages; `pnpm run build:storybook`, `watch:storybook` and `test:storybook` cover Storybook. Validate changed exports in both the package and consuming app or Storybook.
|
||||
- Other packages under `frontend/packages/` are workspace dependencies and need not implement behavior in CLJS. App components and the CLJS Design System are described in `mem:frontend/ui-cljs`; text editing is `mem:frontend/text-editor`.
|
||||
@ -1,34 +0,0 @@
|
||||
# Frontend UI Packages and Text Editor Workflow
|
||||
|
||||
`frontend/packages/`, `frontend/text-editor/`, Storybook/component tests. Separate from CLJS app UI under `frontend/src/app/main/ui`.
|
||||
|
||||
## Package boundaries
|
||||
|
||||
- `frontend/packages/ui` builds `@penpot/ui`, a React/Vite library package. It exports ESM and type declarations from `dist/`; React and ReactDOM are peer dependencies and must stay external in the Vite library build.
|
||||
- The UI package build copies generated `dist/index.css` into `frontend/resources/public/css/ui.css`. If shared UI styles look stale in the app, rebuild the package or check this copy step before debugging CLJS style code.
|
||||
- `frontend/text-editor` builds `@penpot/text-editor` from `src/editor/TextEditor.js`. It is a Vite JS package, not CLJS, and has its own Vitest/browser-test setup.
|
||||
- The text editor consumes render-wasm artifacts copied from `frontend/resources/public/js` into `frontend/text-editor/src/wasm`. Use `pnpm run wasm:update` after rebuilding `render-wasm` if tests or local dev use stale WASM files.
|
||||
- Other packages under `frontend/packages/` such as `tokenscript`, `draft-js`, and `mousetrap` are workspace dependencies used by the frontend app; do not assume their runtime behavior lives in CLJS namespaces.
|
||||
|
||||
## Commands
|
||||
|
||||
From `frontend/`:
|
||||
- Build app-side JS package assets: `pnpm run build:app:libs`.
|
||||
- Watch app-side JS package assets: `pnpm run watch:app:libs`.
|
||||
- Storybook build: `pnpm run build:storybook`; local Storybook: `pnpm run watch:storybook`.
|
||||
- Storybook/component tests: `pnpm run test:storybook`.
|
||||
|
||||
From `frontend/packages/ui`:
|
||||
- Build library and CSS artifact: `pnpm run build`.
|
||||
- Watch library build: `pnpm run watch`.
|
||||
|
||||
From `frontend/text-editor`:
|
||||
- Local Vite dev: `pnpm run dev`.
|
||||
- Tests: `pnpm run test`; coverage: `pnpm run coverage`; browser watch: `pnpm run test:watch:e2e`.
|
||||
- Format check: `pnpm run fmt:js`.
|
||||
|
||||
## Validation notes
|
||||
|
||||
- Frontend root `check-fmt:js` covers stories, Playwright scripts, frontend scripts, and `text-editor/**/*.js`; it does not replace package-specific builds/tests.
|
||||
- Changes to shared UI package exports should be validated both in the package build and in the consuming app/Storybook path.
|
||||
- Changes that alter text rendering/editing can involve `frontend/text-editor`, `render-wasm`, CLJS text integration, and `mem:common/text-subtleties`; verify the runtime that actually owns the changed behavior.
|
||||
6
.serena/memories/frontend/ui-styles.md
Normal file
6
.serena/memories/frontend/ui-styles.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Frontend UI styles
|
||||
|
||||
- Start with `docs/technical-guide/developer/ui.md` and the owning component. Prefer co-located SCSS modules, `app.main.style/stl`, and Design System tokens and mixins over legacy global selectors or deprecated `resources/styles/common/refactor/spacing.scss`. Keep specificity low and style only DOM the component owns.
|
||||
- Use named tokens for colors, spacing, fixed sizes, borders and typography; prefer Design System typography components and mixins. Component-local CSS custom properties can express variants and theme states.
|
||||
- Prefer logical properties for directional layout, but avoid logical and physical declarations that compete for the same dimension. For a dynamically sized element keep the stylesheet and inline declaration consistent; the import progress bar illustrates the conflict. Dynamic inline styles on native CLJS UI elements must be JS objects; see `mem:frontend/ui-cljs`.
|
||||
- For package-generated CSS and a stale shared stylesheet see `mem:frontend/ui-package`. For text editor styles and runtime boundaries see `mem:frontend/text-editor`.
|
||||
Loading…
x
Reference in New Issue
Block a user