import { AppendChildrenAction } from '../../actions/append-child-nodes-action';
import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Remove all nodes and append new nodes strategy.
 */
export class BlockReplaceNodesStrategy extends ActionHandleStrategy {
  /**
   * Empty the text block or image block nodes and add new nodes.
   *
   * @param {ReplaceChildNodesAction} action - The replace child nodes action instance.
   * @param {RTETextBlock | RTEImageBlock} target - The text block or the image block.
   */
  handleAction(action, target) {
    target.children = [];
    target.apply(new AppendChildrenAction(action.newChildNodes));
  }
}
