Skip to content

Commit

Permalink
Merge pull request #138 from break-stuff/vue-add-prefix-and-suffix
Browse files Browse the repository at this point in the history
Vue add prefix and suffix
  • Loading branch information
break-stuff authored Jun 30, 2024
2 parents ebcadf8 + d1a55f8 commit 8e236b4
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 30 deletions.
1 change: 0 additions & 1 deletion .prettierrc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @type {import("prettier").Config}
*/
const config = {
trailingComma: "all",
tabWidth: 2,
semi: true,
singleQuote: false,
Expand Down
14 changes: 11 additions & 3 deletions demo/lit-app/custom-element-jsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { RadioGroup, InterfaceEventType } from "./dist/radio-group/RadioGroup.d.ts";
import type {
RadioGroup,
InterfaceEventType,
} from "./dist/radio-group/RadioGroup.d.ts";
import type { RadioButton } from "./dist/radio-button/RadioButton.d.ts";
import type { DeprecatedElement } from "./dist/deprecated-element/DeprecatedElement.d.ts";
import type { MyButton } from "./dist/my-button/MyButton.d.ts";
Expand All @@ -20,7 +23,10 @@ import type { MyButton } from "./dist/my-button/MyButton.d.ts";
* ```
*
*/
export type ScopedElements<Prefix extends string = "", Suffix extends string = ""> = {
export type ScopedElements<
Prefix extends string = "",
Suffix extends string = "",
> = {
[Key in keyof CustomElements as `${Prefix}${Key}${Suffix}`]: CustomElements[Key];
};

Expand Down Expand Up @@ -179,7 +185,9 @@ export type CustomElements = {
* ---
*
*/
"deprecated-element": Partial<DeprecatedElementProps | BaseProps | BaseEvents>;
"deprecated-element": Partial<
DeprecatedElementProps | BaseProps | BaseEvents
>;

/**
*
Expand Down
5 changes: 4 additions & 1 deletion demo/lit-app/custom-element-vuejs.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { DefineComponent } from "vue";

import type { RadioGroup, InterfaceEventType } from "./dist/radio-group/RadioGroup.d.ts";
import type {
RadioGroup,
InterfaceEventType,
} from "./dist/radio-group/RadioGroup.d.ts";
import type { RadioButton } from "./dist/radio-button/RadioButton.d.ts";
import type { DeprecatedElement } from "./dist/deprecated-element/DeprecatedElement.d.ts";
import type { MyButton } from "./dist/my-button/MyButton.d.ts";
Expand Down
9 changes: 7 additions & 2 deletions demo/lit-app/custom-elements-svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { RadioGroup, InterfaceEventType } from "./dist/radio-group/RadioGroup.d.ts";
import type {
RadioGroup,
InterfaceEventType,
} from "./dist/radio-group/RadioGroup.d.ts";
import type { RadioButton } from "./dist/radio-button/RadioButton.d.ts";
import type { DeprecatedElement } from "./dist/deprecated-element/DeprecatedElement.d.ts";
import type { MyButton } from "./dist/my-button/MyButton.d.ts";
Expand Down Expand Up @@ -156,7 +159,9 @@ export type CustomElements = {
* ---
*
*/
"deprecated-element": Partial<DeprecatedElementProps | BaseProps | BaseEvents>;
"deprecated-element": Partial<
DeprecatedElementProps | BaseProps | BaseEvents
>;

/**
*
Expand Down
4 changes: 2 additions & 2 deletions demo/lit-app/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function load(root) {
const rootTagName = root instanceof Element ? root.tagName.toLowerCase() : "";
const tags =
[...root.querySelectorAll(":not(:defined)")]?.map((el) =>
el.tagName.toLowerCase()
el.tagName.toLowerCase(),
) || [];
if (rootTagName.includes("-") && !customElements.get(rootTagName)) {
tags.push(rootTagName);
Expand Down Expand Up @@ -97,7 +97,7 @@ function register(tagName) {
})
.catch(() => {
console.error(
`Unable to load <${tagName}> from ${component.importPath}`
`Unable to load <${tagName}> from ${component.importPath}`,
);
reject();
});
Expand Down
14 changes: 11 additions & 3 deletions demo/lit-app/solid-js.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { JSX } from "solid-js";

import type { RadioGroup, InterfaceEventType } from "./dist/radio-group/RadioGroup.d.ts";
import type {
RadioGroup,
InterfaceEventType,
} from "./dist/radio-group/RadioGroup.d.ts";
import type { RadioButton } from "./dist/radio-button/RadioButton.d.ts";
import type { DeprecatedElement } from "./dist/deprecated-element/DeprecatedElement.d.ts";
import type { MyButton } from "./dist/my-button/MyButton.d.ts";
Expand All @@ -22,7 +25,10 @@ import type { MyButton } from "./dist/my-button/MyButton.d.ts";
* ```
*
*/
export type ScopedElements<Prefix extends string = "", Suffix extends string = ""> = {
export type ScopedElements<
Prefix extends string = "",
Suffix extends string = "",
> = {
[Key in keyof CustomElements as `${Prefix}${Key}${Suffix}`]: CustomElements[Key];
};

Expand Down Expand Up @@ -179,7 +185,9 @@ export type CustomElements = {
* ---
*
*/
"deprecated-element": Partial<DeprecatedElementProps | BaseProps | BaseEvents>;
"deprecated-element": Partial<
DeprecatedElementProps | BaseProps | BaseEvents
>;

/**
*
Expand Down
18 changes: 12 additions & 6 deletions packages/react-wrappers/src/wrapper-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
saveReactUtils,
saveScopeProvider,
} from "./utils.js";
import { createOutDir, log, logGreen, logYellow, saveFile } from "../../../tools/integrations/index.js";
import {
createOutDir,
log,
logGreen,
logYellow,
saveFile,
} from "../../../tools/integrations/index.js";
import {
CEM,
Component,
Expand Down Expand Up @@ -43,10 +49,7 @@ export function generateReactWrappers(
logYellow("[react-wrappers] - Skipped", options.hideLogs);
return;
}
log(
"[react-wrappers] - Generating wrappers...",
options.hideLogs
);
log("[react-wrappers] - Generating wrappers...", options.hideLogs);

updateConfig(options);
const components = getComponents(customElementsManifest, config.exclude);
Expand Down Expand Up @@ -87,7 +90,10 @@ export function generateReactWrappers(
});

generateManifests(components, config.outdir!);
logGreen(`[react-wrappers] - Generated wrappers in "${config.outdir}".`, config.hideLogs);
logGreen(
`[react-wrappers] - Generated wrappers in "${config.outdir}".`,
config.hideLogs,
);
}

function updateConfig(options: Options) {
Expand Down
4 changes: 4 additions & 0 deletions packages/vuejs-integration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.3.0

- Add tag name prefix and suffix support

## 1.2.0

- Added the ability to hide logs
Expand Down
4 changes: 4 additions & 0 deletions packages/vuejs-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ The configuration has the following optional parameters:
hideLogs?: boolean;
/** Prevents plugin from executing */
skip?: boolean;
/** Adds a prefix to tag name references */
prefix?: string;
/** Adds a suffix to tag name references */
suffix?: string;
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/vuejs-integration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-element-vuejs-integration",
"version": "1.2.0",
"version": "1.3.0",
"description": "Types for integrating custom elements into Vue.js projects",
"main": "index.js",
"module": "index.js",
Expand Down
17 changes: 8 additions & 9 deletions packages/vuejs-integration/src/type-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ export function generateVuejsTypes(manifest: any, options: Options) {
}

function getOptions(options: Options) {
options.fileName =
options.fileName === undefined
? "custom-element-vuejs.d.ts"
: options.fileName;
options.exclude = options.exclude === undefined ? [] : options.exclude;
options.outdir = options.outdir === undefined ? "./" : options.outdir;
options.prefix = options.prefix === undefined ? "" : options.prefix;
options.suffix = options.suffix === undefined ? "" : options.suffix;
return options;
return {
fileName: "custom-element-vuejs.d.ts",
exclude: [],
outdir: "./",
prefix: "",
suffix: "",
...options,
};
}

function getTypeTemplate(components: Component[], options: Options) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vuejs-integration/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export interface Options extends BaseOptions {
typesSrc?: string;
/** Used to add global element props to all component types */
globalEvents?: string;
/** Adds a prefix to tag references */
/** Adds a prefix to tag name references */
prefix?: string;
/** Adds a suffix to tag references */
/** Adds a suffix to tag name references */
suffix?: string;
}

Expand Down

0 comments on commit 8e236b4

Please sign in to comment.