8000 chore: code size improvements by jacobmllr95 · Pull Request #5151 · bootstrap-vue/bootstrap-vue · GitHub
[go: up one dir, main page]

Skip to content

chore: code size improvements #5151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a95e0b0
feat: code size improvements
jacobmllr95 Apr 4, 2020
38914c4
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 Apr 15, 2020
f3a13cd
Update form-rating.js
jacobmllr95 Apr 15, 2020
01954f5
Unify comments
jacobmllr95 Apr 15, 2020
ebe5d30
Merge branch 'dev' into feat-code-size-improvements
tmorehouse Apr 15, 2020
c2e8960
Merge branch 'dev' into feat-code-size-improvements
tmorehouse Apr 15, 2020
eb45f87
Update form-rating.spec.js
jacobmllr95 Apr 15, 2020
8855171
Enhance `b-alert` code
jacobmllr95 Apr 15, 2020
74e8d2d
Update aspect.js
jacobmllr95 Apr 15, 2020
8b2f407
Update avatar.js
jacobmllr95 Apr 15, 2020
331c997
Update badge.js
jacobmllr95 Apr 15, 2020
5eb2433
Update breadcrumb-link.js
jacobmllr95 Apr 15, 2020
7ded553
Update breadcrumb.js
jacobmllr95 Apr 15, 2020
ee9d5b8
Update button-close.js
jacobmllr95 Apr 15, 2020
3ce5f8f
Update number.spec.js
jacobmllr95 Apr 15, 2020
f3f0e5b
Add `suffixClass()` util
jacobmllr95 Apr 15, 2020
9302781
Update test.yml
jacobmllr95 Apr 15, 2020
a8d4e34
Update bv-tooltip.js
tmorehouse Apr 15, 2020
b64587c
Update test.yml
jacobmllr95 Apr 15, 2020
56d4bb4
Merge branch 'feat-code-size-improvements' of https://github.com/boot…
jacobmllr95 Apr 15, 2020
7bf93cb
Update button.js
tmorehouse Apr 15, 2020
eb9b23d
Update form-size.js
tmorehouse Apr 15, 2020
1d51414
Update form-size.js
tmorehouse Apr 15, 2020
1067307
Update button.js
jacobmllr95 Apr 15, 2020
4293b6a
Merge branch 'feat-code-size-improvements' of https://github.com/boot…
jacobmllr95 Apr 15, 2020
116b286
Update button.js
jacobmllr95 Apr 15, 2020
24c4f2d
Create `constants/` dir for constants
jacobmllr95 Apr 15, 2020
01b70b4
Move event options to constants
jacobmllr95 Apr 15, 2020
3e76448
Move common regex to shared constants
jacobmllr95 Apr 15, 2020
3513bd9
Initial components/class-names config implementation
jacobmllr95 Apr 16, 2020
4e6d0b7
Update breadcrumb-link.js
jacobmllr95 Apr 16, 2020
a943fd0
Further use constants/class-names
jacobmllr95 Apr 16, 2020
38c0653
Add `hasChildren()` util
jacobmllr95 Apr 16, 2020
2289553
Update dom.spec.js
tmorehouse Apr 16, 2020
c17bc18
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 16, 2020
830e824
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 16, 2020
ac496b0
Add `isNumeric()` to inspect utils
jacobmllr95 Apr 16, 2020
199cdb0
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 Apr 16, 2020
4f7df72
Merge branch 'dev' into feat-code-size-improvements
tmorehouse Apr 17, 2020
925d4a7
Adjust ignorefiles
jacobmllr95 Apr 18, 2020
4465bc1
Further implement constants implementation
jacobmllr95 Apr 18, 2020
975e9cc
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 18, 2020
6d099e1
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 18, 2020
ae3c86e
Update calendar.js
jacobmllr95 Apr 20, 2020
0cd00b0
Update carousel.js
jacobmllr95 Apr 20, 2020
e2df3d4
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 20, 2020
0066850
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 Apr 20, 2020
e49f675
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 Apr 20, 2020
123b320
Merge branch 'dev' into feat-code-size-improvements
tmorehouse Apr 21, 2020
e03b743
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 6, 2020
14aca03
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 8, 2020
ceedcaa
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 8, 2020
b509e83
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 8, 2020
b36a479
Update test.yml
jacobmllr95 May 8, 2020
97fa3f6
Merge branch 'feat-code-size-improvements' of https://github.com/boot…
jacobmllr95 May 8, 2020
d68c311
Merge branch 'dev' into feat-code-size-improvements
tmorehouse May 8, 2020
ce12e97
Merge branch 'dev' into feat-code-size-improvements
tmorehouse May 10, 2020
9dd2234
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 10, 2020
c0a406c
Prefix BootstrapVue class names
jacobmllr95 May 10, 2020
2176cbb
Further improve code size
jacobmllr95 May 10, 2020
5274992
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 10, 2020
8418f3c
Revert "Update test.yml"
jacobmllr95 May 10, 2020
fecb225
Update components.js
jacobmllr95 May 10, 2020
a03d0ff
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 12, 2020
f9a44bc
Merge branch 'dev' into feat-code-size-improvements
tmorehouse May 12, 2020
27660e6
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 12, 2020
3a4baec
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 15, 2020
d6bcdae
Merge remote-tracking branch 'origin/dev' into feat-code-size-improve…
jacobmllr95 May 15, 2020
0f090a0
Add `slot-name` constants
jacobmllr95 May 15, 2020
38acf6b
Update form.js
jacobmllr95 May 15, 2020
487da45
Update form-checkbox-group.js
jacobmllr95 May 15, 2020
ec47a35
Add event name constants
jacobmllr95 May 15, 2020
a1c93ce
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 15, 2020
b009bff
Add `buildObject()` util and add more constants
jacobmllr95 May 15, 2020
9add554
Merge branch 'dev' into feat-code-size-improvements
jacobmllr95 May 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/play.vue
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ const STORAGE_KEYS = {
// Maximum age of localStorage before we revert back to defaults
const STORAGE_MAX_RETENTION = 7 * 24 * 60 * 60 * 1000 // 7 days

// --- Helper functions ---
// --- Utility methods ---

// Remove a node from its parent's children
const removeNode = node => node && node.parentNode && node.parentNode.removeChild(node)
Expand Down
18 changes: 8 additions & 10 deletions docs/plugins/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ const RX_NAME_DEFINITION = /<!-- .*\.vue -->/
const RX_TEMPLATE = /<template>([\s\S]*)<\/template>/
const RX_SCRIPT = /<script>([\s\S]*)<\/script>/

const CLASS_NAMES = {
editable: 'editable',
live: 'live',
error: 'error'
}
const CLASS_NAMES_EDITABLE = 'editable'
const CLASS_NAMES_LIVE = 'live'
const CLASS_NAMES_ERROR = 'error'

// --- Helper functions ---
// --- Utility methods ---

// Default "transpiler" function
let compiler = code => code
Expand Down Expand Up @@ -117,7 +115,7 @@ const processExamples = (el, binding, vnode) => {
hljs.highlightBlock(pre)

// Add editable class
pre.classList.add(CLASS_NAMES.editable)
pre.classList.add(CLASS_NAMES_EDITABLE)

// Store "previous" content on pre element
pre.$_v_play_content = pre.textContent.trim()
Expand All @@ -131,7 +129,7 @@ const processExamples = (el, binding, vnode) => {
// Enable live edit on double click
pre.ondblclick = async () => {
// Add live class
pre.classList.add(CLASS_NAMES.live)
pre.classList.add(CLASS_NAMES_LIVE)
// Make editable
pre.contentEditable = true

Expand All @@ -158,9 +156,9 @@ const processExamples = (el, binding, vnode) => {

// Toggle error class
if (vm === null) {
pre.classList.add(CLASS_NAMES.error)
pre.classList.add(CLASS_NAMES_ERROR)
} else {
pre.classList.remove(CLASS_NAMES.error)
pre.classList.remove(CLASS_NAMES_ERROR)
}
}, 500)
}
Expand Down
77 changes: 47 additions & 30 deletions src/components/alert/alert.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { ARIA_LIVE_POLITE, ARIA_VALUE_TRUE } from '../../constants/aria'
import { ATTR_ARIA_ATOMIC, ATTR_ARIA_LABEL, ATTR_ARIA_LIVE, ATTR_ROLE } from '../../constants/attrs'
import { CLASS_NAME_ALERT } from '../../constants/class-names'
import { NAME_ALERT } from '../../constants/components'
import { EVENT_NAME_CLICK, EVENT_NAME_INPUT } from '../../constants/events'
import { ROLE_ALERT } from '../../constants/roles'
import { SLOT_NAME_DEFAULT } from '../../constants/slot-names'
import { TAG_DIV } from '../../constants/tags'
import BVTransition from '../../utils/bv-transition'
import Vue from '../../utils/vue'
import { getComponentConfig } from '../../utils/config'
import { requestAF } from '../../utils/dom'
import { isBoolean } from '../../utils/inspect'
import { isBoolean, isNumeric } from '../../utils/inspect'
import { toInteger } from '../../utils/number'
import BVTransition from '../../utils/bv-transition'
import { buildObject } from '../../utils/object'
import { suffixClass } from '../../utils/string'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import { BButtonClose } from '../button/button-close'

const NAME = 'BAlert'
// --- Utility methods ---

// Convert `show` value to a number
const parseCountDown = show => {
Expand All @@ -30,29 +40,27 @@ const parseShow = show => {
return !!show
}

// Is a value number like (i.e. a number or a number as string)
const isNumericLike = value => !isNaN(toInteger(value))

// --- Main component ---
// @vue/component
export const BAlert = /*#__PURE__*/ Vue.extend({
name: NAME,
name: NAME_ALERT,
mixins: [normalizeSlotMixin],
model: {
prop: 'show',
event: 'input'
event: EVENT_NAME_INPUT
},
props: {
variant: {
type: String,
default: () => getComponentConfig(NAME, 'variant')
default: () => getComponentConfig(NAME_ALERT, 'variant')
},
dismissible: {
type: Boolean,
default: false
},
dismissLabel: {
type: String,
default: () => getComponentConfig(NAME, 'dismissLabel')
default: () => getComponentConfig(NAME_ALERT, 'dismissLabel')
},
show: {
type: [Boolean, Number, String],
Expand All @@ -78,12 +86,12 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
},
countDown(newVal) {
this.clearCountDownInterval()
if (isNumericLike(this.show)) {
if (isNumeric(this.show)) {
// Ignore if this.show transitions to a boolean value.
this.$emit('dismiss-count-down', newVal)
if (this.show !== newVal) {
// Update the v-model if needed
this.$emit('input', newVal)
this.$emit(EVENT_NAME_INPUT, newVal)
}
if (newVal > 0) {
this.localShow = true
Expand All @@ -101,13 +109,13 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
}
},
localShow(newVal) {
if (!newVal && (this.dismissible || isNumericLike(this.show))) {
if (!newVal && (this.dismissible || isNumeric(this.show))) {
// Only emit dismissed events for dismissible or auto dismissing alerts
this.$emit('dismissed')
}
if (!isNumericLike(this.show) && this.show !== newVal) {
if (!isNumeric(this.show) && this.show !== newVal) {
// Only emit booleans if we weren't passed a number via `this.show`
this.$emit('input', newVal)
this.$emit(EVENT_NAME_INPUT, newVal)
}
}
},
Expand Down Expand Up @@ -136,32 +144,41 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
}
},
render(h) {
let $alert // undefined
let $alert = h()
if (this.localShow) {
const { dismissible, variant } = this

let $dismissBtn = h()
if (this.dismissible) {
// Add dismiss button
if (dismissible) {
$dismissBtn = h(
BButtonClose,
{ attrs: { 'aria-label': this.dismissLabel }, on: { click: this.dismiss } },
{
attrs: buildObject([[ATTR_ARIA_LABEL, this.dismissLabel]]),
on: buildObject([[EVENT_NAME_CLICK, this.dismiss]])
},
[this.normalizeSlot('dismiss')]
)
}

$alert = h(
'div',
TAG_DIV,
{
key: this._uid,
staticClass: 'alert',
class: {
'alert-dismissible': this.dismissible,
[`alert-${this.variant}`]: this.variant
},
attrs: { role: 'alert', 'aria-live': 'polite', 'aria-atomic': true }
staticClass: CLASS_NAME_ALERT,
class: buildObject([
[suffixClass(CLASS_NAME_ALERT, 'dismissible'), dismissible],
[suffixClass(CLASS_NAME_ALERT, variant), variant]
]),
attrs: buildObject([
[ATTR_ROLE, ROLE_ALERT],
[ATTR_ARIA_LIVE, ARIA_LIVE_POLITE],
[ATTR_ARIA_ATOMIC, ARIA_VALUE_TRUE]
]),
key: this._uid
},
[$dismissBtn, this.normalizeSlot('default')]
[$dismissBtn, this.normalizeSlot(SLOT_NAME_DEFAULT)]
)
$alert = [$alert]
}
return h(BVTransition, { props: { noFade: !this.fade } }, $alert)

return h(BVTransition, { props: { noFade: !this.fade } }, [$alert])
}
})
38 changes: 23 additions & 15 deletions src/components/aspect/aspect.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { CLASS_NAME_BV_ASPECT } from '../../constants/class-names'
import { NAME_ASPECT } from '../../constants/components'
import { RX_ASPECT, RX_ASPECT_SEPARATOR } from '../../constants/regex'
import { SLOT_NAME_DEFAULT } from '../../constants/slot-names'
import Vue from '../../utils/vue'
import { mathAbs } from '../../utils/math'
import { toFloat } from '../../utils/number'
import { suffixClass } from '../../utils/string'
import normalizeSlotMixin from '../../mixins/normalize-slot'

// --- Constants ---
const NAME = 'BAspect'
const CLASS_NAME = 'b-aspect'

const RX_ASPECT = /^\d+(\.\d*)?[/:]\d+(\.\d*)?$/
const RX_SEPARATOR = /[/:]/

// --- Main Component ---
// --- Main component ---
// @vue/component
export const BAspect = /*#__PURE__*/ Vue.extend({
name: NAME,
name: NAME_ASPECT,
mixins: [normalizeSlotMixin],
props: {
aspect: {
Expand All @@ -31,9 +30,9 @@ export const BAspect = /*#__PURE__*/ Vue.extend({
const aspect = this.aspect
let ratio = 1
if (RX_ASPECT.test(aspect)) {
// Width and/or Height can be a decimal value below `1`, so
// Width and/or height can be a decimal value below `1`, so
// we only fallback to `1` if the value is `0` or `NaN`
const [width, height] = aspect.split(RX_SEPARATOR).map(v => toFloat(v) || 1)
const [width, height] = aspect.split(RX_ASPECT_SEPARATOR).map(v => toFloat(v) || 1)
ratio = width / height
} else {
ratio = toFloat(aspect) || 1
Expand All @@ -43,17 +42,26 @@ export const BAspect = /*#__PURE__*/ Vue.extend({
},
render(h) {
const $sizer = h('div', {
staticClass: `${CLASS_NAME}-sizer flex-grow-1`,
staticClass: suffixClass(CLASS_NAME_BV_ASPECT, 'sizer'),
class: 'flex-grow-1',
style: { paddingBottom: this.padding, height: 0 }
})
const $content = h(
'div',
{
staticClass: `${CLASS_NAME}-content flex-grow-1 w-100 mw-100`,
staticClass: suffixClass(CLASS_NAME_BV_ASPECT, 'content'),
class: ['flex-grow-1', 'w-100', 'mw-100'],
style: { marginLeft: '-100%' }
},
[this.normalizeSlot('default')]
[this.normalizeSlot(SLOT_NAME_DEFAULT)]
)
return h(
this.tag,
{
staticClass: CLASS_NAME_BV_ASPECT,
class: 'd-flex'
},
[$sizer, $content]
)
return h(this.tag, { staticClass: `${CLASS_NAME} d-flex` }, [$sizer, $content])
}
})
33 changes: 23 additions & 10 deletions src/components/avatar/avatar-group.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { CLASS_NAME_BV_AVATAR_GROUP } from '../../constants/class-names'
import { NAME_AVATAR_GROUP } from '../../constants/components'
import { ROLE_GROUP } from '../../constants/roles'
import { SLOT_NAME_DEFAULT } from '../../constants/slot-names'
import Vue from '../../utils/vue'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import { mathMax, mathMin } from '../../utils/math'
import { toFloat } from '../../utils/number'
import { suffixClass } from '../../utils/string'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import { computeSize } from './avatar'

// --- Constants ---
const NAME = 'BAvatarGroup'

// --- Main component ---
// @vue/component
export const BAvatarGroup = /*#__PURE__*/ Vue.extend({
name: NAME,
name: NAME_AVATAR_GROUP,
mixins: [normalizeSlotMixin],
provide() {
return { bvAvatarGroup: this }
Expand Down Expand Up @@ -59,10 +60,22 @@ export const BAvatarGroup = /*#__PURE__*/ Vue.extend({
}
},
render(h) {
const $inner = h('div', { staticClass: 'b-avatar-group-inner', style: this.paddingStyle }, [
this.normalizeSlot('default')
])
const $inner = h(
'div',
{
staticClass: suffixClass(CLASS_NAME_BV_AVATAR_GROUP, 'inner'),
style: this.paddingStyle
},
[this.normalizeSlot(SLOT_NAME_DEFAULT)]
)

return h(this.tag, { staticClass: 'b-avatar-group', attrs: { role: 'group' } }, [$inner])
return h(
this.tag,
{
staticClass: CLASS_NAME_BV_AVATAR_GROUP,
attrs: { role: ROLE_GROUP }
},
[$inner]
)
}
})
Loading
0