Batch of fixes from the automated QA pass on develop. Each was reproduced and then verified fixed live (browser/curl); logic-bearing fixes have unit tests. Functional bugs: - #122 collab-token was capped by the anonymous public-share-AI throttler (5/min); skip all non-AUTH named throttlers on this auth-guarded, client-cached route. - #123 editor onAuthenticationFailed threw `jwtDecode(undefined)` and never reconnected; read the token via a ref, guard the decode (incl. missing exp), and refetch+reconnect on any auth failure. - #124 a slash command containing a space ("/Heading 1") inserted literal text; enable allowSpaces and close the menu when the query matches no items. - #125 space slug auto-gen produced uppercase initials for multi-word names; computeSpaceSlug now yields a lowercase alphanumeric slug. - #126 AI chat window position/size now persisted (atomWithStorage) across reload; also fixes a latent ResizeObserver-attach bug on first open. - #127 workspace name update accepted URLs; add @NoUrls (parity with setup). - #132 icon-columns 4/5 passed calc() into SVG width/height attrs (console spam); size via style. share-for-page query returns null instead of undefined. - #134 "Reindex now" counter looked stuck: reindex runs async; the client now polls coverage (bounded) so the counter climbs live; misleading server comment reworded. UX / consistency: - #128 add success toasts to favorite/label/avatar/member-(de)activate. - #129 "1 result found" pluralization; hide the single-option Type filter. - #130 replace raw Zod strings with friendly messages (name/password/group). - #131 unify "Untitled" casing in tree/breadcrumb/tab; stop force-uppercasing space-name chips; fix confirm-dialog labels (Cancel / Remove), invite placeholder typo, Export/Move-to-space labels. - #133 disable profile Save when clean; toast on unsupported avatar image; style the invalid-invitation page with a CTA; hide Share for read-only users; align the dictation "not configured" message; "Go to login page" typo. Tests: computeSpaceSlug, workspace-name NoUrls DTO, share-query null normalization, slash getSuggestionItems empty-close. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
2.6 KiB
TypeScript
71 lines
2.6 KiB
TypeScript
import { Extension } from '@tiptap/core';
|
|
import { PluginKey } from '@tiptap/pm/state';
|
|
import Suggestion, { SuggestionOptions } from '@tiptap/suggestion';
|
|
import renderItems from '@/features/editor/components/slash-menu/render-items';
|
|
import getSuggestionItems from '@/features/editor/components/slash-menu/menu-items';
|
|
|
|
export const slashMenuPluginKey = new PluginKey('slash-command');
|
|
|
|
// @ts-ignore
|
|
const Command = Extension.create({
|
|
name: 'slash-command',
|
|
|
|
addOptions() {
|
|
return {
|
|
suggestion: {
|
|
char: '/',
|
|
// Keep the query alive through spaces so multi-word item labels
|
|
// (e.g. "Heading 1", "Math block") match instead of terminating the
|
|
// query and leaving literal "/Heading 1" text in the document.
|
|
allowSpaces: true,
|
|
command: ({ editor, range, props }) => {
|
|
props.command({ editor, range, props });
|
|
},
|
|
allow: ({ state, range }) => {
|
|
const $from = state.doc.resolve(range.from);
|
|
// Disable slash menu inside code blocks
|
|
if ($from.parent.type.name === 'codeBlock') {
|
|
return false;
|
|
}
|
|
// With `allowSpaces: true` a query that contains a space no longer
|
|
// terminates the suggestion on its own, so a space-bearing query that
|
|
// matches nothing (e.g. "/todo abc") would otherwise keep an empty
|
|
// popup logically active and leave the literal "/todo abc" text in the
|
|
// document, only dismissable via Escape. Deactivate the suggestion when
|
|
// no item matches the current query: returning false here removes the
|
|
// decoration, fires the popup's `onExit`, and lets subsequent keystrokes
|
|
// pass through normally — restoring the pre-`allowSpaces` behavior for
|
|
// non-matching queries while keeping multi-word matches (e.g.
|
|
// "/Heading 1") working.
|
|
const query = state.doc.textBetween(range.from + 1, range.to);
|
|
const groups = getSuggestionItems({ query });
|
|
const hasMatches = Object.values(groups).some(
|
|
(items) => items.length > 0,
|
|
);
|
|
return hasMatches;
|
|
},
|
|
} as Partial<SuggestionOptions>,
|
|
};
|
|
},
|
|
|
|
addProseMirrorPlugins() {
|
|
return [
|
|
Suggestion({
|
|
pluginKey: slashMenuPluginKey,
|
|
...this.options.suggestion,
|
|
editor: this.editor,
|
|
}),
|
|
];
|
|
},
|
|
});
|
|
|
|
const SlashCommand = Command.configure({
|
|
suggestion: {
|
|
items: getSuggestionItems,
|
|
render: renderItems,
|
|
},
|
|
});
|
|
|
|
export { Command as SlashCommandExtension };
|
|
export default SlashCommand;
|