@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
36 lines • 1.65 kB
JavaScript
import { Violation, ViolationState, ViolationInfoResult } from "./Violation";
import { BaseTextItem } from "@aurigma/design-atoms-model/Product/Items";
import { ItemUtils } from "../../../Utils/ItemUtils";
import { NewBaseTextItemHandler } from "../../../ItemHandlers";
export class TextCropViolation extends Violation {
constructor(_productHandler, _messages) {
super();
this._productHandler = _productHandler;
this._messages = _messages;
this.prepareItem = (item) => {
if (!(item instanceof BaseTextItem))
return;
item.checkTextCrop = true;
};
}
isAvailableFor(item) {
return item instanceof BaseTextItem;
}
getViolationInfo(item) {
if (!ItemUtils.isTextItemHandlerReady(item, this._productHandler))
return ViolationInfoResult.none;
if (!item.violationSettings.allowTextCrop)
return ViolationInfoResult.good;
const handler = this._productHandler.getHandler(item);
if (handler instanceof NewBaseTextItemHandler && handler.isInEdit)
return ViolationInfoResult.none;
const violationState = handler.textCropped ? ViolationState.Warning : ViolationState.Good;
const message = violationState === ViolationState.Warning ? this._messages.textCropWarning : null;
return { state: violationState, message: message };
}
getStatePropertyName() {
return TextCropViolation.statePropertyName;
}
}
TextCropViolation.statePropertyName = "textCropViolationState";
//# sourceMappingURL=TextCropViolation.js.map