Skip to content

Commit

Permalink
More code organization changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Troup committed Jul 18, 2024
1 parent 5cb6b2e commit 340366d
Show file tree
Hide file tree
Showing 8 changed files with 760 additions and 689 deletions.
636 changes: 328 additions & 308 deletions dist/peek.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/peek.esm.js.map

Large diffs are not rendered by default.

636 changes: 328 additions & 308 deletions dist/peek.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/peek.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/peek.min.js

Large diffs are not rendered by default.

75 changes: 5 additions & 70 deletions src/peek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@


import {
type ConfigurationText,
type Position,
type Configuration,
type Options } from "./ts/type";

import { type PublicApi } from "./ts/api";
import { Is } from "./ts/data/is";
import { DomElement } from "./ts/dom/dom";
import { Default } from "./ts/data/default";
import { Char, IgnoreState, KeyCode, Mode, Value } from "./ts/data/enum";
import { Constant } from "./ts/constant";
import { Config } from "./ts/options/config";
import { Start } from "./ts/options/options";


type DialogProperties = Record<string, string>;
Expand Down Expand Up @@ -610,71 +610,6 @@ type DialogProperties = Record<string, string>;
}


/*
* ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Options
* ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

function buildOptions( newOptions: any ) : Options {
let options: Options = Default.getObject( newOptions, {} as Options );
options.nodeType = Default.getStringOrArray( options.nodeType, [] );
options.mode = Default.getNumber( options.mode, Mode.css );
options.titleText = Default.getString( options.titleText, Char.empty );
options.showOnly = Default.getStringOrArray( options.showOnly, [] );
options.allowEditing = Default.getBoolean( options.allowEditing, false );
options.showIdOrNameInTitle = Default.getBoolean( options.showIdOrNameInTitle, true );
options.showNodeNameInTitle = Default.getBoolean( options.showNodeNameInTitle, false );

return options;
}


/*
* ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Public API Functions: Helpers: Configuration
* ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

function buildDefaultConfiguration( newConfiguration: Configuration = null! ) : void {
_configuration = Default.getObject( newConfiguration, {} as Configuration );
_configuration.dialogDisplayDelay = Default.getNumber( _configuration.dialogDisplayDelay, 1000 );
_configuration.searchDelayDelay = Default.getNumber( _configuration.searchDelayDelay, 500 );

buildDefaultStringConfiguration();
}

function buildDefaultStringConfiguration() : void {
_configuration.text = Default.getObject( _configuration.text, {} as ConfigurationText );
_configuration.text!.cssText = Default.getAnyString( _configuration.text!.cssText, "CSS" );
_configuration.text!.attributesText = Default.getAnyString( _configuration.text!.attributesText, "Attributes" );
_configuration.text!.sizeText = Default.getAnyString( _configuration.text!.sizeText, "Size" );
_configuration.text!.classesText = Default.getAnyString( _configuration.text!.classesText, "Classes" );
_configuration.text!.noAttributesAvailableText = Default.getAnyString( _configuration.text!.noAttributesAvailableText, "No attributes are available." );
_configuration.text!.closeText = Default.getAnyString( _configuration.text!.closeText, "Close" );
_configuration.text!.copyText = Default.getAnyString( _configuration.text!.copyText, "Copy" );
_configuration.text!.copySymbolText = Default.getAnyString( _configuration.text!.copySymbolText, "❐" );
_configuration.text!.pasteText = Default.getAnyString( _configuration.text!.pasteText, "Paste" );
_configuration.text!.pasteSymbolText = Default.getAnyString( _configuration.text!.pasteSymbolText, "☐" );
_configuration.text!.removeText = Default.getAnyString( _configuration.text!.removeText, "Remove" );
_configuration.text!.removeSymbolText = Default.getAnyString( _configuration.text!.removeSymbolText, "✕" );
_configuration.text!.noClassesAvailableText = Default.getAnyString( _configuration.text!.noClassesAvailableText, "No classes are available." );
_configuration.text!.searchPropertiesPlaceHolderText = Default.getAnyString( _configuration.text!.searchPropertiesPlaceHolderText, "Search properties..." );
_configuration.text!.clearText = Default.getAnyString( _configuration.text!.clearText, "Clear" );
_configuration.text!.clearSymbolText = Default.getAnyString( _configuration.text!.clearSymbolText, "✕" );
_configuration.text!.noPropertiesFoundForSearchText = Default.getAnyString( _configuration.text!.noPropertiesFoundForSearchText, "No properties were found for your search." );
_configuration.text!.dialogMovedSymbolText = Default.getAnyString( _configuration.text!.dialogMovedSymbolText, "✱" );
_configuration.text!.propertyValuePlaceHolderText = Default.getAnyString( _configuration.text!.propertyValuePlaceHolderText, "Enter value..." );
_configuration.text!.modeNotSupportedText = Default.getAnyString( _configuration.text!.modeNotSupportedText, "The mode you have specified is not supported." );
_configuration.text!.unknownModeText = Default.getAnyString( _configuration.text!.unknownModeText, "Unknown Mode" );
_configuration.text!.moveUpText = Default.getAnyString( _configuration.text!.moveUpText, "Move Up" );
_configuration.text!.moveUpSymbolText = Default.getAnyString( _configuration.text!.moveUpSymbolText, "↑" );
_configuration.text!.moveDownText = Default.getAnyString( _configuration.text!.moveDownText, "Move Down" );
_configuration.text!.moveDownSymbolText = Default.getAnyString( _configuration.text!.moveDownSymbolText, "↓" );
_configuration.text!.removeElementSymbolText = Default.getAnyString( _configuration.text!.removeElementSymbolText, "⌫" );
}


/*
* ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Public API Functions:
Expand All @@ -690,7 +625,7 @@ type DialogProperties = Record<string, string>;

start: function ( options: Options ) : PublicApi {
if ( !Is.definedObject( _current_Process_Options ) ) {
_current_Process_Options = buildOptions( options );
_current_Process_Options = Start.Options.get( options );

setDialogTitle();
buildNodeEvents();
Expand Down Expand Up @@ -735,7 +670,7 @@ type DialogProperties = Record<string, string>;
}

if ( configurationHasChanged ) {
buildDefaultConfiguration( newInternalConfiguration );
_configuration = Config.Options.get( newInternalConfiguration );
buildDialog();

if ( Is.definedObject( _current_Process_Options ) ) {
Expand Down Expand Up @@ -767,7 +702,7 @@ type DialogProperties = Record<string, string>;
*/

( () => {
buildDefaultConfiguration();
_configuration = Config.Options.get();

document.addEventListener( "DOMContentLoaded", () => {
buildDialog();
Expand Down
62 changes: 62 additions & 0 deletions src/ts/options/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Peek.js
*
* A lightweight JavaScript library that attaches a viewer to a specific node type, allowing you to view the CSS properties, attributes, and size/position.
*
* @file config.ts
* @version v1.6.1
* @author Bunoon
* @license MIT License
* @copyright Bunoon 2024
*/


import { type Configuration, type ConfigurationText } from "../type";
import { Default } from "../data/default";


export namespace Config {
export namespace Options {
export function get( newConfiguration: Configuration = null! ) : Configuration {
let configuration: Configuration = Default.getObject( newConfiguration, {} as Configuration );
configuration.dialogDisplayDelay = Default.getNumber( configuration.dialogDisplayDelay, 1000 );
configuration.searchDelayDelay = Default.getNumber( configuration.searchDelayDelay, 500 );

configuration = getText( configuration );

return configuration;
}

function getText( configuration: Configuration ) : Configuration {
configuration.text = Default.getObject( configuration.text, {} as ConfigurationText );
configuration.text!.cssText = Default.getAnyString( configuration.text!.cssText, "CSS" );
configuration.text!.attributesText = Default.getAnyString( configuration.text!.attributesText, "Attributes" );
configuration.text!.sizeText = Default.getAnyString( configuration.text!.sizeText, "Size" );
configuration.text!.classesText = Default.getAnyString( configuration.text!.classesText, "Classes" );
configuration.text!.noAttributesAvailableText = Default.getAnyString( configuration.text!.noAttributesAvailableText, "No attributes are available." );
configuration.text!.closeText = Default.getAnyString( configuration.text!.closeText, "Close" );
configuration.text!.copyText = Default.getAnyString( configuration.text!.copyText, "Copy" );
configuration.text!.copySymbolText = Default.getAnyString( configuration.text!.copySymbolText, "❐" );
configuration.text!.pasteText = Default.getAnyString( configuration.text!.pasteText, "Paste" );
configuration.text!.pasteSymbolText = Default.getAnyString( configuration.text!.pasteSymbolText, "☐" );
configuration.text!.removeText = Default.getAnyString( configuration.text!.removeText, "Remove" );
configuration.text!.removeSymbolText = Default.getAnyString( configuration.text!.removeSymbolText, "✕" );
configuration.text!.noClassesAvailableText = Default.getAnyString( configuration.text!.noClassesAvailableText, "No classes are available." );
configuration.text!.searchPropertiesPlaceHolderText = Default.getAnyString( configuration.text!.searchPropertiesPlaceHolderText, "Search properties..." );
configuration.text!.clearText = Default.getAnyString( configuration.text!.clearText, "Clear" );
configuration.text!.clearSymbolText = Default.getAnyString( configuration.text!.clearSymbolText, "✕" );
configuration.text!.noPropertiesFoundForSearchText = Default.getAnyString( configuration.text!.noPropertiesFoundForSearchText, "No properties were found for your search." );
configuration.text!.dialogMovedSymbolText = Default.getAnyString( configuration.text!.dialogMovedSymbolText, "✱" );
configuration.text!.propertyValuePlaceHolderText = Default.getAnyString( configuration.text!.propertyValuePlaceHolderText, "Enter value..." );
configuration.text!.modeNotSupportedText = Default.getAnyString( configuration.text!.modeNotSupportedText, "The mode you have specified is not supported." );
configuration.text!.unknownModeText = Default.getAnyString( configuration.text!.unknownModeText, "Unknown Mode" );
configuration.text!.moveUpText = Default.getAnyString( configuration.text!.moveUpText, "Move Up" );
configuration.text!.moveUpSymbolText = Default.getAnyString( configuration.text!.moveUpSymbolText, "↑" );
configuration.text!.moveDownText = Default.getAnyString( configuration.text!.moveDownText, "Move Down" );
configuration.text!.moveDownSymbolText = Default.getAnyString( configuration.text!.moveDownSymbolText, "↓" );
configuration.text!.removeElementSymbolText = Default.getAnyString( configuration.text!.removeElementSymbolText, "⌫" );

return configuration;
}
}
}
34 changes: 34 additions & 0 deletions src/ts/options/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Peek.js
*
* A lightweight JavaScript library that attaches a viewer to a specific node type, allowing you to view the CSS properties, attributes, and size/position.
*
* @file options.ts
* @version v1.6.1
* @author Bunoon
* @license MIT License
* @copyright Bunoon 2024
*/


import { Default } from "../data/default";
import { Char, Mode } from "../data/enum";
import { type Options } from "../type";


export namespace Start {
export namespace Options {
export function get( newOptions: any ) : Options {
let options: Options = Default.getObject( newOptions, {} as Options );
options.nodeType = Default.getStringOrArray( options.nodeType, [] );
options.mode = Default.getNumber( options.mode, Mode.css );
options.titleText = Default.getString( options.titleText, Char.empty );
options.showOnly = Default.getStringOrArray( options.showOnly, [] );
options.allowEditing = Default.getBoolean( options.allowEditing, false );
options.showIdOrNameInTitle = Default.getBoolean( options.showIdOrNameInTitle, true );
options.showNodeNameInTitle = Default.getBoolean( options.showNodeNameInTitle, false );

return options;
}
}
}

0 comments on commit 340366d

Please sign in to comment.