 #-----------------------------------------------------------------------------------------------------------
 @$main = ( S ) ->
   #.........................................................................................................
+  L = new_local_state()
   return D.TEE.from_pipeline [
-    @$parse_description               S
-    @$collect_field_contents          S
-    # @$dump_table_description          S
+    @$parse_description               S, L
+    @$store_layout_event              S, L
+    @$handle_content_events           S, L
+    # D.$observe ( event ) -> info '23993', ( CND.grey '--------->' ), jr event
+    @$handle_fields                   S, L
+    # @$dump_table_layout          S, L
     ]
+
 
 #===========================================================================================================
 #
 #-----------------------------------------------------------------------------------------------------------
-@$dump_table_description = ( S ) -> D.$observe ( event ) ->
-  return unless select event, '.', 'MKTS/TABLE/description', true
+new_local_state = ->
+  R =
+    layout_name_stack:              []
+    selectors_and_content_events:   {}
+    layout_events:                  {}
+    content_buffer:                 null
+    within_field:                   false
+  return R
+
+
+#-----------------------------------------------------------------------------------------------------------
+@is_within_table = ( S, L ) -> L.layout_name_stack.length > 0
+
+#-----------------------------------------------------------------------------------------------------------
+@get_current_layout_name = ( S, L ) ->
+  unless ( R = L.layout_name_stack[ L.layout_name_stack.length - 1 ] )?
+    throw new Error "#{badge}#µ4451 layout stack empty"
+  return R
+
+#-----------------------------------------------------------------------------------------------------------
+@pop_layout_name = ( S, L ) ->
+  R = @get_current_layout_name S, L
+  L.layout_name_stack.pop()
+  return R
+
+#-----------------------------------------------------------------------------------------------------------
+@layout_from_name = ( S, L, layout_name ) ->
+  unless ( R = L.layout_events[ layout_name ] )?
+    throw new Error "#{badge}#µ4450 unknown layout #{rpr layout_name}"
+  return R[ 2 ]
+
+#-----------------------------------------------------------------------------------------------------------
+@push_layout_name = ( S, L, layout_name ) ->
+  unless L.layout_events[ layout_name ]?
+    throw new Error "#{badge}#µ4445 unknown layout #{rpr layout_name}"
+  L.layout_name_stack.push layout_name
+  return null
+
+#-----------------------------------------------------------------------------------------------------------
+@store_layout_event = ( S, L, event ) ->
+  [ _, _, layout, _, ] = event
+  if L.layout_events[ layout.name ]?
+    throw new Error "#{badge}#µ4449 refusing to re-define layout #{rpr layout.name}"
+  L.layout_events[ layout.name ] = event
+  @_initialize_layout S, L, layout.name
+  return null
+
+#-----------------------------------------------------------------------------------------------------------
+@_initialize_layout = ( S, L, layout_name ) ->
+  L.selectors_and_content_events[ layout_name ] = []
+  return null
+
+#-----------------------------------------------------------------------------------------------------------
+@content_buffer_from_layout_name_and_selector = ( S, L, layout_name, selector ) ->
+  unless ( target = L.selectors_and_content_events[ layout_name ] )?
+    throw new Error "#{badge}#µ4432 unknown layout #{rpr layout_name}"
+  R = [ selector, ]
+  target.push R
+  return R
+
+#-----------------------------------------------------------------------------------------------------------
+@get_selectors_and_content_events = ( S, L, layout_name ) ->
+  unless ( R = L.selectors_and_content_events[ layout_name ] )?
+    debug '88733', L.selectors_and_content_events
+    debug '88733', Object.keys L.selectors_and_content_events
+    throw new Error "#{badge}#µ5745 unknown layout #{rpr layout_name}"
+  return R
+
+#===========================================================================================================
+#
+#-----------------------------------------------------------------------------------------------------------
+@$dump_table_layout = ( S, L ) -> D.$observe ( event ) ->
+  return unless select event, '.', 'MKTS/TABLE/layout', true
   help '99871', ( CND.blue rpr event[ 2 ] )
 
 #-----------------------------------------------------------------------------------------------------------
-@$parse_description = ( S ) ->
+@$parse_description = ( S, L ) ->
   within_mkts_table = false
   return $ ( event, send ) =>
     #.......................................................................................................
+    ### TAINT change tag to sth like `mkts-table-layout` ###
     if select event, '.', 'mkts-table-description'
       [ type, name, text, meta, ] = event
-      [ description, sandbox, ]   = @get_mkts_table_description_and_sandbox S, event
+      [ layout, sandbox, ]        = @get_mkts_table_description_and_sandbox S, event
       try
         ECS.evaluate text, { language: 'coffee', sandbox, }
       catch error

        warn "an error occurred"
        throw error
      send stamp event
      send [ '.', 'MKTS/TABLE/description', description, ( copy meta ), ]
    #.......................................................................................................
    else
      send event

  ### ... more typesetting detail attached here ... ###
  #.........................................................................................................
  f = ->
    @name                 = ( raw_parts ) -> MKTS_TABLE.name                  me, raw_parts.join ''
    @debug                = ( raw_parts ) -> MKTS_TABLE.debug                 me, raw_parts.join ''
    @grid                 = ( raw_parts ) -> MKTS_TABLE.grid                  me, raw_parts.join ''
    @paddingwidth         = ( raw_parts ) -> MKTS_TABLE.paddingwidth          me, raw_parts.join ''
