forked from acenturyandabit/polymorph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.js
More file actions
executable file
·141 lines (113 loc) · 4.04 KB
/
Copy pathreference.js
File metadata and controls
executable file
·141 lines (113 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
core.registerOperator("reference", {
displayName: "Reference",
description: "Here we list all the different features that Polymorph supports for you. If you're looking to get started quick, check out template.js instead!"
}, function (operator) {
let me = this;
me.container = operator;
this.settings = {};
//Add styling info here. Don't worry, it won't affect anything outside your component. (Shadow DOM yay!!!!1)
this.style = document.createElement("style");
this.style.innerHTML = `
button{
width: 5em;
display:block;
}
`
operator.div.appendChild(this.style);
this.rootdiv = document.createElement("div");
//Add content-independent HTML here. fromSaveData will be called if there are any items to load.
this.rootdiv.innerHTML = ``;
operator.div.appendChild(this.rootdiv);
//////////////////Handle core item updates//////////////////
//these are optional but can be used as a reference.
core.on("updateItem", function (d) {
let id = d.id;
let sender = d.sender;
if (sender == me) return;
//Check if item is shown
//Update item if relevant
//This will be called for all items when the items are loaded.
//This is also called when items are created.
});
core.on("focus", function (d) {
let id = d.id;
let s = d.sender;
// An item was focused.
});
core.on("deleteItem", function (d) {
let id = d.id;
let s = d.sender;
if (sender == me) return;
// An item was deleted.
});
core.on("dateUpdate", function (d) {
let id = d.id;
let s = d.sender;
if (sender == me) return;
// The date of an item was updated.
});
this.refresh = function () {
// This is called when my parent rect is resized.
}
//For interoperability between views you may fire() and on() your own events. You may only pass one object to the fire() function; use the properties of that object for additional detail.
//////////////////Handling local changes to push to core//////////////////
//Handle item creation, locally
this.createItem = function () {
//Create a new item
let it = {};
//register it with the core
let id = core.insertItem(it);
//register a change
core.fire("updateItem", {
sender: this,
id: id
});
}
//Register changes with core
this.somethingwaschanged = function () {
core.fire("updateItem", {
id: itemID,
sender: this
});
}
//Register focus with core
this.somethingwasfocused = function () {
core.fire("focus", {
id: itemID,
sender: this
});
}
this.somethingwasdeleted = function () {
core.fire("deleteItem", {
id: itemID,
sender: this
});
//Don't actually delete() the item! core will manage that.
}
//Saving and loading
this.toSaveData = function () {
return this.settings;
}
this.fromSaveData = function (d) {
Object.assign(this.settings, d);
this.processSettings();
}
//Handle a change in settings (either from load or from the settings dialog or somewhere else)
this.processSettings = function () {
}
//Handle the settings dialog click!
this.dialogDiv=document.createElement("div");
this.dialogDiv.innerHTML=`Some html`;
this.showDialog=function(){
// update your dialog elements with your settings
}
this.dialogUpdateSettings=function(){
// pull settings and update when your dialog is closed.
}
this.quickAdd=function(data){
// An operation that is called to quickly add an item. may be called by other operators sometimes. data will always be plaintext. do what you will with it.
}
//Terminal protocol: If you want to add terminal-callable functions, put them under this.callables
this.callables={}
this.callables.fn=this.fn; //etc
});