Skip to content

Commit bcf3c84

Browse files
authored
Merge pull request #256 from polterguy/shadow-dom
Shadow dom
2 parents ba272ee + 09d03d3 commit bcf3c84

File tree

16 files changed

+1149
-1816
lines changed

16 files changed

+1149
-1816
lines changed

backend/files/misc/common-startup-files/default.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ An HTML widget is a small snippet of dynamically created HTML, that can be injec
116116
6. When creating JavaScript for widgets, please account for HTTP endpoints returning nothing. Endpoints returning arrays for instance, will return empty string if there are no items in the array and not `[]`.
117117
7. Offer the user to create an API using the Hyperlambda Generator if the widget the user wants needs backend logic.
118118
8. Do not use inline style attributes when creating widgets, but prefer a `<style>` tag in the HTML itself to apply styling to make it easier to edit the widget's HTML and style properties.
119+
9. Widgets are injected into a shadow DOM container, so you **CANNOT** use `document.querySelector` or `document.getElementById`. Use the following functions instead:
120+
- `ainiro.$` instead of `querySelector`.
121+
- `ainiro.$id` instead of `getElementById`.
122+
- `ainiro.$$` instead of `querySelectorAll`.
119123

120-
**NOTICE** - If a widget is to be associated with an AI chatbot, it is absolutely *crucial* that you apply all styles required to correctly render the widget, and don't rely upon browser defaults at all, since the AI chatbot does `all: initial;` on all style properties. Some CSS properties might also have to be rendered with `!important` for these reaons.
124+
If the user wants a widget with an API, then explicitly ask the user if he or she wants authentication on it or not, and if not, make sure you instruct the Hyperlambda generator to not add authentication requirements.
121125

122126
### Image instructions
123127

@@ -1327,13 +1331,17 @@ This function sends the specified [html] to the client to display it as is. Use
13271331
___
13281332
FUNCTION_INVOCATION[/misc/workflows/workflows/misc/display-widget.hl]:
13291333
{
1330-
"html": "[STRING_VALUE]"
1334+
"html": "[STRING_VALUE]",
1335+
"filename": "[STRING_VALUE]"
13311336
}
13321337
___
13331338

13341339
Arguments;
13351340

1336-
- [html] is mandatory and the HTML to render on the frontend.
1341+
- [html] is a snippet of HTML to render on the frontend.
1342+
- [filename] is a full path to a file that'll be loaded and sent to the frontend.
1343+
1344+
Supply at least one of the arguments, but NOT both!
13371345

13381346
**IMPORTANT** - Remember to always use absolute URLs in your JavaScript if you're invoking the backend. You can find the backend URL further up in this instruction. The widget will be injected into an already preloaded DOM structure, so don't rely upon `DOMContentReady` or similar events.
13391347

backend/files/misc/workflows/workflows/misc/display-widget.hl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,38 @@
1212
// Mandatory argument being the HTML to send to the client.
1313
html:string
1414

15+
// Optional filename argument serving as an alternative to above [html] argument.
16+
filename:string
17+
1518
// Making sure user is allowed to execute function.
1619
auth.ticket.verify:root
1720

18-
// Sanity checking invocation
19-
validators.mandatory:x:@.arguments/*/html
20-
2121
// Buffer for HTML.
2222
.html
23-
set-value:x:@.html
24-
get-value:x:@.arguments/*/html
23+
if
24+
and
25+
exists:x:@.arguments/*/html
26+
not-null:x:@.arguments/*/html
27+
.lambda
28+
set-value:x:@.html
29+
get-value:x:@.arguments/*/html
30+
31+
else-if
32+
33+
and
34+
exists:x:@.arguments/*/filename
35+
not-null:x:@.arguments/*/filename
36+
.lambda
37+
if
38+
not
39+
io.file.exists:x:@.arguments/*/filename
40+
.lambda
41+
throw:"No [html] or [filename] argument provided, provide one of these"
42+
status:int:500
43+
public:bool:true
44+
45+
set-value:x:@.html
46+
io.file.load:x:@.arguments/*/filename
2547

2648
// Verifying this is a valid widget.
2749
if

0 commit comments

Comments
 (0)