Skip to content

Commit

Permalink
various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
acenturyandabit committed Feb 13, 2021
1 parent 1889b3a commit 2259b74
Show file tree
Hide file tree
Showing 9 changed files with 475 additions and 468 deletions.
599 changes: 216 additions & 383 deletions cat.js

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions core_modules/ui/core.contextMenu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
function _contextMenuManager(root) {
this.registerContextMenu = function (menu, element, delegate, contextmenuEventPassThrough) {
//menu is html; element is parent element; delegate is a class as string; contextmenueventpassthrough is a function that returns a bool given the event
/*
let contextMenuManager = new _contextMenuManager(this.rootdiv);
let contextmenu = contextMenuManager.registerContextMenu(
`<div>
<span>Sort by date</span>
</div>`)
contextmenu.addEventListener("click",()=>{
//do stuff
})
*/
this.registerContextMenu = function(menu, element, delegate, contextmenuEventPassThrough) {
let thisCTXM = document.createElement("div");
thisCTXM.innerHTML = menu;
thisCTXM.style.cssText = "display:none;"
Expand All @@ -23,7 +36,7 @@ function _contextMenuManager(root) {
thisCTXM.style.left = _left;
thisCTXM.style.display = "block";
}
let f = function (e) {
let f = function(e) {
//show the context menu
e.preventDefault();
if (contextmenuEventPassThrough) {
Expand All @@ -34,7 +47,7 @@ function _contextMenuManager(root) {
intellishow(e);
}
};
element.addEventListener("contextmenu", function (e) {
element.addEventListener("contextmenu", function(e) {
if (delegate) {
if (e.target.matches(delegate) || e.target.matches(delegate + " *")) f(e);
} else f(e);
Expand Down Expand Up @@ -67,6 +80,7 @@ function _contextMenuManager(root) {
position:relative;
padding: 2px;
display: block;
color:black;
}
.contextMenu li:hover {
background:pink;
Expand All @@ -93,7 +107,7 @@ function _contextMenuManager(root) {
//deps: core.container.js
//add a context menu configuration button to the container menu
polymorph_core.showContextMenu = (container, settings, options) => {
container._tempCtxSettings = settings;//do this otherwise contextmenu will always point to first item contextmenu'ed... but what is this?
container._tempCtxSettings = settings; //do this otherwise contextmenu will always point to first item contextmenu'ed... but what is this?
/*
settings = {
x:int
Expand Down Expand Up @@ -127,7 +141,7 @@ polymorph_core.showContextMenu = (container, settings, options) => {
let setItemProp = (prop, val, assignment, LHS = polymorph_core.items[container._tempCtxSettings.id]) => {
//expect either item.potato.tomato from assignment or potato.tomato.
if (assignment) {
prop = prop.slice(prop.indexOf(".") + 1);//nerf the first item
prop = prop.slice(prop.indexOf(".") + 1); //nerf the first item
}
let props = prop.split(".");
let itm = LHS;
Expand Down Expand Up @@ -285,7 +299,7 @@ polymorph_core.ctxCommands = {
}
}

polymorph_core.container.prototype.registerContextMenu = function (el, delegateFilter) {
polymorph_core.container.prototype.registerContextMenu = function(el, delegateFilter) {
el.addEventListener("contextmenu", (e) => {
let itm = delegateFilter(e.target);
if (itm) {
Expand All @@ -308,7 +322,7 @@ document.addEventListener("mousemove", (e) => {

// add a topbar element that does it.
polymorph_core.on("UIstart", () => {
let contextMenuDialog = htmlwrap(/*html*/`
let contextMenuDialog = htmlwrap( /*html*/ `
<div>
<h2>Context menu settings</h2>
<textarea></textarea>
Expand All @@ -324,8 +338,8 @@ polymorph_core.on("UIstart", () => {
contextMenuDialog.querySelector("textarea").addEventListener("input", () => {
polymorph_core.currentDoc.globalContextMenuOptions = contextMenuDialog.querySelector("textarea").value.split("\n");
});
polymorph_core.topbar.add("File");//add it so that it comes first before settings.
polymorph_core.topbar.add("File"); //add it so that it comes first before settings.
/*polymorph_core.topbar.add("Settings/Context menu").addEventListener("click", () => {
polymorph_core.dialog.prompt(contextMenuDialog);
})*/
})
})
48 changes: 41 additions & 7 deletions core_modules/ui/richText.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
// rich text
polymorph_core.markdownToHTML = (markdown) => {
// convert markdown into HTML
return
}
(() => {
// rich text
polymorph_core.RTRenderProperty = (prop) => {
// convert markdown into HTML
return prop;
}

polymorph_core.HTMLToMarkdown = (innerHTML) => {

}
polymorph_core.RTParseElement = (el, id, prop) => {
// check if there are any child images
let deepCloned = el.cloneNode(true);
let strayImages = 0;
if (deepCloned.children) {
for (c of deepCloned.children) {
if (c.tagName == "IMG" && c.src.slice(0, 5) == "data:") {
strayImages++;
let rq = new XMLHttpRequest();
rq.onreadystatechange = (e) => {
if (rq.readyState == XMLHttpRequest.DONE) {
if (rq.status == 200) {
c.src = `${window.location.protocol}//${window.location.host}/getImage/${rq.responseText}.png`;
}
strayImages--;
if (strayImages == 0) {
// send an updateItem
polymorph_core.items[id][prop] = deepCloned.innerHTML;
polymorph_core.fire("updateItem", { id: id, sender: polymorph_core });
}
}
}
rq.open("POST", `${window.location.protocol}//${window.location.host}/saveImage`);
rq.setRequestHeader('Content-Type', c.src.split(/;/g)[0].slice(5));
rq.send(c.src);
}
}
}
// if there are, grab the url as a dataurl
// POST the dataurl to a backend image handler
// for now, just check whether localhost will take it
// when it comes back, fire an updateItem to update it.
return el.innerHTML;
}
})();
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ These articles outline how polymorph works in terms of its modules and informati
- UI: Operators, containers, rects, helpers
- Data: Save sources, core, backend
- Items: _lu, linking
- Local machine data
- Messaging: event API, on/fire, remapping

## Operator specific
Expand Down
18 changes: 18 additions & 0 deletions docs/local_machine_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Data architecture
The main data repositories of Polymorph include:
- polymorph_core.userData: Device (browser) scope.
```javascript
polymorph_core.userData={
documents:{
document_id:{
saveSources:{
saveSourceName:savesourceData
},
autosave: true/false
}
},
tutorialData:{
operatorName:operatorTutorialData
}
}
```
47 changes: 11 additions & 36 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
# Overview

Polymorph is a highly modular system, which makes it fantastic for modding.
Polymorph is a highly modular system, which makes it fantastic for modding. The main classes of modules outside of the care are savesources and operators:

If you're only looking to mod polymorph by adding your own functionality, you may only need to know about the following structure:
![](https://raw.githubusercontent.com/acenturyandabit/polymorph/largeAssets/docs/polymorph_overview.PNG)

![](https://raw.githubusercontent.com/acenturyandabit/polymorph/largeAssets/assets/readme2.gif)
- Operators operate on the data by rendering it and applying user edits to the underlying data. Operators also subscribe or publish to an event system allowing them to communicate with each other.
- Save sources operate on the data by saving it to a remote location for safekeeping between sessions.

There are also a number of core elements:
- Containers wrap around operators to help isolate operators from each other in a field-reconfigurable manner.
- Rects manage space by dividing the screen into rectangles. Each rect can either hold exactly two other rects; or an indefinite number of containers in tabs.
- The core event system relays events between operators and from operators to realtime savesources.
- The core document loading system reads both the local machine data and the document data to determine which save source instances and operators to create.

The unit of data in polymorph is an item. An item is a plain JSON-encoded entry in the document dictionary. Items can further have properties which are then rendered by operators.



## It's like...
- ROS [https://www.ros.org/], but for user interfaces
- Outlook, but less integrated (sad) and more flexible (yay)
## Software Architecture
Polymorph is made up of a few main components:
- polymorph_core: This represents a shared platform where everything interacts. It contains a main event interface.
- Rects: This represents resizable rectangles that form the basis of Polymorph's UX.
- Containers: Rects hold containers, which hold operators. Containers abstract away some common UX concerns from operators.
- polymorph_core modules: These represent aspects of the polymorph_core's operation.
- Items: These are created by users through operators.
- [MODDING FOCUS] Operators: These represent different ways of representing, interacting with and creating items.

## Data architecture
The main data repositories of Polymorph include:
- polymorph_core.userData: Device (browser) scope.
```javascript
polymorph_core.userData={
documents:{
document_id:{
saveSources:{
saveSourceName:savesourceData
},
autosave: true/false
}
},
tutorialData:{
operatorName:operatorTutorialData
}
}
```
- polymorph_core.items: Instance scope.
## Living architecture
[Back to contents](https://github.com/acenturyandabit/polymorph/tree/master/docs)
3 changes: 2 additions & 1 deletion filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let fileList = [
"core_modules/ui/core.phone.main.js",
"core_modules/ui/core.main.js",
"core_modules/ui/ccleaner.js",
"core_modules/ui/richText.js",
"operators/opSelect.js",
"genui/dateparser.js",
"operators/itemList.searchsort.js",
Expand All @@ -27,7 +28,7 @@ let fileList = [
"genui/intervalParser.js",
"operators/terminal.js",
"operators/workflow.js",
"operators/textflow.js",
//"operators/textflow.js",
"operators/inspector.js",
"operators/inspectolist.js",
"operators/subframe.js",
Expand Down
2 changes: 1 addition & 1 deletion operators/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
type: "array",
object: this.settings,
property: "dateproperties",
label: "Enter the date properties (begin with * for numerical dates instead of smart dates):"
label: "Enter the date properties (begin with * for numerical dates instead of smart dates):",
}),
new polymorph_core._option({
div: this.dialogDiv,
Expand Down
Loading

0 comments on commit 2259b74

Please sign in to comment.