|
@@ -12,6 +12,7 @@ export interface Element {
|
|
type: string;
|
|
type: string;
|
|
id: string;
|
|
id: string;
|
|
properties?: Record<string, unknown>;
|
|
properties?: Record<string, unknown>;
|
|
|
|
+ styles?: Record<string, unknown>;
|
|
renderConfig?: CanvasRenderConfig;
|
|
renderConfig?: CanvasRenderConfig;
|
|
editModeRenderConfig?: CanvasRenderConfig;
|
|
editModeRenderConfig?: CanvasRenderConfig;
|
|
}
|
|
}
|
|
@@ -38,7 +39,13 @@ export class ElementManager {
|
|
this.#canvas = new TaipyCanvas(taipyApp);
|
|
this.#canvas = new TaipyCanvas(taipyApp);
|
|
}
|
|
}
|
|
|
|
|
|
- init(canvasDomElement: HTMLElement, canvasEditModeCanvas?: HTMLElement, propertyEditorElement?: HTMLElement) {
|
|
|
|
|
|
+ init(
|
|
|
|
+ canvasDomElement: HTMLElement,
|
|
|
|
+ canvasEditModeCanvas?: HTMLElement,
|
|
|
|
+ propertyEditorElement?: HTMLElement,
|
|
|
|
+ styleHandler?: (id: string, styles: Record<string, unknown>) => void,
|
|
|
|
+ ) {
|
|
|
|
+ getStore().setStyleHandler(styleHandler);
|
|
this.#canvas.init(canvasDomElement, canvasEditModeCanvas, propertyEditorElement);
|
|
this.#canvas.init(canvasDomElement, canvasEditModeCanvas, propertyEditorElement);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -60,10 +67,14 @@ export class ElementManager {
|
|
rootId: string,
|
|
rootId: string,
|
|
wrapper: CanvasRenderConfig["wrapper"],
|
|
wrapper: CanvasRenderConfig["wrapper"],
|
|
properties: Element["properties"] | undefined = undefined,
|
|
properties: Element["properties"] | undefined = undefined,
|
|
|
|
+ styles: Element["styles"] | undefined = undefined,
|
|
) {
|
|
) {
|
|
if (properties === undefined) {
|
|
if (properties === undefined) {
|
|
properties = {};
|
|
properties = {};
|
|
}
|
|
}
|
|
|
|
+ if (styles === undefined) {
|
|
|
|
+ styles = {};
|
|
|
|
+ }
|
|
const root = document.getElementById(rootId);
|
|
const root = document.getElementById(rootId);
|
|
if (!root) {
|
|
if (!root) {
|
|
console.error(`Root element with id '${rootId}' not found!`);
|
|
console.error(`Root element with id '${rootId}' not found!`);
|
|
@@ -74,11 +85,16 @@ export class ElementManager {
|
|
};
|
|
};
|
|
// add element if not existed
|
|
// add element if not existed
|
|
if (!isElementExisted(id)) {
|
|
if (!isElementExisted(id)) {
|
|
- getStore().addElementAction({ action: ElementActionEnum.Add, id, payload: properties });
|
|
|
|
|
|
+ getStore().addElementAction({
|
|
|
|
+ action: ElementActionEnum.Add,
|
|
|
|
+ id,
|
|
|
|
+ payload: { properties, styles },
|
|
|
|
+ });
|
|
getStore().addElement({
|
|
getStore().addElement({
|
|
type,
|
|
type,
|
|
id,
|
|
id,
|
|
properties,
|
|
properties,
|
|
|
|
+ styles,
|
|
...renderConfig,
|
|
...renderConfig,
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
@@ -88,8 +104,16 @@ export class ElementManager {
|
|
...getStore().elements.find((element) => element.id === id)?.properties,
|
|
...getStore().elements.find((element) => element.id === id)?.properties,
|
|
...properties,
|
|
...properties,
|
|
};
|
|
};
|
|
- getStore().addElementAction({ action: ElementActionEnum.Add, id, payload: editedProperties });
|
|
|
|
- getStore().editElement(id, { ...renderConfig, properties: editedProperties });
|
|
|
|
|
|
+ const editedStyles = {
|
|
|
|
+ ...getStore().elements.find((element) => element.id === id)?.styles,
|
|
|
|
+ ...styles,
|
|
|
|
+ };
|
|
|
|
+ getStore().addElementAction({
|
|
|
|
+ action: ElementActionEnum.Add,
|
|
|
|
+ id,
|
|
|
|
+ payload: { properties: editedProperties, styles: editedStyles },
|
|
|
|
+ });
|
|
|
|
+ getStore().editElement(id, { ...renderConfig, properties: editedProperties, styles: editedStyles });
|
|
}
|
|
}
|
|
|
|
|
|
modifyElement(id: string, elementProperties: Record<string, unknown>) {
|
|
modifyElement(id: string, elementProperties: Record<string, unknown>) {
|