@@ -7,6 +7,10 @@ import { ImageContextItemAdapter } from './adapters/context-items/image.js';
77import { PdfContextItemAdapter } from './adapters/context-items/pdf.js' ;
88
99export class ContextItems extends Collection {
10+ constructor ( smart_context , opts = { } ) {
11+ super ( smart_context . env || smart_context , opts ) ; // OR pass directly for env loading (temp patch, should now be loaded by env)
12+ this . smart_context = smart_context ;
13+ }
1014 async load ( ) {
1115 console . log ( 'ContextItems: load called' ) ;
1216 // TODO DECIDED: add default settings from context_item_merge_template action if not already present????
@@ -51,28 +55,13 @@ export class ContextItems extends Collection {
5155 load_from_data ( context_items_data , params = { } ) {
5256 // delete this.items; // clear existing items (REMOVED TO ALLOW RECURSION FOR NAMED CONTEXTS)
5357 if ( ! this . items ) this . items = { } ;
54- const entries = Object . entries ( context_items_data || { } )
55- // sort by exclude first (exclude === true)
56- . sort ( ( [ , a_data ] , [ , b_data ] ) => {
57- const a_exclude = a_data . exclude === true ? 1 : 0 ;
58- const b_exclude = b_data . exclude === true ? 1 : 0 ;
59- return a_exclude - b_exclude ; // ascending: non-exclude (0) before exclude (1)
60- } )
61- ;
58+ const entries = Object . entries ( context_items_data || { } ) ;
6259 for ( let i = 0 ; i < entries . length ; i ++ ) {
6360 const [ key , item_data ] = entries [ i ] ;
64- if ( item_data . exclude ) {
65- this . load_exclusion_from_data ( key , item_data , params ) ;
66- }
6761 this . load_item_from_data ( key , item_data , params ) ;
6862 }
6963 }
7064
71- load_exclusion_from_data ( key , item_data , params = { } ) {
72- if ( ! this . _exclude_patterns ) this . _exclude_patterns = [ ] ;
73- this . _exclude_patterns . push ( key ) ;
74- }
75-
7665 load_item_from_data ( key , item_data , params = { } ) {
7766 if ( item_data . named_context ) {
7867 const named_context = this . env . smart_contexts . filter ( ( ctx ) => ctx . data . name === key ) [ 0 ] ;
@@ -100,6 +89,7 @@ export class ContextItems extends Collection {
10089 } ) ;
10190 }
10291 }
92+
10393}
10494
10595export default {
0 commit comments