An open source design system that's fully customizable and agent ready
TypeScript
refactor(richtext): keep editor theme classes, autolink patterns and the Transformer re-export internal (#7560)
Cindy Zhang50ce8947f018
diff --git a/packages/richtext/src/RichTextEditor.tsx b/packages/richtext/src/RichTextEditor.tsxindex 0045254b4a..0ac93d9aa5 100644--- a/packages/richtext/src/RichTextEditor.tsx+++ b/packages/richtext/src/RichTextEditor.tsx@@ -81,7 +81,6 @@ import {MarkdownExtensionsPlugin} from './MarkdownExtensionsPlugin';import type {RichTextMarkdownExtension} from './markdownExtensions';import {TaskCheckboxPlugin} from './TaskCheckboxPlugin';import {type Transformer} from '@lexical/markdown';-export type {Transformer} from '@lexical/markdown';import {$generateHtmlFromNodes} from '@lexical/html';import {DEFAULT_NODES} from './editorNodes';import {$exportMarkdownKeepingSource} from './markdownSource';diff --git a/packages/richtext/src/index.ts b/packages/richtext/src/index.tsindex 97cc156868..5cc0dcd767 100644--- a/packages/richtext/src/index.ts+++ b/packages/richtext/src/index.ts@@ -10,8 +10,14 @@* Lexical-based rich text editor and viewer, promoted out of* @astryxdesign/lab so it can be canaried independently.*- * SYNC: When modified, update this header, /packages/richtext/README.md, and- * the editor component doc files.+ * Exports only what a caller builds with (spec:AST-061/DEC-8): the generated+ * editor theme classes and the autolink regular expressions stay internal,+ * and Lexical's `Transformer` type comes from `@lexical/markdown`.+ * `publicSurface.test.ts` holds the runtime list.+ *+ * SYNC: When modified, update this header, /packages/richtext/README.md,+ * /packages/richtext/src/publicSurface.test.ts, and the editor component doc+ * files.*/export {RichTextEditor} from './RichTextEditor';@@ -21,14 +27,11 @@ export type {RichTextEditorStatus,RichTextEditorStatusType,RichTextEditorSize,- Transformer,} from './RichTextEditor';export {RichTextView} from './RichTextView';export type {RichTextViewProps} from './RichTextView';-export {sharedEditorTheme} from './editorTheme';-export {markdownToEditorStateJSON,editorStateJSONToMarkdown,@@ -53,9 +56,4 @@ export {} from './RichTextEditorAutoLinkPlugin';export type {RichTextEditorAutoLinkPluginProps} from './RichTextEditorAutoLinkPlugin';-export {- sanitizeUrl,- validateUrl,- URL_MATCHER,- EMAIL_MATCHER,-} from './linkUtils';+export {sanitizeUrl, validateUrl} from './linkUtils';diff --git a/packages/richtext/src/publicSurface.test.ts b/packages/richtext/src/publicSurface.test.tsnew file mode 100644index 0000000000..8251b46627--- /dev/null+++ b/packages/richtext/src/publicSurface.test.ts@@ -0,0 +1,42 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file publicSurface.test.ts+ * @input The package entry, packages/richtext/src/index.ts+ * @output Pins the runtime exports of @astryxdesign/richtext to the list+ * spec:AST-061/DEC-8 admits, and the internals it keeps out of the entry.+ * @position Package-level contract test.+ */++import {describe, expect, it} from 'vitest';+// @ts-expect-error Transformer is Lexical's type; import it from @lexical/markdown.+import type {Transformer as _NotReExported} from './index';+import * as richtext from './index';++describe('@astryxdesign/richtext public surface', () => {+ it('exports exactly what a caller builds with', () => {+ expect(Object.keys(richtext).sort()).toEqual(+ [+ 'DEFAULT_LINK_MATCHERS',+ 'NEW_TAB_LINK_ATTRIBUTES',+ 'RICHTEXT_ICON_KEYS',+ 'RichTextEditor',+ 'RichTextEditorAutoLinkPlugin',+ 'RichTextEditorToolbar',+ 'RichTextExtensionError',+ 'RichTextView',+ 'createRichTextExtension',+ 'editorStateJSONToMarkdown',+ 'markdownToEditorStateJSON',+ 'sanitizeUrl',+ 'validateUrl',+ ].sort(),+ );+ });++ it('keeps the editor theme classes and autolink patterns internal', () => {+ for (const name of ['sharedEditorTheme', 'URL_MATCHER', 'EMAIL_MATCHER']) {+ expect(richtext).not.toHaveProperty(name);+ }+ });+});