@tarviks/lexical-rich-editor 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -97,6 +97,14 @@ type ContentEditorRef = {
97
97
  isEmpty: () => boolean;
98
98
  /** Whether the editor currently has input focus. */
99
99
  isFocused: () => boolean;
100
+ /**
101
+ * Display one or more error messages inside the editor immediately.
102
+ * These are shown alongside any prop-based `errors`.
103
+ * Example: ref.current.setErrors(['Attachment too large', 'Subject is required'])
104
+ */
105
+ setErrors: (messages: string[]) => void;
106
+ /** Remove all errors that were set via `setErrors`. */
107
+ clearErrors: () => void;
100
108
  /**
101
109
  * Access the underlying Lexical editor instance for advanced usage.
102
110
  * Returned type is `any` to avoid leaking internal Lexical types.
@@ -252,23 +260,62 @@ interface ContentEditorProps {
252
260
  spellCheckEnabled?: boolean;
253
261
  /** When true, shows the floating formatting toolbar near text selections. */
254
262
  showFloatingToolbar?: boolean;
255
- /**
256
- * Maximum word count allowed. When set, a live counter is shown
257
- * below the editor. Exceeding the limit turns the counter red.
258
- * Example: wordLimit={500}
259
- */
263
+ /** Maximum words allowed. Shows a live counter; turns red when exceeded. */
260
264
  wordLimit?: number;
265
+ /** Minimum words required. Error shown after blur if not met. */
266
+ minWords?: number;
267
+ /** Maximum characters allowed. Error shown when exceeded. */
268
+ maxChars?: number;
269
+ /** Minimum characters required. Error shown after blur if not met. */
270
+ minChars?: number;
271
+ /** When true, shows a required-field error after blur if the editor is empty. */
272
+ required?: boolean;
261
273
  /**
262
274
  * Fires when the content crosses the configured word limit boundary.
263
- *
264
- * - exceeded: true -> user just exceeded the limit
265
- * - exceeded: false -> user came back within the limit
275
+ * exceeded: true → user just exceeded; false → came back within limit.
266
276
  */
267
277
  onWordLimitExceeded?: (info: {
268
278
  wordCount: number;
269
279
  wordLimit: number;
270
280
  exceeded: boolean;
271
281
  }) => void;
282
+ /**
283
+ * Extra error messages to display (on top of any built-in validation).
284
+ * Use this for errors that originate outside the editor (e.g. file too large,
285
+ * subject empty, API failure).
286
+ *
287
+ * Example: errors={['Attachment exceeds 5 MB', 'Subject is required']}
288
+ */
289
+ errors?: string[];
290
+ /**
291
+ * Override the text of any built-in validation message.
292
+ * Every key accepts a plain string OR a function receiving the live counts.
293
+ *
294
+ * Covered errors:
295
+ * - wordLimitExceeded — fires when wordCount > wordLimit
296
+ * - required — fires on blur when editor is empty and required=true
297
+ * - minWords — fires on blur when wordCount < minWords
298
+ * - maxCharsExceeded — fires when charCount > maxChars
299
+ * - minCharsRequired — fires on blur when charCount < minChars
300
+ *
301
+ * Example:
302
+ * ```tsx
303
+ * errorMessages={{
304
+ * wordLimitExceeded: (count, limit) => `Too long — ${count}/${limit} words used.`,
305
+ * required: 'Email body cannot be empty.',
306
+ * minWords: (count, min) => `Write at least ${min} words (${count} so far).`,
307
+ * maxCharsExceeded: (count, max) => `${count}/${max} characters — please shorten.`,
308
+ * minCharsRequired: (count, min) => `At least ${min} characters needed (${count} entered).`,
309
+ * }}
310
+ * ```
311
+ */
312
+ errorMessages?: {
313
+ wordLimitExceeded?: string | ((wordCount: number, wordLimit: number) => string);
314
+ required?: string;
315
+ minWords?: string | ((wordCount: number, minWords: number) => string);
316
+ maxCharsExceeded?: string | ((charCount: number, maxChars: number) => string);
317
+ minCharsRequired?: string | ((charCount: number, minChars: number) => string);
318
+ };
272
319
  }
273
320
 
274
321
  declare const ContentEditorComponent: React.ForwardRefExoticComponent<ContentEditorProps & React.RefAttributes<ContentEditorRef>>;
package/dist/index.d.ts CHANGED
@@ -97,6 +97,14 @@ type ContentEditorRef = {
97
97
  isEmpty: () => boolean;
98
98
  /** Whether the editor currently has input focus. */
99
99
  isFocused: () => boolean;
100
+ /**
101
+ * Display one or more error messages inside the editor immediately.
102
+ * These are shown alongside any prop-based `errors`.
103
+ * Example: ref.current.setErrors(['Attachment too large', 'Subject is required'])
104
+ */
105
+ setErrors: (messages: string[]) => void;
106
+ /** Remove all errors that were set via `setErrors`. */
107
+ clearErrors: () => void;
100
108
  /**
101
109
  * Access the underlying Lexical editor instance for advanced usage.
102
110
  * Returned type is `any` to avoid leaking internal Lexical types.
@@ -252,23 +260,62 @@ interface ContentEditorProps {
252
260
  spellCheckEnabled?: boolean;
253
261
  /** When true, shows the floating formatting toolbar near text selections. */
254
262
  showFloatingToolbar?: boolean;
255
- /**
256
- * Maximum word count allowed. When set, a live counter is shown
257
- * below the editor. Exceeding the limit turns the counter red.
258
- * Example: wordLimit={500}
259
- */
263
+ /** Maximum words allowed. Shows a live counter; turns red when exceeded. */
260
264
  wordLimit?: number;
265
+ /** Minimum words required. Error shown after blur if not met. */
266
+ minWords?: number;
267
+ /** Maximum characters allowed. Error shown when exceeded. */
268
+ maxChars?: number;
269
+ /** Minimum characters required. Error shown after blur if not met. */
270
+ minChars?: number;
271
+ /** When true, shows a required-field error after blur if the editor is empty. */
272
+ required?: boolean;
261
273
  /**
262
274
  * Fires when the content crosses the configured word limit boundary.
263
- *
264
- * - exceeded: true -> user just exceeded the limit
265
- * - exceeded: false -> user came back within the limit
275
+ * exceeded: true → user just exceeded; false → came back within limit.
266
276
  */
267
277
  onWordLimitExceeded?: (info: {
268
278
  wordCount: number;
269
279
  wordLimit: number;
270
280
  exceeded: boolean;
271
281
  }) => void;
282
+ /**
283
+ * Extra error messages to display (on top of any built-in validation).
284
+ * Use this for errors that originate outside the editor (e.g. file too large,
285
+ * subject empty, API failure).
286
+ *
287
+ * Example: errors={['Attachment exceeds 5 MB', 'Subject is required']}
288
+ */
289
+ errors?: string[];
290
+ /**
291
+ * Override the text of any built-in validation message.
292
+ * Every key accepts a plain string OR a function receiving the live counts.
293
+ *
294
+ * Covered errors:
295
+ * - wordLimitExceeded — fires when wordCount > wordLimit
296
+ * - required — fires on blur when editor is empty and required=true
297
+ * - minWords — fires on blur when wordCount < minWords
298
+ * - maxCharsExceeded — fires when charCount > maxChars
299
+ * - minCharsRequired — fires on blur when charCount < minChars
300
+ *
301
+ * Example:
302
+ * ```tsx
303
+ * errorMessages={{
304
+ * wordLimitExceeded: (count, limit) => `Too long — ${count}/${limit} words used.`,
305
+ * required: 'Email body cannot be empty.',
306
+ * minWords: (count, min) => `Write at least ${min} words (${count} so far).`,
307
+ * maxCharsExceeded: (count, max) => `${count}/${max} characters — please shorten.`,
308
+ * minCharsRequired: (count, min) => `At least ${min} characters needed (${count} entered).`,
309
+ * }}
310
+ * ```
311
+ */
312
+ errorMessages?: {
313
+ wordLimitExceeded?: string | ((wordCount: number, wordLimit: number) => string);
314
+ required?: string;
315
+ minWords?: string | ((wordCount: number, minWords: number) => string);
316
+ maxCharsExceeded?: string | ((charCount: number, maxChars: number) => string);
317
+ minCharsRequired?: string | ((charCount: number, minChars: number) => string);
318
+ };
272
319
  }
273
320
 
274
321
  declare const ContentEditorComponent: React.ForwardRefExoticComponent<ContentEditorProps & React.RefAttributes<ContentEditorRef>>;