mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
📚 Organize token and schema guidance
Unify token model and workspace behavior, update activation semantics, and keep general schema coercion in a separate memory. AI-assisted-by: gpt-6.1-terra
This commit is contained in:
parent
381b784a0e
commit
2e736233e7
@ -15,17 +15,14 @@ Respect the intended abstraction direction in new/refactored code:
|
||||
|
||||
Some legacy code violates this layering; do not copy those violations into new code when a focused refactor is practical.
|
||||
|
||||
## Build-mode dependent laziness
|
||||
|
||||
`app.common.schema/check-fn` resolves schemas through `app.common.data.macros/lazy-delay`: an invalid schema can fail on namespace load in development and JVM tests, but at first use in production CLJS. See the macro docstring and each target's `:closure-defines` for the evaluation rules.
|
||||
|
||||
## Focused memory routing
|
||||
|
||||
- URL construction on either runtime: `mem:common/uri` for relative-path resolution and preserving a deployment subpath.
|
||||
|
||||
Model, schema, and persistence shape:
|
||||
- File/page/shape/component attr changes, import/export surfaces, inspector/codegen, and cross-module checklist: `mem:common/data-model-change-checklist`.
|
||||
- Token data structures, token import/export, active theme/set semantics, and schema/coercion behavior: `mem:common/tokens-schema-subtleties`.
|
||||
- Design token model, import/export and workspace application: `mem:common/tokens`.
|
||||
- Shared schema coercion, validators and build-mode resolution: `mem:common/schema`.
|
||||
- For organization and team permission rules shared across runtimes, start at `app.common.types.organization`.
|
||||
|
||||
Geometry and layout:
|
||||
|
||||
5
.serena/memories/common/schema.md
Normal file
5
.serena/memories/common/schema.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Common schema and coercion
|
||||
|
||||
- Start at `app.common.schema`. Its `json-transformer` supports key decoding and encoding for map-of schemas as well as value transformation. `coercer` decodes JSON-shaped input with that transformer and validates the result.
|
||||
- `check-fn` returns a reusable validator that raises `ex-info` with default `:type :assertion`, `:code :data-validation` and `::explain`. Prefer a reusable checker in repeated or hot paths; `sm/check` creates one on each call.
|
||||
- `check-fn` resolves its schema through `app.common.data.macros/lazy-delay`: an invalid schema can fail on namespace load in development and JVM tests, but on first use in production CLJS. See the macro docstring and target closure defines.
|
||||
@ -1,17 +0,0 @@
|
||||
# Common Tokens and Schema Subtleties
|
||||
|
||||
## Tokens
|
||||
|
||||
- `TokensLib` always ensures an internal hidden theme exists and defaults active themes to that hidden theme path. That hidden theme represents the UI state where active sets are controlled without modifying a user-created theme.
|
||||
- `get-tokens-in-active-sets` merges tokens from sets selected by active themes in set order, so later active sets with the same token name override earlier ones.
|
||||
- Activating a real theme in `common.logic.tokens` removes the hidden theme from the active-theme set unless it is the only active theme. Toggling active sets directly copies current active sets into the hidden theme.
|
||||
- DTCG import/export deliberately hides the internal hidden theme: exports omit it from `$themes` and activeThemes, while `activeSets` records the hidden/current active sets.
|
||||
- Single-set DTCG/legacy imports throw if no supported tokens are found. Multi-set import normalizes set names, keeps `tokenSetOrder`, rejects conflicting token path names, discards unsupported token types, and validates theme sets against existing sets.
|
||||
- Token values stored on shapes are token names in `:applied-tokens`, not token ids. Renames and group renames must update those name paths.
|
||||
- Token serialization has both Transit handlers for frontend/backend transport and Fressian handlers for internal file-data storage, with migrations for older token-lib internal versions.
|
||||
|
||||
## Schema
|
||||
|
||||
- `app.common.schema/json-transformer` has custom map-of key decoding/encoding, so map keys can be transformed based on the key schema instead of only the value schema.
|
||||
- `check-fn` throws `ex-info` with default `:type :assertion`, `:code :data-validation`, and `::explain`. Prefer reusable `check-fn`/lazy validators in hot or repeated paths; `sm/check` creates a checker every call.
|
||||
- `coercer` decodes with the JSON transformer and then checks. This is the common pattern for accepting external JSON-shaped data into internal types.
|
||||
13
.serena/memories/common/tokens.md
Normal file
13
.serena/memories/common/tokens.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Design tokens
|
||||
|
||||
- Start at `app.common.types.tokens-lib`, `app.common.types.tokens-status`, `app.common.files.tokens` and `app.main.data.workspace.tokens`. Current file activation is stored separately in `TokensStatus` as theme and set IDs. Legacy `TokensLib` activation and its hidden theme support import and migration; workspace theme lists hide that internal theme.
|
||||
- `get-tokens-in-active-sets` resolves the status's active set IDs in library order, so later active sets override earlier tokens with the same name. Activating a theme deactivates other themes in its group and recomputes active sets; directly changing a set clears active themes. When migrating legacy data, `make-tokens-status-from-lib` converts active paths and sets to IDs.
|
||||
- DTCG export omits the internal hidden theme; the status-aware path derives `activeThemes` and `activeSets` from `TokensStatus`, while the legacy overload derives them from the library. Single-set imports reject input with no supported tokens. Multi-set imports normalize names, omit unsupported token types and ignore theme references to missing sets; `import-decoded-json` reports dropped or unknown input.
|
||||
- Shapes store token names in `:applied-tokens`, not IDs. Token and group renames must update those paths. Transport uses Transit handlers; internal file-data storage uses Fressian handlers and migrations for older token-lib versions.
|
||||
|
||||
## Workspace application and propagation
|
||||
|
||||
- Applying a token is blocked while a text shape is being edited. Otherwise the workspace records its name, resolves active tokens through Style Dictionary or tokenscript according to feature flags, updates concrete attrs and groups the operation in an undo transaction.
|
||||
- Composite and atomic typography token attrs replace one another. Spacing application targets gap/padding on layout containers and margins on immediate layout children.
|
||||
- Propagation resolves active tokens and buffers `update-shapes` commits, processing the current page before other pages. It clears affected frame/component thumbnails and drops text `:position-data` on non-current pages so it can be regenerated.
|
||||
- For workspace state and undo see `mem:frontend/workspace-store` and `mem:frontend/workspace-commits`; for geometry and text data see `mem:common/geometry` and `mem:common/text-subtleties`.
|
||||
@ -15,7 +15,7 @@ Start at `app.main.ui` for Rumext components, `app.main.data` for Potok events,
|
||||
- Local and remote commits, rebase, and undo: `mem:frontend/workspace-commits`.
|
||||
- Save queue, rejected edits, retries, and recovery: `mem:frontend/workspace-state-persistence-subtleties`.
|
||||
- Modifier previews, transform commits, and WASM bridge: `mem:frontend/workspace-transforms`.
|
||||
- Token application and propagation: `mem:frontend/workspace-token-subtleties`; token model: `mem:common/tokens-schema-subtleties`.
|
||||
- Design token model, workspace application and propagation: `mem:common/tokens`.
|
||||
|
||||
## App shell
|
||||
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
# Frontend Workspace Token Subtleties
|
||||
|
||||
## Token refs and visibility
|
||||
|
||||
- Workspace token refs intentionally hide the internal hidden theme from theme trees/lists and expose active tokens through `get-tokens-in-active-sets`.
|
||||
- Token values stored on shapes are token names under `:applied-tokens`, not token ids. Renames/group renames must update those paths in common token logic.
|
||||
|
||||
## Token application
|
||||
|
||||
- Token application refuses to run while a text shape is in text-editing mode and shows a warning instead.
|
||||
- Applying a token writes token names into shape `:applied-tokens`, resolves active tokens through Style Dictionary or `tokenscript` depending on feature flags, updates concrete shape attrs, and wraps the operation in an undo transaction.
|
||||
- Applying composite typography removes atomic typography token attrs; applying atomic typography removes the composite typography token attr.
|
||||
- Spacing tokens have a special split path: layout containers receive gap/padding updates, while immediate children of layouts receive margin updates.
|
||||
|
||||
## Propagation
|
||||
|
||||
- Token propagation resolves active tokens, buffers many `update-shapes` commits, walks the current page first then the remaining pages, clears affected frame/component thumbnails, and drops `:position-data` for text shapes on non-current pages so it can be regenerated.
|
||||
Loading…
x
Reference in New Issue
Block a user