This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
hax-store.html
1730 lines (1709 loc) · 69.6 KB
/
hax-store.html
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
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../media-behaviors/media-behaviors.html">
<link rel="import" href="../hax-body-behaviors/hax-body-behaviors.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="hax-app.html">
<link rel="import" href="hax-stax.html">
<link rel="import" href="hax-stax-browser.html">
<link rel="import" href="hax-blox.html">
<link rel="import" href="hax-blox-browser.html">
<!--
`hax-store`
The storage area for all valid custom elements to drop into HAX. This element lives at the top level and lazy-loads all the possible elements that could be added to the document. It also helps with building the hax-panel options as well as brokering what tags register as valid when doing sanitization requests.
@demo demo/index.html
@microcopy - the mental model for this element
- store - a location that is the source of truth for allowed hax custom elements.
- hax-body - the routing board doing all the work for the UI
- app - an end point / structure for an API that HAX knows how to interface with
- hax-panel - a side pallet of options which allows one to select items that they want to add to hax-body.
- element - a custom element tag / node
- hax element - a simplified DOM node that is tag, properties, slot content as Object key names.
-->
<dom-module id="hax-store">
<template>
<style>
:host {
display: none;
}
</style>
<slot></slot>
<iron-ajax id="appstore" url="[[appStore.url]]" params="[[appStore.params]]" method="GET" content-type="application/json"
handle-as="json" last-response="{{__appStoreData}}"></iron-ajax>
</template>
<script>
(function () {
'use strict';
Polymer.HaxStore = Polymer({
is: 'hax-store',
behaviors: [
MediaBehaviors.Video,
HAXBehaviors.PropertiesBehaviors,
],
observers: [
'_loadAppStoreData(__appStoreData, haxAutoloader)',
],
properties: {
/**
* Hax app picker element.
*/
haxAppPicker: {
type: Object,
},
/**
* Hax stax picker element.
*/
haxStaxPicker: {
type: Object,
},
/**
* Hax manager element.
*/
haxManager: {
type: Object,
},
/**
* Hax autoloader element.
*/
haxAutoloader: {
type: Object,
},
/**
* A list of all haxBodies that exist
*/
haxBodies: {
type: Array,
value: [],
},
/**
* An active place holder item reference. This is used
* for inline drag and drop event detection so that we
* know what element replace in context.
*/
activePlaceHolder: {
type: Object,
value: null,
},
/**
* The hax-body that is currently active.
*/
activeHaxBody: {
type: Object,
},
/**
* Possible appStore endpoint for loading in things dynamically.
*/
appStore: {
type: Object,
observer: '_appStoreChanged',
},
/**
* HAX Toast message.
*/
haxToast: {
type: Object,
},
/**
* Hax panel element.
*/
haxPanel: {
type: Object,
},
/**
* Hax export dialog element.
*/
haxExport: {
type: Object,
},
/**
* Hax preferences dialog element.
*/
haxPreferences: {
type: Object,
},
/**
* Active HAX Element if we have one we are working on.
*/
activeHaxElement: {
type: Object,
},
/**
* Active Node.
*/
activeNode: {
type: Object,
},
/**
* Active container Node, 2nd highest parent of activeNode.
*/
activeContainerNode: {
type: Object,
},
/**
* editMode
*/
editMode: {
type: Boolean,
value: false,
},
/**
* Boolean for if this instance has backends that support uploading
*/
canSupportUploads: {
type: Boolean,
value: false,
},
/**
* skip the exit trap to prevent losing data
*/
skipExitTrap: {
type: Boolean,
value: false,
},
/**
* Default settings that can be overridden as needed
*/
defaults: {
type: Object,
value: {
image: {
'src': 'stock.jpg',
'alt': 'A beachfront deep in the heart of Alaska.',
},
iframe: {
'src': 'https://www.wikipedia.org/',
},
},
},
/**
* Available gizmos.
*/
gizmoList: {
type: Array,
value: [],
},
/**
* Available elements keyed by tagName and with
* their haxProperties centrally registered.
*/
elementList: {
type: Object,
value: {},
},
/**
* Available apps of things supplying media / content.
*/
appList: {
type: Array,
value: [],
},
/**
* Available hax stax which are just re-usable templates
*/
staxList: {
type: Array,
value: [],
},
/**
* Available hax blox which are grid plate / layout elements
*/
bloxList: {
type: Array,
value: [],
},
/**
* Global preferences that HAX can write to and
* other elements can use to go off of.
*/
globalPreferences: {
type: Object,
value: {},
},
/**
* Globally active app, used for brokering communications
*/
activeApp: {
type: Object,
value: {},
},
/**
* Valid tag list, tag only and including primatives for a baseline.
*/
validTagList: {
type: Array,
value: ['p', 'div', 'ol', 'ul', 'li', 'a', 'strong', 'kbd', 'em', 'i', 'b', 'hr', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code', 'figure', 'img', 'iframe', 'video', 'audio', 'section', 'grid-plate', 'template', 'webview'],
},
/**
* Gizmo types which can be used to bridge apps to gizmos.
*/
validGizmoTypes: {
type: Array,
value: ['data', 'video', 'audio', 'text', 'link', 'file', 'pdf', 'image', 'csv', 'doc', 'content', 'text', 'inline', '*'],
},
/**
* Sandboxed environment test
*/
_isSandboxed: {
type: Boolean,
value: function () {
let test = document.createElement('webview');
// if this function exists it means that our deploy target
// is in a sandboxed environment and is not able to run iframe
// content with any real stability. This is beyond edge case but
// as this is an incredibly useful tag we want to make sure it
// can mutate to work in chromium and android environments
// which support such sandboxing
if (typeof test.reload === 'function') {
return true;
}
return false;
},
},
/**
* Internal app store data property after request
*/
__appStoreData: {
type: Object,
},
},
/**
* If this is a text node or not so we know if the inline context
* operations are valid.
*/
isTextElement: function (node) {
let tag = node.tagName.toLowerCase();
if (this.validTagList.includes(tag)) {
if (['p', 'ol', 'ul', 'li', 'a', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code', 'figure'].includes(tag)) {
return true;
}
}
return false;
},
/**
* test for being a valid grid plate, li is here because
* nested lists make this really complicated
*/
isGridPlateElement: function (node) {
let tag = node.tagName.toLowerCase();
if (this.validTagList.includes(tag)) {
if (['p', 'ol', 'ul', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'code', 'figure', 'grid-plate'].includes(tag)) {
return true;
}
}
return false;
},
/**
* Notice _appStore changed.
*/
_appStoreChanged: function (newValue, oldValue) {
// if we have an endpoint defined, pull it
if (typeof newValue !== typeof undefined) {
// support having the request or remote loading
// depending on the integration type
if (typeof newValue.apps === typeof undefined) {
this.$.appstore.generateRequest();
}
else {
this.__appStoreData = newValue;
}
}
},
/**
* Load and attach items from the app store.
*/
_loadAppStoreData: function (appDataResponse, haxAutoloader) {
if (typeof appDataResponse !== typeof undefined) {
// autoload elements
if (typeof appDataResponse.autoloader !== typeof undefined) {
for (var i = 0; i < appDataResponse.autoloader.length; i++) {
let loader = document.createElement(appDataResponse.autoloader[i]);
Polymer.dom(haxAutoloader).appendChild(loader);
}
}
// load apps automatically
if (typeof appDataResponse.apps !== typeof undefined) {
var apps = appDataResponse.apps;
for (var i = 0; i < apps.length; i++) {
let app = document.createElement('hax-app');
app.data = apps[i];
// see if anything coming across claims to be a backend for adding items
// and then enable the upload button
if (typeof apps[i].connection.operations.add !== typeof undefined) {
this.async(() => {
Polymer.HaxStore.write('canSupportUploads', true, this);
}); }
Polymer.HaxStore.instance.appendChild(app);
}
}
// load in stax dynamically
if (typeof appDataResponse.stax !== typeof undefined) {
var staxs = appDataResponse.stax;
for (var i = 0; i < staxs.length; i++) {
let stax = document.createElement('hax-stax');
stax.data = staxs[i];
Polymer.HaxStore.instance.appendChild(stax);
}
}
// load in blox dynamically
if (typeof appDataResponse.blox !== typeof undefined) {
var bloxs = appDataResponse.blox;
for (var i = 0; i < bloxs.length; i++) {
let blox = document.createElement('hax-blox');
blox.data = bloxs[i];
Polymer.HaxStore.instance.appendChild(blox);
}
}
}
},
/**
* Detached life cycle
*/
detached: function () {
// notice hax property definitions coming from anywhere
document.body.removeEventListener('hax-register-properties', this._haxStoreRegisterProperties.bind(this));
// app registration can come in automatically from app-stores
// or through direct definition in the DOM
document.body.removeEventListener('hax-register-app', this._haxStoreRegisterApp.bind(this));
// register stax which are groupings of haxElements
document.body.removeEventListener('hax-register-stax', this._haxStoreRegisterStax.bind(this));
// register blox which are grid plate configurations
// with lots of sane visual defaults
document.body.removeEventListener('hax-register-blox', this._haxStoreRegisterBlox.bind(this));
// register the pieces of the body of what we call HAX
// think of this like the core of the system required
// to do anything like have buttons or state management
// write data to the store
document.body.removeEventListener('hax-store-write', this._writeHaxStore.bind(this));
// register the manager panel / modal
document.body.removeEventListener('hax-register-manager', this._haxStoreRegisterManager.bind(this));
// register the autoloader area for elements
document.body.removeEventListener('hax-register-autoloader', this._haxStoreRegisterAutoloader.bind(this));
// register a body, kind of a big deal
document.body.removeEventListener('hax-register-body', this._haxStoreRegisterBody.bind(this));
// register the interaction panel / menu
document.body.removeEventListener('hax-register-panel', this._haxStoreRegisterPanel.bind(this));
// register the app picker for contextual setting / option
document.body.removeEventListener('hax-register-app-picker', this._haxStoreRegisterAppPicker.bind(this));
// stax modal
document.body.removeEventListener('hax-register-stax-picker', this._haxStoreRegisterStaxPicker.bind(this));
// blox modal
document.body.removeEventListener('hax-register-blox-picker', this._haxStoreRegisterBloxPicker.bind(this));
// preferences modal
document.body.removeEventListener('hax-register-preferences', this._haxStoreRegisterPreferences.bind(this));
// export modal
document.body.removeEventListener('hax-register-export', this._haxStoreRegisterExport.bind(this));
// notice content insert and help it along to the body
document.body.removeEventListener('hax-insert-content', this._haxStoreInsertContent.bind(this));
},
/**
* attached.
*/
attached: function () {
window.onbeforeunload = function () {
// ensure we don't leave DURING edit mode
if (!Polymer.HaxStore.instance.skipExitTrap && Polymer.HaxStore.instance.editMode) {
return 'Are you sure you want to leave? Your work will not be saved!';
}
}
window.addEventListener("paste", (e) => {
// only perform this on a text element that is active
if (this.isTextElement(Polymer.HaxStore.instance.activeNode) && !this.haxManager.opened) {
e.preventDefault();
let text = '';
// intercept paste event
if (e.clipboardData || e.originalEvent.clipboardData) {
text = (e.originalEvent || e).clipboardData.getData('text/plain');
} else if (window.clipboardData) {
text = window.clipboardData.getData('Text');
}
let sel, range, html;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(document.createTextNode(text));
}
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().text = text;
}
}
});
// capture events and intercept them globally
window.addEventListener('keypress', (event) => {
const keyName = event.key;
// if we are editing and enter is pressed see if we should
// process it or inject a new p tag
if (typeof Polymer.HaxStore.instance.activeContainerNode !== typeof undefined && keyName === 'Enter' && Polymer.HaxStore.instance.editMode && Polymer.HaxStore.instance.activeNode !== null && Polymer.HaxStore.instance.activeContainerNode === Polymer.HaxStore.instance.activeNode && !Polymer.HaxStore.instance.haxAppPicker.opened) {
const activeNodeTagName = Polymer.HaxStore.instance.activeContainerNode.tagName;
var selection = window.getSelection();
const range = selection.getRangeAt(0).cloneRange();
var tagTest = range.commonAncestorContainer.tagName;
if (typeof tagTest === typeof undefined) {
tagTest = range.commonAncestorContainer.parentNode.tagName;
}
// test if we want to touch Enter based on tag name and range
// we ignore Enter for our purposes when in a list
if (['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6'].includes(activeNodeTagName) && !['UL', 'OL', 'LI'].includes(tagTest)) {
// we need to do goofy stuff for p tags since people
// will expect to be able to split them mid typing
if (range.endOffset !== this.activeContainerNode.textContent.length) {
event.preventDefault();
// create a cloned range where it's sitting
range.setStart(selection.focusNode, range.startOffset);
// generate a completely fake element and insert it so we
// track it's position as a "split point"
var frag = document.createRange().createContextualFragment('<hax-split-point></hax-split-point>');
range.insertNode(frag);
// force this to be a constant since activeNode will
// change mid operation but we want limit to remain
// as a pointer to it's position in the DOM
const limit = Polymer.HaxStore.instance.activeContainerNode;
var node = Polymer.dom(Polymer.HaxStore.instance.activeContainerNode).querySelector('hax-split-point');
// run a split node function as modified from stackoverflow
if (node != null) {
try {
this.__splitNode(node, limit);
}
catch (e) {
}
}
}
else {
event.preventDefault();
Polymer.HaxStore.instance.fire('hax-insert-content', {
tag: 'p',
content: '',
});
}
}
}
});
this._injectToast();
// register built in primitive definitions
this._buildPrimitiveDefinitions();
},
/**
* Magic node splitting function
*/
__splitNode: function (node, limit) {
// kick off activeNode so that we drop classes / cruft
Polymer.HaxStore.write('activeNode', null, this);
// allow that to have processed...
setTimeout(() => {
// find the parent of the item we are splicing
var parent = limit.parentNode;
// get the index of this selected text way down below
var parentOffset = this.__getNodeIndex(parent, limit);
var doc = node.ownerDocument;
// make a fake range of these section of the DOM
var leftRange = doc.createRange();
// start it at the beginning of the element and run it to
// just before that place holder we are targeting
leftRange.setStart(parent, parentOffset);
leftRange.setEndBefore(node);
// convert this front portion into a document fragment
var left = leftRange.extractContents();
// insert this fragment just before the activeNode.
// This probably looks weird but effectively we copy the
// element in these operations and then insert the thing
// next to itself. The extractContents function generates
// a node from the part of the previous one as well as
// deletes what was there from the DOM. This effectively
// lets us take 1 element and split it into two at the
// cursor position as triggered by an Enter press. Insane.
Polymer.dom(this.activeHaxBody).insertBefore(left, limit);
// remove the place holder
node.parentNode.removeChild(node);
// set active back to what it was, technically moved down
// in the document order because of above
Polymer.HaxStore.write('activeNode', limit, this);
}, 100);
},
/**
* Get node index within a parent item so we know
* how far down the object to look for it's position.
* This is a helper with no other meaningful purpose.
*/
__getNodeIndex: function (parent, node) {
var index = parent.childNodes.length;
while (index--) {
if (node === parent.childNodes[index]) {
break;
}
}
return index;
},
/**
* Created life-cycle to ensure a single global store.
*/
created: function () {
window.__startedSelection = false;
// claim the instance spot. This way we can easily
// be referenced globally
if (!Polymer.HaxStore.instance) {
Polymer.HaxStore.instance = this;
}
// notice hax property definitions coming from anywhere
document.body.addEventListener('hax-register-properties', this._haxStoreRegisterProperties.bind(this));
// app registration can come in automatically from app-stores
// or through direct definition in the DOM
document.body.addEventListener('hax-register-app', this._haxStoreRegisterApp.bind(this));
// register stax which are groupings of haxElements
document.body.addEventListener('hax-register-stax', this._haxStoreRegisterStax.bind(this));
// register blox which are grid plate configurations
// with lots of sane visual defaults
document.body.addEventListener('hax-register-blox', this._haxStoreRegisterBlox.bind(this));
// register the pieces of the body of what we call HAX
// think of this like the core of the system required
// to do anything like have buttons or state management
// write data to the store
document.body.addEventListener('hax-store-write', this._writeHaxStore.bind(this));
// register the manager panel / modal
document.body.addEventListener('hax-register-manager', this._haxStoreRegisterManager.bind(this));
// register the autoloader area for elements
document.body.addEventListener('hax-register-autoloader', this._haxStoreRegisterAutoloader.bind(this));
// register a body, kind of a big deal
document.body.addEventListener('hax-register-body', this._haxStoreRegisterBody.bind(this));
// register the interaction panel / menu
document.body.addEventListener('hax-register-panel', this._haxStoreRegisterPanel.bind(this));
// register the app picker for contextual setting / option
document.body.addEventListener('hax-register-app-picker', this._haxStoreRegisterAppPicker.bind(this));
// stax modal
document.body.addEventListener('hax-register-stax-picker', this._haxStoreRegisterStaxPicker.bind(this));
// blox modal
document.body.addEventListener('hax-register-blox-picker', this._haxStoreRegisterBloxPicker.bind(this));
// preferences modal
document.body.addEventListener('hax-register-preferences', this._haxStoreRegisterPreferences.bind(this));
// export modal
document.body.addEventListener('hax-register-export', this._haxStoreRegisterExport.bind(this));
// notice content insert and help it along to the body
document.body.addEventListener('hax-insert-content', this._haxStoreInsertContent.bind(this));
document.body.style.setProperty('--hax-ui-headings', '#d4ff77');
},
/**
* Build HAX property definitions for primitives that we support.
*/
_buildPrimitiveDefinitions: function () {
// sandboxes need a webview definition
// we don't want people making them but we need to
// know how to edit them if asked
if (Polymer.HaxStore.instance._isSandboxed) {
let webview = {
'canScale': true,
'canPosition': true,
'canEditSource': false,
'settings': {
'quick': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
],
'configure': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
],
'advanced': []
}
};
this.setHaxProperties(webview, 'webview');
}
let iframe = {
'canScale': true,
'canPosition': true,
'canEditSource': true,
'gizmo': {
'title': 'Basic iframe',
'description': 'A basic iframe',
'icon': 'icons:fullscreen',
'color': 'grey',
'groups': ['Content'],
'handles': [
{
'type': 'link',
'source': 'src',
'height': 'height',
'width': 'width',
},
],
'meta': {
'author': 'W3C'
}
},
'settings': {
'quick': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
],
'configure': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
],
'advanced': []
}
};
this.setHaxProperties(iframe, 'iframe');
let img = {
'canScale': true,
'canPosition': true,
'canEditSource': false,
'gizmo': {
'title': 'Basic image',
'description': 'A basic img tag',
'icon': 'image:image',
'color': 'grey',
'groups': ['Image', 'Media'],
'handles': [
{
'type': 'link',
'source': 'src'
},
{
'type': 'image',
'source': 'src',
'height': 'height',
'width': 'width',
},
],
'meta': {
'author': 'W3C'
}
},
'settings': {
'quick': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
{
'attribute': 'alt',
'title': 'Alt text',
'description': 'Useful for screen readers and improved SEO.',
'inputMethod': 'alt',
'icon': 'accessibility',
},
{
'attribute': 'height',
'title': 'Height',
'description': 'height in pixels of the item',
'inputMethod': 'textfield',
'icon': 'icons:swap-vert',
},
{
'attribute': 'width',
'title': 'Width',
'description': 'width in pixels of the item',
'inputMethod': 'textfield',
'icon': 'icons:swap-horiz',
},
],
'configure': [
{
'attribute': 'src',
'title': 'Source',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'link',
'required': true,
'validationType': 'url',
},
{
'attribute': 'alt',
'title': 'Alt text',
'description': 'Useful for screen readers and improved SEO.',
'inputMethod': 'alt',
'icon': 'accessibility',
},
{
'attribute': 'height',
'title': 'Height',
'description': 'height in pixels of the item',
'inputMethod': 'textfield',
'icon': 'icons:swap-vert',
},
{
'attribute': 'width',
'title': 'Width',
'description': 'width in pixels of the item',
'inputMethod': 'textfield',
'icon': 'icons:swap-horiz',
},
],
'advanced': []
}
};
this.setHaxProperties(img, 'img');
let ahref = {
'canScale': false,
'canPosition': false,
'canEditSource': false,
'gizmo': {
'title': 'Basic link',
'description': 'A basic a tag',
'icon': 'icons:link',
'color': 'grey',
'groups': ['Link'],
'handles': [
{
'type': 'link',
'source': 'href',
'title': 'innerText',
'alt': 'title',
}
],
'meta': {
'author': 'W3C'
}
},
'settings': {
'quick': [
{
'attribute': 'href',
'title': 'Link',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'icons:link',
'required': true,
'validationType': 'url',
},
{
'attribute': 'title',
'title': 'Title text',
'description': 'Useful for screen readers and improved SEO.',
'inputMethod': 'textfield',
'icon': 'icons:accessibility',
},
],
'configure': [
{
'attribute': 'innerText',
'title': 'Text',
'description': 'Text of the link',
'inputMethod': 'textfield',
'required': true,
},
{
'attribute': 'href',
'title': 'Link',
'description': 'The URL for this video.',
'inputMethod': 'textfield',
'icon': 'icons:link',
'required': true,
'validationType': 'url',
},
{
'attribute': 'title',
'title': 'Title text',
'description': 'Useful for screen readers and improved SEO.',
'inputMethod': 'textfield',
'icon': 'icons:accessibility',
},
{
'attribute': 'target',
'title': 'Target',
'description': 'Where to place the link.',
'inputMethod': 'select',
'icon': 'icons:launch',
'options': {
'': 'Same window',
'_blank': 'New window',
'_top': 'Top window',
'_parent': 'Parent window',
}
},
],
'advanced': []
}
};
this.setHaxProperties(ahref, 'a');
let p = {
'canScale': false,
'canPosition': false,
'canEditSource': true,
'settings': {
'quick': [],
'configure': [],
'advanced': []
}
};
this.setHaxProperties(p, 'p');
let hr = {
'canScale': true,
'canPosition': false,
'canEditSource': false,
'settings': {
'quick': [],
'configure': [],
'advanced': []
}
};
this.setHaxProperties(hr, 'hr');
},
/**
* Inject a toast element to manage our messages
*/
_injectToast: function () {
var toast = document.createElement('paper-toast');
toast.id = "haxtoast";
toast.duration = 3000;
// move this object to the body level so it doesn't
// run into stack order context issues
document.body.appendChild(toast);
this.haxToast = toast;
},
/**
* Set the haxManager node so we can interface with it.
* This also allows for using a different manager that supplies
* the same functions if that would be desired at some point.
*/
_haxStoreRegisterManager: function (e) {
if (e.detail && typeof this.haxManager === typeof undefined) {
this.haxManager = e.detail;
}
},
/**
* Register autoloader so we can ship to it from app-store spec
*/
_haxStoreRegisterAutoloader: function (e) {
if (e.detail && typeof this.haxAutoloader === typeof undefined) {
this.haxAutoloader = e.detail;
}
},
/**
* Set the appPicker node so we can interface with it.
* This helps with picking between multiple options when we need the user
* to decide between a sub-set of options
*/
_haxStoreRegisterAppPicker: function (e) {
if (e.detail && typeof this.haxAppPicker === typeof undefined) {
this.haxAppPicker = e.detail;
}
},
/**
* Set the stax picker so that we have an element in charge
* of the listing of available stax.
*/
_haxStoreRegisterStaxPicker: function (e) {
if (e.detail && typeof this.haxStaxPicker === typeof undefined) {
this.haxStaxPicker = e.detail;
}
},
/**
* Set the blox picker so that we have an element in charge
* of the listing of available blox.
*/
_haxStoreRegisterBloxPicker: function (e) {
if (e.detail && typeof this.haxBloxPicker === typeof undefined) {
this.haxBloxPicker = e.detail;
}
},
/**
* Close all drawers
*/
closeAllDrawers: function (active = false) {
// walk all drawers, close everything
// except active. This also will allow them
// to close everything then.
let drawers = [
'haxManager',
'haxBloxPicker',
'haxStaxPicker',
'haxPreferences',
'haxExport'
];
for (var i in drawers) {
if (active === this[drawers[i]]) {
active.open();
if (drawers[i] === 'haxManager') {
setTimeout(() => {
if (active.querySelector('#activepage .iron-selected paper-input') != null) {
active.querySelector('#activepage .iron-selected paper-input').focus();
}
}, 200);
}
else {
setTimeout(() => {
if (active.querySelector('paper-checkbox,paper-input,textarea,paper-button') != null) {
active.querySelector('paper-checkbox,paper-input,textarea,paper-button').focus();
}
}, 100);
}
}
else {
this[drawers[i]].close();
}
}
},
/**
* Insert content in the body.
*/
_haxStoreInsertContent: function (e) {
if (e.detail) {
var properties = {};
// support for properties to be set automatically optionally
if (typeof e.detail.properties !== typeof undefined) {
properties = e.detail.properties;
}
// invoke insert or replacement on body, same function so it's easier to trace
if (e.detail.replace && e.detail.replacement) {
let node = Polymer.HaxStore.haxElementToNode(e.detail.tag, e.detail.content, properties);
if (this.activeNode !== this.activeContainerNode) {
this.activeHaxBody.haxReplaceNode(this.activeNode, node, this.activeContainerNode);
}
else {
this.activeHaxBody.haxReplaceNode(this.activeNode, node);