@@ -14,6 +14,8 @@ import {
1414 type TemplateConfig ,
1515 type CustomFilterField
1616} from './types' ;
17+ import type { InternalCustomFilter } from '../filter/types' ;
18+
1719import { DOMParser , XMLSerializer } from '@xmldom/xmldom' ;
1820import * as xpath from 'xpath' ;
1921import format from 'xml-formatter' ;
@@ -55,7 +57,7 @@ export async function generateBuildingBlock<T extends BuildingBlock>(
5557 fs ?: Editor
5658) : Promise < Editor > {
5759 debugger ;
58- console . log ( 'last attempt ' ) ;
60+ console . log ( 'last kitty ' ) ;
5961
6062 const { viewOrFragmentPath, aggregationPath, buildingBlockData, allowAutoAddDependencyLib = true } = config ;
6163 // Validate the base and view paths
@@ -256,33 +258,39 @@ function processBuildingBlock<T extends BuildingBlock>(
256258
257259 if ( isCustomFilterField ( buildingBlockData ) && buildingBlockData . embededFragment ) {
258260 const embededFragment = setCommonDefaults ( buildingBlockData . embededFragment , manifestPath , manifest ) ;
261+
262+ const config : InternalCustomFilter = { } as InternalCustomFilter ;
263+ if ( buildingBlockData . embededFragment ) {
264+ config . controlID = buildingBlockData . filterFieldKey ! ;
265+ config . label = buildingBlockData . label ! ;
266+ config . property = buildingBlockData . property ! ;
267+ config . required = buildingBlockData . required ?? false ;
268+ config . position = buildingBlockData . position ! ;
269+
270+ config . eventHandler = buildingBlockData . embededFragment . eventHandler ;
271+ config . ns = embededFragment . ns ;
272+ config . name = embededFragment . name ;
273+ config . path = embededFragment . path ;
274+ }
275+
259276 const viewPath = join (
260277 embededFragment . path ,
261278 `${ embededFragment . fragmentFile ?? embededFragment . name } .fragment.xml`
262279 ) ;
263280
264281 // Apply event handler
265- if ( buildingBlockData . embededFragment . eventHandler ) {
266- buildingBlockData . embededFragment . eventHandler = applyEventHandlerConfiguration (
267- fs ,
268- buildingBlockData . embededFragment ,
269- buildingBlockData . embededFragment . eventHandler ,
270- {
271- controllerSuffix : false ,
272- typescript : buildingBlockData . embededFragment . typescript
273- }
274- ) ;
282+ if ( config . eventHandler ) {
283+ config . eventHandler = applyEventHandlerConfiguration ( fs , config , config . eventHandler , {
284+ controllerSuffix : false ,
285+ typescript : buildingBlockData . embededFragment . typescript ,
286+ templatePath : 'filter/Controller'
287+ } ) ;
275288 }
276289
277- buildingBlockData . embededFragment . content = getDefaultFragmentContent (
278- 'Sample Text' ,
279- buildingBlockData . embededFragment . eventHandler
280- ) ;
281290 if ( ! fs . exists ( viewPath ) ) {
282- fs . copyTpl ( getTemplatePath ( 'common /Fragment.xml' ) , viewPath , buildingBlockData . embededFragment ) ;
291+ fs . copyTpl ( getTemplatePath ( 'filter /Fragment.xml' ) , viewPath , config ) ;
283292 }
284293
285- // check xmlDocument for macrosFilterBar element
286294 const filterBarResult = updateAggregationPathForFilterBar ( xmlDocument , aggregationPath , buildingBlockData ) ;
287295 updatedAggregationPath = filterBarResult . updatedAggregationPath ;
288296 hasAggregation = filterBarResult . hasFilterFields ;
0 commit comments