Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: Frontend [Stage 1] #53884

Merged
merged 118 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
34dd73e
adding files from original branch try/font-library
matiasbenedetto Aug 14, 2023
d56b8fd
importing remaining files
matiasbenedetto Aug 16, 2023
a57e99a
renaming font library to fonts library
matiasbenedetto Aug 16, 2023
e1588ea
renaming FontLibraryModal to FontsLibraryModal
matiasbenedetto Aug 16, 2023
5df8f78
Merge branch 'trunk' into try/fonts-library-frontend
matiasbenedetto Aug 16, 2023
051756c
update frontend based on backend changes
matiasbenedetto Aug 16, 2023
28ae9b8
TEMPORAL FIX: Adding Google fonts endpoint a font families list
matiasbenedetto Aug 16, 2023
6f4edd0
update uninstall functionality to latest backend implementation
matiasbenedetto Aug 16, 2023
0cc9566
fix loadedUrls state
matiasbenedetto Aug 17, 2023
9697545
fixing library not refreshing after uninstall
matiasbenedetto Aug 17, 2023
3a6d6e2
move uninstall notification functionality to context
matiasbenedetto Aug 17, 2023
953f2c1
Add notification on snackbar when installing fonts
matiasbenedetto Aug 17, 2023
626b04c
lint js
matiasbenedetto Aug 17, 2023
5e9b771
Merge branch trunk into try/fonts-library-frontend
matiasbenedetto Aug 17, 2023
460eb66
merge with trunk
matiasbenedetto Aug 22, 2023
de8c186
renaming FontS Library to Font Library
matiasbenedetto Aug 22, 2023
cf3785d
Removing google_fonts api endpoint
matiasbenedetto Aug 22, 2023
bab1793
Removing Google fonts specific code
matiasbenedetto Aug 23, 2023
c068c4b
refresh library after local fonts upload
matiasbenedetto Aug 23, 2023
0cf4510
remove unwanted console.log
matiasbenedetto Aug 23, 2023
626c321
css fix
matiasbenedetto Aug 23, 2023
4bfae33
removing file key from fontface data sent to the server
matiasbenedetto Aug 23, 2023
2290c98
open local fonts tab when click the + button
matiasbenedetto Aug 23, 2023
c3a31d8
remove font slug prefix
matiasbenedetto Aug 23, 2023
8c3d7b6
removing empty line
matiasbenedetto Aug 23, 2023
26bf51a
check by source (theme and custom)if fonts are activated
matiasbenedetto Aug 24, 2023
3e7eba8
delete demo related component and function
matiasbenedetto Aug 28, 2023
e5b720c
remove font family previews
matiasbenedetto Aug 28, 2023
c0db410
modal width
matiasbenedetto Aug 28, 2023
6d9714b
implementing mockups look for library font variants
matiasbenedetto Aug 28, 2023
0141571
reduce margin
matiasbenedetto Aug 28, 2023
84c2e32
display unintall button disabled when the font can not be uninstalled
matiasbenedetto Aug 28, 2023
a86f1b6
removing preview controls link
matiasbenedetto Aug 28, 2023
5814e03
removing unused imports
matiasbenedetto Aug 28, 2023
a28d2db
lint css
matiasbenedetto Aug 29, 2023
79f71de
lint css
matiasbenedetto Aug 29, 2023
af387ed
fix import
matiasbenedetto Aug 29, 2023
2efb763
deactivate font families before uninstalling them
matiasbenedetto Aug 31, 2023
7e4a414
flip buttons order
matiasbenedetto Aug 31, 2023
559bcb0
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 1, 2023
c59f2e1
Moving uninstall button to modal footer
matiasbenedetto Sep 1, 2023
f77066d
be able to indicate nested paths on __experimentalSaveSpecifiedEntity…
matiasbenedetto Sep 4, 2023
efe375a
save only fontFamilies when persisting global styles from font librar…
matiasbenedetto Sep 5, 2023
99dc420
Add edits data to the useEntityRecord
matiasbenedetto Sep 5, 2023
595b3bf
disable save button when there are no changes to be saved
matiasbenedetto Sep 5, 2023
6b0ce78
add notification when font families are updated
matiasbenedetto Sep 5, 2023
4f029a5
upload local fonts just after selecting them
matiasbenedetto Sep 5, 2023
0669eea
Removing upload local fonts tab from modal
matiasbenedetto Sep 5, 2023
559dbe2
drop zone background color
matiasbenedetto Sep 5, 2023
53d7c5c
remove unused import
matiasbenedetto Sep 5, 2023
5de552a
activate fonts just after installed
matiasbenedetto Sep 6, 2023
7c0f5f5
fix typo
matiasbenedetto Sep 6, 2023
82cee5c
hide confirm dialog after deleting font
matiasbenedetto Sep 6, 2023
3de8efa
remove + button
matiasbenedetto Sep 6, 2023
85fdafa
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 6, 2023
4496b4d
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 6, 2023
a2017c0
fix merging font families functions
matiasbenedetto Sep 6, 2023
1993c3a
add tests for mergeFontFamilies and mergeFontFaces functions
matiasbenedetto Sep 6, 2023
bcbd8f1
add tests for getFontFaceVariantName
matiasbenedetto Sep 6, 2023
93261a8
fix logic bug and add tests for isUrlEnconded function
matiasbenedetto Sep 6, 2023
3d3a191
fix logic bug in setUIValuesNeeded function
matiasbenedetto Sep 6, 2023
7496d89
add tests for setUIValuesNeeded function
matiasbenedetto Sep 6, 2023
bc5289a
move utils and utils tests
matiasbenedetto Sep 6, 2023
8297ed9
remove import not needed
matiasbenedetto Sep 6, 2023
670cd90
remove default demo config
matiasbenedetto Sep 6, 2023
43fd8ee
fix typo
matiasbenedetto Sep 6, 2023
ebd765f
update file extensions allowed in file dialog on mac
matiasbenedetto Sep 6, 2023
27868b0
remove extra space
matiasbenedetto Sep 6, 2023
09bc77d
Apply coding standards
mikachan Sep 7, 2023
4cd05a4
Make font cards buttons
mikachan Sep 7, 2023
8d4ed5f
Fix linter errors
mikachan Sep 7, 2023
71e651d
Fix max depth error
mikachan Sep 7, 2023
c841f0b
Revert font lib formatting
mikachan Sep 7, 2023
47cc979
Fix linter errors
mikachan Sep 7, 2023
3f86b10
Undo e2e test linter fixes
mikachan Sep 7, 2023
7225cc9
Remove more e2e test changes
mikachan Sep 7, 2023
5f8e955
fixing error persisting activation changes
matiasbenedetto Sep 7, 2023
8745fd4
improving font previews
matiasbenedetto Sep 7, 2023
23a3608
adding unit tests for getPreviewStyle util
matiasbenedetto Sep 7, 2023
304921f
lint fix
matiasbenedetto Sep 7, 2023
f649f8b
fix accepted file extensions not working properly on firefox
matiasbenedetto Sep 7, 2023
1800e50
sort font faces by weight
matiasbenedetto Sep 7, 2023
77b6201
move the code of toggleActivatedFont to a another file to reduce thei…
matiasbenedetto Sep 7, 2023
4828788
adding tests for toggleFont
matiasbenedetto Sep 7, 2023
cf1f38e
lint
matiasbenedetto Sep 7, 2023
b3e2c4e
avoid resetting theme font families when activating or deactivating f…
matiasbenedetto Sep 7, 2023
c54fda0
fix issue where fontFace length is zero
madhusudhand Sep 8, 2023
5242b85
Add deps comment to toggleFont file
mikachan Sep 8, 2023
6161311
Fix theme and custom undefined errors
mikachan Sep 8, 2023
6ca4bc4
Add initial e2e tests
mikachan Sep 8, 2023
7359c40
Merge branch 'trunk' into try/fonts-library-frontend-stage1
mikachan Sep 8, 2023
f2f228f
Refactor e2e test order
mikachan Sep 8, 2023
14aa39a
avoid re-activating all the font faces of a installed font when a new…
matiasbenedetto Sep 8, 2023
d216f30
adding tests for utils functions
matiasbenedetto Sep 8, 2023
b337852
renaming parameters
matiasbenedetto Sep 8, 2023
1c20021
adding jsdoc for function
matiasbenedetto Sep 8, 2023
61f7db3
remove code no longer needed
matiasbenedetto Sep 8, 2023
43dae16
avoid potential errors with non existing fontFace array
matiasbenedetto Sep 8, 2023
17d5885
Revert "avoid potential errors with non existing fontFace array"
matiasbenedetto Sep 8, 2023
83ae921
fix error uploading several font faces from different font families
matiasbenedetto Sep 8, 2023
e0f3f70
Fix font library modal prop typo
vcanales Sep 10, 2023
94e714c
activate the right font faces (the installed ones instead of the loca…
matiasbenedetto Sep 11, 2023
6bb6a98
Font library: load font assets on editor canvas (#54334)
vcanales Sep 11, 2023
99cbc39
removing success snackbar notifications
matiasbenedetto Sep 11, 2023
e44b58b
update uninstall font family button look
matiasbenedetto Sep 11, 2023
326065e
delete any change to save-button component
matiasbenedetto Sep 11, 2023
7ec227c
use a simple file id for uploaded files
matiasbenedetto Sep 12, 2023
31b16fd
Update delete button to be tertiary.
jasmussen Sep 12, 2023
4f0abf7
fix test
matiasbenedetto Sep 12, 2023
d01a98d
use FONT_LIBRARY_DISABLE constant to disable Font Library and Font Fa…
matiasbenedetto Sep 12, 2023
3f626b7
move confirm uninstall dialog to a new component
matiasbenedetto Sep 12, 2023
ac848dd
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 13, 2023
d1a98bc
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 13, 2023
a71eedc
adding progress bar while installing fonts
matiasbenedetto Sep 13, 2023
bb4f403
add early return
matiasbenedetto Sep 13, 2023
8736452
format php
matiasbenedetto Sep 13, 2023
1e43b4a
Merge branch 'trunk' into try/fonts-library-frontend-stage1
matiasbenedetto Sep 14, 2023
93eb81a
removing not needed changes to save hub button
matiasbenedetto Sep 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import deprecated from '@wordpress/deprecated';
/**
* Internal dependencies
*/
import { getNestedValue, setNestedValue } from './utils';
import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
import { createBatch } from './batch';
Expand Down Expand Up @@ -779,7 +780,7 @@ export const saveEditedEntityRecord =
* @param {string} kind Kind of the entity.
* @param {string} name Name of the entity.
* @param {Object} recordId ID of the record.
* @param {Array} itemsToSave List of entity properties to save.
* @param {Array} itemsToSave List of entity properties or properties paths to save.
* @param {Object} options Saving options.
*/
export const __experimentalSaveSpecifiedEntityEdits =
Expand All @@ -794,10 +795,9 @@ export const __experimentalSaveSpecifiedEntityEdits =
recordId
);
const editsToSave = {};
for ( const edit in edits ) {
if ( itemsToSave.some( ( item ) => item === edit ) ) {
editsToSave[ edit ] = edits[ edit ];
}

for ( const item of itemsToSave ) {
setNestedValue( editsToSave, item, getNestedValue( edits, item ) );
}

const configs = await dispatch( getOrLoadEntitiesConfig( kind ) );
Expand All @@ -814,7 +814,6 @@ export const __experimentalSaveSpecifiedEntityEdits =
if ( recordId ) {
editsToSave[ entityIdKey ] = recordId;
}

return await dispatch.saveEntityRecord(
kind,
name,
Expand Down
20 changes: 20 additions & 0 deletions packages/core-data/src/utils/get-nested-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Helper util to return a value from a certain path of the object.
* Path is specified as either:
* - a string of properties, separated by dots, for example: "x.y".
* - an array of properties, for example `[ 'x', 'y' ]`.
* You can also specify a default value in case the result is nullish.
*
* @param {Object} object Input object.
* @param {string|Array} path Path to the object property.
* @param {*} defaultValue Default value if the value at the specified path is nullish.
* @return {*} Value of the object property at the specified path.
*/
export default function getNestedValue( object, path, defaultValue ) {
const normalizedPath = Array.isArray( path ) ? path : path.split( '.' );
let value = object;
normalizedPath.forEach( ( fieldName ) => {
value = value?.[ fieldName ];
} );
return value !== undefined ? value : defaultValue;
}
1 change: 1 addition & 0 deletions packages/core-data/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { default as replaceAction } from './replace-action';
export { default as withWeakMapCache } from './with-weak-map-cache';
export { default as isRawAttribute } from './is-raw-attribute';
export { default as setNestedValue } from './set-nested-value';
export { default as getNestedValue } from './get-nested-value';
18 changes: 12 additions & 6 deletions packages/core-data/src/utils/set-nested-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Arrays are created for missing index properties while objects are created
* for all other missing properties.
*
* Path is specified as either:
* - a string of properties, separated by dots, for example: "x.y".
* - an array of properties, for example `[ 'x', 'y' ]`.
*
* This function intentionally mutates the input object.
*
* Inspired by _.set().
Expand All @@ -12,24 +16,26 @@
*
* @todo Needs to be deduplicated with its copy in `@wordpress/edit-site`.
*
* @param {Object} object Object to modify
* @param {Array} path Path of the property to set.
* @param {*} value Value to set.
* @param {Object} object Object to modify
* @param {Array|string} path Path of the property to set.
* @param {*} value Value to set.
*/
export default function setNestedValue( object, path, value ) {
if ( ! object || typeof object !== 'object' ) {
return object;
}

path.reduce( ( acc, key, idx ) => {
const normalizedPath = Array.isArray( path ) ? path : path.split( '.' );

normalizedPath.reduce( ( acc, key, idx ) => {
if ( acc[ key ] === undefined ) {
if ( Number.isInteger( path[ idx + 1 ] ) ) {
if ( Number.isInteger( normalizedPath[ idx + 1 ] ) ) {
acc[ key ] = [];
} else {
acc[ key ] = {};
}
}
if ( idx === path.length - 1 ) {
if ( idx === normalizedPath.length - 1 ) {
acc[ key ] = value;
}
return acc[ key ];
Expand Down
61 changes: 61 additions & 0 deletions packages/core-data/src/utils/test/get-nested-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Internal dependencies
*/
import getNestedValue from '../get-nested-value';

describe( 'setNestedValue', () => {
it( 'should return the same object unmodified if path is an empty array', () => {
const input = { x: 'y' };
const result = getNestedValue( input, [] );
expect( result ).toEqual( input );
} );

it( 'should the nested value', () => {
const input = { x: { y: { z: 123 } } };
const result = getNestedValue( input, [ 'x', 'y', 'z' ] );

expect( result ).toEqual( 123 );
} );

it( 'should return the nested value if the path is a string', () => {
const input = { x: { y: { z: 123 } } };
const result = getNestedValue( input, 'x.y.z' );

expect( result ).toEqual( 123 );
} );

it( 'should return the shallow value', () => {
const input = { x: { y: { z: 123 } } };
const result = getNestedValue( input, 'x' );

expect( result ).toEqual( { y: { z: 123 } } );
} );

it( 'should return the default value if the nested value is undefined', () => {
const input = { x: { y: { z: undefined } } };
const result = getNestedValue( input, [ 'x', 'y', 'z' ], 456 );

expect( result ).toEqual( 456 );
} );

it( 'should return the nested value if it different to undefined', () => {
const input = { x: { y: { z: null } } };
const result = getNestedValue( input, 'x.y.z', 456 );

expect( result ).toBeNull();
} );

it( 'should return the default value if the nested value does not exist', () => {
const input = { x: { y: { z: 123 } } };
const result = getNestedValue( input, [ 'x', 'y', 'z1' ], 456 );

expect( result ).toEqual( 456 );
} );

it( 'should return undefined if the nested value does not exist', () => {
const input = { x: { y: { z: 123 } } };
const result = getNestedValue( input, [ 'x', 'y', 'z1' ] );

expect( result ).toBeUndefined();
} );
} );
7 changes: 7 additions & 0 deletions packages/core-data/src/utils/test/set-nested-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe( 'setNestedValue', () => {
expect( result ).toEqual( { x: { y: { z: 456 } } } );
} );

it( 'should set values at deep level having a string as path', () => {
const input = { x: { y: { z: 123 } } };
const result = setNestedValue( input, 'x.y.z', 456 );

expect( result ).toEqual( { x: { y: { z: 456 } } } );
} );

it( 'should create nested objects if necessary', () => {
const result = setNestedValue( {}, [ 'x', 'y', 'z' ], 123 );

Expand Down
Loading
Loading