@ucd-lib/theme-elements 0.0.13 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/brand/ucd-theme-list-accordion/ucd-theme-list-accordion.tpl.js +3 -0
- package/package.json +2 -1
- package/ucdlib/ucdlib-icon/ucdlib-icon.js +19 -7
- package/ucdlib/ucdlib-iconset/ucdlib-iconset.js +23 -5
- package/ucdlib/ucdlib-sils-search-redirect/ucdlib-sils-search-redirect.tpl.js +3 -0
- package/utils/ip-check.js +133 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucd-lib/theme-elements",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Custom elements for the UCD brand theme",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@ucd-lib/theme-sass": "^5.0.15",
|
|
13
|
+
"ip-cidr": "^3.0.4",
|
|
13
14
|
"lit": "^2.0.2",
|
|
14
15
|
"photoswipe": "^4.1.3",
|
|
15
16
|
"slim-select": "^1.26.2"
|
|
@@ -44,17 +44,19 @@ export default class UcdlibIcon extends LitElement {
|
|
|
44
44
|
* @private
|
|
45
45
|
*/
|
|
46
46
|
disconnectedCallback() {
|
|
47
|
-
|
|
47
|
+
if ( this._setListener ){
|
|
48
|
+
window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
|
|
49
|
+
}
|
|
48
50
|
super.disconnectedCallback();
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
|
-
* @method
|
|
53
|
-
* @description Lit lifecyle method called
|
|
54
|
+
* @method willUpdate
|
|
55
|
+
* @description Lit lifecyle method called right before element updates
|
|
54
56
|
* @param {Map} props - Updated properties
|
|
55
57
|
* @private
|
|
56
58
|
*/
|
|
57
|
-
|
|
59
|
+
willUpdate(props){
|
|
58
60
|
if ( props.has('icon') || props.has('src') ){
|
|
59
61
|
if ( this.src ) {
|
|
60
62
|
this._updateIcon();
|
|
@@ -85,17 +87,27 @@ export default class UcdlibIcon extends LitElement {
|
|
|
85
87
|
_updateIcon(){
|
|
86
88
|
// using the icon attribute
|
|
87
89
|
if ( this._usesIconSet() ) {
|
|
90
|
+
|
|
91
|
+
// previously using the src attribute. remove it.
|
|
88
92
|
if ( this._img && this._img.parentNode ) this.renderRoot.removeChild(this._img);
|
|
89
93
|
|
|
94
|
+
// empty icon name, remove it
|
|
90
95
|
if ( this._iconName === '') {
|
|
91
96
|
if ( this._iconset ) this._iconset.removeIcon(this);
|
|
97
|
+
|
|
98
|
+
// check if iconset exists, add event listener if it doesn't
|
|
92
99
|
} else if ( this._iconsetName ){
|
|
93
100
|
this._iconset = this._getIconset();
|
|
94
|
-
if ( this._iconset ) {
|
|
101
|
+
if ( this._iconset && this._iconset.applyIcon ) {
|
|
95
102
|
this._iconset.applyIcon(this, this._iconName);
|
|
96
|
-
|
|
103
|
+
if ( this._setListener ){
|
|
104
|
+
window.removeEventListener('ucdlib-iconset-added', this._onAddedIconset);
|
|
105
|
+
this._setListener = false;
|
|
106
|
+
}
|
|
97
107
|
} else {
|
|
98
|
-
|
|
108
|
+
if ( !this._setListener ){
|
|
109
|
+
this._setListener = window.addEventListener('ucdlib-iconset-added', this._onAddedIconset);
|
|
110
|
+
}
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
|
|
@@ -10,6 +10,7 @@ import { MutationObserverController } from '../../utils/controllers';
|
|
|
10
10
|
* @property {String} name - Name of the icon set. Usage: <ucdlib-icon icon="{thisProperty}:{icon}"></ucdlib-icon>
|
|
11
11
|
* @property {Number} size - The size of an individual icon. Note that icons must be square.
|
|
12
12
|
* @property {String} label - Optional friendly label for iconset.
|
|
13
|
+
* @property {String} suppressWarnings - Suppress any "you're doing it wrong" console warnings
|
|
13
14
|
* @example
|
|
14
15
|
* <ucdlib-iconset name="arrows">
|
|
15
16
|
<svg>
|
|
@@ -28,6 +29,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
|
|
|
28
29
|
name: {type: String},
|
|
29
30
|
size: {type: Number},
|
|
30
31
|
label: {type: String},
|
|
32
|
+
suppressWarnings: {type: Boolean, attribute: 'suppress-warnings'},
|
|
31
33
|
_iconMap: {type: Object, state: true}
|
|
32
34
|
};
|
|
33
35
|
}
|
|
@@ -40,7 +42,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
|
|
|
40
42
|
this.label = "";
|
|
41
43
|
this.size = 24;
|
|
42
44
|
this._iconMap = {};
|
|
43
|
-
this.
|
|
45
|
+
this.suppressWarnings = false;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
@@ -51,12 +53,28 @@ export default class UcdlibIconset extends Mixin(LitElement)
|
|
|
51
53
|
*/
|
|
52
54
|
updated( props ){
|
|
53
55
|
if (props.has('name') && this.name ) {
|
|
54
|
-
this.
|
|
55
|
-
new CustomEvent('ucdlib-iconset-added', {bubbles: true, composed: true})
|
|
56
|
-
);
|
|
56
|
+
this.dispatchLoadEvent();
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @method firstUpdated
|
|
62
|
+
* @description Lit lifecycle method when element is first updated
|
|
63
|
+
*/
|
|
64
|
+
firstUpdated(){
|
|
65
|
+
this.style.display = "none";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @method dispatchLoadEvent
|
|
70
|
+
* @description fires off a 'ucdlib-iconset-added' event so ucdlib-icon elements can re-render if applicable
|
|
71
|
+
*/
|
|
72
|
+
dispatchLoadEvent(){
|
|
73
|
+
this.dispatchEvent(
|
|
74
|
+
new CustomEvent('ucdlib-iconset-added', {bubbles: true, composed: true})
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
60
78
|
/**
|
|
61
79
|
* @method getIconNames
|
|
62
80
|
* @description Returns a list of icon names for this set
|
|
@@ -173,7 +191,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
|
|
|
173
191
|
iconMap[icon.id] = icon;
|
|
174
192
|
});
|
|
175
193
|
|
|
176
|
-
if ( !Object.keys(iconMap).length ) {
|
|
194
|
+
if ( !Object.keys(iconMap).length && !this.suppressWarnings ) {
|
|
177
195
|
console.warn('No g elements with an id attribute found!.');
|
|
178
196
|
}
|
|
179
197
|
this._iconMap = iconMap;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const IPCIDR = require("ip-cidr");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @class IpDetect
|
|
6
|
+
* @classdesc Utility for detecting type of IP and if it is in campus ip list and vpn ips
|
|
7
|
+
*/
|
|
8
|
+
export class IpDetect {
|
|
9
|
+
constructor(){
|
|
10
|
+
this.ip = '';
|
|
11
|
+
this.hasIP6 = false;
|
|
12
|
+
this.ip6 = '';
|
|
13
|
+
this.ipVPNRange = [
|
|
14
|
+
// VPN
|
|
15
|
+
{"setIP":"128.120.234.0", "mask":"24"},
|
|
16
|
+
{"setIP":"128.120.235.0", "mask":"24"},
|
|
17
|
+
{"setIP":"128.120.236.0", "mask":"24"},
|
|
18
|
+
{"setIP":"128.120.237.0", "mask":"24"},
|
|
19
|
+
{"setIP":"128.120.238.0", "mask":"24"},
|
|
20
|
+
{"setIP":"128.120.239.0", "mask":"24"},
|
|
21
|
+
{"setIP":"128.120.251.0", "mask":"24"},
|
|
22
|
+
{"setIP":"169.237.45.0", "mask":"24"},
|
|
23
|
+
// Staff VPN
|
|
24
|
+
{"setIP":"169.237.240.2", "mask":"32"},
|
|
25
|
+
{"setIP":"172.19.19.0", "mask":"24"},
|
|
26
|
+
{"setIP":"172.19.19.64", "mask":"26"}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
this.campusRange = [
|
|
30
|
+
{"setIP":"128.120.0.0", "mask":"16"},
|
|
31
|
+
{"setIP":"152.79.0.0", "mask":"16"},
|
|
32
|
+
{"setIP":"169.237.0.0", "mask":"16"},
|
|
33
|
+
{"setIP":"162.251.203.0", "mask":"27"},
|
|
34
|
+
{"setIP":"12.235.42.0", "mask":"25"},
|
|
35
|
+
{"setIP":"168.150.0.0", "mask":"17"},
|
|
36
|
+
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
this.isVPN = false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @method runIP
|
|
43
|
+
* @description This runs the ip check services
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
async runIP(){
|
|
47
|
+
this.isOnCampus = await this.verifyCidr(this.campusRange, this.ipVPNRange);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @method checkIp
|
|
52
|
+
* @description This retrieves the host's ip address
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
async checkIp(){
|
|
56
|
+
let ips;
|
|
57
|
+
await fetch('https://api64.ipify.org?format=json', )
|
|
58
|
+
.then(response => response.json())
|
|
59
|
+
.then(data => {ips = data; });
|
|
60
|
+
this.ip = ips["ip"];
|
|
61
|
+
|
|
62
|
+
if (this.ip.includes(":")){
|
|
63
|
+
this.hasIP6 = true;
|
|
64
|
+
this.ip6 = this.ip;
|
|
65
|
+
await fetch('https://api.ipify.org?format=json', )
|
|
66
|
+
.then(response => response.json())
|
|
67
|
+
.then(data => {ips = data; });
|
|
68
|
+
this.ip = ips["ip"];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @method isInRange
|
|
75
|
+
* @description verify if the ip is in the range given
|
|
76
|
+
*
|
|
77
|
+
* @param {Array} range
|
|
78
|
+
*
|
|
79
|
+
* @returns {Boolean}
|
|
80
|
+
*/
|
|
81
|
+
checkRange(range){
|
|
82
|
+
if (range.includes(this.ip))
|
|
83
|
+
return true;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @method cidrCheck
|
|
89
|
+
* @description cidr check that takes a range
|
|
90
|
+
*
|
|
91
|
+
* @param {Object} identifier
|
|
92
|
+
*
|
|
93
|
+
* @returns {Array}
|
|
94
|
+
*/
|
|
95
|
+
cidrCheck(identifier){
|
|
96
|
+
let cidr;
|
|
97
|
+
|
|
98
|
+
let currentIP = identifier["setIP"].concat('/', identifier["mask"] );
|
|
99
|
+
cidr = new IPCIDR(currentIP);
|
|
100
|
+
let ipRange = cidr.toArray();
|
|
101
|
+
|
|
102
|
+
return ipRange;
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @method verifyCidr
|
|
108
|
+
* @description verify req ip addressess in cidr array
|
|
109
|
+
*
|
|
110
|
+
* @param {Array} campusAddress
|
|
111
|
+
* @param {Array} vpnaddress
|
|
112
|
+
*
|
|
113
|
+
* @returns {Boolean}
|
|
114
|
+
*/
|
|
115
|
+
async verifyCidr(campusAddress, vpnaddress) {
|
|
116
|
+
await this.checkIp();
|
|
117
|
+
for (let i of vpnaddress){
|
|
118
|
+
let vpn_range = this.cidrCheck(i);
|
|
119
|
+
if(this.checkRange(vpn_range))
|
|
120
|
+
this.isVPN = true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (let i of campusAddress){
|
|
124
|
+
let campus_range = this.cidrCheck(i);
|
|
125
|
+
if(this.checkRange(campus_range))
|
|
126
|
+
return this.ip;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|