feat(ui): export BUILT_IN_COMMAND_IDS, add commands.has and commands.require (SD-2920)#3095
Open
caio-pizzol wants to merge 2 commits intomainfrom
Open
feat(ui): export BUILT_IN_COMMAND_IDS, add commands.has and commands.require (SD-2920)#3095caio-pizzol wants to merge 2 commits intomainfrom
caio-pizzol wants to merge 2 commits intomainfrom
Conversation
…require (SD-2920) Config-driven toolbars had no way to validate their command id arrays. `ui.commands.get(id)` returns undefined silently for unknown ids, so typos surfaced as buttons that rendered disabled with no warning at startup, in the type checker, or in the dev console. This PR exposes three small helpers on the public superdoc/ui surface: - BUILT_IN_COMMAND_IDS: readonly array of the canonical built-in command ids. PublicToolbarItemId is now derived from this const so the type and runtime list cannot drift from each other. - ui.commands.has(id): boolean check, true for built-ins and currently registered customs. - ui.commands.require(id): throwing variant for trusted dispatch sites (keyboard routers, tests, internal pipelines) where an unknown id is a bug not a user error. Re-exported through superdoc/ui (and the public superdoc/ui sub-entry) so consumers can import directly from the entry point they already use. Tests pin: BUILT_IN_COMMAND_IDS matches the runtime toolbar registry (drift guard), has() returns true for every built-in and toggles correctly across custom register/unregister, require() returns handles for built-ins and customs and throws for unknown ids. Consumer-typecheck exercises every helper at value level.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6dd9af03e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…es (SD-2920) - ui.commands.register() now refuses ids that match Proxy property names (register / get / has / require). Index access on the ui.commands Proxy intercepts those names before the registry lookup, so a custom command registered under one of them would be reachable through get(id) / require(id) but unreachable through ui.commands[id]. Refuse + warn instead, matching the build-in collision pattern. - override: true does not bypass: Proxy index access cannot be routed around at registration time. Use a namespaced id instead (e.g. 'company.has'). - Test pins the contract: every reserved name is refused, has(id) returns false for the refused id, index access still returns the Proxy helper. - Replace em-dashes added in the prior commit per project rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Config-driven toolbars had no way to validate their command id arrays. `ui.commands.get(id)` returns undefined silently for unknown ids, so typos surfaced as buttons that rendered disabled with no warning at startup, in the type checker, or in the dev console.
This PR exposes three small helpers on the public `superdoc/ui` surface:
`BUILT_IN_COMMAND_IDS` — readonly array of canonical built-in command ids. `PublicToolbarItemId` is now derived from this const, so the type and runtime list cannot drift from each other.
`ui.commands.has(id)` — boolean check, true for built-ins and currently registered customs.
`ui.commands.require(id)` — throwing variant for trusted dispatch sites (keyboard routers, tests, internal pipelines) where an unknown id is a bug.
Linear: SD-2920
8 vitest cases pin behavior: BUILT_IN_COMMAND_IDS matches the runtime toolbar registry (drift guard), has() flips correctly across custom register/unregister, require() throws for unknown ids.
Consumer-typecheck exercises every helper at value level.
Verified: `pnpm --filter @superdoc/super-editor test src/ui/` passes 181/181; `pnpm --filter superdoc build` clean; consumer-typecheck on the modified file clean.