Skip to content

Commit 222e1be

Browse files
committed
chore: refactor jsx types
1 parent 9b5b86e commit 222e1be

File tree

11 files changed

+107
-51
lines changed

11 files changed

+107
-51
lines changed

src/blocks/CloudImageEditor/src/CloudImageEditorBlock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type TabIdValue = (typeof TabId)[keyof typeof TabId];
3030
const DEFAULT_TABS = serializeCsv([...ALL_TABS]);
3131

3232
export class CloudImageEditorBlock extends LitBlock {
33+
public declare attributesMeta: ({ uuid: string } | { 'cdn-url': string }) &
34+
Partial<{ tabs: string; 'crop-preset': string }> & {
35+
'ctx-name': string;
36+
};
37+
3338
public override ctxOwner = true;
3439
public static override styleAttrs = ['uc-cloud-image-editor'];
3540

src/blocks/CloudImageEditor/src/elements/button/BtnUi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export class BtnUi extends LitBlock {
3232
@property({ attribute: 'title-prop' })
3333
public titleProp = '';
3434

35-
protected override firstUpdated(_changed: PropertyValues<this>): void {
36-
super.firstUpdated(_changed);
35+
protected override firstUpdated(changed: PropertyValues<this>): void {
36+
super.firstUpdated(changed);
3737
this._applyReverse();
3838
this._applyThemeClass();
3939
}

src/blocks/Config/Config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const getLocalPropName = (key: string) => `__${key}`;
5353

5454
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: This is intentional interface merging, used to add configuration setters/getters
5555
export class Config extends LitBlock {
56+
public declare attributesMeta: Partial<ConfigPlainType> & {
57+
'ctx-name': string;
58+
};
59+
5660
public override init$ = {
5761
...this.init$,
5862
...Object.fromEntries(

src/blocks/FormInput/FormInput.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type { OutputCollectionState } from '../../types/index';
33
import { applyStyles } from '../../utils/applyStyles';
44

55
export class FormInput extends LitUploaderBlock {
6+
public declare propertiesMeta: {
7+
'ctx-name': string;
8+
};
69
private _validationInputElement: HTMLInputElement | null = null;
710
private _dynamicInputsContainer: HTMLDivElement | null = null;
811

src/blocks/UploadCtxProvider/UploadCtxProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { type EventPayload, EventType } from './EventEmitter';
55

66
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: This is intentional interface merging, used to add event listener types
77
export class UploadCtxProvider extends LitUploaderBlock {
8+
public declare propertiesMeta: {
9+
'ctx-name': string;
10+
};
811
public static override styleAttrs = ['uc-wgt-common'];
912
public static EventType = EventType;
1013

src/lit/LitBlock.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import { TestModeController } from './TestModeController';
2424

2525
const LitBlockBase = RegisterableElementMixin(SymbioteMixin<SharedState>()(CssDataMixin(LightDomMixin(LitElement))));
2626
export class LitBlock extends LitBlockBase {
27+
/** Special property to reflect properties metadata to build proper JSX types */
28+
public declare attributesMeta: {
29+
[key: string]: unknown;
30+
};
2731
private __cfgProxy!: ConfigType;
2832

2933
public static styleAttrs: string[] = [];

src/solutions/file-uploader/inline/FileUploaderInline.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type FileUploaderInlineInitState = BaseInitState & {
1313
};
1414

1515
export class FileUploaderInline extends LitSolutionBlock {
16+
public declare propertiesMeta: {
17+
'ctx-name': string;
18+
};
1619
public static override styleAttrs = [...super.styleAttrs, 'uc-file-uploader-inline'];
1720

1821
@state()

src/solutions/file-uploader/minimal/FileUploaderMinimal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type FileUploaderMinimalInitState = BaseInitState & {
1616
};
1717

1818
export class FileUploaderMinimal extends LitSolutionBlock {
19+
public declare propertiesMeta: {
20+
'ctx-name': string;
21+
};
1922
public static override styleAttrs = [...super.styleAttrs, 'uc-file-uploader-minimal'];
2023

2124
@state()

src/solutions/file-uploader/regular/FileUploaderRegular.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ interface FileUploaderRegularInitState extends BaseInitState {
1010
}
1111

1212
export class FileUploaderRegular extends LitSolutionBlock {
13+
public declare attributesMeta: {
14+
headless: boolean;
15+
'ctx-name': string;
16+
};
1317
public static override styleAttrs = [...super.styleAttrs, 'uc-file-uploader-regular'];
1418

1519
@property({ type: Boolean })

types/jsx.d.ts

Lines changed: 75 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,93 @@
11
/// <reference types="react" />
22

3-
type ConfigPlainType = import('../dist/index.ts').ConfigPlainType;
3+
type LitBlock = import('../dist/index.ts').Block;
44
type UploadCtxProvider = import('../dist/index.ts').UploadCtxProvider;
55
type Config = import('../dist/index.ts').Config;
66
type FileUploaderInline = import('../dist/index.ts').FileUploaderInline;
77
type FileUploaderRegular = import('../dist/index.ts').FileUploaderRegular;
88
type FileUploaderMinimal = import('../dist/index.ts').FileUploaderMinimal;
9+
type BtnUi = import('../dist/index.ts').BtnUi;
10+
type LineLoaderUi = import('../dist/index.ts').LineLoaderUi;
11+
type PresenceToggle = import('../dist/index.ts').PresenceToggle;
12+
type SliderUi = import('../dist/index.ts').SliderUi;
13+
type CropFrame = import('../dist/index.ts').CropFrame;
14+
type EditorCropButtonControl = import('../dist/index.ts').EditorCropButtonControl;
15+
type EditorAspectRatioButtonControl = import('../dist/index.ts').EditorAspectRatioButtonControl;
16+
type EditorFreeformButtonControl = import('../dist/index.ts').EditorFreeformButtonControl;
17+
type EditorFilterControl = import('../dist/index.ts').EditorFilterControl;
18+
type EditorOperationControl = import('../dist/index.ts').EditorOperationControl;
19+
type EditorImageCropper = import('../dist/index.ts').EditorImageCropper;
20+
type EditorImageFader = import('../dist/index.ts').EditorImageFader;
21+
type EditorScroller = import('../dist/index.ts').EditorScroller;
22+
type EditorSlider = import('../dist/index.ts').EditorSlider;
23+
type EditorToolbar = import('../dist/index.ts').EditorToolbar;
24+
type Icon = import('../dist/index.ts').Icon;
25+
type Img = import('../dist/index.ts').Img;
26+
type SimpleBtn = import('../dist/index.ts').SimpleBtn;
27+
type StartFrom = import('../dist/index.ts').StartFrom;
28+
type DropArea = import('../dist/index.ts').DropArea;
29+
type SourceBtn = import('../dist/index.ts').SourceBtn;
30+
type SourceList = import('../dist/index.ts').SourceList;
31+
type FileItem = import('../dist/index.ts').FileItem;
32+
type Modal = import('../dist/index.ts').Modal;
33+
type UploadList = import('../dist/index.ts').UploadList;
34+
type UrlSource = import('../dist/index.ts').UrlSource;
35+
type CameraSource = import('../dist/index.ts').CameraSource;
36+
type ProgressBarCommon = import('../dist/index.ts').ProgressBarCommon;
37+
type ProgressBar = import('../dist/index.ts').ProgressBar;
38+
type ExternalSource = import('../dist/index.ts').ExternalSource;
39+
type CloudImageEditorActivity = import('../dist/index.ts').CloudImageEditorActivity;
940
type FormInput = import('../dist/index.ts').FormInput;
1041
type CloudImageEditorBlock = import('../dist/index.ts').CloudImageEditorBlock;
11-
type CtxAttributes = {
12-
'ctx-name': string;
13-
testMode?: boolean;
14-
};
42+
1543
type CommonHtmlAttributes<T> = Partial<
1644
Pick<React.HTMLAttributes<T>, 'id' | 'children' | 'hidden'> & { class: React.HTMLAttributes<T>['className'] }
1745
>;
1846

19-
type CustomElement<C, A = {}> = React.DetailedHTMLProps<CommonHtmlAttributes<C>, C> & A;
47+
type ReflectAttributes<T extends LitBlock> = T['attributesMeta'];
48+
49+
type CustomElement<C> = React.DetailedHTMLProps<CommonHtmlAttributes<C>, C> & ReflectAttributes<C>;
2050

2151
declare namespace JSX {
2252
interface IntrinsicElements {
23-
'uc-crop-frame': any;
24-
'uc-editor-crop-button-control': any;
25-
'uc-editor-aspect-ratio-button-control': any;
26-
'uc-editor-freeform-button-control': any;
27-
'uc-editor-filter-control': any;
28-
'uc-editor-operation-control': any;
29-
'uc-editor-image-cropper': any;
30-
'uc-editor-image-fader': any;
31-
'uc-editor-scroller': any;
32-
'uc-editor-slider': any;
33-
'uc-editor-toolbar': any;
34-
'uc-btn-ui': any;
35-
'uc-line-loader-ui': any;
36-
'uc-presence-toggle': any;
37-
'uc-slider-ui': any;
38-
'uc-icon': any;
39-
'uc-img': any;
40-
'uc-simple-btn': any;
41-
'uc-start-from': any;
42-
'uc-drop-area': any;
43-
'uc-source-btn': any;
44-
'uc-source-list': any;
45-
'uc-file-item': any;
46-
'uc-modal': any;
47-
'uc-upload-list': any;
48-
'uc-url-source': any;
49-
'uc-camera-source': any;
50-
'uc-progress-bar-common': any;
51-
'uc-progress-bar': any;
52-
'uc-external-source': any;
53-
'uc-cloud-image-editor-activity': any;
54-
'uc-cloud-image-editor-block': CustomElement<
55-
CloudImageEditorBlock,
56-
CtxAttributes & ({ uuid: string } | { 'cdn-url': string }) & Partial<{ tabs: string; 'crop-preset': string }>
57-
>;
58-
'uc-cloud-image-editor': CustomElement<CloudImageEditorBlock, JSX.IntrinsicElements['uc-cloud-image-editor-block']>;
59-
'uc-form-input': CustomElement<FormInput, CtxAttributes>;
60-
'uc-file-uploader-regular': CustomElement<FileUploaderRegular, CtxAttributes & Partial<{ headless: boolean }>>;
61-
'uc-file-uploader-minimal': CustomElement<FileUploaderMinimal, CtxAttributes>;
62-
'uc-file-uploader-inline': CustomElement<FileUploaderInline, CtxAttributes>;
63-
'uc-upload-ctx-provider': CustomElement<UploadCtxProvider, CtxAttributes>;
64-
'uc-config': CustomElement<Config, CtxAttributes & Partial<ConfigPlainType>>;
53+
'uc-crop-frame': CustomElement<CropFrame>;
54+
'uc-editor-crop-button-control': CustomElement<EditorCropButtonControl>;
55+
'uc-editor-aspect-ratio-button-control': CustomElement<EditorAspectRatioButtonControl>;
56+
'uc-editor-freeform-button-control': CustomElement<EditorFreeformButtonControl>;
57+
'uc-editor-filter-control': CustomElement<EditorFilterControl>;
58+
'uc-editor-operation-control': CustomElement<EditorOperationControl>;
59+
'uc-editor-image-cropper': CustomElement<EditorImageCropper>;
60+
'uc-editor-image-fader': CustomElement<EditorImageFader>;
61+
'uc-editor-scroller': CustomElement<EditorScroller>;
62+
'uc-editor-slider': CustomElement<EditorSlider>;
63+
'uc-editor-toolbar': CustomElement<EditorToolbar>;
64+
'uc-btn-ui': CustomElement<BtnUi>;
65+
'uc-line-loader-ui': CustomElement<LineLoaderUi>;
66+
'uc-presence-toggle': CustomElement<PresenceToggle>;
67+
'uc-slider-ui': CustomElement<SliderUi>;
68+
'uc-icon': CustomElement<Icon>;
69+
'uc-img': CustomElement<Img>;
70+
'uc-simple-btn': CustomElement<SimpleBtn>;
71+
'uc-start-from': CustomElement<StartFrom>;
72+
'uc-drop-area': CustomElement<DropArea>;
73+
'uc-source-btn': CustomElement<SourceBtn>;
74+
'uc-source-list': CustomElement<SourceList>;
75+
'uc-file-item': CustomElement<FileItem>;
76+
'uc-modal': CustomElement<Modal>;
77+
'uc-upload-list': CustomElement<UploadList>;
78+
'uc-url-source': CustomElement<UrlSource>;
79+
'uc-camera-source': CustomElement<CameraSource>;
80+
'uc-progress-bar-common': CustomElement<ProgressBarCommon>;
81+
'uc-progress-bar': CustomElement<ProgressBar>;
82+
'uc-external-source': CustomElement<ExternalSource>;
83+
'uc-cloud-image-editor-activity': CustomElement<CloudImageEditorActivity>;
84+
'uc-cloud-image-editor-block': CustomElement<CloudImageEditorBlock>;
85+
'uc-cloud-image-editor': CustomElement<CloudImageEditorBlock>;
86+
'uc-form-input': CustomElement<FormInput>;
87+
'uc-file-uploader-regular': CustomElement<FileUploaderRegular>;
88+
'uc-file-uploader-minimal': CustomElement<FileUploaderMinimal>;
89+
'uc-file-uploader-inline': CustomElement<FileUploaderInline>;
90+
'uc-upload-ctx-provider': CustomElement<UploadCtxProvider>;
91+
'uc-config': CustomElement<Config>;
6592
}
6693
}

0 commit comments

Comments
 (0)