Merged PR 189: Simplify usage of SmartComponent
- Added new Events : - AddContainer, AddContainerToSelectedContainer, AppendContainer, AppendContainerToSelectedContainer, SelectContainer, DeleteContainer - AddSymbol, SelectSymbol, DeleteSymbol - Changed the component to an iframe (you only need to copy the whole dist now) - Added callbacks to every methods in the component - Create event listener on demand: no need to initialize the event listener! - Update d.ts - Added Fastboot and enable it by default on production build
This commit is contained in:
parent
07dbac1b12
commit
23ed3ed1ad
14 changed files with 1047 additions and 108 deletions
101
src/dts/generate_dts.py
Normal file
101
src/dts/generate_dts.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
'''
|
||||
Generate a definition file with a global namespace
|
||||
from a typescript module definition file
|
||||
'''
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import argparse
|
||||
|
||||
parser = parser = argparse.ArgumentParser(description='Generate a definition file with a global namespace from a typescript module definition file')
|
||||
parser.add_argument('namespace',
|
||||
help='Namespace used in the global script. (example: Three.js use THREE as its namespace)')
|
||||
parser.add_argument('output_filename',
|
||||
help='Output d.ts definition file. (example: three.d.ts)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
output_filename = args.output_filename
|
||||
namespace = args.namespace
|
||||
|
||||
|
||||
import_pattern = re.compile(
|
||||
r"import(?:[\"'\s]*([\w*{}\n\r\t, ]+)from\s*)?[\"'\s].*([@\w_-]+)[\"'\s].*;"
|
||||
)
|
||||
export_pattern = re.compile(
|
||||
r"export ([*] from [\"'\s].*[\"'\s]|{.*}(?: from [\"'\s].*[\"'\s])?);"
|
||||
)
|
||||
|
||||
filter_directories = ["./Enums", "./Interfaces"]
|
||||
|
||||
def main():
|
||||
'''
|
||||
Entry point function
|
||||
'''
|
||||
with open(output_filename, 'w') as output_file:
|
||||
output_file.write(('declare namespace {} {{\n'.format(namespace)))
|
||||
for root, subdirs, files in os.walk('./'):
|
||||
if root not in filter_directories:
|
||||
continue
|
||||
|
||||
print('--\nroot = ' + root)
|
||||
|
||||
for subdir in subdirs:
|
||||
print('\t- subdirectory ' + subdir)
|
||||
|
||||
for filename in files:
|
||||
if filename == 'output.d.ts':
|
||||
continue
|
||||
|
||||
if filename == 'my-directory-list.txt':
|
||||
os.remove(os.path.join(root, filename))
|
||||
continue
|
||||
|
||||
suffixes = pathlib.Path(filename).suffixes
|
||||
if (suffixes != ['.d', '.ts']):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(root, filename)
|
||||
file_path = file_path.replace('\\', '/')
|
||||
|
||||
print('\t- file %s (full path: %s)' % (filename, file_path))
|
||||
with open(file_path, 'r') as cur_file:
|
||||
f_content = cur_file.read()
|
||||
|
||||
# removes imports
|
||||
# see https://gist.github.com/manekinekko/7e58a17bc62a9be47172
|
||||
f_content = import_pattern.sub('', f_content)
|
||||
|
||||
# Replace 'export { my_class as synonym };'
|
||||
# => 'class synonym extend my_class {}'
|
||||
f_content = re.sub(
|
||||
r"export ({ ([A-Z].*) as ([A-Z].*) });",
|
||||
"export class \\g<3> extends \\g<2> {}",
|
||||
f_content,
|
||||
0,
|
||||
re.MULTILINE
|
||||
)
|
||||
|
||||
# Replace 'export declare class' => 'export class'
|
||||
f_content = re.sub(r"export (declare) class", 'export class', f_content, 0, re.MULTILINE)
|
||||
f_content = re.sub(r"export (declare) enum", 'export enum', f_content, 0, re.MULTILINE)
|
||||
f_content = re.sub(r"export (declare) function", 'export function', f_content, 0, re.MULTILINE)
|
||||
f_content = re.sub(r"export (declare) type", 'export type', f_content, 0, re.MULTILINE)
|
||||
|
||||
# Replace 'export { my_func as synonym }' => 'export function synonym = my_func'
|
||||
|
||||
# Replace 'export default class' => 'export class'
|
||||
f_content = re.sub(r"(export) default", "\\1", f_content, 0, re.MULTILINE)
|
||||
|
||||
# Replace other exports : 'export { .* } from '.*';' and 'export [*] from '.*';
|
||||
f_content = export_pattern.sub('', f_content)
|
||||
|
||||
# Specific to your module
|
||||
f_content = re.sub('export as namespace {};'.format(namespace), '', f_content)
|
||||
|
||||
output_file.write(f_content)
|
||||
output_file.write('\n')
|
||||
output_file.write(('}\n'))
|
||||
|
||||
main()
|
469
src/dts/svgld.d.ts
vendored
Normal file
469
src/dts/svgld.d.ts
vendored
Normal file
|
@ -0,0 +1,469 @@
|
|||
declare namespace SVGLD {
|
||||
/**
|
||||
* Add method when creating a container
|
||||
* - Append will append to the last children in list
|
||||
* - Insert will always place it at the begining
|
||||
* - Replace will remove the selected container and insert a new one
|
||||
* (default: Append)
|
||||
*/
|
||||
export enum AddMethod {
|
||||
Append = 0,
|
||||
Insert = 1,
|
||||
Replace = 2
|
||||
}
|
||||
|
||||
export enum MessageType {
|
||||
Normal = 0,
|
||||
Success = 1,
|
||||
Warning = 2,
|
||||
Error = 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe the type of the property.
|
||||
* Used for the assignation in the OnPropertyChange function
|
||||
* See ContainerOperations.ts's OnPropertyChange
|
||||
*/
|
||||
export enum PropertyType {
|
||||
/**
|
||||
* Simple property: is not inside any object: id, x, width... (default)
|
||||
*/
|
||||
Simple = 0,
|
||||
/**
|
||||
* Style property: is inside the style object: stroke, fillOpacity...
|
||||
*/
|
||||
Style = 1,
|
||||
/**
|
||||
* Margin property: is inside the margin property: left, bottom, top, right...
|
||||
*/
|
||||
Margin = 2
|
||||
}
|
||||
|
||||
export enum XPositionReference {
|
||||
Left = 0,
|
||||
Center = 1,
|
||||
Right = 2
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface IAction {
|
||||
Id: string;
|
||||
CustomLogo: IImage;
|
||||
Label: string;
|
||||
Description: string;
|
||||
Action: string;
|
||||
AddingBehavior: AddMethod;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Model of available container used in application configuration */
|
||||
export interface IAvailableContainer {
|
||||
/** type */
|
||||
Type: string;
|
||||
/** displayed text */
|
||||
DisplayedText?: string;
|
||||
/** category */
|
||||
Category?: string;
|
||||
/** horizontal offset */
|
||||
X?: number;
|
||||
/** vertical offset */
|
||||
Y?: number;
|
||||
/** width */
|
||||
Width?: number;
|
||||
/** height */
|
||||
Height?: number;
|
||||
/**
|
||||
* Minimum width (min=1)
|
||||
* Allows the container to set isRigidBody to false when it gets squeezed
|
||||
* by an anchor
|
||||
*/
|
||||
MinWidth?: number;
|
||||
/**
|
||||
* Maximum width
|
||||
*/
|
||||
MaxWidth?: number;
|
||||
/** margin */
|
||||
Margin?: IMargin;
|
||||
/** true if anchor, false otherwise */
|
||||
IsAnchor?: boolean;
|
||||
/** true if flex, false otherwise */
|
||||
IsFlex?: boolean;
|
||||
/** Method used on container add */
|
||||
AddMethod?: AddMethod;
|
||||
/** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */
|
||||
XPositionReference?: XPositionReference;
|
||||
/**
|
||||
* (optional)
|
||||
* Replace a <rect> by a customized "SVG". It is not really an svg but it at least allows
|
||||
* to draw some patterns that can be bind to the properties of the container
|
||||
* Use {prop} to bind a property. Use {{ styleProp }} to use an object.
|
||||
* Example :
|
||||
* ```
|
||||
* `<rect width="{width}" height="{height}" style="{style}"></rect>
|
||||
* <rect width="{width}" height="{height}" stroke="black" fill-opacity="0"></rect>
|
||||
* <line x1="0" y1="0" x2="{width}" y2="{height}" stroke="black" style='{{ "transform":"scaleY(0.5)"}}'></line>
|
||||
* <line x1="{width}" y1="0" x2="0" y2="{height}" stroke="black" style='{userData.styleLine}'></line>
|
||||
* `
|
||||
* ```
|
||||
*/
|
||||
CustomSVG?: string;
|
||||
/**
|
||||
* (optional)
|
||||
* Disabled when Pattern is used.
|
||||
*
|
||||
* Replace a <rect> by a customized "SVG". It is not really an svg but it at least allows
|
||||
* to draw some patterns that can be bind to the properties of the container
|
||||
* Use {prop} to bind a property. Use {{ styleProp }} to use an object.
|
||||
* Example :
|
||||
* ```
|
||||
* `<rect width="{width}" height="{height}" style="{style}"></rect>
|
||||
* <rect width="{width}" height="{height}" stroke="black" fill-opacity="0"></rect>
|
||||
* <line x1="0" y1="0" x2="{width}" y2="{height}" stroke="black" style='{{ "transform":"scaleY(0.5)"}}'></line>
|
||||
* <line x1="{width}" y1="0" x2="0" y2="{height}" stroke="black" style='{userData.styleLine}'></line>
|
||||
* `
|
||||
* ```
|
||||
*/
|
||||
DefaultChildType?: string;
|
||||
/**
|
||||
* Allow to use a Pattern to create the list of children
|
||||
* Cannot be used with DefaultChildType,
|
||||
* DefaultChildType will be disabled for this container and the children
|
||||
*/
|
||||
Pattern?: string;
|
||||
/** if true, show the dimension of the container */
|
||||
ShowSelfDimensions?: boolean;
|
||||
/** if true show the overall dimensions of its children */
|
||||
ShowChildrenDimensions?: boolean;
|
||||
/**
|
||||
* if true, allows a parent dimension borrower to uses its x coordinate for as a reference point for a dimension
|
||||
*/
|
||||
MarkPositionToDimensionBorrower?: boolean;
|
||||
/**
|
||||
* if true, show a dimension from the edge of the container to end
|
||||
* and insert dimensions marks at lift up children (see liftDimensionToBorrower)
|
||||
*/
|
||||
IsDimensionBorrower?: boolean;
|
||||
/**
|
||||
* if true, hide the entry in the sidebar (default: false)
|
||||
*/
|
||||
IsHidden?: boolean;
|
||||
/**
|
||||
* Disable a list of available container to be added inside
|
||||
*/
|
||||
Blacklist?: string[];
|
||||
/**
|
||||
* Cannot be used with blacklist. Whitelist will be prioritized.
|
||||
* To disable the whitelist, Whitelist must be undefined.
|
||||
* Only allow a set of available container to be added inside
|
||||
*/
|
||||
Whitelist?: string[];
|
||||
/**
|
||||
* (optional)
|
||||
* Style of the <rect>
|
||||
*/
|
||||
Style?: React.CSSProperties;
|
||||
/**
|
||||
* List of possible actions shown on right-click
|
||||
*/
|
||||
Actions?: IAction[];
|
||||
/**
|
||||
* (optional)
|
||||
* User data that can be used for data storage or custom SVG
|
||||
*/
|
||||
UserData?: object;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Model of available symbol to configure the application */
|
||||
export interface IAvailableSymbol {
|
||||
Name: string;
|
||||
Image: IImage;
|
||||
Width?: number;
|
||||
Height?: number;
|
||||
XPositionReference?: XPositionReference;
|
||||
}
|
||||
|
||||
export interface ICategory {
|
||||
Type: string;
|
||||
DisplayedText?: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Model of configuration for the application to configure it */
|
||||
export interface IConfiguration {
|
||||
AvailableContainers: IAvailableContainer[];
|
||||
AvailableSymbols: IAvailableSymbol[];
|
||||
Categories: ICategory[];
|
||||
Patterns: IPattern[];
|
||||
MainContainer: IAvailableContainer;
|
||||
}
|
||||
|
||||
|
||||
export interface IContainerModel {
|
||||
children: IContainerModel[];
|
||||
parent: IContainerModel | null;
|
||||
properties: IContainerProperties;
|
||||
userData: Record<string, string | number>;
|
||||
}
|
||||
/**
|
||||
* Macro for creating the interface
|
||||
* Do not add methods since they will be lost during serialization
|
||||
*/
|
||||
export class ContainerModel implements IContainerModel {
|
||||
children: IContainerModel[];
|
||||
parent: IContainerModel | null;
|
||||
properties: IContainerProperties;
|
||||
userData: Record<string, string | number>;
|
||||
constructor(parent: IContainerModel | null, properties: IContainerProperties, children?: IContainerModel[], userData?: {});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Properties of a container
|
||||
*/
|
||||
export interface IContainerProperties {
|
||||
/** id of the container */
|
||||
id: string;
|
||||
/** type matching the configuration on construction */
|
||||
type: string;
|
||||
/** id of the parent container (null when there is no parent) */
|
||||
parentId: string;
|
||||
/** id of the linked symbol ('' when there is no parent) */
|
||||
linkedSymbolId: string;
|
||||
/** Text displayed in the container */
|
||||
displayedText: string;
|
||||
/** horizontal offset */
|
||||
x: number;
|
||||
/** vertical offset */
|
||||
y: number;
|
||||
/** margin */
|
||||
margin: IMargin;
|
||||
/**
|
||||
* Minimum width (min=1)
|
||||
* Allows the container to set isRigidBody to false when it gets squeezed
|
||||
* by an anchor
|
||||
*/
|
||||
minWidth: number;
|
||||
/**
|
||||
* Maximum width
|
||||
*/
|
||||
maxWidth: number;
|
||||
/** width */
|
||||
width: number;
|
||||
/** height */
|
||||
height: number;
|
||||
/** true if anchor, false otherwise */
|
||||
isAnchor: boolean;
|
||||
/** true if flex, false otherwise */
|
||||
isFlex: boolean;
|
||||
/** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */
|
||||
xPositionReference: XPositionReference;
|
||||
/** if true, show the dimension of the container */
|
||||
showSelfDimensions: boolean;
|
||||
/** if true show the overall dimensions of its children */
|
||||
showChildrenDimensions: boolean;
|
||||
/**
|
||||
* if true, allows a parent dimension borrower to borrow its x coordinate
|
||||
* as a reference point for a dimension
|
||||
*/
|
||||
markPositionToDimensionBorrower: boolean;
|
||||
/**
|
||||
* if true, show a dimension from the edge of the container to end
|
||||
* and insert dimensions marks at lift up children (see liftDimensionToBorrower)
|
||||
*/
|
||||
isDimensionBorrower: boolean;
|
||||
/**
|
||||
* Warnings of a container
|
||||
*/
|
||||
warning: string;
|
||||
/**
|
||||
* (optional)
|
||||
* Replace a <rect> by a customized "SVG". It is not really an svg but it at least allows
|
||||
* to draw some patterns that can be bind to the properties of the container
|
||||
* Use {prop} to bind a property. Use {{ styleProp }} to use an object.
|
||||
* Example :
|
||||
* ```
|
||||
* `<rect width="{width}" height="{height}" style="{style}"></rect>
|
||||
* <rect width="{width}" height="{height}" stroke="black" fill-opacity="0"></rect>
|
||||
* <line x1="0" y1="0" x2="{width}" y2="{height}" stroke="black" style='{{ "transform":"scaleY(0.5)"}}'></line>
|
||||
* <line x1="{width}" y1="0" x2="0" y2="{height}" stroke="black" style='{userData.styleLine}'></line>
|
||||
* `
|
||||
* ```
|
||||
*/
|
||||
customSVG?: string;
|
||||
/**
|
||||
* (optional)
|
||||
* Style of the <rect>
|
||||
*/
|
||||
style?: React.CSSProperties;
|
||||
/**
|
||||
* (optional)
|
||||
* User data that can be used for data storage or custom SVG
|
||||
*/
|
||||
userData?: object;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface IEditorState {
|
||||
history: IHistoryState[];
|
||||
historyCurrentStep: number;
|
||||
configuration: IConfiguration;
|
||||
}
|
||||
|
||||
|
||||
export interface IGetFeedbackRequest {
|
||||
/** Current application state */
|
||||
ApplicationState: IHistoryState;
|
||||
}
|
||||
|
||||
|
||||
export interface IGetFeedbackResponse {
|
||||
messages: IMessage[];
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface IHistoryState {
|
||||
/** Last editor action */
|
||||
lastAction: string;
|
||||
/** Reference to the main container */
|
||||
mainContainer: IContainerModel;
|
||||
/** Id of the selected container */
|
||||
selectedContainerId: string;
|
||||
/** Counter of type of container. Used for ids. */
|
||||
typeCounters: Record<string, number>;
|
||||
/** List of symbols */
|
||||
symbols: Map<string, ISymbolModel>;
|
||||
/** Selected symbols id */
|
||||
selectedSymbolId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model of an image with multiple source
|
||||
* It must at least have one source.
|
||||
*
|
||||
* If Url/Base64Image and Svg are set,
|
||||
* Url/Base64Image will be shown in the menu while SVG will be drawn
|
||||
*/
|
||||
export interface IImage {
|
||||
/** Name of the image */
|
||||
Name: string;
|
||||
/** (optional) Url of the image */
|
||||
Url?: string;
|
||||
/** (optional) base64 data of the image */
|
||||
Base64Image?: string;
|
||||
/** (optional) SVG string */
|
||||
Svg?: string;
|
||||
}
|
||||
|
||||
|
||||
export interface IInputGroup {
|
||||
text: React.ReactNode;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface IMargin {
|
||||
left?: number;
|
||||
bottom?: number;
|
||||
top?: number;
|
||||
right?: number;
|
||||
}
|
||||
|
||||
|
||||
export interface IMessage {
|
||||
text: string;
|
||||
type: MessageType;
|
||||
}
|
||||
|
||||
|
||||
export interface IPattern {
|
||||
/**
|
||||
* Unique id for the pattern
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Text to display in the sidebar
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* IAvailableContainer id used to wrap the children.
|
||||
*/
|
||||
wrapper: string;
|
||||
/**
|
||||
* List of ids of Pattern or IAvailableContainer
|
||||
* If a IAvailableContainer and a Pattern have the same id,
|
||||
* IAvailableContainer will be prioritized
|
||||
*/
|
||||
children: string[];
|
||||
}
|
||||
export type ContainerOrPattern = IAvailableContainer | IPattern;
|
||||
export function GetPattern(id: string, configs: Map<string, IAvailableContainer>, patterns: Map<string, IPattern>): ContainerOrPattern | undefined;
|
||||
export function IsPattern(id: string, configs: Map<string, IAvailableContainer>, patterns: Map<string, IPattern>): boolean;
|
||||
|
||||
export interface IPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface ISetContainerListRequest {
|
||||
/** Name of the action declared in the API */
|
||||
Action: string;
|
||||
/** Selected container */
|
||||
Container: IContainerModel;
|
||||
/** The previous sibling container */
|
||||
PreviousContainer: IContainerModel | undefined;
|
||||
/** The next sibling container */
|
||||
NextContainer: IContainerModel | undefined;
|
||||
/** Current application state */
|
||||
ApplicationState: IHistoryState;
|
||||
}
|
||||
|
||||
|
||||
export interface ISetContainerListResponse {
|
||||
Containers: IAvailableContainer[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A SizePointer is a pointer in a 1 dimensional array of width/space
|
||||
* x being the address where the pointer is pointing
|
||||
* width being the overall (un)allocated space affected to the address
|
||||
*/
|
||||
export interface ISizePointer {
|
||||
x: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
|
||||
export interface ISymbolModel {
|
||||
/** Identifier */
|
||||
id: string;
|
||||
/** Type */
|
||||
type: string;
|
||||
/** Configuration of the symbol */
|
||||
config: IAvailableSymbol;
|
||||
/** Horizontal offset */
|
||||
x: number;
|
||||
/** Width */
|
||||
width: number;
|
||||
/** Height */
|
||||
height: number;
|
||||
/** List of linked container id */
|
||||
linkedContainers: Set<string>;
|
||||
}
|
||||
|
||||
}
|
15
src/dts/tsconfig.dts.json
Normal file
15
src/dts/tsconfig.dts.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
// Change this to match your project
|
||||
"include": ["../Enums/*", "../Interfaces/*"],
|
||||
"compilerOptions": {
|
||||
"target": "ES2021",
|
||||
"module": "es2020",
|
||||
"allowJs": false,
|
||||
"declaration": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "dist",
|
||||
"declarationMap": false
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue