From 35d7e1b32e1ffd34f0b0a30e79b8b0e9d3703e12 Mon Sep 17 00:00:00 2001 From: NBTX Date: Sat, 24 Aug 2019 15:51:03 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=8C=20Add=20websocket=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/css/styles.scss | 11 +- layouts/default.vue | 47 +++++++++ pages/index.vue | 2 +- pages/websocket.vue | 225 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 282 insertions(+), 3 deletions(-) create mode 100644 pages/websocket.vue diff --git a/assets/css/styles.scss b/assets/css/styles.scss index ed3e08281..05e894ed2 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -70,6 +70,12 @@ footer { justify-content: space-between; } +nav { + a:not(:last-of-type) { + margin-right: 15px; + } +} + body.sticky-footer footer { position: fixed; bottom: 0; @@ -104,7 +110,7 @@ legend { cursor: pointer; } -fieldset textarea { +fieldset textarea, fieldset pre { resize: vertical; } @@ -163,7 +169,8 @@ fieldset.response legend { select, input, option, -textarea { +textarea, +pre { margin: 4px; padding: 8px 16px; width: calc(100% - 8px); diff --git a/layouts/default.vue b/layouts/default.vue index 6a17733d9..d3f92bedc 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -7,6 +7,11 @@

Lightweight API request builder

+ + @@ -41,6 +46,43 @@ margin: 0 auto; max-width: 1200px; } + + header { padding-right: 0; } + + nav { + a { + display: inline-block; + position: relative; + padding: 8px 16px; + + &.nuxt-link-exact-active { + color: black; + &:before { width: 100%; height: 100% } + } + + &:before { + content: ""; + position: absolute; + bottom: 0; + left: 0; + right: 0; + z-index: -1; + + background-color: var(--ac-color); + border-radius: 4px; + margin: auto; + } + + &:not(.nuxt-link-exact-active):hover:before { + animation: linkHover 0.3s forwards ease-in-out; + } + + @keyframes linkHover { + 0% { width: 0; height: 2px; } + 100% { width: 100%; height: 2px; } + } + } + } From 67f0600702a7f66a62f1d6b726b5954aeba518ae Mon Sep 17 00:00:00 2001 From: NBTX Date: Sat, 24 Aug 2019 19:35:39 +0100 Subject: [PATCH 2/6] Improve mobile navigation --- assets/css/styles.scss | 16 +++++++++++++++- layouts/default.vue | 15 +++++++++++++-- pages/settings.vue | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 pages/settings.vue diff --git a/assets/css/styles.scss b/assets/css/styles.scss index 05e894ed2..7aa80149a 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -5,6 +5,8 @@ --err-color: #393939; } +$responsiveWidth: 720px; + ::selection { background-color: var(--ac-color); color: var(--bg-color); @@ -70,6 +72,18 @@ footer { justify-content: space-between; } +@media(max-width: $responsiveWidth){ + header { + display: block; + text-align: center; + + nav { + display: inline-flex; + margin-top: 20px; + } + } +} + nav { a:not(:last-of-type) { margin-right: 15px; @@ -210,7 +224,7 @@ ol li { flex-grow: 1; } -@media (max-width: 720px) { +@media (max-width: $responsiveWidth) { ul, ol { diff --git a/layouts/default.vue b/layouts/default.vue index d3f92bedc..9b9fd5f12 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -11,6 +11,12 @@ @@ -47,16 +53,21 @@ max-width: 1200px; } - header { padding-right: 0; } - nav { + svg { + vertical-align: sub; + } + a { display: inline-block; position: relative; padding: 8px 16px; + fill: white; + color: white; &.nuxt-link-exact-active { color: black; + fill: black; &:before { width: 100%; height: 100% } } diff --git a/pages/settings.vue b/pages/settings.vue new file mode 100644 index 000000000..af9fa97fa --- /dev/null +++ b/pages/settings.vue @@ -0,0 +1,3 @@ + \ No newline at end of file From 55849284899e2981a4ff00cb08ddb30e6fef0445 Mon Sep 17 00:00:00 2001 From: izerozlu Date: Sat, 24 Aug 2019 22:40:47 +0300 Subject: [PATCH 3/6] Response status colors added. --- assets/css/styles.scss | 52 +++++++++++++++++++++++++++++------------- pages/index.vue | 13 ++++++++++- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/assets/css/styles.scss b/assets/css/styles.scss index 05e894ed2..ed51df54a 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -1,7 +1,7 @@ :root { --bg-color: #121212; - --fg-color: #FFF; - --ac-color: #51FF0D; + --fg-color: #fff; + --ac-color: #51ff0d; --err-color: #393939; } @@ -22,7 +22,7 @@ box-sizing: border-box; outline: 0; border: 0; - font-family: 'Poppins', 'Roboto', 'Noto', sans-serif; + font-family: "Poppins", "Roboto", "Noto", sans-serif; } @keyframes fadein { @@ -47,7 +47,7 @@ body { color: var(--fg-color); font-weight: 500; line-height: 1.5; - animation: fadein .2s; + animation: fadein 0.2s; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; @@ -110,7 +110,8 @@ legend { cursor: pointer; } -fieldset textarea, fieldset pre { +fieldset textarea, +fieldset pre { resize: vertical; } @@ -123,43 +124,43 @@ fieldset.request legend { } fieldset.history { - border-color: #9B9B9B; + border-color: #9b9b9b; } fieldset.history legend { - color: #9B9B9B; + color: #9b9b9b; } fieldset.authentication { - border-color: #B8E986; + border-color: #b8e986; } fieldset.authentication legend { - color: #B8E986; + color: #b8e986; } fieldset.parameters { - border-color: #50E3C2; + border-color: #50e3c2; } fieldset.parameters legend { - color: #50E3C2; + color: #50e3c2; } fieldset.reqbody { - border-color: #4A90E2; + border-color: #4a90e2; } fieldset.reqbody legend { - color: #4A90E2; + color: #4a90e2; } fieldset.response { - border-color: #C198FB; + border-color: #c198fb; } fieldset.response legend { - color: #C198FB; + color: #c198fb; } .hidden .collapsible { @@ -211,7 +212,6 @@ ol li { } @media (max-width: 720px) { - ul, ol { flex-direction: column; @@ -226,3 +226,23 @@ ol li { #installPWA { display: none; } + +.info-response { + background-color: #ffeb3b; +} + +.success-response { + background-color: #66BB6A; +} + +.redir-response { + background-color: #ff5722; +} + +.cl-error-response { + background-color: #ef5350; +} + +.sv-error-response { + background-color: #b71c1c; +} \ No newline at end of file diff --git a/pages/index.vue b/pages/index.vue index 4be215994..b17f61df3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -138,7 +138,7 @@
  • - +
    @@ -230,6 +230,17 @@ } }, computed: { + statusCategory(){ + const statusCategory = [ + {name: 'informational', statusCodeRegex: new RegExp(/[1][0-9]+/), className: 'info-response'}, + {name: 'successful', statusCodeRegex: new RegExp(/[2][0-9]+/), className: 'success-response'}, + {name: 'redirection', statusCodeRegex: new RegExp(/[3][0-9]+/), className: 'redir-response'}, + {name: 'client error', statusCodeRegex: new RegExp(/[4][0-9]+/), className: 'cl-error-response'}, + {name: 'server error', statusCodeRegex: new RegExp(/[5][0-9]+/), className: 'sv-error-response'}, + ].find(status => status.statusCodeRegex.test(this.response.status)); + + return statusCategory; + }, noHistoryToClear() { return this.history.length === 0; }, From 02ef69f0f7190ca319d8754773b882cfe76113b2 Mon Sep 17 00:00:00 2001 From: NBTX Date: Sun, 25 Aug 2019 00:42:41 +0100 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=8E=A8=20Add=20theme=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move root (var) style properties to `/assets/css/themes.scss` - Improve mobile navigation - Create section component for the collapsable sections. - Create logo component, so color can be changed. - Add settings page - Add option to select theme color - Add option to select theme background - Add option to enable/disable multi-colored frames. - Add settings to VueX Store - Persist VueX store in LocalStorage. --- assets/css/styles.scss | 54 +++-- assets/css/themes.scss | 39 ++++ components/logo.vue | 29 +++ components/section.vue | 47 ++++ components/settings/swatch.vue | 67 ++++++ layouts/default.vue | 36 ++- nuxt.config.js | 3 + package-lock.json | 19 ++ package.json | 3 +- pages/index.vue | 387 ++++++++++++++++----------------- pages/settings.vue | 125 ++++++++++- pages/websocket.vue | 346 ++++++++++++++--------------- plugins/vuex-persist.js | 5 + store/index.js | 3 + store/postwoman.js | 51 +++++ 15 files changed, 810 insertions(+), 404 deletions(-) create mode 100644 assets/css/themes.scss create mode 100644 components/logo.vue create mode 100644 components/section.vue create mode 100644 components/settings/swatch.vue create mode 100644 plugins/vuex-persist.js create mode 100644 store/index.js create mode 100644 store/postwoman.js diff --git a/assets/css/styles.scss b/assets/css/styles.scss index 7aa80149a..20c3c6781 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -1,15 +1,8 @@ -:root { - --bg-color: #121212; - --fg-color: #FFF; - --ac-color: #51FF0D; - --err-color: #393939; -} - $responsiveWidth: 720px; ::selection { background-color: var(--ac-color); - color: var(--bg-color); + color: var(--act-color); } ::-webkit-scrollbar { @@ -106,7 +99,7 @@ button { padding: 8px 16px; border-radius: 4px; background-color: var(--ac-color); - color: var(--bg-color); + color: var(--act-color); font-weight: 700; font-size: 16px; cursor: pointer; @@ -128,55 +121,55 @@ fieldset textarea, fieldset pre { resize: vertical; } -fieldset.request { +fieldset.blue { border-color: #57b5f9; } -fieldset.request legend { +fieldset.blue legend { color: #57b5f9; } -fieldset.history { +fieldset.gray { border-color: #9B9B9B; } -fieldset.history legend { +fieldset.gray legend { color: #9B9B9B; } -fieldset.authentication { +fieldset.green { border-color: #B8E986; } -fieldset.authentication legend { +fieldset.green legend { color: #B8E986; } -fieldset.parameters { +fieldset.cyan { border-color: #50E3C2; } -fieldset.parameters legend { +fieldset.cyan legend { color: #50E3C2; } -fieldset.reqbody { +fieldset.blue-dark { border-color: #4A90E2; } -fieldset.reqbody legend { +fieldset.blue-dark legend { color: #4A90E2; } -fieldset.response { +fieldset.purple { border-color: #C198FB; } -fieldset.response legend { +fieldset.purple legend { color: #C198FB; } -.hidden .collapsible { +.collapsible.hidden { display: none; } @@ -189,13 +182,28 @@ pre { padding: 8px 16px; width: calc(100% - 8px); border-radius: 4px; - background-color: #000; + background-color: var(--bg-dark-color); color: var(--fg-color); font-weight: 700; font-size: 18px; font-family: monospace; } +// Force the same height, for dropdowns and regular input boxes. +select, +input, +option { + height: 38px; +} + +input[type="checkbox"] { + width: initial; + + &, & + label { + vertical-align: middle; + } +} + .error { background-color: var(--err-color); } diff --git a/assets/css/themes.scss b/assets/css/themes.scss new file mode 100644 index 000000000..11606549b --- /dev/null +++ b/assets/css/themes.scss @@ -0,0 +1,39 @@ +/** + Main Themes: + + - dark (default) + - light + */ + +// Dark is the default theme variant. +:root { + --bg-dark-color: #000000; + // Background color + --bg-color: #121212; + // Text color + --fg-color: #FFF; + + // Error color + --err-color: #393939; + + // Active color + --ac-color: #51FF0D; + // Active text color + --act-color: #121212; +} + +:root.light { + --bg-dark-color: #ffffff; + // Background color + --bg-color: #F6F8FA; + // Text color + --fg-color: #121212; + + // Error color + --err-color: invert(#393939, 1); + + // Active color + --ac-color: #51FF0D; + // Active text color + --act-color: #121212; +} \ No newline at end of file diff --git a/components/logo.vue b/components/logo.vue new file mode 100644 index 000000000..d3af5f4a7 --- /dev/null +++ b/components/logo.vue @@ -0,0 +1,29 @@ + + + + + \ No newline at end of file diff --git a/components/section.vue b/components/section.vue new file mode 100644 index 000000000..4d2af5b5e --- /dev/null +++ b/components/section.vue @@ -0,0 +1,47 @@ + + + + + \ No newline at end of file diff --git a/components/settings/swatch.vue b/components/settings/swatch.vue new file mode 100644 index 000000000..262c718f2 --- /dev/null +++ b/components/settings/swatch.vue @@ -0,0 +1,67 @@ + + + + + \ No newline at end of file diff --git a/layouts/default.vue b/layouts/default.vue index 9b9fd5f12..10af963b6 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -3,7 +3,7 @@
    -

    Postwoman

    +

    Postwoman

    Lightweight API request builder

    @@ -23,7 +23,10 @@
    - GitHub +
    + GitHub +
    + @@ -62,12 +65,12 @@ display: inline-block; position: relative; padding: 8px 16px; - fill: white; - color: white; + fill: var(--fg-color); + color: var(--fg-color); &.nuxt-link-exact-active { - color: black; - fill: black; + color: var(--act-color); + fill: var(--act-color); &:before { width: 100%; height: 100% } } @@ -98,8 +101,13 @@ \ No newline at end of file diff --git a/pages/websocket.vue b/pages/websocket.vue index ec7e89bf9..d3369c5d6 100644 --- a/pages/websocket.vue +++ b/pages/websocket.vue @@ -1,50 +1,44 @@ @@ -61,7 +55,7 @@ padding: 8px 16px; width: calc(100% - 8px); border-radius: 4px; - background-color: #000; + background-color: var(--bg-dark-color); color: var(--fg-color); height: 300px; overflow: auto; @@ -80,146 +74,152 @@ diff --git a/plugins/vuex-persist.js b/plugins/vuex-persist.js new file mode 100644 index 000000000..09fc9ad02 --- /dev/null +++ b/plugins/vuex-persist.js @@ -0,0 +1,5 @@ +import VuexPersistence from "vuex-persist"; + +export default ({ store }) => { + new VuexPersistence().plugin(store); +} \ No newline at end of file diff --git a/store/index.js b/store/index.js new file mode 100644 index 000000000..5c933b16b --- /dev/null +++ b/store/index.js @@ -0,0 +1,3 @@ +export default { + +} \ No newline at end of file diff --git a/store/postwoman.js b/store/postwoman.js new file mode 100644 index 000000000..fb07b5d13 --- /dev/null +++ b/store/postwoman.js @@ -0,0 +1,51 @@ +export const SETTINGS_KEYS = [ + /** + * The CSS class that should be applied to the root element. + * Essentially, the name of the background theme. + */ + "THEME_CLASS", + + /** + * The hex color code for the currently active theme. + */ + "THEME_COLOR", + + /** + * Whether or not THEME_COLOR is considered 'vibrant'. + * + * For readability reasons, if the THEME_COLOR is vibrant, + * any text placed on the theme color will have its color + * inverted from white to black. + */ + "THEME_COLOR_VIBRANT", + + /** + * Normally, section frames are multicolored in the UI + * to emphasise the different sections. + * This setting allows that to be turned off. + */ + "DISABLE_FRAME_COLORS" +]; + +export const state = () => ({ + settings: {} +}); + +export const mutations = { + + applySetting (state, setting) { + if(setting == null || !(setting instanceof Array) || setting.length !== 2) + throw new Error("You must provide a setting (array in the form [key, value])"); + + let key = setting[0]; + let value = setting[1]; + // Do not just remove this check. + // Add your settings key to the SETTINGS_KEYS array at the + // top of the file. + // This is to ensure that application settings remain documented. + if(!SETTINGS_KEYS.includes(key)) throw new Error("The settings key does not include the key " + key); + + state.settings[key] = value; + } + +}; \ No newline at end of file From bd434ff285e313eb71880698df9eb428d0b08f02 Mon Sep 17 00:00:00 2001 From: NBTX Date: Sun, 25 Aug 2019 02:41:30 +0100 Subject: [PATCH 5/6] Improve URL validation check. (See https://github.com/liyasthomas/postwoman/issues/56) --- assets/css/styles.scss | 1 - pages/index.vue | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/assets/css/styles.scss b/assets/css/styles.scss index e403b7d7f..6fc3f46ab 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -132,7 +132,6 @@ fieldset.blue legend { color: #57b5f9; } -<<<<<<< HEAD fieldset.gray { border-color: #9B9B9B; } diff --git a/pages/index.vue b/pages/index.vue index b7d26f0ed..c3b4e4f05 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -15,7 +15,7 @@
  • - +
  • @@ -23,7 +23,7 @@
  • - +
@@ -235,14 +235,13 @@ noHistoryToClear() { return this.history.length === 0; }, - urlNotValid() { - const pattern = new RegExp('^(https?:\\/\\/)?' + - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + - '((\\d{1,3}\\.){3}\\d{1,3}))' + - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + - '(\\?[;&a-z\\d%_.~+=-]*)?' + - '(\\#[-a-z\\d_]*)?$', 'i'); - return !pattern.test(this.url) + isValidURL() { + const protocol = '^(https?:\\/\\/)?'; + + const validIP = new RegExp(protocol + "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"); + const validHostname = new RegExp(protocol + "(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"); + + return validIP.test(this.url) || validHostname.test(this.url); }, rawRequestBody() { const { @@ -302,8 +301,8 @@ }) }, sendRequest() { - if (this.urlNotValid) { - alert('Please check the formatting of the URL') + if (!this.isValidURL()) { + alert('Please check the formatting of the URL'); return } const n = new Date().toLocaleTimeString() From 5a8c9f5533df3fe153a82b88190334aff6c94ffa Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Sun, 25 Aug 2019 11:26:55 +0530 Subject: [PATCH 6/6] :alembic: Typo --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index c3b4e4f05..bc1c3f052 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -301,7 +301,7 @@ }) }, sendRequest() { - if (!this.isValidURL()) { + if (!this.isValidURL) { alert('Please check the formatting of the URL'); return }