-ReactiveRunner = require('reactive-runner')
-TextLoader = require('text-loader')
-TextParser = require('text-parser')
+Freesheet = require 'freesheet'
 CoreFunctions = require('core-functions')
 PageFunctions = require('page-functions')
 TimeFunctions = require('time-functions')



  constructor: (el, @changeCallback) ->
    @runner = new ReactiveRunner()
    @runner.onChange @changeCallback
    @runner.addProvidedStreams CoreFunctions
    @runner.addProvidedStreams TimeFunctions
    @runner.addProvidedStreams PageFunctions
    @runner.onChange (name, value) => @_updateTable name, value
    @loader = new TextLoader(@runner)
    @data = ({name: null, formula: null, value: null} for i in [1..5] )

    @table = new Handsontable el.get(0), {

    if @loading then existingRow or @_newRow(name) else existingRow

  _newRow: (name) ->
    def = (d for d in @sheet.formulas() when d.name == name)[0]
    row = {name: def?.name, formula: def?.expr.text, value: null}
    @data.push row
    row
