Skip to content

Commit 789b3d3

Browse files
authored
chore: code refactoring to separate constants from utils and better code sharing (#5772)
* Initial improvements * Separate inspect from other utils * feat: code refactoring to reparte constants from utils and better code sharing * Update modal.js * Update form-group.spec.js * Update .bundlewatch.config.json * Update form-group.spec.js
1 parent b484301 commit 789b3d3

File tree

179 files changed

+1370
-1155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+1370
-1155
lines changed

.bundlewatch.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@
3434
},
3535
{
3636
"path": "./dist/bootstrap-vue.js",
37-
"maxSize": "235 kB"
37+
"maxSize": "240 kB"
3838
},
3939
{
4040
"path": "./dist/bootstrap-vue.min.js",
4141
"maxSize": "105 kB"
4242
},
4343
{
4444
"path": "./dist/bootstrap-vue.common.js",
45-
"maxSize": "320 kB"
45+
"maxSize": "325 kB"
4646
},
4747
{
4848
"path": "./dist/bootstrap-vue.common.min.js",
4949
"maxSize": "200 kB"
5050
},
5151
{
5252
"path": "./dist/bootstrap-vue.esm.js",
53-
"maxSize": "320 kB"
53+
"maxSize": "325 kB"
5454
},
5555
{
5656
"path": "./dist/bootstrap-vue.esm.min.js",

docs/pages/play.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ const STORAGE_KEYS = {
356356
// Maximum age of localStorage before we revert back to defaults
357357
const STORAGE_MAX_RETENTION = 7 * 24 * 60 * 60 * 1000 // 7 days
358358
359-
// --- Helper functions ---
359+
// --- Helper methods ---
360360
361361
// Remove a node from its parent's children
362362
const removeNode = node => node && node.parentNode && node.parentNode.removeChild(node)

docs/plugins/play.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ const RX_NAME_DEFINITION = /<!-- .*\.vue -->/
1010
const RX_TEMPLATE = /<template>([\s\S]*)<\/template>/
1111
const RX_SCRIPT = /<script>([\s\S]*)<\/script>/
1212

13-
const CLASS_NAMES = {
14-
editable: 'editable',
15-
live: 'live',
16-
error: 'error'
17-
}
13+
const CLASS_NAMES_EDITABLE = 'editable'
14+
const CLASS_NAMES_LIVE = 'live'
15+
const CLASS_NAMES_ERROR = 'error'
1816

19-
// --- Helper functions ---
17+
// --- Helper methods ---
2018

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

119117
// Add editable class
120-
pre.classList.add(CLASS_NAMES.editable)
118+
pre.classList.add(CLASS_NAMES_EDITABLE)
121119

122120
// Store "previous" content on pre element
123121
pre.$_v_play_content = pre.textContent.trim()
@@ -131,7 +129,7 @@ const processExamples = (el, binding, vnode) => {
131129
// Enable live edit on double click
132130
pre.ondblclick = async () => {
133131
// Add live class
134-
pre.classList.add(CLASS_NAMES.live)
132+
pre.classList.add(CLASS_NAMES_LIVE)
135133
// Make editable
136134
pre.contentEditable = true
137135

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

159157
// Toggle error class
160158
if (vm === null) {
161-
pre.classList.add(CLASS_NAMES.error)
159+
pre.classList.add(CLASS_NAMES_ERROR)
162160
} else {
163-
pre.classList.remove(CLASS_NAMES.error)
161+
pre.classList.remove(CLASS_NAMES_ERROR)
164162
}
165163
}, 500)
166164
}

src/components/alert/alert.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { NAME_ALERT } from '../../constants/components'
12
import Vue from '../../utils/vue'
23
import { getComponentConfig } from '../../utils/config'
34
import { requestAF } from '../../utils/dom'
4-
import { isBoolean } from '../../utils/inspect'
5+
import { isBoolean, isNumeric } from '../../utils/inspect'
56
import { toInteger } from '../../utils/number'
67
import BVTransition from '../../utils/bv-transition'
78
import normalizeSlotMixin from '../../mixins/normalize-slot'
89
import { BButtonClose } from '../button/button-close'
910

10-
const NAME = 'BAlert'
11-
1211
// Convert `show` value to a number
1312
const parseCountDown = show => {
1413
if (show === '' || isBoolean(show)) {
@@ -30,12 +29,9 @@ const parseShow = show => {
3029
return !!show
3130
}
3231

33-
// Is a value number like (i.e. a number or a number as string)
34-
const isNumericLike = value => !isNaN(toInteger(value))
35-
3632
// @vue/component
3733
export const BAlert = /*#__PURE__*/ Vue.extend({
38-
name: NAME,
34+
name: NAME_ALERT,
3935
mixins: [normalizeSlotMixin],
4036
model: {
4137
prop: 'show',
@@ -44,15 +40,15 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
4440
props: {
4541
variant: {
4642
type: String,
47-
default: () => getComponentConfig(NAME, 'variant')
43+
default: () => getComponentConfig(NAME_ALERT, 'variant')
4844
},
4945
dismissible: {
5046
type: Boolean,
5147
default: false
5248
},
5349
dismissLabel: {
5450
type: String,
55-
default: () => getComponentConfig(NAME, 'dismissLabel')
51+
default: () => getComponentConfig(NAME_ALERT, 'dismissLabel')
5652
},
5753
show: {
5854
type: [Boolean, Number, String],
@@ -78,7 +74,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
7874
},
7975
countDown(newVal) {
8076
this.clearCountDownInterval()
81-
if (isNumericLike(this.show)) {
77+
if (isNumeric(this.show)) {
8278
// Ignore if this.show transitions to a boolean value.
8379
this.$emit('dismiss-count-down', newVal)
8480
if (this.show !== newVal) {
@@ -101,11 +97,11 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
10197
}
10298
},
10399
localShow(newVal) {
104-
if (!newVal && (this.dismissible || isNumericLike(this.show))) {
100+
if (!newVal && (this.dismissible || isNumeric(this.show))) {
105101
// Only emit dismissed events for dismissible or auto dismissing alerts
106102
this.$emit('dismissed')
107103
}
108-
if (!isNumericLike(this.show) && this.show !== newVal) {
104+
if (!isNumeric(this.show) && this.show !== newVal) {
109105
// Only emit booleans if we weren't passed a number via `this.show`
110106
this.$emit('input', newVal)
111107
}
@@ -158,7 +154,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
158154
},
159155
attrs: { role: 'alert', 'aria-live': 'polite', 'aria-atomic': true }
160156
},
161-
[$dismissBtn, this.normalizeSlot('default')]
157+
[$dismissBtn, this.normalizeSlot()]
162158
)
163159
$alert = [$alert]
164160
}

src/components/aspect/aspect.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
import { NAME_ASPECT } from '../../constants/components'
2+
import { RX_ASPECT, RX_ASPECT_SEPARATOR } from '../../constants/regex'
13
import Vue from '../../utils/vue'
24
import { mathAbs } from '../../utils/math'
35
import { toFloat } from '../../utils/number'
46
import normalizeSlotMixin from '../../mixins/normalize-slot'
57

68
// --- Constants ---
7-
const NAME = 'BAspect'
89
const CLASS_NAME = 'b-aspect'
910

10-
const RX_ASPECT = /^\d+(\.\d*)?[/:]\d+(\.\d*)?$/
11-
const RX_SEPARATOR = /[/:]/
12-
1311
// --- Main Component ---
1412
export const BAspect = /*#__PURE__*/ Vue.extend({
15-
name: NAME,
13+
name: NAME_ASPECT,
1614
mixins: [normalizeSlotMixin],
1715
props: {
1816
aspect: {
@@ -33,7 +31,7 @@ export const BAspect = /*#__PURE__*/ Vue.extend({
3331
if (RX_ASPECT.test(aspect)) {
3432
// Width and/or Height can be a decimal value below `1`, so
3533
// we only fallback to `1` if the value is `0` or `NaN`
36-
const [width, height] = aspect.split(RX_SEPARATOR).map(v => toFloat(v) || 1)
34+
const [width, height] = aspect.split(RX_ASPECT_SEPARATOR).map(v => toFloat(v) || 1)
3735
ratio = width / height
3836
} else {
3937
ratio = toFloat(aspect) || 1
@@ -52,7 +50,7 @@ export const BAspect = /*#__PURE__*/ Vue.extend({
5250
staticClass: `${CLASS_NAME}-content flex-grow-1 w-100 mw-100`,
5351
style: { marginLeft: '-100%' }
5452
},
55-
[this.normalizeSlot('default')]
53+
[this.normalizeSlot()]
5654
)
5755
return h(this.tag, { staticClass: `${CLASS_NAME} d-flex` }, [$sizer, $content])
5856
}

src/components/avatar/avatar-group.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
import { NAME_AVATAR_GROUP } from '../../constants/components'
12
import Vue from '../../utils/vue'
23
import normalizeSlotMixin from '../../mixins/normalize-slot'
34
import { mathMax, mathMin } from '../../utils/math'
45
import { toFloat } from '../../utils/number'
56
import { computeSize } from './avatar'
67

7-
// --- Constants ---
8-
const NAME = 'BAvatarGroup'
9-
108
// --- Main component ---
119
// @vue/component
1210
export const BAvatarGroup = /*#__PURE__*/ Vue.extend({
13-
name: NAME,
11+
name: NAME_AVATAR_GROUP,
1412
mixins: [normalizeSlotMixin],
1513
provide() {
1614
return { bvAvatarGroup: this }
@@ -60,7 +58,7 @@ export const BAvatarGroup = /*#__PURE__*/ Vue.extend({
6058
},
6159
render(h) {
6260
const $inner = h('div', { staticClass: 'b-avatar-group-inner', style: this.paddingStyle }, [
63-
this.normalizeSlot('default')
61+
this.normalizeSlot()
6462
])
6563

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

src/components/avatar/avatar.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { NAME_AVATAR } from '../../constants/components'
2+
import { RX_NUMBER } from '../../constants/regex'
13
import Vue from '../../utils/vue'
24
import { getComponentConfig } from '../../utils/config'
35
import { isNumber, isString } from '../../utils/inspect'
@@ -12,13 +14,10 @@ import { BIconPersonFill } from '../../icons/icons'
1214
import normalizeSlotMixin from '../../mixins/normalize-slot'
1315

1416
// --- Constants ---
15-
const NAME = 'BAvatar'
1617
const CLASS_NAME = 'b-avatar'
1718

1819
const SIZES = ['sm', null, 'lg']
1920

20-
const RX_NUMBER = /^[0-9]*\.?[0-9]+$/
21-
2221
const FONT_SIZE_SCALE = 0.4
2322
const BADGE_FONT_SIZE_SCALE = FONT_SIZE_SCALE * 0.7
2423

@@ -44,7 +43,7 @@ const props = {
4443
},
4544
variant: {
4645
type: String,
47-
default: () => getComponentConfig(NAME, 'variant')
46+
default: () => getComponentConfig(NAME_AVATAR, 'variant')
4847
},
4948
size: {
5049
type: [Number, String],
@@ -72,7 +71,7 @@ const props = {
7271
},
7372
badgeVariant: {
7473
type: String,
75-
default: () => getComponentConfig(NAME, 'badgeVariant')
74+
default: () => getComponentConfig(NAME_AVATAR, 'badgeVariant')
7675
},
7776
badgeTop: {
7877
type: Boolean,
@@ -104,7 +103,7 @@ export const computeSize = value => {
104103
// --- Main component ---
105104
// @vue/component
106105
export const BAvatar = /*#__PURE__*/ Vue.extend({
107-
name: NAME,
106+
name: NAME_AVATAR,
108107
mixins: [normalizeSlotMixin],
109108
inject: {
110109
bvAvatarGroup: { default: null }
@@ -193,9 +192,9 @@ export const BAvatar = /*#__PURE__*/ Vue.extend({
193192
const ariaLabel = this.ariaLabel || null
194193

195194
let $content = null
196-
if (this.hasNormalizedSlot('default')) {
195+
if (this.hasNormalizedSlot()) {
197196
// Default slot overrides props
198-
$content = h('span', { staticClass: 'b-avatar-custom' }, [this.normalizeSlot('default')])
197+
$content = h('span', { staticClass: 'b-avatar-custom' }, [this.normalizeSlot()])
199198
} else if (src) {
200199
$content = h('img', {
201200
style: variant ? {} : { width: '100%', height: '100%' },

src/components/badge/badge.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import { mergeData } from 'vue-functional-data-merge'
2-
import Vue from '../../utils/vue'
1+
import { NAME_BADGE } from '../../constants/components'
2+
import Vue, { mergeData } from '../../utils/vue'
33
import { getComponentConfig } from '../../utils/config'
44
import { omit } from '../../utils/object'
55
import { pluckProps } from '../../utils/props'
66
import { isLink } from '../../utils/router'
77
import { BLink, props as BLinkProps } from '../link/link'
88

9-
// --- Constants ---
10-
11-
const NAME = 'BBadge'
12-
139
// --- Props ---
1410

1511
const linkProps = omit(BLinkProps, ['event', 'routerTag'])
@@ -23,7 +19,7 @@ export const props = {
2319
},
2420
variant: {
2521
type: String,
26-
default: () => getComponentConfig(NAME, 'variant')
22+
default: () => getComponentConfig(NAME_BADGE, 'variant')
2723
},
2824
pill: {
2925
type: Boolean,
@@ -35,7 +31,7 @@ export const props = {
3531
// --- Main component ---
3632
// @vue/component
3733
export const BBadge = /*#__PURE__*/ Vue.extend({
38-
name: NAME,
34+
name: NAME_BADGE,
3935
functional: true,
4036
props,
4137
render(h, { props, data, children }) {

src/components/breadcrumb/breadcrumb-item.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Vue from '../../utils/vue'
2-
import { mergeData } from 'vue-functional-data-merge'
1+
import { NAME_BREADCRUMB_ITEM } from '../../constants/components'
2+
import Vue, { mergeData } from '../../utils/vue'
33
import { BBreadcrumbLink, props } from './breadcrumb-link'
44

55
// @vue/component
66
export const BBreadcrumbItem = /*#__PURE__*/ Vue.extend({
7-
name: 'BBreadcrumbItem',
7+
name: NAME_BREADCRUMB_ITEM,
88
functional: true,
99
props,
1010
render(h, { props, data, children }) {

src/components/breadcrumb/breadcrumb-link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { mergeData } from 'vue-functional-data-merge'
2-
import Vue from '../../utils/vue'
1+
import { NAME_BREADCRUMB_LINK } from '../../constants/components'
2+
import Vue, { mergeData } from '../../utils/vue'
33
import { htmlOrText } from '../../utils/html'
44
import { omit } from '../../utils/object'
55
import { pluckProps } from '../../utils/props'
@@ -26,7 +26,7 @@ export const props = {
2626
// --- Main component ---
2727
// @vue/component
2828
export const BBreadcrumbLink = /*#__PURE__*/ Vue.extend({
29-
name: 'BBreadcrumbLink',
29+
name: NAME_BREADCRUMB_LINK,
3030
functional: true,
3131
props,
3232
render(h, { props: suppliedProps, data, children }) {

src/components/breadcrumb/breadcrumb.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Vue from '../../utils/vue'
2-
import { mergeData } from 'vue-functional-data-merge'
1+
import { NAME_BREADCRUMB } from '../../constants/components'
2+
import Vue, { mergeData } from '../../utils/vue'
33
import { isArray, isObject } from '../../utils/inspect'
44
import { toString } from '../../utils/string'
55
import { BBreadcrumbItem } from './breadcrumb-item'
@@ -13,7 +13,7 @@ export const props = {
1313

1414
// @vue/component
1515
export const BBreadcrumb = /*#__PURE__*/ Vue.extend({
16-
name: 'BBreadcrumb',
16+
name: NAME_BREADCRUMB,
1717
functional: true,
1818
props,
1919
render(h, { props, data, children }) {

0 commit comments

Comments
 (0)