@@ -3,15 +3,12 @@ import { Contract } from "@paperbits/common";
33import { CustomWidgetModel } from "./customWidgetModel" ;
44import { CustomWidgetContract } from "./customWidgetContract" ;
55import { widgetName } from "./constants" ;
6+ import { customWidgetPrefixName , customWidgetRemovePrefixName } from "./ko/utils" ;
67
78export class CustomWidgetModelBinder implements IModelBinder < CustomWidgetModel > {
8- public canHandleModel ( model : unknown , widgetName : string ) : boolean {
9- return model instanceof CustomWidgetModel && model [ "name" ] == widgetName ;
10- }
11-
129 public async contractToModel ( contract : CustomWidgetContract ) : Promise < CustomWidgetModel > {
1310 const model = new CustomWidgetModel ( ) ;
14- model . name = contract . name ?? "" ;
11+ model . name = customWidgetPrefixName ( contract . name ) ?? "" ;
1512 model . displayName = contract . displayName || contract . widgetDisplayName ;
1613 model . customInputValue = contract . customInputValue ?? "{}" ;
1714 model . instanceId = contract . instanceKey ;
@@ -22,7 +19,7 @@ export class CustomWidgetModelBinder implements IModelBinder<CustomWidgetModel>
2219 public modelToContract ( model : CustomWidgetModel ) : Contract {
2320 return {
2421 type : widgetName ,
25- name : model . name ,
22+ name : customWidgetRemovePrefixName ( model . name ) ,
2623 displayName : model . displayName ,
2724 customInputValue : model . customInputValue ,
2825 instanceKey : model . instanceId ,
0 commit comments