Skip to content

Commit

Permalink
[duoyun-ui] <dy-pat-form> support input group
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Mar 16, 2024
1 parent fa35987 commit c2acdd6
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 163 deletions.
2 changes: 1 addition & 1 deletion packages/duoyun-ui/docs/en/01-guide/20-form.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class MyEleElement extends GemElement {
<dy-form-item
.rules=${
[
/** support validtor */
/** support validator */
]
}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/docs/zh/01-guide/20-form.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class MyEleElement extends GemElement {
<dy-form-item
.rules=${
[
/** support validtor */
/** support validator */
]
}
>
Expand Down
17 changes: 14 additions & 3 deletions packages/duoyun-ui/src/elements/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ type FormItemRule = {
* @attr disabled
* @attr searchable
* @attr clearable
* @attr rows
* @attr step
* @attr min
* @attr max
*/
@customElement('dy-form-item')
@adoptedStyle(formItemStyle)
Expand All @@ -241,7 +245,7 @@ export class DuoyunFormItemElement extends GemElement<FormItemState> {
| 'radio-group'
| 'select'
| 'textarea'
| 'slot';
| 'slot'; // need value and change custom event
@boolattribute multiple: boolean; // picker/select/text
@attribute name: string;
@attribute label: string;
Expand All @@ -266,8 +270,6 @@ export class DuoyunFormItemElement extends GemElement<FormItemState> {
@numattribute min: number;
@numattribute max: number;

@property rules?: FormItemRule[];

/**@deprecated */
@property dataList?: DataList | PickerOption[] | SelectOption[];
@property options?: DataList | PickerOption[] | SelectOption[];
Expand Down Expand Up @@ -300,6 +302,10 @@ export class DuoyunFormItemElement extends GemElement<FormItemState> {
if (this.#type === 'slot') {
this.#itemchange(evt.detail);
}
// `dy-input-group` 触发
if (!this.name && this.value === undefined) {
this.clearInvalidMessage();
}
});
}

Expand Down Expand Up @@ -520,7 +526,12 @@ export class DuoyunFormItemElement extends GemElement<FormItemState> {
this.setState({ invalidMessage: undefined });
}

rules?: FormItemRule[];

// 不绑定 `value` 将只支持 `validator`
async valid() {
if (this.hidden) return true;

const rules = [...(this.rules || [])];
if (this.required && !rules.find((e) => 'required' in e)) {
rules.push({ required: true });
Expand Down
3 changes: 2 additions & 1 deletion packages/duoyun-ui/src/elements/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ const inputGroupStyle = createCSSSheet(css`
z-index: 1;
}
dy-input-group > * {
flex-grow: 1;
flex-grow: 10;
width: 0;
}
dy-input-group > :not(:last-child) {
border-top-right-radius: 0;
Expand Down
1 change: 0 additions & 1 deletion packages/duoyun-ui/src/elements/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export class DuoyunTableElement<T = any, K = any> extends GemElement {

@property noData?: string | TemplateResult;

/**@deprecated */
@property rowKey?: string | string[];
@property getKey?: (record: T) => K;
@property expandedRowRender?: (record: T) => undefined | string | TemplateResult;
Expand Down
23 changes: 14 additions & 9 deletions packages/duoyun-ui/src/helper/error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* effect module, handle other module error
*/
import { Toast } from '../elements/toast';
import { ignoredPromiseReasonSet } from '../lib/utils';

Expand All @@ -8,16 +11,18 @@ addEventListener('beforeunload', () => {
setTimeout(() => (unloading = false), 1000);
});

// TODO: configurable, support regexp, handle
const ignoreError = [
// chrome
'ResizeObserver',
'Script error.',
];

function printError(err: Error | ErrorEvent | DOMException) {
if (err instanceof DOMException && err.name === 'AbortError') {
return;
}
const ignoreError = [
// chrome
'ResizeObserver',
'Script error.',
];
if (unloading || ignoreError.some((msg) => err.message?.startsWith(msg))) return;
if (unloading) return;
if (err instanceof DOMException && err.name === 'AbortError') return;
if (ignoreError.some((msg) => err.message?.startsWith(msg))) return;

Toast.open('error', err.message || String(err));
}

Expand Down
3 changes: 2 additions & 1 deletion packages/duoyun-ui/src/helper/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type PaginationStore<T> = {
items: Partial<{ [id: string]: T }>;
// 正在加载,避免重复请求
loader: Partial<Record<string, Promise<T>>>;
// 用来触发 `<dy-pro-table>` fetch 事件
updatedItem?: T;
};

Expand All @@ -47,7 +48,7 @@ type PaginationStoreOptions<T> = {
export function createPaginationStore<T extends Record<string, any>>(options: PaginationStoreOptions<T>) {
const { idKey = 'id', storageKey, cacheItems, pageContainItem, ...rest } = options;

const cacheExcludeKeys: (keyof PaginationStore<T>)[] = ['loader'];
const cacheExcludeKeys: (keyof PaginationStore<T>)[] = ['loader', 'updatedItem'];
if (!cacheItems) cacheExcludeKeys.push('items');

const initStore: PaginationStore<T> = {
Expand Down
18 changes: 16 additions & 2 deletions packages/duoyun-ui/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ export function proxyObject(object: Record<string | symbol | number, any>) {
});
}

type ReadPropOptions = {
fill?: boolean;
onlyFillIntermediate?: boolean;
};
/**Deep read prop */
export function readProp(obj: Record<string, any>, paths: string | number | symbol | string[]) {
return Array.isArray(paths) ? paths.reduce((p, c) => p?.[c], obj) : obj[paths as string];
export function readProp(
obj: Record<string, any>,
paths: string | number | symbol | string[],
options: ReadPropOptions = {},
) {
if (!Array.isArray(paths)) return obj[paths as string];
const len = paths.length;
return paths.reduce((p, c, i) => {
if (!options.fill) return p?.[c];
if (options.onlyFillIntermediate && i === len - 1) return p[c];
return (p[c] ||= {});
}, obj);
}

/**Only let the last add Promise take effect, don’t care about the order of Resolve */
Expand Down
Loading

0 comments on commit c2acdd6

Please sign in to comment.