Skip to content

Commit dd12708

Browse files
committed
Add files from monorepo
0 parents  commit dd12708

File tree

7 files changed

+359
-0
lines changed

7 files changed

+359
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore bundler config.
2+
/.bundle
3+
4+
# Ignore all logfiles and tempfiles.
5+
.DS_Store
6+
*.log
7+
/tmp
8+
node_modules/**/*

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Crate cloudflare apps integration
2+
3+
![Demo](https://i.imgur.com/B3AKkRG.gif)

install.json

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
{
2+
"resources": {
3+
"body": [
4+
{
5+
"type": "script",
6+
"src": "./src/app.js"
7+
}
8+
]
9+
},
10+
"preview": {
11+
"handlers": [
12+
{
13+
"options": ["_default"],
14+
"execute": "INSTALL_SCOPE.setOptions(INSTALL_OPTIONS)"
15+
}
16+
]
17+
},
18+
"options": {
19+
"properties": {
20+
"tier": {
21+
"order": 1,
22+
"title": "WidgetBot patreon tier",
23+
"description":
24+
"Becoming a <a href=\"https://www.patreon.com/bePatron?u=5594164\" target=\"_blank\">patreon</a>, enables access to more customization",
25+
"type": "string",
26+
"enum": ["free", "patreon", "ultimate"],
27+
"enumNames": {
28+
"free": "Free",
29+
"patreon": "Patreon ($1)",
30+
"ultimate": "Ultimate patreon ($5)"
31+
},
32+
"default": "free"
33+
},
34+
"buttons": {
35+
"order": 2,
36+
"title": "Crate buttons",
37+
"type": "array",
38+
"items": {
39+
"type": "object",
40+
"properties": {
41+
"server": {
42+
"order": 1,
43+
"title": "Discord server ID",
44+
"placeholder": "339515332702240769",
45+
"type": "string"
46+
},
47+
"channel": {
48+
"order": 2,
49+
"title": "Discord channel ID",
50+
"placeholder": "339515332702240769",
51+
"type": "string"
52+
},
53+
"position": {
54+
"order": 3,
55+
"title": "Position",
56+
"type": "string",
57+
"enum": ["top-left", "top-right", "bottom-left", "bottom-right"],
58+
"enumNames": {
59+
"top-left": "Top left",
60+
"top-right": "Top right",
61+
"bottom-left": "Bottom left",
62+
"bottom-right": "Bottom right"
63+
},
64+
"default": "bottom-right"
65+
},
66+
"colors": {
67+
"order": 4,
68+
"type": "object",
69+
"title": "Colors",
70+
"properties": {
71+
"toggle": {
72+
"default": "#7289DA",
73+
"format": "color",
74+
"title": "Toggle button",
75+
"type": "string"
76+
},
77+
"button": {
78+
"showIf": {
79+
"tier": {
80+
"op": "!=",
81+
"value": "free"
82+
}
83+
},
84+
"default": "#607CDA",
85+
"format": "color",
86+
"title": "Widget button",
87+
"type": "string"
88+
},
89+
"background": {
90+
"showIf": {
91+
"tier": {
92+
"op": "!=",
93+
"value": "free"
94+
}
95+
},
96+
"default": "#36393E",
97+
"format": "color",
98+
"title": "Widget background",
99+
"type": "string"
100+
}
101+
}
102+
},
103+
"showCustomization": {
104+
"order": 5,
105+
"type": "boolean",
106+
"title": "More customization options",
107+
"default": false
108+
},
109+
"customization": {
110+
"order": 6,
111+
"showIf": {
112+
"buttons[].showCustomization": true
113+
},
114+
"type": "object",
115+
"title": "Customization options",
116+
"properties": {
117+
"image": {
118+
"title": "Custom toggle icon",
119+
"type": "string",
120+
"format": "image"
121+
},
122+
"imageSize": {
123+
"showIf": {
124+
"buttons[].customization.image": {
125+
"op": "!=",
126+
"value": ""
127+
}
128+
},
129+
"title": "Adjust toggle icon zoom",
130+
"type": "number",
131+
"format": "slider",
132+
"default": 50,
133+
"minimum": 0,
134+
"maximum": 200,
135+
"step": 1
136+
},
137+
"showToasts": {
138+
"title": "Enable notifications",
139+
"type": "boolean",
140+
"default": true
141+
},
142+
"indicator": {
143+
"title": "Enable unread indicator",
144+
"type": "boolean",
145+
"default": true
146+
},
147+
"toasts": {
148+
"showIf": {
149+
"buttons[].customization.showToasts": true
150+
},
151+
"type": "object",
152+
"title": "Notification options",
153+
"properties": {
154+
"visibilityTime": {
155+
"title": "Visibility time (seconds)",
156+
"type": "number",
157+
"default": 10
158+
}
159+
}
160+
}
161+
}
162+
},
163+
"showAdvanced": {
164+
"order": 7,
165+
"type": "boolean",
166+
"title": "Show advanced options",
167+
"default": false
168+
},
169+
"advanced": {
170+
"order": 8,
171+
"showIf": {
172+
"buttons[].showAdvanced": true
173+
},
174+
"type": "object",
175+
"title": "Advanced options",
176+
"properties": {
177+
"delay": {
178+
"default": false,
179+
"type": "boolean",
180+
"title": "Delay until interaction",
181+
"description":
182+
"Only load the WidgetBot embed when the user toggles it open"
183+
},
184+
"beta": {
185+
"default": false,
186+
"type": "boolean",
187+
"title": "WidgetBot BETA",
188+
"description":
189+
"<a href=\"https://beta.widgetbot.io\" class=\"more\" target=\"_blank\">Learn more</a>"
190+
}
191+
}
192+
}
193+
}
194+
}
195+
}
196+
}
197+
}
198+
}

media/icon.png

55.3 KB
Loading

media/tile.png

38.3 KB
Loading

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@cloudflare-apps/widgetbot-crate",
3+
"version": "2.0.3",
4+
"description": "Popup Discord chat widgets for your website.",
5+
"main": "app.js",
6+
"private": true,
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/widgetbot-io/crate-cloudflare.git"
10+
},
11+
"license": "MIT",
12+
"bugs": {
13+
"url": "https://github.com/widgetbot-io/crate-cloudflare/issues"
14+
},
15+
"homepage": "https://github.com/widgetbot-io/crate-cloudflare#readme",
16+
"dependencies": {}
17+
}

src/app.js

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
;(function() {
2+
'use strict'
3+
4+
var options = INSTALL_OPTIONS
5+
var js = {
6+
loaded: false
7+
}
8+
9+
js.script = document.createElement('script')
10+
js.script.src = 'https://cdn.jsdelivr.net/npm/@widgetbot/crate@3'
11+
js.script.async = true
12+
js.script.defer = true
13+
14+
if (document.head) {
15+
document.head.appendChild(js.script)
16+
} else {
17+
document.addEventListener('DOMContentLoaded', function() {
18+
document.head.appendChild(js.script)
19+
})
20+
}
21+
22+
js.script.onload = function() {
23+
js.loaded = true
24+
renderApp()
25+
}
26+
27+
function handlerRender() {
28+
if (js.loaded) renderApp()
29+
}
30+
31+
function renderApp() {
32+
if (!window.Crate) return
33+
if (options.buttons) {
34+
if (options.buttons.length) {
35+
// Kill any previous crate instances
36+
var index
37+
if (window.crates) {
38+
for (index = 0, len = window.crates.length; index < len; index++) {
39+
try {
40+
console.debug(
41+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Removing ${index}`,
42+
'color: #40b8ff',
43+
'color: #fff816'
44+
)
45+
window.crates[index].remove()
46+
window.crates.splice(index, 1)
47+
} catch (e) {
48+
console.warn(
49+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Could not remove an existing crate instance, this *may* cause duplication issues`,
50+
'color: #40b8ff',
51+
'color: #fff816',
52+
e
53+
)
54+
}
55+
}
56+
}
57+
for (var i = 0, len = options.buttons.length; i < len; i++) {
58+
var button = options.buttons[i]
59+
var config = {
60+
server: button.server || '339515332702240769', // Default cloudflare discord server,
61+
channel: button.channel || '407710314424172544', // Default cloudflare discord channel
62+
color: button.colors.toggle,
63+
indicator: button.customization.indicator,
64+
timeout: button.customization.toasts.visibilityTime,
65+
notifications: button.customization.showToasts,
66+
location: button.position.split('-'),
67+
defer: button.advanced.delay
68+
}
69+
70+
if (button.customization.image) {
71+
config.glyph = [
72+
button.customization.image,
73+
button.customization.imageSize +
74+
'% ' +
75+
button.customization.imageSize +
76+
'% '
77+
]
78+
}
79+
80+
if (button.advanced.beta) config.shard = 'https://beta.widgetbot.io'
81+
82+
if (i === 0) {
83+
if (window.crate) {
84+
// Update the state without re-mounting
85+
console.debug(
86+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Updating window.crate options`,
87+
'color: #40b8ff',
88+
'color: #fff816'
89+
)
90+
window.crate.setOptions(config)
91+
} else {
92+
console.debug(
93+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Creating window.crate`,
94+
'color: #40b8ff',
95+
'color: #fff816'
96+
)
97+
window.crate = new window.Crate(config)
98+
}
99+
} else {
100+
if (!window.crates) {
101+
console.debug(
102+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Created the window.crates variable`,
103+
'color: #40b8ff',
104+
'color: #fff816'
105+
)
106+
window.crates = []
107+
}
108+
window.crates.push(new Crate(config))
109+
console.debug(
110+
`%c\u2604\uFE0F cloudflare-apps [Crate] %c Pushed ${index} to window.crates`,
111+
'color: #40b8ff',
112+
'color: #fff816',
113+
window.crates
114+
)
115+
}
116+
}
117+
} else if (window.crate && window.crate.state) {
118+
// TODO: Re-implement .remove()
119+
window.crate.hide()
120+
window.crate = null
121+
}
122+
}
123+
// window.crate = new window.Crate({
124+
// })
125+
}
126+
127+
window.INSTALL_SCOPE = {
128+
setOptions: function setOptions(nextOptions) {
129+
options = nextOptions
130+
handlerRender()
131+
}
132+
}
133+
})()

0 commit comments

Comments
 (0)