Skip to content

Commit

Permalink
Explorer view (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertprz committed Apr 21, 2024
1 parent 18384f8 commit 2b945b8
Show file tree
Hide file tree
Showing 33 changed files with 916 additions and 277 deletions.
12 changes: 12 additions & 0 deletions lib/Array.pursh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ module Array


def add (xs: [Number], ys: [Number]): [Number] =
// Adds elementwise the numbers of two collections
// >>> [1, 2, 3], [4, 5, 6]
// >>> [1, 2, 3], [-1, -2, -3]
Prelude.zipWith (Prelude.add, xs, ys)

def sub (xs: [Number], ys: [Number]): [Number] =
// Substracts elementwise the numbers of two collections
// >>> [1, 2, 3], [4, 5, 6]
// >>> [1, 2, 3], [-1, -2, -3]
Prelude.zipWith (Prelude.sub, xs, ys)

def mult (xs: [Number], ys: [Number]): [Number] =
// Multiplies elementwise the numbers of two collections
// >>> [1, 2, 3], [4, 5, 6]
// >>> [1, 2, 3], [-1, -2, -3]
Prelude.zipWith (Prelude.mult, xs, ys)

def div (xs: [Number], ys: [Number]): [Number] =
// Divides elementwise the numbers of two collections
// >>> [1, 2, 3], [4, 5, 6]
// >>> [1, 2, 3], [-1, -2, -3]
Prelude.zipWith (Prelude.div, xs, ys)
38 changes: 37 additions & 1 deletion lib/Matrix.pursh
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,73 @@ module Matrix


def add (xss: [[Number]], yss: [[Number]]): [[Number]] =
// Adds elementwise the numbers of two matrixes
// >>> [[1], [2, 3]], [[4], [5, 6]]
// >>> [[1, 2], [3]], [[-1, -2], [-3]]
zipWith (Prelude.add, xss, yss)

def sub (xss: [[Number]], yss: [[Number]]): [[Number]] =
// Substracts elementwise the numbers of two matrixes
// >>> [[1], [2, 3]], [[4], [5, 6]]
// >>> [[1, 2], [3]], [[-1, -2], [-3]]
zipWith (Prelude.sub, xss, yss)

def mult (xss: [[Number]], yss: [[Number]]): [[Number]] =
// Multiplies elementwise the numbers of two matrixes
// >>> [[1], [2, 3]], [[4], [5, 6]]
// >>> [[1, 2], [3]], [[-1, -2], [-3]]
zipWith (Prelude.mult, xss, yss)

def div (xss: [[Number]], yss: [[Number]]): [[Number]] =
// Divides elementwise the numbers of two matrixes
// >>> [[1], [2, 3]], [[4], [5, 6]]
// >>> [[1, 2], [3]], [[-1, -2], [-3]]
zipWith (Prelude.div, xss, yss)

def map (f: A -> B, xss: [[A]]): [[B]] =
// Maps a unary function over a matrix
// >>> _ / 2, [[1, 3], [5, 7]]
// >>> _ ++ "x", [["a"], ["c"], ["c"]]
Prelude.map (Prelude.map (f), xss)

def filter (f: A -> Boolean, xss: [[A]]): [[A]] =
// Uses a predicate to filter a matrix
// >>> x -> x % 2 == 0, [[1, 2], [3, 4]]
// >>> x -> length (x) > 2, [["abc"], ["de"], ["f"]]
Prelude.map (Prelude.filter (f), xss)

def reduce (f: B -> A -> B, start: B, xss: [A]): B =
// Uses a reducer function and initial value to accumulate a value over a matrix
// >>> '+, 7, [[1, 2], [3, 4]]
// >>> '++, "hello", [["abc"], ["de"], ["f"]]
Prelude.reduce (f, start, Prelude.map (Prelude.reduce (f, start), xss))

def fold (f: A -> A -> A, xss: [[A]]): A =
// Uses a reducer function to accumulate a value over a non-empty matrix
// >>> '+, [[1, 2], [3, 4]]
// >>> '++, [["abc"], ["de"], ["f"]]
Prelude.fold (f, Prelude.map (Prelude.fold(f), xss))

def zipWith (f: A -> B -> C, xss: [[A]], yss: [[B]]): [[C]] =
// Maps a binary function over two matrixes
// >>> '-, [[1], [2], [3]], [[5], [6], [7]]
// >>> '++, [["a", "b"]], [["c", "d"]]
Prelude.zipWith (Prelude.zipWith (f), xss, yss)

def sum (xss: [[Number]]): Number =
def sum (xss: [[Number]]): Number =
// Calculates the sum of a matrix of numbers
// >>> [[1, 2], [3, 4]]
// >>> [[-1.5, 3.2], [-5.8]]
reduce (Prelude.add, 0, xss)

def product (xss: [[Number]]): Number =
// Calculates the product of a matrix of numbers
// >>> [[1, 2], [3, 4]]
// >>> [[-1.5, 3.2], [-5.8]]
reduce (Prelude.mult, 0, xss)

def average (xss: [[Number]]): Number =
// Calculates the average of a matrix of numbers
// >>> [[1, 2], [3, 4]]
// >>> [[-1.5, 3.2], [-5.8]]
Prelude.div (sum (xss), 2)
67 changes: 61 additions & 6 deletions lib/Prelude.pursh
Original file line number Diff line number Diff line change
Expand Up @@ -59,80 +59,135 @@ op % = mod L11


def id (x: A): A =
// Returns its argument
// >>> []
// >>> true
x

def const (x: A): B -> A =
// Returns its first argument
// >>> 2, 7
// >>> true, false
y -> x

def apply (f: A -> B, x: A): B =
// Applies a unary function to an argument
// >>> _ * 3, 6
// >>> head, ['a', 'b', 'c']
f (x)

def compose (f: A -> B, g: B -> C): A -> C =
// Composes two functions
// >>> _ * 3, _ + 1, 2
// >>> head, tail, [2, 4, 6]
x -> f (g (x))

def flip (f: A -> B -> C): B -> A -> C =
// Flips the arguments of the function
// >>> '-, 2, 1
// >>> '++, "hel", "lo"
(x, y) -> f (y, x)

def map (f: A -> B, xs: [A]): [B] =
// Maps a unary function over a collection
// >>> _ / 2, [1, 3, 5, 7]
// >>> _ ++ "x", ["a", "c", "c"]
switch (xs) {
| [] => []
| [ x, xs @ ... ] => f (x) +: map (f, xs)
}

def filter (f: A -> Boolean, xs: [A]): [A] =
// Uses a predicate to filter a collection
// >>> x -> x % 2 == 0, [1, 2, 3, 4]
// >>> x -> length (x) > 2, ["abc", "de", "f"]
switch (xs) {
| [] => []
| [ x, xs @ ... ] ? f(x) => x +: filter (f, xs)
? otherwise => filter (f, xs)
}

def reduce (f: B -> A -> B, start: B, xs: [A]): B =
switch (xs) {
| [] => start
| [ x, xs @ ... ] => f (x, reduce (f, start, xs))
// Uses a reducer function and initial value to accumulate a value over a collection
// >>> '+, 7, [1, 2, 3, 4]
// >>> '++, "hello", ["abc", "de", "f"]
reduceRight (f, start, reverse (xs)) where {
| reduceRight (f, start, xs) = switch (xs) {
| [] => start
| [ x, xs @ ... ] => f (reduceRight (f, start, xs), x)
}
}

def fold (f: A -> A -> A, xs: [A]): A =
// Uses a reducer function to accumulate a value over a non-empty collection
// >>> '+, [1, 2, 3, 4]
// >>> '++, ["abc", "de", "f"]
switch (xs) {
| [] => null
| [ x, xs @ ... ] => reduce (f, x, xs)
}

def zipWith (f: A -> B -> C, xs: [A], ys: [B]): [C] =
// Maps a binary function over two collections
// >>> '-, [1, 2, 3], [5, 6, 7]
// >>> '++, ["a", "b"], ["c", "d"]
cond {
? isEmpty (xs) || isEmpty (ys) => []
? otherwise =>
f (head (xs), head (ys)) +: zipWith (f, tail (xs), tail (ys))
}

def iterate (f: A -> A, start: A, n: Int): [A] =
// Generates a collection by applying a unary function with an initial value n times
// >>> _ * 2, 1, 6
// >>> _ ++ "x", "a", 3
cond {
? n == 0 => [start]
? otherwise => start +: iterate (f, f (start), n - 1)
}

def isEmpty (xs: [A]): Boolean =
// Checks if a collection is empty
// >>> "asd"
// >>> []
switch (xs) {
| [] => true
| "" => true
| _ => false
}

def isNotEmpty (xs: [A]): Boolean =
// Checks if a collection is not empty
// >>> "asd"
// >>> []
not (isEmpty (xs))

def all (f: A -> Boolean, xs: [A]): Boolean =
// Checks if a predicate succeeds for all of the elements in a collection
// >>> _ > 7, []
// >>> _ > 7, [3, 6, 9]
reduce (and, true, map (f, xs))

def any (f: A -> Boolean, xs: [A]): Boolean =
// Checks if a predicate succeeds for at least some of the elements in a collection
// >>> _ > 7, []
// >>> _ > 7, [3, 6, 9]
reduce (or, false, map (f, xs))


def sum (xs: [Number]): Number =
def sum (xs: [Number]): Number =
// Calculates the sum of a collection of numbers
// >>> [1, 2, 3, 4]
// >>> [-1.5, 3.2, -5.8]
reduce (add, 0, xs)

def product (xs: [Number]): Number =
reduce (mult, 0, xs)
// Calculates the product of a collection of numbers
// >>> [1, 2, 3, 4]
// >>> [-1.5, 3.2, -5.8]
reduce (mult, 1, xs)

def average (xs: [Number]): Number =
// Calculates the average of a collection of numbers
// >>> [1, 2, 3, 4]
// >>> [-1.5, 3.2, -5.8]
sum (xs) / 2
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
, "newtype"
, "numbers"
, "ordered-collections"
, "orders"
, "partial"
, "point-free"
, "prelude"
Expand Down
4 changes: 2 additions & 2 deletions src/CSS/Application.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module App.CSS.Application where

import CSSPrelude

import App.CSS.ClassNames (invisibleContainer)
import App.CSS.Editor as Editor
import App.CSS.Explorer as Explorer
import App.CSS.HeaderMenu as HeaderMenu
import App.CSS.Spreadsheet as Spreadsheet
import Tecton.Rule as Rule
Expand All @@ -15,14 +15,14 @@ css = do
HeaderMenu.css
Editor.css
Spreadsheet.css
Explorer.css

appCss :: CSS
appCss = do

body ? Rule.do
margin := px 0
padding := px 0
overflow := hidden

universal &. invisibleContainer ? Rule.do
display := none
8 changes: 4 additions & 4 deletions src/CSS/CSSPrelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module CSSPrelude
, module Halogen
, module Tecton.Internal
, module Common
, module ClassNames
, module Ids
, module ClassNames
) where

import Tecton hiding (ElementId(..))

import App.CSS.ClassNames (aboveSelection, atLeftSelection, atRightSelection, belowSelection, cellSyntax, columnHeader, copySelection, cornerHeader, formulaBox, formulaCellInput, formulaSectionContainer, inSelection, invalidFormula, keywordSyntax, numberSyntax, operatorSyntax, regularSyntax, rowHeader, selectedCellInput, selectedHeader, selectedSheetCell, sheet, sheetCell, spreadsheetContainer, stringSyntax, strippedSheet, symbolSyntax, unknownFormula, validFormula) as ClassNames
import App.CSS.Common (black, blue, brown, darkGrey, green, grey, grey2, hex, lightGreen, lightGrey, lighterGreen, lighterGrey, lighterRed, lighterYellow, mustard, orange, pink, purple, red, white, yellow) as Common
import App.CSS.Ids (ElementId(..), cellId, formulaBoxId, formulaCellInputId, inputElement, selectedCellInputId) as Ids
import App.CSS.ClassNames as ClassNames
import App.CSS.Common as Common
import App.CSS.Ids as Ids
import Data.Tuple (Tuple) as Tuple
import Data.Tuple.Nested ((/\)) as Tuple.Nested
import Halogen (AttrName(..), ClassName(..), Component, ComponentHTML, ElemName(..), PropName(..), RefLabel(..))
Expand Down
32 changes: 25 additions & 7 deletions src/CSS/ClassNames.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ headerMenu = ClassName "header-menu"
navButton :: ClassName
navButton = ClassName "nav-button"

sheet :: ClassName
sheet = ClassName "sheet"
spreadsheetTable :: ClassName
spreadsheetTable = ClassName "spreadsheet-table"

strippedSheet :: ClassName
strippedSheet = ClassName "stripped-sheet"
sheetCell :: ClassName
sheetCell = ClassName "sheet-cell"

selectedSheetCell :: ClassName
selectedSheetCell = ClassName "selected-sheet-cell"
Expand All @@ -35,9 +35,6 @@ atLeftSelection = ClassName "at-left-selection"
atRightSelection :: ClassName
atRightSelection = ClassName "at-right-selection"

sheetCell :: ClassName
sheetCell = ClassName "sheet-cell"

formulaBox :: ClassName
formulaBox = ClassName "formula-box"

Expand Down Expand Up @@ -121,3 +118,24 @@ regularSyntax = ClassName "regular-syntax"

materialIcons :: ClassName
materialIcons = ClassName "material-icons"

functionsList :: ClassName
functionsList = ClassName "functions-list"

functionRow :: ClassName
functionRow = ClassName "function-row"

functionDescription :: ClassName
functionDescription = ClassName "function-description"

termTypeLabel :: ClassName
termTypeLabel = ClassName "term-type-label"

functionName :: ClassName
functionName = ClassName "function-name"

functionDoc :: ClassName
functionDoc = ClassName "function-doc"

functionContainer :: ClassName
functionContainer = ClassName "function-container"
8 changes: 7 additions & 1 deletion src/CSS/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ formulaFontSize :: Measure Length
formulaFontSize = px 21

signatureFontSize :: Measure Length
signatureFontSize = px 24
signatureFontSize = px 28

functionDescriptionFontSize :: Measure Length
functionDescriptionFontSize = px 30

termTypeFontSize :: Measure Length
termTypeFontSize = px 24

hex :: String -> Color
hex = fromMaybe black <<< fromHexString
Expand Down
7 changes: 2 additions & 5 deletions src/CSS/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module App.CSS.Editor where

import CSSPrelude

import App.CSS.ClassNames (formulaBoxContainer, functionSignature, functionSyntax, selectedSuggestionOption, suggestionOption, suggestionsDropdown)
import App.CSS.Common (darkGreen, darkPink, formulaFontSize, lightBlue, signatureFontSize)
import Tecton.Rule as Rule

css :: CSS
Expand All @@ -21,12 +19,12 @@ css = do
margin := px 20
marginTop := px 40
marginBottom := px 10
padding := px 20
padding := px 20 ~ px 25
borderStyle := solid
borderColor := grey2
borderWidth := px 3
fontFamily := monospace
fontSize := formulaFontSize
fontWeight := bold
whiteSpace := breakSpaces
overflow := auto

Expand Down Expand Up @@ -54,7 +52,6 @@ css = do
marginTop := px 10
padding := px 0 ~ px 50
fontSize := signatureFontSize
fontWeight := bold
textAlign := center

universal &. unknownFormula ? Rule.do
Expand Down
Loading

0 comments on commit 2b945b8

Please sign in to comment.