Skip to content

Commit 49065da

Browse files
committed
feat: Support fontawesome-pro
1 parent 1bdc41a commit 49065da

File tree

10 files changed

+63
-147
lines changed

10 files changed

+63
-147
lines changed

.gitignore

Lines changed: 3 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,5 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
81

9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
2+
build/node_modules
113

12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
4+
# fontawesome-pro
5+
build/fontawesome-pro*

build/index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
/**
2-
* build categories.json
3-
* toPath fontawesomepicker/asset/categories.json
2+
* to fontawesomepicker/asset/categories.js
43
*/
54

65
const fs = require('fs')
76
const path = require('path')
87
const yamljs = require('yamljs')
98

10-
const rawIcons = yamljs.parse(fs.readFileSync('./node_modules/@fortawesome/fontawesome-free/metadata/icons.yml', 'utf-8'))
11-
const rawCategories = yamljs.parse(fs.readFileSync('./node_modules/@fortawesome/fontawesome-free/metadata/categories.yml', 'utf-8'))
9+
const fontawesomeVer = 'pro' // free/pro
10+
const fontawesomePath = './fontawesome-pro-5.14.0-web'
11+
const rawIcons = yamljs.parse(fs.readFileSync(fontawesomePath + '/metadata/icons.yml', 'utf-8'))
12+
const rawCategories = yamljs.parse(fs.readFileSync(fontawesomePath + '/metadata/categories.yml', 'utf-8'))
1213

1314

14-
function getCategories(name) {
15+
function iconClasses(name, styles) {
16+
return styles.map(style =>{
17+
switch ( style ) {
18+
case 'brands' : return 'fab-' + name
19+
case 'solid' : return 'fas-' + name
20+
case 'regular' : return 'far-' + name
21+
case 'light' : return 'fal-' + name
22+
case 'duotone' : return 'fad-' + name
23+
}
24+
})
25+
}
26+
27+
function iconCategories(name) {
1528
const categories = []
1629
for ( const key in rawCategories ) {
1730
if ( rawCategories[key].icons.includes(name) ) categories.push(key)
@@ -20,35 +33,22 @@ function getCategories(name) {
2033
return categories
2134
}
2235

23-
function toNames(name, styles) {
24-
return styles.map(type =>{
25-
switch ( type ) {
26-
case 'brands':
27-
return 'fab-' + name
28-
case 'solid':
29-
return 'fas-' + name
30-
case 'regular':
31-
return 'far-' + name
32-
}
33-
})
34-
}
35-
3636

3737
const data = {}
3838

3939
const keys = Object.keys(rawIcons)
4040
keys.forEach(name =>{
4141
if ( rawIcons[name].private ) return
4242
const styles = rawIcons[name].styles
43-
const categories = getCategories(name)
43+
const categories = iconCategories(name)
4444

4545
categories.forEach(item =>{
4646
data[item] = data[item] || {
4747
icons: [],
4848
label: item
4949
}
5050

51-
data[item].icons.push(...toNames(name, styles))
51+
data[item].icons.push(...iconClasses(name, styles))
5252
})
5353
})
5454

@@ -59,11 +59,11 @@ delete data.others
5959
data.others = others
6060

6161

62+
// fs.writeFileSync(
63+
// path.resolve(__dirname, `../fontawesomepicker/asset/categories-${fontawesomeVer}.json`),
64+
// JSON.stringify(data)
65+
// )
6266
fs.writeFileSync(
63-
path.resolve(__dirname, '../fontawesomepicker/asset/categories.json'),
64-
JSON.stringify(data)
65-
)
66-
fs.writeFileSync(
67-
path.resolve(__dirname, '../fontawesomepicker/asset/categories.js'),
67+
path.resolve(__dirname, `../fontawesomepicker/asset/categories-${fontawesomeVer}.js`),
6868
`fontawesomepickerCallback(${JSON.stringify(data)})`
6969
)

build/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"dependencies": {
3-
"@fortawesome/fontawesome-free": "^5.14.0",
43
"yamljs": "^0.3.0"
54
}
65
}
File renamed without changes.

fontawesomepicker/asset/categories-pro.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fontawesomepicker/asset/categories.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

fontawesomepicker/asset/style-pro.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,17 @@
66
.tox .far {
77
font-family: 'Font Awesome 5 Pro';
88
font-weight: 400;
9-
}
9+
}
10+
.tox .fad {
11+
position: relative;
12+
font-family: 'Font Awesome 5 Duotone';
13+
font-weight: 900;
14+
}
15+
.tox .fal {
16+
font-family: 'Font Awesome 5 Pro';
17+
font-weight: 300;
18+
}
19+
.tox .far {
20+
font-family: 'Font Awesome 5 Pro';
21+
font-weight: 400;
22+
}

fontawesomepicker/plugin.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,22 @@
8686
function initAsset(editor, pluginUrl) {
8787
var fontawesomeUrl = editor.getParam('fontawesomeUrl')
8888
var fontawesomePro = editor.getParam('fontawesomePro')
89+
var fontawesomeVer = !!fontawesomePro ? 'pro' : 'free'
90+
8991
utils.loadStyle(document, fontawesomeUrl)
9092
utils.loadStyle(document, pluginUrl + '/asset/style.css')
91-
if (fontawesomePro === undefined || fontawesomePro === false) {
92-
utils.loadStyle(document, pluginUrl + '/asset/style-free.css')
93-
}
94-
else {
95-
utils.loadStyle(document, pluginUrl + '/asset/style-pro.css')
96-
}
93+
utils.loadStyle(document, pluginUrl + '/asset/style-'+ fontawesomeVer +'.css')
9794
utils.loadStyle(editor.contentDocument, fontawesomeUrl)
9895

9996
if ( !categories.all ) {
100-
loadCategories(pluginUrl)
97+
loadCategories(pluginUrl + '/asset/categories-'+ fontawesomeVer +'.js')
10198
}
10299
}
103100

104-
function loadCategories(pluginUrl) {
105-
utils.jsonp(
106-
pluginUrl + '/asset/categories.js',
107-
CALLBACK_NAME,
108-
function (data) {
109-
formatCategories(data)
110-
}
111-
)
101+
function loadCategories(src) {
102+
utils.jsonp(src, CALLBACK_NAME, function(data) {
103+
formatCategories(data)
104+
})
112105
}
113106

114107
function formatCategories(data) {

fontawesomepicker/plugin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ A plugin for `tinymce v5` that selects the `fontawesome` icon.
3030
})
3131
```
3232

33+
### fontawesome-pro
34+
```js
35+
window.tinymce.init({
36+
selector: 'textarea',
37+
plugins: 'fontawesomepicker',
38+
toolbar: 'fontawesomepicker',
39+
fontawesomeUrl: 'fontawesome-pro/css/all.min.css',
40+
fontawesomePro: true
41+
})
42+
```
3343

34-
# preview [example](http://gitpages.wo2.me/tinymce-fontawesomepicker/)
44+
# preview
3545
![icons](icons.png)
3646

0 commit comments

Comments
 (0)