Skip to content

Commit da370da

Browse files
authored
Merge pull request #520 from Harbour-Enterprises/fatima_text_o
Detecting fillable fields
2 parents db71d7f + 90a1170 commit da370da

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,39 @@ export const FieldAnnotation = Node.create({
448448
commands.addFieldAnnotation(from, attrs, editorFocus);
449449
},
450450

451+
/**
452+
* Replace field annotation.
453+
* @param fieldsArray array of fields with attrs to add as annotation.
454+
* @example
455+
* editor.commands.replaceWithFieldAnnotation([
456+
* from: 20,
457+
* to: 45,
458+
* attrs: {
459+
* fieldType: 'TEXTINPUT'
460+
* fieldColor: '#980043'
461+
* }
462+
* ])
463+
*/
464+
replaceWithFieldAnnotation:
465+
(fieldsArray) =>
466+
({editor, dispatch, state, tr}) => {
467+
if (!dispatch) return true;
468+
tr.setMeta('fieldAnnotationReplace', true);
469+
470+
fieldsArray.forEach((annotation) => {
471+
let {from, to, attrs} = annotation;
472+
let {schema} = editor;
473+
474+
let newPosFrom = tr.mapping.map(from);
475+
let newPosTo = tr.mapping.map(to);
476+
let node = schema.nodes[this.name].create({...attrs}, null, null);
477+
478+
tr.replaceWith(newPosFrom, newPosTo, node);
479+
});
480+
481+
return true;
482+
},
483+
451484
/**
452485
* Update annotations associated with a field.
453486
* @param fieldIdOrArray The field ID or array of field IDs.

0 commit comments

Comments
 (0)