-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
13,065 additions
and
911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const { url: PLUGIN_URL } = window.frmGlobal; | ||
export const HIDDEN_CLASS = 'frm_hidden'; | ||
export const HIDE_JS_CLASS = 'frm-hide-js'; | ||
export const CURRENT_CLASS = 'frm-current'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Creates a page elements manager. | ||
* | ||
* @param {Object} [initialElements={}] An object containing initial DOM elements. | ||
* @throws {Error} Throws an error if the `initialElements` is not an object. | ||
* @return {Object} An object with methods to get and add elements. | ||
*/ | ||
export function createPageElements( initialElements = {} ) { | ||
let elements = null; | ||
|
||
/** | ||
* Initializes the page elements with the provided initial elements. | ||
* | ||
* @throws {Error} Throws an error if `initialElements` is not a plain object. | ||
* @return {void} | ||
*/ | ||
const initializePageElements = () => { | ||
if ( typeof initialElements !== 'object' || initialElements === null ) { | ||
throw new Error( | ||
'initializePageElements: initialElements must be a non-null object' | ||
); | ||
} | ||
|
||
elements = initialElements; | ||
}; | ||
|
||
/** | ||
* Retrieve the initialized essential DOM elements. | ||
* | ||
* @return {Object} The initialized elements object. | ||
*/ | ||
function getElements() { | ||
return elements; | ||
} | ||
|
||
/** | ||
* Add new elements to the elements object. | ||
* | ||
* @param {Object} newElements An object containing new elements to be added. | ||
* @throws {Error} Throws an error if the `newElements` is not a non-null object. | ||
* @return {void} Updates the elements object by merging the new elements into it. | ||
*/ | ||
function addElements( newElements ) { | ||
if ( typeof newElements !== 'object' || newElements === null ) { | ||
throw new Error( | ||
'addElements: newElements must be a non-null object' | ||
); | ||
} | ||
|
||
elements = { ...elements, ...newElements }; | ||
} | ||
|
||
return { initializePageElements, getElements, addElements }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Creates a page state manager. | ||
* | ||
* @param {Object} [initialState={}] An object containing the initial state. | ||
* @throws {Error} Throws an error if the `initialState` is not a plain object. | ||
* @return {Object} An object with methods to initialize, get, and set the page state. | ||
*/ | ||
export function createPageState( initialState = {} ) { | ||
let state = null; | ||
|
||
/** | ||
* Initializes the page state with the provided initial state. | ||
* | ||
* @throws {Error} Throws an error if `initialState` is not a plain object. | ||
* @return {void} | ||
*/ | ||
const initializePageState = () => { | ||
if ( typeof initialState !== 'object' || initialState === null ) { | ||
throw new Error( | ||
'initializePageState: initialState must be a non-null object' | ||
); | ||
} | ||
|
||
state = initialState; | ||
}; | ||
|
||
/** | ||
* Returns the current page state. | ||
* | ||
* @return {Object|null} The current state of the page or null if not initialized. | ||
*/ | ||
const getState = () => state; | ||
|
||
/** | ||
* Returns a specific property from the current page state. | ||
* | ||
* @param {string} propertyName The name of the property to retrieve. | ||
* @return {*} The value of the specified property, or null if it doesn't exist. | ||
*/ | ||
const getSingleState = ( propertyName ) => | ||
Reflect.get( state, propertyName ) ?? null; | ||
|
||
/** | ||
* Updates the page state with new values. | ||
* | ||
* @param {Object} newState The new values to update the state with. | ||
* @throws {Error} Throws an error if `newState` is not a plain object. | ||
* @return {void} | ||
*/ | ||
const setState = ( newState ) => { | ||
if ( typeof newState !== 'object' || newState === null ) { | ||
throw new Error( 'setState: newState must be a non-null object' ); | ||
} | ||
|
||
state = { ...state, ...newState }; | ||
}; | ||
|
||
/** | ||
* Updates a specific property in the page state with a new value. | ||
* | ||
* @param {string} propertyName The name of the property to update. | ||
* @param {*} value The new value to set for the property. | ||
* @return {void} | ||
*/ | ||
const setSingleState = ( propertyName, value ) => { | ||
if ( Reflect.has( state, propertyName ) ) { | ||
Reflect.set( state, propertyName, value ); | ||
} | ||
}; | ||
|
||
return { | ||
initializePageState, | ||
getState, | ||
getSingleState, | ||
setState, | ||
setSingleState, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './createPageElements'; | ||
export * from './createPageState'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './constants'; | ||
export * from './factory'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const PREFIX = 'frm-page-sidebar'; | ||
export const SEARCH_RESULT_ITEM = 'frm-card-item'; | ||
export const VIEW_SLUGS = { | ||
ALL_ITEMS: 'all-items', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createPageElements } from 'core/factory'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PREFIX, VIEW_SLUGS } from '../constants'; | ||
import { createEmptyStateElement, getEmptyStateElements } from './emptyStateElement'; | ||
|
||
const bodyContent = document.getElementById( 'post-body-content' ); | ||
|
||
// Sidebar Elements | ||
const sidebar = document.getElementById( `${PREFIX}-panel` ); | ||
const searchInput = sidebar.querySelector( '.frm-search-input' ); | ||
const categoryItems = sidebar.querySelectorAll( `.${PREFIX}-cat` ); | ||
const allItemsCategory = sidebar.querySelector( | ||
`.${PREFIX}-cat[data-category="${VIEW_SLUGS.ALL_ITEMS}"]` | ||
); | ||
|
||
// Empty State Elements | ||
const emptyState = createEmptyStateElement(); | ||
bodyContent?.appendChild( emptyState ); | ||
const emptyStateElements = getEmptyStateElements(); | ||
|
||
export const { getElements, addElements } = createPageElements({ | ||
bodyContent, | ||
sidebar, | ||
searchInput, | ||
categoryItems, | ||
allItemsCategory, | ||
...emptyStateElements, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.