Skip to content

Commit 1acf462

Browse files
committed
0.33.0
1 parent f677057 commit 1acf462

File tree

14 files changed

+121
-58
lines changed

14 files changed

+121
-58
lines changed

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
- [`balm-ui-pro@legacy`](https://github.com/balmjs/balm-ui-pro/tree/legacy) for Vue 2
44

5+
## v0.33.0 / 2025-02-28
6+
7+
### Chore
8+
9+
- `<ui-multi-select>`: optimize v-show for options
10+
- `<ui-detail-view>`:
11+
- add `action` params for `setModelDataFn`
12+
- update `modelValueDefaults` handler for `getModelData`
13+
- `$dialog`: update `actionConfig` for supporting `if` attribute
14+
- update vetur
15+
16+
### Bug Fixes
17+
18+
- `<ui-list-view>`: fix resetListData bug for handleAction
19+
- `<ui-checkbox-group>`: fix handleSelectAll bug for init
20+
521
## v0.32.0 / 2024-10-10
622

723
### Features
@@ -10,6 +26,8 @@
1026

1127
## v0.31.2 / 2024-09-06
1228

29+
### Bug Fixes
30+
1331
- `<ui-list-view>`: fix usePlaceholder bug for init
1432

1533
## v0.31.1 / 2024-03-20

config/vetur/attributes/ui-checkbox-group.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"config": {
2+
"pro-config": {
33
"type": "object",
44
"description": "Form item config"
55
},
6-
"form-data": {
6+
"pro-form-data": {
77
"type": "object",
88
"description": "Form model data"
99
},
10-
"form-data-source": {
10+
"pro-form-data-source": {
1111
"type": "object",
1212
"description": "Form model data source"
1313
},

config/vetur/attributes/ui-multi-select.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"config": {
2+
"pro-config": {
33
"type": "object",
44
"description": "Form item config"
55
},
6-
"form-data": {
6+
"pro-form-data": {
77
"type": "object",
88
"description": "Form model data"
99
},
10-
"form-data-source": {
10+
"pro-form-data-source": {
1111
"type": "object",
1212
"description": "Form model data source"
1313
},

config/vetur/attributes/ui-radio-group.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"config": {
2+
"pro-config": {
33
"type": "object",
44
"description": "Form item config"
55
},
6-
"form-data": {
6+
"pro-form-data": {
77
"type": "object",
88
"description": "Form model data"
99
},
10-
"form-data-source": {
10+
"pro-form-data-source": {
1111
"type": "object",
1212
"description": "Form model data source"
1313
},

config/vetur/attributes/ui-switch-box.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"config": {
2+
"pro-config": {
33
"type": "object",
44
"description": "Form item config"
55
},
6-
"form-data": {
6+
"pro-form-data": {
77
"type": "object",
88
"description": "Form model data"
99
},
10-
"form-data-source": {
10+
"pro-form-data-source": {
1111
"type": "object",
1212
"description": "Form model data source"
1313
},

config/vetur/tags.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
},
2727
"ui-checkbox-group": {
2828
"attributes": [
29-
"config",
30-
"form-data",
31-
"form-data-source",
29+
"pro-config",
30+
"pro-form-data",
31+
"pro-form-data-source",
3232
"option-format",
3333
"model-value",
3434
"options",
@@ -40,9 +40,9 @@
4040
},
4141
"ui-radio-group": {
4242
"attributes": [
43-
"config",
44-
"form-data",
45-
"form-data-source",
43+
"pro-config",
44+
"pro-form-data",
45+
"pro-form-data-source",
4646
"option-format",
4747
"model-value",
4848
"options"
@@ -51,9 +51,9 @@
5151
},
5252
"ui-switch-box": {
5353
"attributes": [
54-
"config",
55-
"form-data",
56-
"form-data-source",
54+
"pro-config",
55+
"pro-form-data",
56+
"pro-form-data-source",
5757
"option-format",
5858
"model-value",
5959
"options",
@@ -63,9 +63,9 @@
6363
},
6464
"ui-multi-select": {
6565
"attributes": [
66-
"config",
67-
"form-data",
68-
"form-data-source",
66+
"pro-config",
67+
"pro-form-data",
68+
"pro-form-data-source",
6969
"option-format",
7070
"model-value",
7171
"components"

mock-server/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const NAMESPACE = '/mock/api';
1+
export const BALM_API_REGEX = /\/browser-sync\/socket\.io\//;
22

3+
export const NAMESPACE = '/mock/api';
34
export const MOCK_API_REGEX = /^\/mock\/api/;
5+
46
export const PROXY_API_REGEX = /^\/(api)\//; // NOTE: sync from balm config `server.proxyConfig.context`

mock-server/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import axios from 'axios';
22
import useAdapter from 'miragejs-axios-adapter';
33
import { createServer } from 'miragejs';
4-
import { NAMESPACE, PROXY_API_REGEX, MOCK_API_REGEX } from './config';
4+
import {
5+
BALM_API_REGEX,
6+
NAMESPACE,
7+
PROXY_API_REGEX,
8+
MOCK_API_REGEX
9+
} from './config';
510
import createApis from './modules';
611

712
export function mockServer() {
@@ -21,7 +26,9 @@ export function mockServer() {
2126
}
2227
});
2328

24-
server.passthrough(({ url }) => PROXY_API_REGEX.test(url));
29+
server.passthrough(
30+
({ url }) => BALM_API_REGEX.test(url) || PROXY_API_REGEX.test(url)
31+
);
2532

2633
return server;
2734
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "balm-ui-pro",
3-
"version": "0.32.0",
3+
"version": "0.33.0",
44
"description": "More configuration definition, less code implementation for Vue.js",
55
"keywords": [
66
"balm",

src/scripts/components/checkbox-group/checkbox-group.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
v-model="selectedAll"
66
:input-id="uuid"
77
:indeterminate="indeterminate"
8-
@update:model-value="handleSelectAll"
8+
@update:model-value="handleSelectAllAndChange"
99
></ui-checkbox>
1010
<label :for="uuid">{{ allSelectedLabel }}</label>
1111
</ui-form-field>
@@ -106,7 +106,10 @@ function handleSelectAll(checked) {
106106
state.selectedValue = checked
107107
? currentOptions.value.map((option) => option[props.optionFormat.value])
108108
: [];
109+
}
109110
111+
function handleSelectAllAndChange(checked) {
112+
handleSelectAll(checked);
110113
handleChange(state.selectedValue);
111114
}
112115
</script>

src/scripts/components/detail-view/detail-view.vue

+25-12
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ async function setModelConfig() {
218218
function initModelData(formData = {}) {
219219
state.loading = false;
220220
221-
nextTick(async () => {
222-
state.detailData = Object.assign(formData, props.modelValueDefaults);
223-
await getModelData();
221+
nextTick(() => {
222+
state.detailData = formData;
223+
getModelData();
224224
});
225225
}
226226
@@ -231,18 +231,29 @@ function resetDetailData() {
231231
state.loading = true;
232232
}
233233
234+
function updateDetailData(originalData) {
235+
instance.ctx.$refs.formView.formDataSource = originalData;
236+
state.detailDataSource = originalData;
237+
Object.keys(state.detailData).forEach(
238+
(key) =>
239+
originalData.hasOwnProperty(key) &&
240+
(state.detailData[key] = originalData[key])
241+
);
242+
}
243+
234244
async function getModelData() {
235245
try {
236-
const formDataSource = await props.getModelDataFn()(fullInstanceData.value);
246+
let originalData = await props.getModelDataFn()(fullInstanceData.value);
237247
238-
if (isObject(formDataSource) && Object.keys(formDataSource).length) {
239-
instance.ctx.$refs.formView.formDataSource = formDataSource;
240-
state.detailDataSource = formDataSource;
241-
Object.keys(state.detailData).forEach(
242-
(key) =>
243-
formDataSource.hasOwnProperty(key) &&
244-
(state.detailData[key] = formDataSource[key])
248+
if (isObject(originalData) && Object.keys(originalData).length) {
249+
updateDetailData(originalData);
250+
} else {
251+
originalData = Object.assign(
252+
{},
253+
state.detailData,
254+
props.modelValueDefaults
245255
);
256+
Object.keys(originalData).length && updateDetailData(originalData);
246257
}
247258
} catch (err) {
248259
console.warn(`[${UI_DETAIL_VIEW.NAME}]: ${err.toString()}`);
@@ -285,7 +296,9 @@ async function handleAction(action, result) {
285296
}
286297
287298
if (canSubmit && action.submit !== false) {
288-
await props.setModelDataFn()(fullInstanceData.value);
299+
await props.setModelDataFn()(
300+
Object.assign({ action }, fullInstanceData.value)
301+
);
289302
props.redirectOnSave && redirect(props.to, false);
290303
}
291304
break;

src/scripts/components/list-view/list-view.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,15 @@ async function handleAction(action, result) {
495495
state.searchForm.message = result.message;
496496
}
497497
498-
resetListData();
499-
500498
switch (action.type) {
501499
case UI_LIST_VIEW.EVENTS.submit:
500+
resetListData();
502501
if (canSubmit && action.submit !== false) {
503502
await getModelData();
504503
}
505504
break;
506505
case UI_LIST_VIEW.EVENTS.reset:
506+
resetListData();
507507
// NOTE: automatic processing in `<ui-form-view>`
508508
if (canSubmit && props.searchOnReset) {
509509
await getModelData();

src/scripts/components/multi-select/multi-select.vue

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
:key="`${component.key}-${index}`"
66
>
77
<ui-select
8+
v-show="
9+
selectedKeys[index - 1] ? selectedOptions[component.key].length : true
10+
"
811
v-model="selectedData[component.key]"
912
:options="selectedOptions[component.key]"
1013
v-bind="component.attrOrProp || {}"

src/scripts/plugins/dialog.js

+32-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from 'vue';
1010
import createVueApp from '../config/ssr';
1111
import MdcDialog from '../components/dialog/mdc-dialog.vue';
12-
import { isObject } from '../utils/typeof';
12+
import { isObject, isFunction } from '../utils/typeof';
1313
import { createDiv, removeDiv } from '../utils/div';
1414

1515
// Define confirm dialog constants
@@ -56,20 +56,22 @@ const template = `<mdc-dialog :class="className" :open="open" :title="title" :ma
5656
<div v-else class="mdc-dialog__custom-content" v-html="content"></div>
5757
<template v-if="actionConfig.length" #actions>
5858
<template v-for="(buttonData, buttonIndex) in actionConfig">
59-
<ui-button
60-
v-if="buttonData.type === PRO_DIALOG_BUTTON_TYPES.submit"
61-
v-debounce="handleDialogAction(buttonData)"
62-
v-bind="buttonData.attrOrProp || {}"
63-
>
64-
{{ buttonData.text }}
65-
</ui-button>
66-
<ui-button
67-
v-else
68-
v-bind="buttonData.attrOrProp || {}"
69-
@click="handleDialogAction(buttonData)"
70-
>
71-
{{ buttonData.text }}
72-
</ui-button>
59+
<template v-if="ifAction(buttonData)">
60+
<ui-button
61+
v-if="buttonData.type === PRO_DIALOG_BUTTON_TYPES.submit"
62+
v-debounce="handleDialogAction(buttonData)"
63+
v-bind="buttonData.attrOrProp || {}"
64+
>
65+
{{ buttonData.text }}
66+
</ui-button>
67+
<ui-button
68+
v-else
69+
v-bind="buttonData.attrOrProp || {}"
70+
@click="handleDialogAction(buttonData)"
71+
>
72+
{{ buttonData.text }}
73+
</ui-button>
74+
</template>
7375
</template>
7476
</template>
7577
</mdc-dialog>`;
@@ -136,6 +138,20 @@ function createDialog(options) {
136138

137139
onBeforeUnmount(() => removeElement(el));
138140

141+
function ifAction(action) {
142+
let result = false;
143+
144+
const currentAction = action.if;
145+
const formViewData = {
146+
data: state.modelValue,
147+
dataSource: state.modelValueSource
148+
};
149+
150+
result = isFunction(currentAction) ? currentAction(formViewData) : true;
151+
152+
return result;
153+
}
154+
139155
function handleClose(onSave = false) {
140156
if (dialogApp) {
141157
state.open = false;
@@ -227,6 +243,7 @@ function createDialog(options) {
227243
return {
228244
PRO_DIALOG_BUTTON_TYPES,
229245
...toRefs(state),
246+
ifAction,
230247
handleClose,
231248
handleComponentAction,
232249
handleDialogAction

0 commit comments

Comments
 (0)