Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{-
Welcome to your new Dhall package-set!

Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.

## Warning: Don't Move This Top-Level Comment!

Due to how `dhall format` currently works, this comment's
instructions cannot appear near corresponding sections below
because `dhall format` will delete the comment. However,
it will not delete a top-level comment like this one.

## Use Cases

Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set

This file will continue to work whether you use one or both options.
Instructions for each option are explained below.

### Overriding/Patching a package

Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo

Syntax:
Replace the overrides' "{=}" (an empty record) with the following idea
The "//" or "⫽" means "merge these two records and
when they have the same value, use the one on the right:"
-------------------------------
let overrides =
{ packageName =
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
, packageName =
upstream.packageName // { version = "v4.0.0" }
, packageName =
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
}
-------------------------------

Example:
-------------------------------
let overrides =
{ halogen =
upstream.halogen // { version = "master" }
, halogen-vdom =
upstream.halogen-vdom // { version = "v4.0.0" }
}
-------------------------------

### Additions

Purpose:
- Add packages that aren't already included in the default package set

Syntax:
Replace the additions' "{=}" (an empty record) with the following idea:
-------------------------------
let additions =
{ package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, etc.
}
-------------------------------

Example:
-------------------------------
let additions =
{ benchotron =
{ dependencies =
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
, repo =
"https://github.com/hdgarrood/purescript-benchotron.git"
, version =
"v7.0.0"
}
}
-------------------------------
-}


let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200309/packages.dhall sha256:9221987b4e7ea99ccd0efbe056f7bebc872cd92e0058efe5baa181d73359e7b3

let overrides = {=}

let additions = {=}

in upstream // overrides // additions
18 changes: 18 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "monaco"
, dependencies =
[ "aff"
, "aff-promise"
, "console"
, "effect"
, "foreign"
, "psci-support"
, "record"
, "web-html"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
42 changes: 23 additions & 19 deletions src/Monaco/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ const LeftObjName = "Left"
const RightObjName = "Right"

mapMaybes = function (options) {
var newObj = {}
var newObj = {};
for (prop in options) {
var propKey = prop
var propValue = options[prop]
var newValue = undefined
var propKey = prop;
var propValue = options[prop];
var newValue = undefined;
if (propValue.constructor.name == JustObjName) {
newValue = propValue["value0"];
if (newValue.constructor.name == LeftObjName
|| newValue.constructor.name == RightObjName) {
if (newValue.constructor.name == LeftObjName ||
newValue.constructor.name == RightObjName) {
newValue = newValue["value0"];
}
else if (newValue === Object(newValue) && newValue.constructor != Array) {
else if (newValue === Object(newValue) &&
newValue.constructor != Array) {
newValue = mapMaybes(newValue);
}
newObj[propKey] = newValue
newObj[propKey] = newValue;
}
}
return newObj
return newObj;
}


Expand All @@ -34,19 +35,20 @@ exports.createImpl = function (options) {
return function () {
return new Promise(function (resolve, reject) {
// Check for nodejs environment (e.g. electron)
if(self.process != null){
if (self.process != null) {
// make it happy for nodejs env
var path = require('path');
const path = require('path');
function uriFromPath(_path) {
var pathName = path.resolve(_path).replace(/\\/g, '/');
let pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = '/' + pathName;
}
console.log(pathName);
return encodeURI('file://' + pathName);
}

monacoRequire.config({
baseUrl: uriFromPath(path.join(__dirname, './monaco-editor/min'))
baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
});
// workaround monaco-css not understanding the environment
self.module = undefined;
Expand All @@ -57,15 +59,17 @@ exports.createImpl = function (options) {
// make it happy for browser env
monacoRequire.config({ paths: { 'vs': './monaco-editor/min/vs' } });
}


monacoRequire(['vs/editor/editor.main'], function () {
var mappedOpts = mapMaybes(options)
var editor = monaco.editor.create(el, mappedOpts);
console.log(options);
const mappedOpts = mapMaybes(options);
console.log(mappedOpts);
console.log(el);
const editor = monaco.editor.create(el, mappedOpts);
console.log(editor);
resolve(editor);
});
});
}
};
};
};

25 changes: 11 additions & 14 deletions src/Monaco/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ module Monaco.Editor
( create
) where

import Control.Monad.Aff
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Effect.Aff (Aff)
import Effect (Effect)
import Control.Promise (Promise, toAffE)
import DOM (DOM)
import DOM.HTML.Types (HTMLElement)
import Data.Foreign (Foreign, toForeign)
import Monaco.Types (Editor, EditorConstructionOptions, MONACO)
import Web.HTML (HTMLElement)
import Foreign (Foreign, unsafeToForeign)
import Monaco.Types (Editor, EditorConstructionOptions)

foreign import createImpl
∷ forall e. Foreign
:: Foreign
-> HTMLElement
-> Eff (monaco :: MONACO, dom ∷ DOM, exception ∷ EXCEPTION|e) (Promise Editor)
-> Effect (Promise Editor)

create
∷ forall e.
EditorConstructionOptions
:: EditorConstructionOptions
-> HTMLElement
-> Aff (monaco :: MONACO, dom ∷ DOM, exception ∷ EXCEPTION|e) Editor
-> Aff Editor
create options el =
let effProm = createImpl (toForeign options) el in
toAffE effProm
let effProm = createImpl (unsafeToForeign options) el in
toAffE effProm
Loading