Skip to content

Commit

Permalink
feat: add browZer tool button (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect authored May 22, 2024
1 parent e032491 commit 0e96bc5
Show file tree
Hide file tree
Showing 47 changed files with 5,246 additions and 34 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openziti/ziti-browzer-runtime",
"version": "0.67.1",
"version": "0.67.2-beta.0",
"type": "module",
"description": "The Ziti JavaScript runtime that is auto-injected into the Page of a Zitified web app",
"scripts": {
Expand Down Expand Up @@ -70,6 +70,7 @@
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.17.10",
"@babel/register": "^7.17.7",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/localforage": "^0.0.34",
Expand All @@ -95,15 +96,20 @@
"@auth0/auth0-spa-js": "^2.0.4",
"@azure/msal-browser": "^2.38.0",
"@babel/runtime": "^7.17.9",
"@openziti/ziti-browzer-core": "^0.40.2",
"@openziti/ziti-browzer-core": "^0.40.3",
"bowser": "^2.11.0",
"cookie-interceptor": "^1.0.0",
"core-js": "^3.22.8",
"events": "^3.3.0",
"js-base64": "^3.7.2",
"jwt-decode": "^3.1.2",
"licia": "^1.39.2",
"localforage": "^1.10.0",
"lodash-es": "^4.17.21",
"luna-modal": "^1.2.3",
"luna-notification": "^0.2.0",
"luna-setting": "^1.0.1",
"luna-tab": "^0.3.0",
"oauth4webapi": "^2.10.3",
"rollup-plugin-css-only": "^4.5.2",
"uplot": "^1.6.24",
Expand Down
7 changes: 5 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import babel from "rollup-plugin-babel";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import json from '@rollup/plugin-json';
// import commonjs from '@rollup/plugin-commonjs';
import commonjs from '@rollup/plugin-commonjs';
import prettier from 'rollup-plugin-prettier';
import copy from 'rollup-plugin-copy';
import nodePolyfills from 'rollup-plugin-polyfill-node';
Expand All @@ -21,7 +21,10 @@ let plugins = [
exclude: "node_modules/**"
}),
json(),
// commonjs(),
commonjs({
include: /node_modules/,
requireReturnsDefault: 'auto'
}),
// terser(),
prettier({
tabWidth: 2,
Expand Down
37 changes: 17 additions & 20 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
PKCEToken,
} from './oidc/utils';
import { jspi } from "wasm-feature-detect";
import {eruda} from './tool-button/eruda';


/**
Expand Down Expand Up @@ -330,7 +331,7 @@ class ZitiBrowzerRuntime {
setTimeout(this._createPolipop, 1000, this);

// HotKey infra
setTimeout(this._createHotKey, 5000, this);
// setTimeout(this._createHotKey, 5000, this);

// Click intercept infra
setTimeout(this._createClickIntercept, 3000, this);
Expand Down Expand Up @@ -833,7 +834,7 @@ class ZitiBrowzerRuntime {
<div class="row">
<div class="form-group col-xs-12" id="changelog___div">
<div>
<div class="changelogButtonContainer" data-canny-changelog="true" style="position: relative;">
<div class="changelogButtonContainer" Xdata-canny-changelog="true" style="position: relative;">
<button type="button" class="btn btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5">
<path fill-rule="evenodd" d="M15.312 11.424a5.5 5.5 0 0 1-9.201 2.466l-.312-.311h2.433a.75.75 0 0 0 0-1.5H3.989a.75.75 0 0 0-.75.75v4.242a.75.75 0 0 0 1.5 0v-2.43l.31.31a7 7 0 0 0 11.712-3.138.75.75 0 0 0-1.449-.39Zm1.23-3.723a.75.75 0 0 0 .219-.53V2.929a.75.75 0 0 0-1.5 0V5.36l-.31-.31A7 7 0 0 0 3.239 8.188a.75.75 0 1 0 1.448.389A5.5 5.5 0 0 1 13.89 6.11l.311.31h-2.432a.75.75 0 0 0 0 1.5h4.243a.75.75 0 0 0 .53-.219Z" clip-rule="evenodd" />
Expand Down Expand Up @@ -1531,23 +1532,19 @@ class ZitiBrowzerRuntime {
*/
async initialize(options) {

// Initialize eruda if it's present in the DOM
if (typeof eruda !== 'undefined') {
eruda.init({
tool: [
'console',
'resources',
'info',
],
useShadowDom: true,
autoScale: true,
defaults: {
displaySize: 50,
transparency: 0.9,
theme: 'Monokai Pro'
}
});
}
eruda.init({
tool: [
'info',
'changelog',
'feedback',
],
useShadowDom: false,
autoScale: true,
defaults: {
displaySize: 50,
transparency: 1.0
}
});

let logLevel = await window.zitiBrowzerRuntime.localStorage.get(
'ZITI_BROWZER_RUNTIME_LOGLEVEL',
Expand Down Expand Up @@ -1585,7 +1582,7 @@ class ZitiBrowzerRuntime {
this.zitiConfig.token_type = 'Bearer';

/** ===================================================================
* Loded via the BrowZer Bootstrapper
* Loaded via the BrowZer Bootstrapper
/** ================================================================= */
if (options.loadedViaBootstrapper) {

Expand Down
158 changes: 158 additions & 0 deletions src/tool-button/Changelog/Changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import Tool from '../DevTools/Tool'
import each from 'licia/each'
import isFn from 'licia/isFn'
import isUndef from 'licia/isUndef'
import cloneDeep from 'licia/cloneDeep'
import evalCss from '../lib/evalCss'
import map from 'licia/map'
import escape from 'licia/escape'
import copy from 'licia/copy'
import $ from 'licia/$'
import { classPrefix as c } from '../lib/util'
import { INFO_CSS } from '../Info/info_css';
import { isUndefined, isNull, isEqual } from 'lodash-es';


export default class Changelog extends Tool {
constructor() {
super()

this._style = evalCss(INFO_CSS)

this.name = 'changelog'
this._infos = []
}
init($el, container) {
super.init($el)
this._container = container

this._addDefChangelog()
this._bindEvent()

}
destroy() {
super.destroy()

evalCss.remove(this._style)
}
add(name, val) {
const infos = this._infos
let isUpdate = false

each(infos, (info) => {
if (name !== info.name) return

info.val = val
isUpdate = true
})

if (!isUpdate) infos.push({ name, val })

this._render()

return this
}
get(name) {
const infos = this._infos

if (isUndef(name)) {
return cloneDeep(infos)
}

let result

each(infos, (info) => {
if (name === info.name) result = info.val
})

return result
}
remove(name) {
const infos = this._infos

for (let i = infos.length - 1; i >= 0; i--) {
if (infos[i].name === name) infos.splice(i, 1)
}

this._render()

return this
}
clear() {
this._infos = []

this._render()

return this
}
_addDefChangelog() {

let updateAvailable = '';
if (!isUndefined(window.zitiBrowzerRuntime.zitiConfig.browzer.bootstrapper.self.latestReleaseVersion)) {
updateAvailable = isEqual(window.zitiBrowzerRuntime.zitiConfig.browzer.bootstrapper.self.version, window.zitiBrowzerRuntime.zitiConfig.browzer.bootstrapper.self.latestReleaseVersion) ? ''
: `NOTE: A Newer BrowZer Release <span style="color:#ec1f2d;font-size: 18px;font-weight:600">(v${window.zitiBrowzerRuntime.zitiConfig.browzer.bootstrapper.self.latestReleaseVersion})</span> is Available`;
}

let defChangelog = [
{
name: 'Your Version',
val:
'You are running <a href="https://openziti.io/docs/learn/quickstarts/browzer/" target="_blank">OpenZiti BrowZer v' +
zitiBrowzerRuntime.zitiConfig.browzer.bootstrapper.self.version +
'</a>' +
`
<br/><br/>
<button type="button" class="btn btn-primary" data-canny-changelog="true">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5">
<path fill-rule="evenodd" d="M15.312 11.424a5.5 5.5 0 0 1-9.201 2.466l-.312-.311h2.433a.75.75 0 0 0 0-1.5H3.989a.75.75 0 0 0-.75.75v4.242a.75.75 0 0 0 1.5 0v-2.43l.31.31a7 7 0 0 0 11.712-3.138.75.75 0 0 0-1.449-.39Zm1.23-3.723a.75.75 0 0 0 .219-.53V2.929a.75.75 0 0 0-1.5 0V5.36l-.31-.31A7 7 0 0 0 3.239 8.188a.75.75 0 1 0 1.448.389A5.5 5.5 0 0 1 13.89 6.11l.311.31h-2.432a.75.75 0 0 0 0 1.5h4.243a.75.75 0 0 0 .53-.219Z" clip-rule="evenodd" />
</svg>
View Changelog
</button>
<label style="position: absolute;top: 43px;left: 300px; height: 32px;">
${updateAvailable}
</label>
`
,
},
]

each(defChangelog, (info) => this.add(info.name, info.val))
}
_render() {
const infos = []

each(this._infos, ({ name, val }) => {
if (isFn(val)) val = val()

infos.push({ name, val })
})

const html = `<ul>${map(
infos,
(info) =>
`<li><h2 class="${c('title')}">${escape(info.name)}
<span class="${c(
'icon-copy copy'
)}"></span>
</h2><div class="${c('content')}">${info.val}</div></li>`
).join('')}</ul>`

this._renderHtml(html)
}
_bindEvent() {
const container = this._container

this._$el.on('click', c('.copy'), function () {
const $li = $(this).parent().parent()
const name = $li.find(c('.title')).text()
const content = $li.find(c('.content')).text()
copy(`${name}: ${content}`)
container.notify('Copied')
})
}
_renderHtml(html) {
if (html === this._lastHtml) return
this._lastHtml = html
this._$el.html(html)
}
}
Loading

0 comments on commit 0e96bc5

Please sign in to comment.