Skip to content

Commit a475730

Browse files
committed
docs: enhance JSDoc comments for field annotation methods to improve clarity and type definitions
1 parent aaebb57 commit a475730

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

packages/super-editor/src/extensions/field-annotation/field-annotation.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @typedef {import('./types').FieldAttributes} FieldAttributes
33
* @typedef {import('./types').FieldValue} FieldValue
4+
* @typedef {import('./types').FieldType} FieldType
45
*/
56

67
// @ts-ignore
@@ -440,10 +441,10 @@ export const FieldAnnotation = Node.create({
440441

441442
return {
442443
/**
443-
* Add field at position
444-
* @param {number} pos
445-
* @param {Partial<FieldAttributes>} attrs // NOTE: attrs = {} doesn't match the FieldAttributes
446-
* @param {boolean} [editorFocus]
444+
* Add a field annotation at a specific position
445+
* @param {number} pos - Document position where to insert the field
446+
* @param {Partial<FieldAttributes>} [attrs={}] - Field attributes
447+
* @param {boolean} [editorFocus=false] - Whether to focus the editor after insertion
447448
* @returns {Function}
448449
*/
449450
addFieldAnnotation:
@@ -484,13 +485,24 @@ export const FieldAnnotation = Node.create({
484485
return true;
485486
},
486487

488+
/**
489+
* Add a field annotation at the current selection
490+
* @param {Partial<FieldAttributes>} [attrs={}] - Field attributes
491+
* @param {boolean} [editorFocus=false] - Whether to focus the editor
492+
* @returns {Function}
493+
*/
487494
addFieldAnnotationAtSelection:
488495
(attrs = {}, editorFocus = false) =>
489496
({ state, commands }) => {
490497
const { from } = state.selection;
491498
return commands.addFieldAnnotation(from, attrs, editorFocus);
492499
},
493500

501+
/**
502+
* Replace text ranges with field annotations
503+
* @param {Array<{from: number, to: number, attrs: Partial<FieldAttributes>}>} fieldsArray - Array of replacements
504+
* @returns {Function}
505+
*/
494506
replaceWithFieldAnnotation:
495507
(fieldsArray) =>
496508
({ editor, dispatch, tr }) => {
@@ -523,6 +535,13 @@ export const FieldAnnotation = Node.create({
523535
return true;
524536
},
525537

538+
/**
539+
* Replace field annotations with their display labels in selection
540+
* @param {Object} [options={}] - Replacement options
541+
* @param {boolean} [options.addToHistory=false] - Whether to add to undo history
542+
* @param {FieldType[]} [options.types] - Limit to specific field types
543+
* @returns {Function}
544+
*/
526545
replaceFieldAnnotationsWithLabelInSelection:
527546
(options = {}) =>
528547
({ commands }) => {
@@ -532,6 +551,15 @@ export const FieldAnnotation = Node.create({
532551
});
533552
},
534553

554+
/**
555+
* Replace field annotations with their display labels
556+
* @param {string | string[] | null} fieldIdOrArray - Field ID(s) to replace, or null for selection
557+
* @param {Object} [options={}] - Replacement options
558+
* @param {boolean} [options.isInSelection=false] - Process only fields in selection
559+
* @param {boolean} [options.addToHistory=false] - Whether to add to undo history
560+
* @param {FieldType[]} [options.types] - Limit to specific field types
561+
* @returns {Function}
562+
*/
535563
replaceFieldAnnotationsWithLabel:
536564
(fieldIdOrArray, { isInSelection = false, addToHistory = false, types = annotationTypes } = {}) =>
537565
({ dispatch, state, tr }) => {

0 commit comments

Comments
 (0)