Skip to content

Commit

Permalink
reorganize @emotion/utils types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome De Leon committed Jul 15, 2023
1 parent f3b268f commit 0b9529c
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 110 deletions.
10 changes: 10 additions & 0 deletions .changeset/six-hotels-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@emotion/cache': minor
'@emotion/css': minor
'@emotion/react': minor
'@emotion/serialize': minor
'@emotion/server': minor
'@emotion/utils': minor
---

Reorganize @emotion/utils types
3 changes: 2 additions & 1 deletion packages/cache/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { StyleSheet } from '@emotion/sheet'
import { type EmotionCache, type SerializedStyles } from '@emotion/utils'
import { type SerializedStyles } from '@emotion/serialize'
import { type EmotionCache } from '@emotion/cache'
import {
serialize,
compile,
Expand Down
23 changes: 21 additions & 2 deletions packages/cache/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.2
import { EmotionCache } from '@emotion/utils'
import { SerializedStyles } from '@emotion/serialize'

export { EmotionCache }
export interface RegisteredCache {
[key: string]: string
}

export interface EmotionCache {
inserted: {
[key: string]: string | true
}
registered: RegisteredCache
sheet: StyleSheet & { constructor: StyleSheet }
key: string
compat?: true
nonce?: string
insert(
selector: string,
serialized: SerializedStyles,
sheet: StyleSheet,
shouldCache: boolean
): string | void
}

export interface StylisElement {
type: string
Expand Down
11 changes: 3 additions & 8 deletions packages/css/src/create-instance.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// @flow
import createCache from '@emotion/cache'
import { serializeStyles } from '@emotion/serialize'
import {
insertStyles,
getRegisteredStyles,
type EmotionCache,
type SerializedStyles
} from '@emotion/utils'
import createCache, { type EmotionCache } from '@emotion/cache'
import { serializeStyles, type SerializedStyles } from '@emotion/serialize'
import { insertStyles, getRegisteredStyles } from '@emotion/utils'

function insertWithoutScoping(cache, serialized: SerializedStyles) {
if (cache.inserted[serialized.name] === undefined) {
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/context.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @flow
import { type EmotionCache } from '@emotion/utils'
import * as React from 'react'
import { useContext, forwardRef } from 'react'
import createCache from '@emotion/cache'
import createCache, { type EmotionCache } from '@emotion/cache'
import { isBrowser } from './utils'

let EmotionCacheContext: React.Context<EmotionCache | null> =
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/css.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// @flow

import type { Interpolation, SerializedStyles } from '@emotion/utils'
import { serializeStyles } from '@emotion/serialize'
import {
serializeStyles,
type SerializedStyles,
type ArrayInterpolation
} from '@emotion/serialize'

function css(...args: Array<Interpolation>): SerializedStyles {
function css(...args: ArrayInterpolation): SerializedStyles {
return serializeStyles(args)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import pkg from '../package.json'
export type { SerializedStyles } from '@emotion/utils'
export type { SerializedStyles } from '@emotion/serialize'
export {
withEmotionCache,
CacheProvider,
Expand Down
7 changes: 2 additions & 5 deletions packages/serialize/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// @flow
import type {
Interpolation,
SerializedStyles,
RegisteredCache
} from '@emotion/utils'
import type { SerializedStyles, Interpolation } from '@emotion/serialize'
import type { RegisteredCache } from '@emotion/cache'
import hashString from '@emotion/hash'
import unitless from '@emotion/unitless'
import memoize from '@emotion/memoize'
Expand Down
10 changes: 7 additions & 3 deletions packages/serialize/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.8

import { RegisteredCache, SerializedStyles } from '@emotion/utils'
import type { RegisteredCache } from '@emotion/cache'
import * as CSS from 'csstype'

export { RegisteredCache, SerializedStyles }
export interface SerializedStyles {
name: string
styles: string
map?: string
next?: SerializedStyles
}

export type CSSProperties = CSS.PropertiesFallback<number | string>
export type CSSPropertiesWithMultiValues = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'
import { generateStyleTag } from './utils'

const createConstructStyleTagsFromChunks =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'

const createExtractCriticalToChunks =
(cache: EmotionCache) => (html: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/create-instance/extract-critical.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'

const createExtractCritical = (cache: EmotionCache) => (html: string) => {
// parse out ids from html
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/create-instance/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'
import createExtractCritical from './extract-critical'
import createExtractCriticalToChunks from './extract-critical-to-chunks'
import createRenderStylesToString from './inline'
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/create-instance/inline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'
import { generateStyleTag } from './utils'

const createRenderStylesToString =
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/create-instance/stream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { EmotionCache } from '@emotion/utils'
import type { EmotionCache } from '@emotion/cache'
import through from 'through'
import tokenize from 'html-tokenize'
import pipe from 'multipipe'
Expand Down
2 changes: 1 addition & 1 deletion packages/server/types/create-instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TypeScript Version: 2.8

/// <reference types="node" />
import { EmotionCache } from '@emotion/utils'
import { EmotionCache } from '@emotion/cache'

export interface EmotionCritical {
html: string
Expand Down
2 changes: 1 addition & 1 deletion packages/server/types/tests-create-instance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createEmotionServer from '@emotion/server/create-instance'
import { EmotionCache } from '@emotion/utils'
import { EmotionCache } from '@emotion/cache'

declare const cache: EmotionCache

Expand Down
5 changes: 2 additions & 3 deletions packages/utils/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import type { RegisteredCache, EmotionCache, SerializedStyles } from './types'
import type { RegisteredCache, EmotionCache } from '@emotion/cache'
import type { SerializedStyles } from '@emotion/serialize'

const isBrowser = typeof document !== 'undefined'

Expand Down Expand Up @@ -73,5 +74,3 @@ export const insertStyles = (
}
}
}

export * from './types'
28 changes: 0 additions & 28 deletions packages/utils/src/types.js

This file was deleted.

39 changes: 2 additions & 37 deletions packages/utils/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.2

export interface RegisteredCache {
[key: string]: string
}

export interface StyleSheet {
container: HTMLElement
nonce?: string
key: string
insert(rule: string): void
flush(): void
tags: Array<HTMLStyleElement>
}

export interface EmotionCache {
inserted: {
[key: string]: string | true
}
registered: RegisteredCache
sheet: StyleSheet
key: string
compat?: true
nonce?: string
insert(
selector: string,
serialized: SerializedStyles,
sheet: StyleSheet,
shouldCache: boolean
): string | void
}

export interface SerializedStyles {
name: string
styles: string
map?: string
next?: SerializedStyles
}
import type { SerializedStyles } from '@emotion/serialize'
import type { RegisteredCache, EmotionCache } from '@emotion/cache'

export const isBrowser: boolean

Expand Down
11 changes: 2 additions & 9 deletions packages/utils/types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
EmotionCache,
RegisteredCache,
SerializedStyles,
StyleSheet,
getRegisteredStyles,
insertStyles,
isBrowser
} from '@emotion/utils'
import type { EmotionCache, RegisteredCache } from '@emotion/cache'
import { getRegisteredStyles, insertStyles, isBrowser } from '@emotion/utils'

declare const testCache: EmotionCache
declare const testRegisteredCache: RegisteredCache
Expand Down

0 comments on commit 0b9529c

Please sign in to comment.