Skip to content

Commit

Permalink
Merge pull request #16 from SimplyEdit/tripleBinding
Browse files Browse the repository at this point in the history
Triple binding
  • Loading branch information
Hoxolotl authored Sep 20, 2024
2 parents 1956134 + b37bd56 commit 7015003
Show file tree
Hide file tree
Showing 74 changed files with 45,815 additions and 930 deletions.
95 changes: 89 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ const createWindow = () => {
});
}

const createTestWindow = () => {
if (codeWindow) {
codeWindow.focus();
return;
}
codeWindow = new BrowserWindow({
width: 1024,
height: 786,
title: "Simply Code",
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
})
codeWindow.loadURL('simplycode://index.html/tests/triplebinding/index.html')
codeWindow.on('close', function() {
codeWindow = false;
});
}

const createSecondWindow = (dataDir) => {
if (appWindow) {
appWindow.focus();
Expand All @@ -62,6 +83,7 @@ const createSecondWindow = (dataDir) => {
},
icon: path.join(__dirname,'/simplycode/camil_512x512.png')
})
/*
let menuTemplate = [
{
label: "File",
Expand All @@ -77,6 +99,19 @@ const createSecondWindow = (dataDir) => {
}
];
let menu = Menu.buildFromTemplate(menuTemplate);
*/

let menu = Menu.getApplicationMenu();
menu.items.forEach(function(menuItem) {
if (menuItem.role == "filemenu") {
if(menuItem.submenu.items[0].label !== "View app") {
menuItem.submenu.insert(0, new MenuItem({
label: 'View code',
click: function() {createWindow(dataDir)}
}));
}
}
});
appWindow.setMenu(menu);
appWindow.loadURL('simplyapp://generated.html')
appWindow.on('close', function() {
Expand Down Expand Up @@ -209,7 +244,7 @@ app.whenReady().then(() => {
} else {
return new Response('"Not found"', { status: 404})
}
break
break
case 'PUT':
return createComponentDirectory(componentDirectory)
.then(createComponentFile(componentDirectory + "/" + componentName, request))
Expand All @@ -226,6 +261,22 @@ app.whenReady().then(() => {
}
break
}
} else if(pathicles[0] === "assets") {
componentDirectory = pathicles.join('/');
switch (request.method){
case 'GET':
default:
let target = dataDir + componentDirectory + "/" + componentName;
if(fs.existsSync(target)){
const filestuff = fs.readFileSync(target)
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
} else {
return new Response('"Not found"', { status: 404})
}
break
}
} else {
switch (request.method){
default:
Expand Down Expand Up @@ -276,6 +327,27 @@ app.whenReady().then(() => {
let componentDirectory = pathicles.join('/');

switch (request.method){
case 'OPTIONS':
if(fs.existsSync(dataDir + componentDirectory + "/" + componentName)){
return new Response('"ok"', { status: 200})
} else {
return new Response('"Not found"', { status: 404})
}
break
case 'DELETE':
if(fs.existsSync(dataDir + componentDirectory + "/" + componentName)){
fs.rmSync((dataDir + componentDirectory + "/" + componentName), { recursive: true, force: true })
return new Response('"deleted"', { status: 200})
} else {
return new Response('"Not found"', { status: 404})
}
break
case 'PUT':
return createComponentDirectory(componentDirectory)
.then(createComponentFile(componentDirectory + "/" + componentName, request))
.then(function() { return new Response('"ok"', { status: 200})})
.catch(function(){ return new Response('"something went wrong"', { status : 500 })}) // @TODO : return the error code
break
default:
if(componentPath.endsWith('\/')){
componentPath = componentPath.substring(0, (componentPath.length - 1))
Expand All @@ -296,8 +368,9 @@ app.whenReady().then(() => {
})
} else {
if (
(componentPath === "/js/simply-edit.js") ||
(componentPath === "/js/simply.everything.js")
(componentPath.indexOf("/js/simply") === 0) ||
(componentPath.indexOf("/simply") === 0) ||
(componentPath.indexOf("/hope") === 0)
) {
const filestuff = fs.readFileSync(__dirname + '/simplycode' + componentDirectory + '\/' + componentName)
return new Response(filestuff, {
Expand All @@ -317,7 +390,8 @@ app.whenReady().then(() => {
try {
dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0];
} catch(e) {
app.quit();
createTestWindow();
// app.quit();
return;
}
}
Expand All @@ -327,8 +401,8 @@ app.whenReady().then(() => {
console.log(dataDir);
}
createWindow()

app.on('activate', () => { // needed for macos
createSecondWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
if (!process.argv[0].match(/electron$/) && process.argv[1]) {
dataDir = path.resolve(process.argv[1]);
Expand All @@ -344,10 +418,19 @@ app.whenReady().then(() => {
dataDir += "/";
}
createWindow()
createSecondWindow()
}
})
})

// SSL/TSL: this is the self signed certificate support
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// On certificate error we disable default behaviour (stop loading the page)
// and we then say "it is all fine - true" to the callback
event.preventDefault();
callback(true);
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
11 changes: 8 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions simplycode/hope/hope.annotation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
hope.register( 'hope.annotation', function() {

function hopeAnnotation(range, tag) {
this.range = hope.range.create(range);
this.tag = tag;
Object.freeze(this);
}

hopeAnnotation.prototype.delete = function( range ) {
return new hopeAnnotation( this.range.delete( range ), this.tag );
};

hopeAnnotation.prototype.copy = function( range ) {
return new hopeAnnotation( this.range.copy( range ), this.tag );
};

hopeAnnotation.prototype.compare = function( annotation ) {
return this.range.compare( annotation.range );
};

hopeAnnotation.prototype.has = function( tag ) {
//FIXME: should be able to specify attributes and attribute values as well
return this.stripTag() == hope.annotation.stripTag(tag);
};

hopeAnnotation.prototype.toString = function() {
return this.range + ':' + this.tag;
};

hopeAnnotation.prototype.stripTag = function() {
return hope.annotation.stripTag(this.tag);
};

hopeAnnotation.prototype.isBlock = function() {
return (hope.render.html.rules.nestingSets.block.indexOf(hope.annotation.stripTag(this.tag)) != -1 ); // FIXME: this should not know about hope.render.html;
};

this.create = function( range, tag ) {
return new hopeAnnotation( range, tag );
};

this.stripTag = function(tag) {
return tag.split(' ')[0];
};
});

35 changes: 35 additions & 0 deletions simplycode/hope/hope.editor.events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
hope.register('hope.editor.events', function() {

if ( typeof hope.global.addEventListener != 'undefined' ) {
this.listen = function( el, event, callback, capture ) {
return el.addEventListener( event, callback, capture );
};
} else if ( typeof hope.global.attachEvent != 'undefined' ) {
this.listen = function( el, event, callback, capture ) {
return el.attachEvent( 'on' + event, function() {
var evt = hope.global.event;
var self = evt.srcElement;
if ( !self ) {
self = hope.global;
}
return callback.call( self, evt );
} );
};
} else {
throw new hope.Exception( 'Browser is not supported', 'hope.editor.events.1' );
}

this.cancel = function( evt ) {
if ( typeof evt.stopPropagation != 'undefined' ) {
evt.stopPropagation();
}
if ( typeof evt.preventDefault != 'undefined' ) {
evt.preventDefault();
}
if ( typeof evt.cancelBubble != 'undefined' ) {
evt.cancelBubble = true;
}
return false;
};

} );
Loading

0 comments on commit 7015003

Please sign in to comment.