Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into w/#WIK-16218
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa committed Aug 5, 2024
2 parents e4a44ec + 93e28ab commit 8bc9680
Show file tree
Hide file tree
Showing 39 changed files with 597 additions and 167 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## [0.0.4](https://github.com/worktile/ai-table/compare/0.0.3...0.0.4) (2024-08-02)


### Features

* **action:** add AIPlugin ([#18](https://github.com/worktile/ai-table/issues/18)) ([024fa5f](https://github.com/worktile/ai-table/commit/024fa5fa8502febddef9b0b8ac1cc4802dc30451))
* add shared demo ([#15](https://github.com/worktile/ai-table/issues/15)) ([488a8e1](https://github.com/worktile/ai-table/commit/488a8e182daa5d0d8709153b87e3256c4c7239b5))
* apply icon and width #WIK-16166 ([cf46f10](https://github.com/worktile/ai-table/commit/cf46f102e5471ca19ed873e4daf0642cb4066ec3)), closes [#WIK-16166](https://github.com/worktile/ai-table/issues/WIK-16166)
* **core:** add set_field action #WIK-16194 ([#20](https://github.com/worktile/ai-table/issues/20)) ([6b34150](https://github.com/worktile/ai-table/commit/6b34150b78058da8b8f1b9e60e97524b6165abee)), closes [#WIK-16194](https://github.com/worktile/ai-table/issues/WIK-16194)
* **core:** support move_record and move_field #WIK-16196 ([#24](https://github.com/worktile/ai-table/issues/24)) ([3ebf3fc](https://github.com/worktile/ai-table/commit/3ebf3fc7801fb7780cc118388f5418ae8992a483)), closes [#WIK-16196](https://github.com/worktile/ai-table/issues/WIK-16196)
* **core:** support remove_field and remove_record #WIK-16192 ([#19](https://github.com/worktile/ai-table/issues/19)) ([2bc106e](https://github.com/worktile/ai-table/commit/2bc106ebbae3305e17ec2592ab3422c3042a46b4)), closes [#WIK-16192](https://github.com/worktile/ai-table/issues/WIK-16192)
* **demo:** add shared demo #WIK-16223 ([#27](https://github.com/worktile/ai-table/issues/27)) ([009a234](https://github.com/worktile/ai-table/commit/009a2348d9336fb111605b04c9ac18087a53725c)), closes [#WIK-16223](https://github.com/worktile/ai-table/issues/WIK-16223)
* **demo:** add ws server ([#23](https://github.com/worktile/ai-table/issues/23)) ([bd7bf6b](https://github.com/worktile/ai-table/commit/bd7bf6b1db525954dd5e35f4f83343066382640d))
* **selection:** add selection feature #WIK-16060 ([#12](https://github.com/worktile/ai-table/issues/12)) ([0392723](https://github.com/worktile/ai-table/commit/039272385a3b32f6d0a874e863a9a1d87301f8c0)), closes [#WIK-16060](https://github.com/worktile/ai-table/issues/WIK-16060)
* **types:** adjust field type and record value #WIK-16187 ([#21](https://github.com/worktile/ai-table/issues/21)) ([2938add](https://github.com/worktile/ai-table/commit/2938add3ebf4497b0367b6499bc8c163c395dc3b)), closes [#WIK-16187](https://github.com/worktile/ai-table/issues/WIK-16187)



## [0.0.3](https://github.com/worktile/ai-table/compare/0.0.2...0.0.3) (2024-07-22)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai-table",
"version": "0.0.3",
"version": "0.0.4",
"workspaces": [
"packages/*"
],
Expand Down Expand Up @@ -39,7 +39,7 @@
"@tethys/icons": "^1.4.62",
"date-fns": "^3.6.0",
"immer": "^10.0.3",
"ngx-tethys": "^17.0.8",
"ngx-tethys": "^17.0.14",
"npm": "^10.8.1",
"rxjs": "~7.8.0",
"tslib": "^2.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ai-table/grid",
"version": "0.0.3",
"version": "0.0.4",
"peerDependencies": {
"@angular/common": "^18.0.0",
"@angular/core": "^18.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export abstract class AbstractEditCellEditor<TValue, TFieldType extends AITableF
}

closePopover() {
this.thyPopoverRef.close();
this.thyPopoverRef?.close();
}
}
9 changes: 9 additions & 0 deletions packages/grid/src/components/cell-editors/cell-editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
height: 100%;
}
}

.text-cell-editor {
display: block;

textarea {
min-height: 44px;
resize: none;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use 'ngx-tethys/styles/variables.scss';

.progress-editor {
display: flex;
align-items: center;
height: 100%;
padding: 0 12px;

.thy-slider {
flex: 1;
padding: 2px 0;
}
.progress-text {
display: inline-block;
margin-left: 8px;
width: 40px;
white-space: nowrap;
font-size: 0.875rem;
flex-shrink: 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ChangeDetectionStrategy, Component, HostListener, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ThySlider, ThySliderSize, ThySliderType } from 'ngx-tethys/slider';
import { AbstractEditCellEditor } from '../abstract-cell-editor.component';

export interface AITableProgressConfig {
max?: number;
min?: number;
step?: number;
progressType?: ThySliderType;
suffix?: string;
size?: ThySliderSize;
}

@Component({
selector: 'progress-editor',
template: `
<thy-slider
[(ngModel)]="modelValue"
[thyMax]="config?.max || 100"
[thyMin]="config?.min || 0"
[thyStep]="config?.step || 1"
[thyType]="config?.progressType || 'success'"
[thySize]="config?.size || 'md'"
(ngModelChange)="updateValue($event)"
></thy-slider>
<span class="progress-text">{{ modelValue }}{{ config?.suffix || '%' }}</span>
`,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [FormsModule, ThySlider],
host: {
class: 'progress-editor'
}
})
export class ProgressEditorComponent extends AbstractEditCellEditor<number> implements OnInit {
config: Partial<AITableProgressConfig | undefined> = {
max: 100,
min: 0,
step: 1,
progressType: 'success',
suffix: '%',
size: 'md'
};

@HostListener('mousedown', ['$event'])
mousedownHandler(event: Event) {
event.preventDefault();
}

constructor() {
super();
}

updateValue(value: number) {
this.updateFieldValue();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AbstractEditCellEditor } from '../abstract-cell-editor.component';
import { ThyRate } from 'ngx-tethys/rate';
import { ThyTooltipModule } from 'ngx-tethys/tooltip';
import { AbstractEditCellEditor } from '../abstract-cell-editor.component';

@Component({
selector: 'rating-cell-editor',
template: ` <thy-rate [(ngModel)]="modelValue" (ngModelChange)="updateValue()"></thy-rate> `,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [FormsModule, ThyRate, ThyTooltipModule]
imports: [FormsModule, ThyRate]
})
export class RatingCellEditorComponent extends AbstractEditCellEditor<number> {
updateValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
import { NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, inject, Renderer2 } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ThyInputDirective } from 'ngx-tethys/input';
import { ThyAutofocusDirective, ThyEnterDirective } from 'ngx-tethys/shared';
import { AbstractEditCellEditor } from '../abstract-cell-editor.component';

@Component({
selector: 'text-cell-editor',
template: `<input
thyInput
[thyAutofocus]="true"
[(ngModel)]="modelValue"
(thyEnter)="updateValue()"
(blur)="updateValue()"
placeholder=""
/> `,
template: `
<textarea
placeholder=""
thyInput
[thyAutofocus]="true"
[(ngModel)]="modelValue"
(ngModelChange)="valueChange()"
(thyEnter)="updateValue()"
(blur)="updateValue()"
></textarea>
`,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgIf, FormsModule, ThyAutofocusDirective, ThyInputDirective, ThyEnterDirective]
imports: [NgIf, FormsModule, ThyAutofocusDirective, ThyInputDirective, ThyEnterDirective],
host: {
class: 'd-block'
}
})
export class TextCellEditorComponent extends AbstractEditCellEditor<string> {
export class TextCellEditorComponent extends AbstractEditCellEditor<string> implements AfterViewInit {
private elementRef = inject(ElementRef);

private render2 = inject(Renderer2);

private maxHeight = 148;

constructor() {
super();
}

ngAfterViewInit() {
setTimeout(() => {
this.updateStyle();
});
}

updateStyle() {
const textarea = this.elementRef.nativeElement.querySelector('textarea');
const height = textarea.scrollHeight <= this.maxHeight ? textarea.scrollHeight : this.maxHeight;

this.render2.setStyle(textarea, 'height', `${height}px`);
this.render2.setStyle(textarea, 'min-height', `44px`);
this.render2.setStyle(textarea, 'max-height', `${this.maxHeight}px`);
this.render2.setStyle(textarea, 'resize', 'none');
}

valueChange() {
this.updateStyle();
}

updateValue() {
this.updateFieldValue();
this.closePopover();
Expand Down
8 changes: 7 additions & 1 deletion packages/grid/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export * from './field-property-editor/field-property-editor.component'
export * from './cell-editors/date-time/date-time-editor.component';
export * from './cell-editors/link/number-editor.component';
export * from './cell-editors/number/number-editor.component';
export * from './cell-editors/progress/progress-editor.component';
export * from './cell-editors/rating/rating-editor.component';
export * from './cell-editors/text/text-editor.component';
export * from './field-property-editor/field-property-editor.component';
22 changes: 14 additions & 8 deletions packages/grid/src/constants/editor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { AITableFieldType } from '../core';
import { TextCellEditorComponent } from '../components/cell-editors/text/text-editor.component';
import { NumberCellEditorComponent } from '../components/cell-editors/number/number-editor.component';
import { DateTimeCellEditorComponent } from '../components/cell-editors/date-time/date-time-editor.component';
import { RatingCellEditorComponent } from '../components/cell-editors/rating/rating-editor.component';
import { LinkCellEditorComponent } from '../components/cell-editors/link/number-editor.component';
import {
DateTimeCellEditorComponent,
LinkCellEditorComponent,
NumberCellEditorComponent,
ProgressEditorComponent,
RatingCellEditorComponent,
TextCellEditorComponent
} from '../components';
import { SelectCellEditorComponent } from '../components/cell-editors/select/select-editor.component';
import { AITableFieldType } from '../core';

export const GRID_CELL_EDITOR_MAP: Partial<Record<AITableFieldType, any>> = {
export const GRID_CELL_EDITOR_MAP: Record<AITableFieldType, any> = {
[AITableFieldType.text]: TextCellEditorComponent,
[AITableFieldType.richText]: TextCellEditorComponent,
[AITableFieldType.select]: SelectCellEditorComponent,
[AITableFieldType.number]: NumberCellEditorComponent,
[AITableFieldType.member]: null,
[AITableFieldType.date]: DateTimeCellEditorComponent,
[AITableFieldType.rate]: RatingCellEditorComponent,
[AITableFieldType.link]: LinkCellEditorComponent
[AITableFieldType.link]: LinkCellEditorComponent,
[AITableFieldType.progress]: ProgressEditorComponent
};
11 changes: 4 additions & 7 deletions packages/grid/src/constants/grid.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { AITable, AITableFieldType } from '../core';
import { AITableFieldType } from '../core';

export const DEFAULT_COLUMN_WIDTH = 200;

export const MIN_COLUMN_WIDTH = 80;

export const DBL_CLICK_EDIT_TYPE = [
AITableFieldType.text,
AITableFieldType.number,
AITableFieldType.select,
AITableFieldType.date
];
export const DBL_CLICK_EDIT_TYPE = [AITableFieldType.text, AITableFieldType.number, AITableFieldType.select, AITableFieldType.date];

export const MOUSEOVER_EDIT_TYPE = [AITableFieldType.progress];

export const RowHeight = {
Short: 32,
Expand Down
8 changes: 7 additions & 1 deletion packages/grid/src/core/constants/field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AITableFieldInfo, AITableFieldType } from '../types';
import { helpers } from 'ngx-tethys/util';
import { AITableFieldInfo, AITableFieldType } from '../types';

export const BasicFields = [
{
Expand Down Expand Up @@ -37,6 +37,12 @@ export const BasicFields = [
name: '链接',
icon: 'link-insert',
width: 300
},
{
type: AITableFieldType.progress,
name: '进度',
icon: 'progress',
width: 200
}
];

Expand Down
4 changes: 2 additions & 2 deletions packages/grid/src/core/types/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WritableSignal } from '@angular/core';
import { AITableAction } from './action';
import { AITableSelection } from '../../types';
import { Id } from 'ngx-tethys/types';
import { AITableSelection } from '../../types';
import { AITableAction } from './action';

export enum AITableFieldType {
text = 'text', // 包含多行文本
Expand Down
20 changes: 16 additions & 4 deletions packages/grid/src/grid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</div>
@for (field of gridData().fields; track $index) {
<div
#cell
class="grid-cell"
[ngClass]="{
highlight: aiTable.selection().selectedCells.has(record.id) || aiTable.selection().selectedFields.has(field.id),
Expand All @@ -56,7 +57,6 @@
[attr.fieldId]="[field.id]"
[attr.recordId]="[record.id]"
[ngStyle]="{ width: field.width + 'px' }"
#cell
>
@switch (field.type) {
@case (AITableFieldType.select) {
Expand All @@ -73,13 +73,25 @@
@case (AITableFieldType.link) {
<a
class="d-block"
target="_blank"
[href]="record.values[field.id]?.url"
thyStopPropagation
thyFlexibleText
[thyTooltipContent]="record.values[field.id]?.text"
[href]="record.values[field.id]?.url"
target="_blank"
>{{ record.values[field.id]?.text }}</a
>
{{ record.values[field.id]?.text }}
</a>
}
@case (AITableFieldType.progress) {
<thy-progress
class="w-100"
[thyValue]="record.values[field.id]"
[thySize]="record.values[field.id]?.config?.size || 'md'"
[thyMax]="record.values[field.id]?.config?.max || 100"
[thyType]="record.values[field.id]?.config?.progressType || 'success'"
>
<span> {{ record.values[field.id] }}{{ record.values[field.id]?.config?.suffix || '%' }} </span>
</thy-progress>
}
@default {
<span class="text-truncate"> {{ record.values[field.id] }}</span>
Expand Down
Loading

0 comments on commit 8bc9680

Please sign in to comment.