import * as ko from "knockout" ; import { Base , ItemValue , property , Question , QuestionRowModel , QuestionSelectBase , SurveyModel , LocalizableString } from "survey-core" ; import { Survey , ImplementorBase , Panel } from "survey-knockout-ui" ; import { ICreatorOptions , CreatorBase , getElementWrapperComponentName , isStringEditable , getElementWrapperComponentData , getItemValueWrapperComponentName , getItemValueWrapperComponentData } from "@survey/creator" ; import { editableStringRendererName } from "./components/string-editor" ; if ( ! ! ko . options ) { ko . options . useOnlyNativeEvents = true ; } export class DesignTimeSurveyModel extends Survey { constructor ( public creator , jsonObj ? ) { super ( jsonObj ) ; } public isPopupEditorContent = false ; public getElementWrapperComponentName ( element , reason ? ) { let componentName = getElementWrapperComponentName ( element , reason , this . isPopupEditorContent ) ; return ( componentName || super . getElementWrapperComponentName ( element , reason ) ) ; } public getElementWrapperComponentData ( element , reason ? ) { const data = getElementWrapperComponentData ( element , reason , this . creator ) ; return data || super . getElementWrapperComponentData ( element ) ; } public getRowWrapperComponentName ( row ) { return "svc-row" ; } public getRowWrapperComponentData ( row ) { return { creator : this . creator , row } ; } public getItemValueWrapperComponentName ( item , question ) { return getItemValueWrapperComponentName ( item , question ) ; } public getItemValueWrapperComponentData ( item , question ) { return getItemValueWrapperComponentData ( item , question , this . creator ) ; } public getRendererForString ( element , name ) { if ( ! this . creator . readOnly && isStringEditable ( element , name ) ) { return editableStringRendererName ; } return undefined ; } public getRendererContextForString ( element , locStr ) { if ( ! this . creator . readOnly && isStringEditable ( element , locStr . name ) ) { return { creator : this . creator , element , locStr } ; } return < any > locStr ; } } export class SurveyCreator extends CreatorBase < Survey > { constructor ( options = { } , options2 ? ) { super ( options , options2 ) ; } protected createSurveyCore ( json = { } , reason ) { if ( reason === "designer" || reason === "modal-question-editor" ) return new DesignTimeSurveyModel ( this , json ) ; return new Survey ( json ) ; } protected onViewTypeChanged ( newType ) { const plugin = this . plugins [ newType ] ; ! ! plugin && plugin . activate ( ) ; } render ( target ) { let node = target as HTMLElement ; if ( typeof target === "string" ) { node = document . getElementById ( target ) ; } node . innerHTML = "<survey-creator params=\"creator: creator\"></survey-creator>" ; ko . cleanNode ( node ) ; ko . applyBindings ( { creator : this } , node ) ; } }