Skip to content

Commit

Permalink
fix: svelte component slot types (#972)
Browse files Browse the repository at this point in the history
* fix: svelte component slot types

* fix: script fixed by someone smarter <3
  • Loading branch information
quentinderoubaix authored Oct 25, 2024
1 parent 1247f00 commit c30b945
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/accordion';

export type AccordionItemContext = WidgetSlotContext<AccordionItemWidget>;
export interface AccordionItemContext extends WidgetSlotContext<AccordionItemWidget> {}

interface AccordionExtraProps {
/**
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/alert';

export type AlertContext = WidgetSlotContext<AlertWidget>;
export interface AlertContext extends WidgetSlotContext<AlertWidget> {}

interface AlertExtraProps {
/**
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/modal';

export type ModalContext<Data> = WidgetSlotContext<ModalWidget<Data>>;
export interface ModalContext<Data> extends WidgetSlotContext<ModalWidget<Data>> {}

interface ModalExtraProps<Data> {
/**
Expand Down
6 changes: 3 additions & 3 deletions core-bootstrap/src/components/pagination/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export * from '@agnos-ui/core/components/pagination';
/**
* A type for the slot context of the pagination widget
*/
export type PaginationContext = WidgetSlotContext<PaginationWidget>;
export interface PaginationContext extends WidgetSlotContext<PaginationWidget> {}

/**
* A type for the slot context of the pagination widget when the slot is the number label
*/
export type PaginationNumberContext = PaginationContext & {
export interface PaginationNumberContext extends PaginationContext {
/**
* Displayed page
*/
displayedPage: number;
};
}

interface PaginationExtraProps {
/**
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/progressbar/progressbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {BSContextualClass} from '../../types';

export * from '@agnos-ui/core/components/progressbar';

export type ProgressbarContext = WidgetSlotContext<ProgressbarWidget>;
export interface ProgressbarContext extends WidgetSlotContext<ProgressbarWidget> {}

interface ProgressbarExtraProps {
/**
Expand Down
6 changes: 3 additions & 3 deletions core-bootstrap/src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export * from '@agnos-ui/core/components/select';
/**
* A type for the slot context of the pagination widget
*/
export type SelectContext<Item> = WidgetSlotContext<SelectWidget<Item>>;
export interface SelectContext<Item> extends WidgetSlotContext<SelectWidget<Item>> {}

export type SelectItemContext<Item> = SelectContext<Item> & {
export interface SelectItemContext<Item> extends SelectContext<Item> {
/**
* Contextual data related to an item
*/
itemContext: ItemContext<Item>;
};
}

interface SelectExtraProps<Item> {
/**
Expand Down
16 changes: 13 additions & 3 deletions core-bootstrap/src/components/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import type {SlotContent, Widget, WidgetFactory, WidgetSlotContext} from '@agnos

export * from '@agnos-ui/core/components/slider';

export type SliderContext = WidgetSlotContext<SliderWidget>;
export type SliderSlotLabelContext = SliderContext & {value: number};
export type SliderSlotHandleContext = SliderContext & {item: SliderHandle};
export interface SliderContext extends WidgetSlotContext<SliderWidget> {}
export interface SliderSlotLabelContext extends SliderContext {
/**
* the value of the handle the label is attached to
*/
value: number;
}
export interface SliderSlotHandleContext extends SliderContext {
/**
* the handle context
*/
item: SliderHandle;
}

interface SliderExtraProps {
/**
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/toast';

export type ToastContext = WidgetSlotContext<ToastWidget>;
export interface ToastContext extends WidgetSlotContext<ToastWidget> {}

export interface ToastExtraProps {
/**
Expand Down
13 changes: 8 additions & 5 deletions scripts/bootstrapTypes/genTypeExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const hardCodedImports: Record<string, string> = {
function getTypesImportsMap(nodes: Node[], excludedNames: Set<string>) {
const importsByModule = new Map<string, string[]>();
const processedNames = new Set<string>(excludedNames);

function visit(node: Node) {
if (ts.isTypeReferenceNode(node)) {
const name = ts.isIdentifier(node.typeName) ? node.typeName.text : node.typeName.getText();
if (ts.isIdentifier(node)) {
const name = node.text;
if (!processedNames.has(name)) {
let symbol = typeChecker.getSymbolAtLocation(node.typeName);
let symbol = typeChecker.getSymbolAtLocation(node);
let moduleSpecifier: string | undefined;
while (symbol && symbol.flags & ts.SymbolFlags.Alias && !(symbol.declarations?.[0] && ts.isImportSpecifier(symbol.declarations?.[0]))) {
symbol = typeChecker.getImmediateAliasedSymbol(symbol);
Expand Down Expand Up @@ -111,8 +112,10 @@ for (const component of components) {
)) {
exportNames.add(bootstrapExport.name);
const node = bootstrapExport.getDeclarations()![0];
if (ts.isTypeAliasDeclaration(node)) {
// type aliases are copied as defined
if (ts.isTypeAliasDeclaration(node) || (ts.isInterfaceDeclaration(node) && bootstrapExport.name.endsWith('Context'))) {
// type aliases
// and interfaces whose name ends with "Context"
// are copied as defined
exports += node.getFullText() + '\n\n';
exportedNodes.push(node);
} else if (ts.isInterfaceDeclaration(node)) {
Expand Down

0 comments on commit c30b945

Please sign in to comment.