-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg-htmx.js
872 lines (827 loc) · 35.3 KB
/
pg-htmx.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
$(function () {
$('body').one('pinegrow-ready', function (e, pinegrow) {
let type_prefix = 'pg-htmx';
var framework = new PgFramework(type_prefix, 'HTMXforPG');
framework.type = 'htmx';
framework.allow_single_type = true;
framework.description = 'This framework adds support for the HTMX library to Pinegrow.';
framework.author = "'Bo' @ springhilldesign.net";
framework.author_link = 'https://plugins.springhilldesign.net';
framework.has_actions = true;
//to keep the plugin loaded between pages and projects we need to set the default to true.
//Comment the line below out to block this behavior
framework.default = true;
pinegrow.addFramework(framework);
//Uncomment the line below to get the inspector window to automatically open
//require('nw.gui').Window.get().showDevTools();
//Adds a menu item for adding the HTMX script
framework.on_page_menu = (page, items) => {
items.push({
type: 'divider'
});
items.push({
type: 'header',
label: 'HTMX'
});
items.push({
label: 'Add HTMX script',
action: function () {
addHTMXScript();
}
});
items.push({
type: 'divider'
})
};
//Function to add HTMX script - ommited version so should load latest
let addHTMXScript = () => {
let thePage = pinegrow.getSelectedPage();
thePage.addScript('https://unpkg.com/htmx.org', true, false, false);
}
/*
This section adds in all of the HTMX attributes.
These are being added to the Actions panel since they can be added to essentially any HTML element.
*/
let htmx_attributes = []; // Attributes to be added to the Actions panel
let boostAttribute = new PgComponentType('htmx-hx-boost', 'hx-Boost', {
selector: '[hx-boost]',
attribute: 'hx-boost',
action: true,
not_main_type: true,
meta: {
helptext: 'Boost normal anchors and form tags to use AJAX. Inheritable.',
helplink: 'https://htmx.org/attributes/hx-boost/',
},
sections: {
hx_att_boost: {
name: 'Boost',
fields: {
hx_boost: {
'name': 'Add hx-boost?',
'type': 'checkbox',
'action': 'element_attribute',
'attribute': 'hx-boost',
'value': 'true',
'attribute_keep_if_empty': true
}
}
}
}
});
htmx_attributes.push(boostAttribute);
let confirmAttribute = new PgComponentType('htmx-hx-confirm', 'hx-Confirm', {
selector: '[hx-confirm]',
attribute: 'hx-confirm',
action: true,
not_main_type: true,
meta: {
helptext: 'Adds a confirmation event prior to action, for example <code>hx-delete</code>.',
helplink: 'https://htmx.org/attributes/hx-confirm/',
},
sections: {
hx_att_confirm: {
name: 'Confirm',
fields: {
hx_confirm: {
'name': 'Confirm message?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-confirm',
'empty_attribute': false
}
}
}
}
});
htmx_attributes.push(confirmAttribute);
let deleteAttribute = new PgComponentType('htmx-hx-delete', 'hx-Delete', {
selector: '[hx-delete]',
attribute: 'hx-delete',
action: true,
not_main_type: true,
meta: {
helptext: 'Issues a DELETE to the specified URL and then swaps the returned HTML into the DOM - use with <code>hx-target</code>.',
helplink: 'https://htmx.org/attributes/hx-delete/'
},
sections: {
hx_att_delete: {
name: 'Delete',
fields: {
hx_delete: {
'name': 'Delete URL?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-delete',
'empty_attribute': false
}
}
}
}
});
htmx_attributes.push(deleteAttribute);
let disableAttribute = new PgComponentType('htmx-hx-disable', 'hx-Disable', {
selector: '[hx-disable]',
attribute: 'hx-disable',
action: true,
not_main_type: true,
meta: {
helptext: 'Disables HTMX processing for a section. Inheritable',
helplink: 'https://htmx.org/attributes/hx-disable/'
},
sections: {
hx_att_disable: {
name: 'Disable',
fields: {
hx_disable: {
'name': 'Disable section?',
'type': 'checkbox',
'action': 'element_attribute',
'attribute': 'hx-disable',
'empty_attribute': true,
'attribute_keep_if_empty': true
}
}
}
}
});
htmx_attributes.push(disableAttribute);
let disinheritAttribute = new PgComponentType('htmx-hx-disinherit', 'hx-Disinherit', {
selector: '[hx-disinherit]',
attribute: 'hx-disinherit',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to control automatic attribute inheritance. An example scenario is to allow you to place an <b>hx-boost</b> on the <b>body</b> element of a page, but overriding that behavior in a specific part of the page to allow for more specific behaviors. Examples: <code>hx-disinherit=\'*\'</code> all attribute inheritance for this element will be disabled, <code>hx-disinherit=\'hx-select hx-get hx-target\'</code> disable inheritance for only one or multiple specified attributes',
helplink: 'https://htmx.org/attributes/hx-disinherit/'
},
sections: {
hx_att_disinherit: {
name: 'Disinherit',
fields: {
hx_disinherit: {
'name': 'Disinherit parent attribute?',
'type': 'input',
'action': 'element_attribute',
'attribute': 'hx-disinherit',
'empty_attribute': false
}
}
}
}
});
htmx_attributes.push(disinheritAttribute);
let encodingAttribute = new PgComponentType('htmx-hx-encoding', 'hx-Encoding', {
selector: '[hx-encoding]',
attribute: 'hx-encoding',
action: true,
not_main_type: true,
meta: {
helptext: 'Changes encoding to <code>multipart/form-data</code> for section. Inheritable',
helplink: 'https://htmx.org/attributes/hx-encoding/'
},
sections: {
hx_att_encoding: {
name: 'Encoding',
fields: {
hx_encoding: {
'name': 'Change encoding?',
'type': 'checkbox',
'action': 'element_attribute',
'attribute': 'hx-encoding',
'empty_attribute': false,
'attribute_keep_if_empty': false,
'value': 'multipart/form-data'
}
}
}
}
});
htmx_attributes.push(encodingAttribute);
let extAttribute = new PgComponentType('htmx-hx-ext', 'hx-Ext', {
selector: '[hx-ext]',
attribute: 'hx-ext',
action: true,
not_main_type: true,
meta: {
helptext: 'Enables an HTMX extension for a section. For multiple extensions add a comma separated list. Inheritable. Use the \'ignore:\' prefix on children that you don\'t want to target.',
helplink: 'https://htmx.org/attributes/hx-ext/'
},
sections: {
hx_att_ext: {
name: 'Ext',
fields: {
hx_ext: {
'name': 'Extension name(s)?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-ext',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(extAttribute);
let getAttribute = new PgComponentType('htmx-hx-get', 'hx-Get', {
selector: '[hx-get]',
attribute: 'hx-get',
action: true,
not_main_type: true,
meta: {
helptext: 'Issues a GET to the specified URL and then swaps the returned HTML into the DOM - use with <code>hx-target</code>.',
helplink: 'https://htmx.org/attributes/hx-get/'
},
sections: {
hx_att_get: {
name: 'get',
fields: {
hx_get: {
'name': 'GET URL?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-get',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(getAttribute);
let headersAttribute = new PgComponentType('htmx-hx-headers', 'hx-Headers', {
selector: '[hx-headers]',
attribute: 'hx-headers',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to add to the AJAX headers. Should be valid JSON, but can be evaluated by prefixing with <code>js:</code>. Inheritable, but overridden by child declaration.',
helplink: 'https://htmx.org/attributes/hx-headers/'
},
sections: {
hx_att_headers: {
name: 'headers',
fields: {
hx_headers: {
'name': 'Header JSON (should be surrounded by {}).',
'placeholder': '{"myHeader": "My Value"}',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-headers',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(headersAttribute);
let historyeltAttribute = new PgComponentType('htmx-hx-history-elt', 'hx-History-Elt', {
selector: '[hx-history-elt]',
attribute: 'hx-history-elt',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to specify an element to snapahot and restore page state. Usually added to the body element',
helplink: 'https://htmx.org/attributes/hx-history-elt/'
},
sections: {
hx_att_history_elt: {
name: 'history-elt',
fields: {
hx_history_elt: {
'name': 'Add attribute?',
'type': 'checkbox',
'action': 'element_attribute',
'attribute': 'hx-history-elt',
'empty_attribute': true,
'attribute_keep_if_empty': true
}
}
}
}
});
htmx_attributes.push(historyeltAttribute);
let includeAttribute = new PgComponentType('htmx-hx-include', 'hx-Include', {
selector: '[hx-include]',
attribute: 'hx-include',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows inclusion of additional values in AJAX request. Inheritable.',
helplink: 'https://htmx.org/attributes/hx-include/'
},
sections: {
hx_att_include: {
name: 'Include',
fields: {
hx_include: {
'name': 'CSS selector?',
'placeholder': '[name="email"]',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-include',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(includeAttribute);
let indicatorAttribute = new PgComponentType('htmx-hx-indicator', 'hx-Indicator', {
selector: '[hx-indicator]',
attribute: 'hx-indicator',
action: true,
not_main_type: true,
meta: {
helptext: 'Specifies the element that will have the <code>htmx-request</code> class added and takes a CSS query selector with or without the closest keyword, (e.g. <code>closest tr</code>).',
helplink: 'https://htmx.org/attributes/hx-indicator/'
},
sections: {
hx_att_indicator: {
name: 'Indicator',
fields: {
hx_indicator: {
'name': 'CSS selector?',
'placeholder': '#spinner',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-indicator',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(indicatorAttribute);
let paramsAttribute = new PgComponentType('htmx-hx-params', 'hx-Params', {
selector: '[hx-params]',
attribute: 'hx-params',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to filter the parameters submitted with an AJAX request. Takes \'*\', \'none\', \'not <param-list>\', or \'<param-list>\' with the list as a comma separated list of names. Inhertitable.',
helplink: 'https://htmx.org/attributes/hx-params/'
},
sections: {
hx_att_params: {
name: 'Params',
fields: {
hx_params: {
'name': 'Parameters?',
'placeholder': '*',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-params',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(paramsAttribute);
let patchAttribute = new PgComponentType('htmx-hx-patch', 'hx-Patch', {
selector: '[hx-patch]',
attribute: 'hx-patch',
action: true,
not_main_type: true,
meta: {
helptext: 'Submits a PATCH to the specified URL and swaps the returned HTML into the DOM - use with <code>hx-target</code>.',
helplink: 'https://htmx.org/attributes/hx-params/'
},
sections: {
hx_att_patch: {
name: 'Patch',
fields: {
hx_patch: {
'name': 'URL?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-patch',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(patchAttribute);
let postAttribute = new PgComponentType('htmx-hx-post', 'hx-Post', {
selector: '[hx-post]',
attribute: 'hx-post',
action: true,
not_main_type: true,
meta: {
helptext: 'Submits a POST to the specified URL and swaps the returned HTML into the DOM - use with <code>hx-target</code>.',
helplink: 'https://htmx.org/attributes/hx-post/'
},
sections: {
hx_att_post: {
name: 'Post',
fields: {
hx_post: {
'name': 'URL?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-post',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(postAttribute);
let preserveAttribute = new PgComponentType('htmx-hx-preserve', 'hx-Preserve', {
selector: '[hx-preserve]',
attribute: 'hx-preserve',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows a section of content to remain unchanged between HTML replacement. Element <i>must</i> have an <b>id</b>.',
helplink: 'https://htmx.org/attributes/hx-preserve/'
},
sections: {
hx_att_preserve: {
name: 'Preserve',
fields: {
hx_preserve: {
'name': 'Preserve section?',
'type': 'checkbox',
'action': 'element_attribute',
'attribute': 'hx-preserve',
'value': true
}
}
}
}
});
htmx_attributes.push(preserveAttribute);
let promptAttribute = new PgComponentType('htmx-hx-prompt', 'hx-Prompt', {
selector: '[hx-prompt]',
attribute: 'hx-prompt',
action: true,
not_main_type: true,
meta: {
helptext: 'Shows a prompt and collects value before issuing a request. Value is added into header. Inherited.',
helplink: 'https://htmx.org/attributes/hx-prompt/'
},
sections: {
hx_att_prompt: {
name: 'Prompt',
fields: {
hx_post: {
'name': 'Prompt?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-prompt',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(promptAttribute);
let push_urlAttribute = new PgComponentType('htmx-hx-push-url', 'hx-Push-Url', {
selector: '[hx-push-url]',
attribute: 'hx-push-url',
action: true,
not_main_type: true,
meta: {
helptext: 'Pushes a new entry into the browser location bar and creates a history entry. Can be \'true\', \'false\', or a custom string. Inherited.',
helplink: 'https://htmx.org/attributes/hx-push-url/'
},
sections: {
hx_att_push_url: {
name: 'Push-url',
fields: {
hx_post: {
'name': 'String?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-push-url',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(push_urlAttribute);
let putAttribute = new PgComponentType('htmx-hx-put', 'hx-Put', {
selector: '[hx-put]',
attribute: 'hx-put',
action: true,
not_main_type: true,
meta: {
helptext: 'Submits a PUT to the specified URL and swaps the returned HTML into the DOM - use with <code>hx-target</code>.',
helplink: 'https://htmx.org/attributes/hx-put/'
},
sections: {
hx_att_put: {
name: 'Put',
fields: {
hx_put: {
'name': 'URL?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-put',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(putAttribute);
let requestAttribute = new PgComponentType('htmx-hx-request', 'hx-Request', {
selector: '[hx-request]',
attribute: 'hx-request',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to configure various aspects of the request. Takes \'timeout\' in ms, \'credentials\', or \'noHeaders\'. Special characters should be escaped and <code>js:</code> can be used to pass a function. Inheritable.',
helplink: 'https://htmx.org/attributes/hx-request/'
},
sections: {
hx_att_request: {
name: 'Request',
fields: {
hx_request: {
'name': 'Request value?',
'placeholder': '\'timeout\':100',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-request',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(requestAttribute);
let selectAttribute = new PgComponentType('htmx-hx-select', 'hx-Select', {
selector: '[hx-select]',
attribute: 'hx-select',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to select content to be swapped from a response using a CSS selector. Inheritable.',
helplink: 'https://htmx.org/attributes/hx-select/'
},
sections: {
hx_att_select: {
name: 'Select',
fields: {
hx_select: {
'name': 'CSS selector?',
'placeholder': '#info-details',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-select',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(selectAttribute);
let sseAttribute = new PgComponentType('htmx-hx-sse', 'hx-Sse', {
selector: '[hx-sse]',
attribute: 'hx-sse',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to work with <a href=\'https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events\' target=\'_blank\'>Server Sent Event</a> <b>EventSources</b> directly from HTML. The value of the attribute can be one or more of the following, separated by white space: connect:<url> or swap<eventName>. Inheritable.',
helplink: 'https://htmx.org/attributes/hx-sse/'
},
sections: {
hx_att_sse: {
name: 'Sse',
fields: {
hx_sse: {
'name': 'Events?',
'placeholder': 'connect:/event_stream swap:eventName',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-sse',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(sseAttribute);
let swapoobAttribute = new PgComponentType('htmx-hx-swap-oob', 'hx-Swap-oob', {
selector: '[hx-swap-oob]',
attribute: 'hx-swap-oob',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to specify content to be swapped into the DOM other than at the target. Values can be \'true\', <hx-swap value>, or <hx-swap value>:<CSS selector>.',
helplink: 'https://htmx.org/attributes/hx-swap-oob/'
},
sections: {
hx_att_swap_oob: {
name: 'Swap-oob',
fields: {
hx_swap_oob: {
'name': 'Value?',
'placeholder': 'afterend:#alert',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-swap-oob',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(swapoobAttribute);
let swapAttribute = new PgComponentType('htmx-hx-swap', 'hx-Swap', {
selector: '[hx-swap]',
attribute: 'hx-swap',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to specify how the response will be swapped relative to the target of an AJAX request.',
helplink: 'https://htmx.org/attributes/hx-swap/'
},
sections: {
hx_att_swap: {
name: 'Swap',
fields: {
hx_swap: {
'name': 'Swap type?',
'type': 'select',
'action': 'element_attribute',
'attribute': 'hx-swap',
'options': [
{
key: 'innerHTML',
name: 'innerHTML'
},
{
key: 'outerHTML',
name: 'outerHTML'
},
{
key: 'beforebegin',
name: 'beforebegin'
},
{
key: 'afterbegin',
name: 'afterbegin'
},
{
key: 'beforeend',
name: 'beforeend'
},
{
key: 'afterend',
name: 'afterend'
},
{
key: 'none',
name: 'none'
}
],
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(swapAttribute);
let syncAttribute = new PgComponentType('htmx-hx-sync', 'hx-Sync', {
selector: '[hx-sync]',
attribute: 'hx-sync',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to synchronize AJAX requests between multiple elements. Takes the form of a <CSS selector> or <code>this</code>, followed by an optional colon and synching strategy. Strategies are: \'drop\', \'abort\', \'replace\', or \'queue\'. It can also take a <code>queue</code> modifier of \'first\', \'last\', or \'all\'. It is inherited and can be placed on a parent.',
helplink: 'https://htmx.org/attributes/hx-sync/'
},
sections: {
hx_att_sync: {
name: 'Sync',
fields: {
hx_sync: {
'name': 'Sync value?',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-sync',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(syncAttribute);
let targetAttribute = new PgComponentType('htmx-hx-target', 'hx-Target', {
selector: '[hx-target]',
attribute: 'hx-target',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to target a different element for swapping than the AJAX request element. Can be a CSS query, <b>this</b>, <b>closest <CSS selector></b>,or <b>find <CSS selector></b>.',
helplink: 'https://htmx.org/attributes/hx-target/'
},
sections: {
hx_att_target: {
name: 'Target',
fields: {
hx_target: {
'name': 'Target selector?',
'placeholder': 'closest tr',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-target',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(targetAttribute);
let triggerAttribute = new PgComponentType('htmx-hx-trigger', 'hx-Trigger', {
selector: '[hx-trigger]',
attribute: 'hx-trigger',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to specify what triggers an AJAX response. Can be an event name (with filters and modifiers), a polling def. of the form <b>every <timing declaration></b>, or comma-separated list of events.',
helplink: 'https://htmx.org/attributes/hx-trigger/'
},
sections: {
hx_att_trigger: {
name: 'Trigger',
fields: {
hx_trigger: {
'name': 'Trigger?',
'placeholder': 'keyup changed delay:1s',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-trigger',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(triggerAttribute);
let valsAttribute = new PgComponentType('htmx-hx-vals', 'hx-Vals', {
selector: '[hx-vals]',
attribute: 'hx-vals',
action: true,
not_main_type: true,
meta: {
helptext: 'Allows you to add to the parameters submitted with an AJAX request. Typically in JSON surrounded by {}, but can be prefixed with <code>javascript:</code> for evaluation. Inherited, but a child declaration will override.',
helplink: 'https://htmx.org/attributes/hx-vals/'
},
sections: {
hx_att_vals: {
name: 'vals',
fields: {
hx_vals: {
'name': 'Trigger?',
'placeholder': '{"myVal": "My Value"}',
'type': 'text',
'action': 'element_attribute',
'attribute': 'hx-vals',
'empty_attribute': false,
'attribute_keep_if_empty': false
}
}
}
}
});
htmx_attributes.push(valsAttribute);
//function to add all of the components
let addComponentTypesToPG = (list) => {
list.forEach(component => {
framework.addComponentType(component);
});
};
//Add all of the defined components
addComponentTypesToPG(htmx_attributes);
//Define all of our sections
//Actions
let section = new PgFrameworkLibSection('htmxattributesactions', 'Attributes');
section.setComponentTypes(htmx_attributes);
section.closed = true;
framework.addActionsSection(section);
});
});