Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Nov 24, 2023
1 parent e5dc549 commit 8eddf0d
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 384 deletions.
4 changes: 2 additions & 2 deletions examples/astro-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"devDependencies": {
"astro": "^3.3.2",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"unplugin-solid-styled": "0.9.2"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"serve": "vite preview"
},
"devDependencies": {
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"unplugin-solid-styled": "0.9.2",
"vite": "^4.5.0",
"vite-plugin-solid": "^2.7.2"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"examples/*"
],
"devDependencies": {
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"lerna": "^7.4.1",
"typescript": "^5.2.2"
"lerna": "^8.0.0",
"typescript": "^5.3.2"
}
}
4 changes: 2 additions & 2 deletions packages/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
],
"devDependencies": {
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"pridepack": "2.5.1",
"rollup": "^3.5.1",
"solid-styled": "0.9.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"dependencies": {
"@rollup/pluginutils": "^5.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/solid-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
"@types/babel__core": "^7.20.3",
"@types/babel__traverse": "^7.20.3",
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"pridepack": "2.5.1",
"solid-js": "^1.8.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vitest": "^0.34.6"
},
"peerDependencies": {
Expand Down
51 changes: 13 additions & 38 deletions packages/solid-styled/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { JSX } from 'solid-js';
import {
createComponent,
createContext,
createMemo,
createRoot,
JSX,
onCleanup,
useContext,
} from 'solid-js';
import { isServer } from 'solid-js/web';

interface StyleRegistryContext {
interface StyleRegistryContextValue {
insert(id: string, sheet: string): void;
remove(id: string): void;
}

const StyleRegistryContext = createContext<StyleRegistryContext>();
const StyleRegistryContext = createContext<StyleRegistryContextValue>();

const SOLID_SHEET_ATTR = 's:id';
const SOLID_SHEET_ATTR_ESCAPED = 's\\:id';
Expand All @@ -29,7 +29,7 @@ if (!isServer) {
});
}

function insert(id: string, sheet: string) {
function insert(id: string, sheet: string): void {
if (!tracked.has(id)) {
tracked.add(id);

Expand All @@ -43,7 +43,7 @@ function insert(id: string, sheet: string) {
references.set(id, (references.get(id) ?? 0) + 1);
}

function remove(id: string) {
function remove(id: string): void {
const count = references.get(id) ?? 0;
if (count > 1) {
references.set(id, count - 1);
Expand Down Expand Up @@ -72,7 +72,7 @@ export interface StyleRegistryProps {
export function StyleRegistry(props: StyleRegistryProps): JSX.Element {
const sheets = new Set<string>();

function wrappedInsert(id: string, sheet: string) {
function wrappedInsert(id: string, sheet: string): void {
if (!sheets.has(id)) {
sheets.add(id);
if (isServer && props.styles) {
Expand Down Expand Up @@ -102,7 +102,9 @@ export function useSolidStyled(
const index = `${id}-${offset}`;
const ctx = useContext(StyleRegistryContext) ?? { insert, remove };
ctx.insert(index, sheet);
onCleanup(() => ctx.remove(index));
onCleanup(() => {
ctx.remove(index);
});
}

type CSSVarsMerge = () => Record<string, string>;
Expand Down Expand Up @@ -178,43 +180,16 @@ export function renderSheets(sheets: StyleData[]): string {
return sheet;
}

// export type CSSStyleSpan<Args extends any[]> = (...args: Args) => string | boolean;
// export type CSSStyleFunction<Args extends any[]> = (...args: Args) => Record<string, any>;

// export interface CSSClassFunction {

// }

export interface CSSConstructorNS {
// style<Args extends any[]>(template: TemplateStringsArray, ...spans: CSSStyleSpan<Args>[]): CSSStyleFunction<Args>;
// class(template: TemplateStringsArray): string;
}

export interface CSSBaseConstructor {
export interface CSSConstructor {
(template: TemplateStringsArray, ...spans: (string | boolean)[]): void;
}

export type CSSConstructor = CSSBaseConstructor & CSSConstructorNS;


// eslint-disable-next-line @typescript-eslint/no-unused-vars

function invariant(methodName: string) {
return new Error(`Unexpected use of \`${methodName}\`. Make sure that solid-styled\'s plugin is setup correctly.`);
function invariant(methodName: string): Error {
return new Error(`Unexpected use of \`${methodName}\`. Make sure that solid-styled's plugin is setup correctly.`);
}

// const cssNamespace: CSSConstructorNS = {
// style() {
// throw invariant('css.style');
// },
// class() {
// throw invariant('css.class');
// },
// };

const cssConstructor: CSSBaseConstructor = () => {
export const css: CSSConstructor = () => {
throw invariant('css');
};

// export const css: CSSConstructor = /* @__PURE__ */Object.assign(cssConstructor, cssNamespace);
export const css: CSSConstructor = cssConstructor;
4 changes: 2 additions & 2 deletions packages/unplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
],
"devDependencies": {
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"pridepack": "2.5.1",
"solid-styled": "0.9.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vite": "^4.5.0"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
],
"devDependencies": {
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"eslint-config-lxsmnsyc": "^0.6.5",
"pridepack": "2.5.1",
"solid-styled": "0.9.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vite": "^4.5.0"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 8eddf0d

Please sign in to comment.