Skip to content

feat(@formatjs/editor): add scoped exact search and source copy controls - #7424

Merged
longlho merged 1 commit into
formatjs:mainfrom
pgonsolin:psi/editor-search-and-copy-controls
Sep 15, 2026
Merged

longlho merged 1 commit into
formatjs:mainfrom
pgonsolin:psi/editor-search-and-copy-controls

Conversation

@pgonsolin

Copy link
Copy Markdown
Contributor

Why

Localization editors need predictable full-catalog search controls and unambiguous copy actions without each host reimplementing those behaviors. Multi-word description queries should match all terms in one description regardless of order, while exact text search should distinguish Open from Open window and respect whether the user selected source text, translations, or both.

This is the reusable editor portion of the next AGI localization-editor iteration. Product-specific fetching, locale selection, and design-system presentation remain in the host application.

What changed

  • Adds pure, case-insensitive search matchers for source/translation scope and partial/exact modes. Partial source+translation remains the default.
  • Splits description queries on whitespace and requires every term in the same description. General and description filters remain conjunctive.
  • Keeps generated IDs discoverable in exact mode through complete-ID or long (8+ character) ID-fragment lookup, without allowing short text such as Open to match an unrelated ID. Optional metadata is partial in partial mode and whole-value in exact mode.
  • Extends headless editor state with controlled mode/scope and resets workflow pagination when either changes.
  • Adds an adaptable search-controls UI contract with an unstyled native implementation.
  • Adds distinct opt-in source and description copy controls to SourceMessage / TranslationEditorView. Each copies its exact raw value; absent descriptions render no description action.
  • Documents server-backed selected-locale behavior and all defaults.

Verification

  • //packages/editor:unit_test: 57 tests pass, including token order/all-term behavior, partial versus exact matching, all scopes, ID lookup, pagination resets, controlled UI callbacks, and exact multiline source/description clipboard payloads.
  • //packages/editor:typecheck, :unit_test_typecheck, and :pkg build successfully.
  • Gazelle and Oxfmt were run on the changed package and documentation.

The new controls are adapter-driven and disabled by default, so existing consumers have no visual change until they opt in.

@pgonsolin
pgonsolin force-pushed the psi/editor-search-and-copy-controls branch from 02bbeab to a25efda Compare September 15, 2026 21:08
@pgonsolin
pgonsolin marked this pull request as ready for review September 15, 2026 22:04
@longlho
longlho merged commit e9b8976 into formatjs:main Sep 15, 2026
16 of 18 checks passed
longlho added a commit that referenced this pull request Oct 27, 2026
… editors (#7706)

## Motivation

A consumer can run several independent translation workspaces (for
example a web app and two mobile apps) in one editor deployment, and
each workspace receives messages from several upload streams (for
example a main branch and a release branch). Today `@formatjs/editor`
models a single message set with optional per-message `catalogs` and a
`catalog` filter, and location links have to be built by every consumer
through `renderLocation`. This PR adds:

1. A **project model** so the shell can list and switch workspaces while
the consumer loads that project's messages, locales, and save handler.
2. **Per-message source membership**, distinct from catalogs, with a
composable filter, a context row, and row badges.
3. Enough **location metadata** plus exported helpers to build source
links without consumer-side hardcoding. Default rendering stays plain
text.

Follows the conventions of #7403 and #7424: flat files under
`packages/editor`, tests next to code, exports through `index.ts` /
`ui.tsx`, CHANGELOG left to the release tooling, no consumer-specific
naming.

## API additions

| Area | Addition | Notes |
| --- | --- | --- |
| `workflow.ts` | `EditorProject {id, label, description?}` | New type |
| `workflow.ts` | `TranslationEditorOptions.projects?`, `project?`
(controlled), `defaultProject?`, `onProjectChange?` | All optional; the
hook never loads data |
| `workflow.ts` | `TranslationEditorState.projects`, `project`,
`setProject(id, {discardDrafts?})` | Returns `ProjectChangeResult`:
`changed` / `unchanged` / `blocked` (`unsaved-drafts` or
`unknown-project`). Resets page, selection, and catalog/source filters |
| `workflow.ts` | `ProjectChangeResult`, `ProjectChangeOptions` | New
types |
| `workflow.ts` | `EditorMessage.sources?: readonly string[]` | Upload
streams, distinct from `catalogs` |
| `workflow.ts` | `TranslationEditorState.sources`, `source`,
`setSource` | Empty-string "all" sentinel, same as `catalog`; composes
with status, catalog, and search |
| `source-location.ts` | `SourceLocation.source?`, `repository?`,
`revision?` | `SourceLocation` is still exported from `workflow.ts` |
| `source-location.ts` | `formatSourceLocation(location)` | The `file`,
`file:start`, `file:start–end` text `MessageContext` already used |
| `source-location.ts` | `resolveSourceLocationHref(location, {baseUrl?,
repository?, revision?, lineFragment?})`, `SourceLocationHrefOptions` |
`baseUrl` is a string with optional `{repository}` / `{revision}`
placeholders or a function; returns `undefined` without a base or a
placeholder value |
| `core.tsx` | `EditorState.clearSelection()` | Lets workflows drop an
explicit selection |
| `message-context.tsx` | "Sources" row, `copySources`, labels `sources`
/ `sourceCopy` | Hidden when the message has no sources |
| `design-system.tsx` | `ProjectPicker`, `SourceFilter`, `SourceBadge`
adapters and their props types | Optional additions to
`EditorToolComponents`; native `<select>` / `<select>` / `<span>`
implementations |
| `ui.tsx` | `TranslationEditorViewProps.projects?`, `sourceFilter?`;
`EditorProjectSelection`, `EditorSourceSelection` | Picker renders when
more than one project exists, filter when any source exists |
| `ui.tsx` | `EditorMessageRenderState.sources`,
`EditorViewMessage.sources?` | Default rows render `SourceBadge`s;
custom `renderMessage` receives `state.sources` |
| `ui.tsx` | Labels `project`, `sources`, `sourceFilter`, `allSources`,
`sourceBadge(source)` | Overridable through `labels` |

The spec called for `ProjectPicker` and `SourceBadge`; a third
`SourceFilter` adapter was added so the composed view can render the
source filter through the design system instead of a raw `<select>`.

## Compatibility

- Every option, prop, message field, and label is optional; `projects`
defaults to an empty list and `project` to `undefined`.
- Existing design-system registries keep type-checking: the new adapters
sit in `EditorToolComponents`, which is already `Partial` in
`EditorComponents`, and fall back to the native implementations.
- `TranslationEditorView` passes `filters` through unchanged when no
project or source data is supplied.
- `SourceLocation` keeps its shape and export path; `MessageContext`
default location text is unchanged.
- All 57 existing editor tests pass unchanged; 16 tests were added (73
total).

## Test plan

Run in this environment (no Bazel available on the machine):

- [x] `tsc` over `packages/editor/*.ts(x)` with the root `tsconfig.json`
(`isolatedDeclarations`, `strict`) and the `#packages/*` path mapping –
clean
- [x] `vitest run` for all 7 editor test files with happy-dom – 73
passed (57 on `main`)
- [x] `oxfmt --check packages/editor/` and `oxlint packages/editor/` –
clean
- [x] `codescythe` dead-export check – clean
- [ ] `bazel test //packages/editor/...` – not run locally; relies on CI

New tests:

- `workflow.test.tsx`: source filter composing with status, catalog, and
search; uncontrolled switching resets page/selection/filters and reports
`unchanged` / `unknown-project`; `unsaved-drafts` blocks until reset or
`discardDrafts`; controlled projects wait for the consumer.
- `source-location.test.ts`: file-only, `file:start`, `file:start–end`,
placeholders with repository/revision present and absent, fallbacks,
path encoding, resolver and fragment overrides, no link without a base.
- `tools.test.tsx`: `MessageContext` sources row with copy controls and
omission without sources; text-only default locations with
resolver-built links via `renderLocation`; native `ProjectPicker`
(keyboard-focusable `<select>`, labelled options, disabled),
`SourceFilter`, and `SourceBadge`.
- `ui.test.tsx`: view renders the picker only with more than one project
and the filter only with sources, badges only on rows with sources;
custom registries without the new adapters still work and
`renderMessage` receives `state.sources`.

The demo under `packages/editor/demo` and the VRT gallery were left
unchanged: wiring new controls into the StyleX demo is not cheap enough
to include here, and nothing new renders without project or source data,
so existing visual baselines are unaffected.

## Consumer binding

This package only models projects, sources, and location metadata.
Loading a project's messages, confirming draft discards, and mapping
`repository` / `revision` to a specific hosting URL live in the
consuming application, outside this package.

---------

Co-authored-by: pgonsolin <[email protected]>
Co-authored-by: Long Ho <[email protected]>
longlho added a commit that referenced this pull request Oct 28, 2026
… editors (#7706)

## Motivation

A consumer can run several independent translation workspaces (for
example a web app and two mobile apps) in one editor deployment, and
each workspace receives messages from several upload streams (for
example a main branch and a release branch). Today `@formatjs/editor`
models a single message set with optional per-message `catalogs` and a
`catalog` filter, and location links have to be built by every consumer
through `renderLocation`. This PR adds:

1. A **project model** so the shell can list and switch workspaces while
the consumer loads that project's messages, locales, and save handler.
2. **Per-message source membership**, distinct from catalogs, with a
composable filter, a context row, and row badges.
3. Enough **location metadata** plus exported helpers to build source
links without consumer-side hardcoding. Default rendering stays plain
text.

Follows the conventions of #7403 and #7424: flat files under
`packages/editor`, tests next to code, exports through `index.ts` /
`ui.tsx`, CHANGELOG left to the release tooling, no consumer-specific
naming.

## API additions

| Area | Addition | Notes |
| --- | --- | --- |
| `workflow.ts` | `EditorProject {id, label, description?}` | New type |
| `workflow.ts` | `TranslationEditorOptions.projects?`, `project?`
(controlled), `defaultProject?`, `onProjectChange?` | All optional; the
hook never loads data |
| `workflow.ts` | `TranslationEditorState.projects`, `project`,
`setProject(id, {discardDrafts?})` | Returns `ProjectChangeResult`:
`changed` / `unchanged` / `blocked` (`unsaved-drafts` or
`unknown-project`). Resets page, selection, and catalog/source filters |
| `workflow.ts` | `ProjectChangeResult`, `ProjectChangeOptions` | New
types |
| `workflow.ts` | `EditorMessage.sources?: readonly string[]` | Upload
streams, distinct from `catalogs` |
| `workflow.ts` | `TranslationEditorState.sources`, `source`,
`setSource` | Empty-string "all" sentinel, same as `catalog`; composes
with status, catalog, and search |
| `source-location.ts` | `SourceLocation.source?`, `repository?`,
`revision?` | `SourceLocation` is still exported from `workflow.ts` |
| `source-location.ts` | `formatSourceLocation(location)` | The `file`,
`file:start`, `file:start–end` text `MessageContext` already used |
| `source-location.ts` | `resolveSourceLocationHref(location, {baseUrl?,
repository?, revision?, lineFragment?})`, `SourceLocationHrefOptions` |
`baseUrl` is a string with optional `{repository}` / `{revision}`
placeholders or a function; returns `undefined` without a base or a
placeholder value |
| `core.tsx` | `EditorState.clearSelection()` | Lets workflows drop an
explicit selection |
| `message-context.tsx` | "Sources" row, `copySources`, labels `sources`
/ `sourceCopy` | Hidden when the message has no sources |
| `design-system.tsx` | `ProjectPicker`, `SourceFilter`, `SourceBadge`
adapters and their props types | Optional additions to
`EditorToolComponents`; native `<select>` / `<select>` / `<span>`
implementations |
| `ui.tsx` | `TranslationEditorViewProps.projects?`, `sourceFilter?`;
`EditorProjectSelection`, `EditorSourceSelection` | Picker renders when
more than one project exists, filter when any source exists |
| `ui.tsx` | `EditorMessageRenderState.sources`,
`EditorViewMessage.sources?` | Default rows render `SourceBadge`s;
custom `renderMessage` receives `state.sources` |
| `ui.tsx` | Labels `project`, `sources`, `sourceFilter`, `allSources`,
`sourceBadge(source)` | Overridable through `labels` |

The spec called for `ProjectPicker` and `SourceBadge`; a third
`SourceFilter` adapter was added so the composed view can render the
source filter through the design system instead of a raw `<select>`.

## Compatibility

- Every option, prop, message field, and label is optional; `projects`
defaults to an empty list and `project` to `undefined`.
- Existing design-system registries keep type-checking: the new adapters
sit in `EditorToolComponents`, which is already `Partial` in
`EditorComponents`, and fall back to the native implementations.
- `TranslationEditorView` passes `filters` through unchanged when no
project or source data is supplied.
- `SourceLocation` keeps its shape and export path; `MessageContext`
default location text is unchanged.
- All 57 existing editor tests pass unchanged; 16 tests were added (73
total).

## Test plan

Run in this environment (no Bazel available on the machine):

- [x] `tsc` over `packages/editor/*.ts(x)` with the root `tsconfig.json`
(`isolatedDeclarations`, `strict`) and the `#packages/*` path mapping –
clean
- [x] `vitest run` for all 7 editor test files with happy-dom – 73
passed (57 on `main`)
- [x] `oxfmt --check packages/editor/` and `oxlint packages/editor/` –
clean
- [x] `codescythe` dead-export check – clean
- [ ] `bazel test //packages/editor/...` – not run locally; relies on CI

New tests:

- `workflow.test.tsx`: source filter composing with status, catalog, and
search; uncontrolled switching resets page/selection/filters and reports
`unchanged` / `unknown-project`; `unsaved-drafts` blocks until reset or
`discardDrafts`; controlled projects wait for the consumer.
- `source-location.test.ts`: file-only, `file:start`, `file:start–end`,
placeholders with repository/revision present and absent, fallbacks,
path encoding, resolver and fragment overrides, no link without a base.
- `tools.test.tsx`: `MessageContext` sources row with copy controls and
omission without sources; text-only default locations with
resolver-built links via `renderLocation`; native `ProjectPicker`
(keyboard-focusable `<select>`, labelled options, disabled),
`SourceFilter`, and `SourceBadge`.
- `ui.test.tsx`: view renders the picker only with more than one project
and the filter only with sources, badges only on rows with sources;
custom registries without the new adapters still work and
`renderMessage` receives `state.sources`.

The demo under `packages/editor/demo` and the VRT gallery were left
unchanged: wiring new controls into the StyleX demo is not cheap enough
to include here, and nothing new renders without project or source data,
so existing visual baselines are unaffected.

## Consumer binding

This package only models projects, sources, and location metadata.
Loading a project's messages, confirming draft discards, and mapping
`repository` / `revision` to a specific hosting URL live in the
consuming application, outside this package.

---------

Co-authored-by: pgonsolin <[email protected]>
Co-authored-by: Long Ho <[email protected]>
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