Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 7715830

Browse files
committed
Move picker to packages
1 parent 5894126 commit 7715830

File tree

137 files changed

+369
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+369
-15
lines changed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
22
"name": "picmo",
3+
"private": true,
34
"version": "5.0.0-beta.3",
45
"description": "JavaScript emoji picker - any app, any framework.",
56
"keywords": [
67
"emoji",
78
"emoji picker",
89
"javascript"
910
],
11+
"workspaces": [
12+
"./projects/*"
13+
],
1014
"main": "dist/index.js",
1115
"scripts": {
1216
"build": "npm run check && rollup -c",

packages/picmo/jest-setup.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import '@testing-library/jest-dom';
2+
3+
global.afterEach(() => {
4+
document.body.replaceChildren();
5+
});

packages/picmo/jest.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'jsdom',
4+
moduleNameMapper: {
5+
'\\.scss$': 'identity-obj-proxy'
6+
},
7+
transform: {
8+
'\\.{jt}s$': 'ts-jest',
9+
'\\.svg$': 'jest-raw-loader'
10+
},
11+
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts']
12+
};

packages/picmo/package-lock.json

+178
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/picmo/package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "picmo",
3+
"version": "5.0.0-beta.3",
4+
"description": "JavaScript emoji picker. any app, any framework.",
5+
"keywords": [
6+
"emoji",
7+
"emoji picker",
8+
"javascript"
9+
],
10+
"main": "index.js",
11+
"scripts": {
12+
"update-scss-types": "typed-scss-modules src",
13+
"lint": "eslint src/*.ts",
14+
"test": "jest --coverage src",
15+
"test:watch": "jest --watch src"
16+
},
17+
"author": "Joe Attardi <[email protected]> (https://joeattardi.dev)",
18+
"repository": "joeattardi/picmo",
19+
"homepage": "https://picmojs.com",
20+
"bugs": "https://github.com/joeattardi/picmo/issues",
21+
"funding": "https://github.com/sponsors/joeattardi",
22+
"license": "MIT",
23+
"dependencies": {
24+
"@popperjs/core": "^2.11.5",
25+
"emojibase": "^6.1.0",
26+
"tslib": "^2.4.0",
27+
"twemoji": "^14.0.2"
28+
}
29+
}

packages/picmo/rollup.config.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
import { string } from 'rollup-plugin-string';
3+
import postcss from 'rollup-plugin-postcss';
4+
import { nodeResolve } from '@rollup/plugin-node-resolve';
5+
import replace from '@rollup/plugin-replace';
6+
import { terser } from 'rollup-plugin-terser';
7+
8+
const bundles = [
9+
{
10+
input: 'src/umd/picmo.ts',
11+
output: {
12+
sourcemap: true,
13+
file: 'dist/umd/picmo.js',
14+
format: 'umd',
15+
name: 'picmo'
16+
}
17+
},
18+
{
19+
input: 'src/umd/picmo.twemoji.ts',
20+
output: {
21+
sourcemap: true,
22+
file: 'dist/umd/picmo.twemoji.js',
23+
format: 'umd',
24+
name: 'TwemojiRenderer'
25+
}
26+
},
27+
{
28+
input: {
29+
'index': './src/index.ts',
30+
'renderers/native': './src/renderers/native.ts',
31+
'renderers/twemoji': './src/renderers/twemoji.ts',
32+
'themes': './src/themes.ts',
33+
'i18n/en': './src/i18n/lang-en.ts'
34+
},
35+
output: {
36+
dir: 'dist',
37+
format: 'es'
38+
}
39+
}
40+
];
41+
42+
export default bundles.map(bundle => ({
43+
...bundle,
44+
plugins: [
45+
replace({
46+
'process.env.NODE_ENV': JSON.stringify('production'),
47+
preventAssignment: true
48+
}),
49+
nodeResolve(),
50+
string({ include: ['**/*.svg']}),
51+
typescript(),
52+
postcss({ modules: true }),
53+
terser()
54+
]
55+
}));
File renamed without changes.
File renamed without changes.

src/LazyLoader.ts packages/picmo/src/LazyLoader.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { Image } from './views/Image';
2-
import { View } from './views/view';
3-
41
type Callback = () => void;
52

63
export class LazyLoader {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/db.ts packages/picmo/src/db.ts

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.twemoji {
2+
height: 1em;
3+
width: 1em;
4+
margin: 0 0.05em 0 0.1em;
5+
vertical-align: -0.1em;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const twemoji: string;
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import twemoji from 'twemoji';
2+
3+
import { EmojiRecord, EmojiSelection } from '../types';
4+
import { Renderer } from './renderer';
5+
6+
import classes from './twemoji.scss';
7+
8+
type TwemojiCallbackOptions = {
9+
base: string;
10+
size: string;
11+
ext: string;
12+
};
13+
14+
type TwemojiOptions = {
15+
ext: string;
16+
folder: string;
17+
}
18+
19+
type TwemojiImageFormat = 'svg' | 'png';
20+
21+
const formatOptions: Record<TwemojiImageFormat, TwemojiOptions> = {
22+
png: {
23+
ext: '.png',
24+
folder: '72x72'
25+
},
26+
svg: {
27+
ext: '.svg',
28+
folder: 'svg'
29+
}
30+
}
31+
32+
function getTwemojiUrl(record: EmojiRecord, options: TwemojiOptions): Promise<string> {
33+
return new Promise(resolve => {
34+
twemoji.parse(record.emoji, {
35+
...options,
36+
callback: (icon, options) => {
37+
const { base, size, ext } = options as TwemojiCallbackOptions;
38+
const url = `${base}${size}/${icon}${ext}`;
39+
resolve(url);
40+
return url;
41+
}
42+
});
43+
});
44+
}
45+
46+
/**
47+
* Renders emojis using Twemoji images.
48+
*/
49+
export class TwemojiRenderer extends Renderer {
50+
private options: TwemojiOptions;
51+
52+
constructor(format: TwemojiImageFormat = 'svg') {
53+
super();
54+
this.options = formatOptions[format];
55+
}
56+
57+
render(record: EmojiRecord, classNames = classes.twemoji) {
58+
return this.renderImage(classNames, () => getTwemojiUrl(record, this.options));
59+
}
60+
61+
async emit(record: EmojiRecord): Promise<EmojiSelection> {
62+
const url = await getTwemojiUrl(record, this.options);
63+
return { url, hexcode: record.hexcode,emoji: record.emoji, label: record.label };
64+
}
65+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const categoryButton: string;
2-
export const categoryButtonActive: string;
32
export const categoryButtons: string;
43
export const categoryTab: string;
54
export const categoryTabActive: string;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/views/Search.scss.d.ts packages/picmo/src/views/Search.scss.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export const notFound: string;
44
export const searchAccessory: string;
55
export const searchContainer: string;
66
export const searchField: string;
7-
export const searchResults: string;
File renamed without changes.

0 commit comments

Comments
 (0)