@node-projects/web-component-designer 0.0.267 → 0.0.268
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/item/DesignItem.d.ts +1 -0
- package/dist/elements/item/DesignItem.js +12 -0
- package/dist/elements/services/copyPasteService/CopyPasteAsJsonService.js +10 -0
- package/dist/elements/services/dragDropService/ExternalDragDropService.d.ts +1 -1
- package/dist/elements/services/dragDropService/ExternalDragDropService.js +10 -16
- package/dist/elements/services/propertiesService/DefaultEditorTypesService.js +5 -0
- package/dist/elements/services/propertiesService/propertyEditors/FontPropertyEditor.d.ts +9 -0
- package/dist/elements/services/propertiesService/propertyEditors/FontPropertyEditor.js +37 -0
- package/dist/elements/services/propertiesService/propertyEditors/SelectPropertyEditor copy.d.ts +7 -0
- package/dist/elements/services/propertiesService/propertyEditors/SelectPropertyEditor copy.js +28 -0
- package/dist/elements/services/propertiesService/services/CssProperties.json +3 -1
- package/dist/elements/services/propertiesService/services/CssPropertiesService.js +1 -0
- package/package.json +1 -1
|
@@ -87,4 +87,5 @@ export declare class DesignItem implements IDesignItem {
|
|
|
87
87
|
_removeChildInternal(designItem: IDesignItem): void;
|
|
88
88
|
_refreshIfStyleSheet(): void;
|
|
89
89
|
getPlacementService(style?: CSSStyleDeclaration): IPlacementService;
|
|
90
|
+
static createDesignItemFromImageBlob(serviceContainer: ServiceContainer, instanceServiceContainer: InstanceServiceContainer, data: Blob): Promise<IDesignItem>;
|
|
90
91
|
}
|
|
@@ -482,4 +482,16 @@ export class DesignItem {
|
|
|
482
482
|
style ??= getComputedStyle(this.element);
|
|
483
483
|
return this.serviceContainer.getLastServiceWhere('containerService', x => x.serviceForContainer(this, style));
|
|
484
484
|
}
|
|
485
|
+
static createDesignItemFromImageBlob(serviceContainer, instanceServiceContainer, data) {
|
|
486
|
+
return new Promise(resolve => {
|
|
487
|
+
let reader = new FileReader();
|
|
488
|
+
reader.onloadend = () => {
|
|
489
|
+
const img = document.createElement('img');
|
|
490
|
+
img.src = reader.result;
|
|
491
|
+
const di = DesignItem.createDesignItemFromInstance(img, serviceContainer, instanceServiceContainer);
|
|
492
|
+
return resolve(di);
|
|
493
|
+
};
|
|
494
|
+
reader.readAsDataURL(data);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
485
497
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DomConverter } from "../../widgets/designerView/DomConverter.js";
|
|
2
2
|
import { copyToClipboard, getFromClipboard, getTextFromClipboard } from "../../helper/ClipboardHelper.js";
|
|
3
|
+
import { DesignItem } from "../../item/DesignItem.js";
|
|
3
4
|
export class CopyPasteAsJsonService {
|
|
4
5
|
async copyItems(designItems) {
|
|
5
6
|
const copyText = DomConverter.ConvertToString(designItems, false);
|
|
@@ -26,6 +27,15 @@ export class CopyPasteAsJsonService {
|
|
|
26
27
|
data = await (await items[0].getType('application/json'))?.text();
|
|
27
28
|
}
|
|
28
29
|
catch { }
|
|
30
|
+
try {
|
|
31
|
+
let imageFmt = items[0].types.find(x => x.startsWith("image/"));
|
|
32
|
+
if (imageFmt) {
|
|
33
|
+
let imgData = await items[0].getType(imageFmt);
|
|
34
|
+
let di = await DesignItem.createDesignItemFromImageBlob(serviceContainer, instanceServiceContainer, imgData);
|
|
35
|
+
return [[di]];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
29
39
|
}
|
|
30
40
|
else {
|
|
31
41
|
data = await getTextFromClipboard();
|
|
@@ -2,5 +2,5 @@ import { IDesignerCanvas } from "../../widgets/designerView/IDesignerCanvas.js";
|
|
|
2
2
|
import { IExternalDragDropService } from "./IExternalDragDropService.js";
|
|
3
3
|
export declare class ExternalDragDropService implements IExternalDragDropService {
|
|
4
4
|
dragOver(event: DragEvent): 'none' | 'copy' | 'link' | 'move';
|
|
5
|
-
drop(designerCanvas: IDesignerCanvas, event: DragEvent): void
|
|
5
|
+
drop(designerCanvas: IDesignerCanvas, event: DragEvent): Promise<void>;
|
|
6
6
|
}
|
|
@@ -6,23 +6,17 @@ export class ExternalDragDropService {
|
|
|
6
6
|
return 'copy';
|
|
7
7
|
return 'none';
|
|
8
8
|
}
|
|
9
|
-
drop(designerCanvas, event) {
|
|
9
|
+
async drop(designerCanvas, event) {
|
|
10
10
|
if (event.dataTransfer.files[0].type.startsWith('image/')) {
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
di.setStyle('left', event.offsetX + targetRect.left - designerCanvas.containerBoundingRect.x + 'px');
|
|
21
|
-
designerCanvas.instanceServiceContainer.undoService.execute(new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, di));
|
|
22
|
-
grp.commit();
|
|
23
|
-
requestAnimationFrame(() => designerCanvas.instanceServiceContainer.selectionService.setSelectedElements([di]));
|
|
24
|
-
};
|
|
25
|
-
reader.readAsDataURL(event.dataTransfer.files[0]);
|
|
11
|
+
let di = await DesignItem.createDesignItemFromImageBlob(designerCanvas.serviceContainer, designerCanvas.instanceServiceContainer, event.dataTransfer.files[0]);
|
|
12
|
+
let grp = di.openGroup("Insert of <img>");
|
|
13
|
+
di.setStyle('position', 'absolute');
|
|
14
|
+
const targetRect = event.target.getBoundingClientRect();
|
|
15
|
+
di.setStyle('top', event.offsetY + targetRect.top - designerCanvas.containerBoundingRect.y + 'px');
|
|
16
|
+
di.setStyle('left', event.offsetX + targetRect.left - designerCanvas.containerBoundingRect.x + 'px');
|
|
17
|
+
designerCanvas.instanceServiceContainer.undoService.execute(new InsertAction(designerCanvas.rootDesignItem, designerCanvas.rootDesignItem.childCount, di));
|
|
18
|
+
grp.commit();
|
|
19
|
+
requestAnimationFrame(() => designerCanvas.instanceServiceContainer.selectionService.setSelectedElements([di]));
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
22
|
}
|
|
@@ -7,6 +7,7 @@ import { TextPropertyEditor } from './propertyEditors/TextPropertyEditor.js';
|
|
|
7
7
|
import { BooleanPropertyEditor } from './propertyEditors/BooleanPropertyEditor.js';
|
|
8
8
|
import { ImageButtonListPropertyEditor } from './propertyEditors/ImageButtonListPropertyEditor.js';
|
|
9
9
|
import { ThicknessPropertyEditor } from "./propertyEditors/ThicknessPropertyEditor.js";
|
|
10
|
+
import { FontPropertyEditor } from './propertyEditors/FontPropertyEditor.js';
|
|
10
11
|
export class DefaultEditorTypesService {
|
|
11
12
|
getEditorForProperty(property) {
|
|
12
13
|
if (property.createEditor)
|
|
@@ -20,6 +21,10 @@ export class DefaultEditorTypesService {
|
|
|
20
21
|
{
|
|
21
22
|
return new ColorPropertyEditor(property);
|
|
22
23
|
}
|
|
24
|
+
case "font":
|
|
25
|
+
{
|
|
26
|
+
return new FontPropertyEditor(property);
|
|
27
|
+
}
|
|
23
28
|
case "date":
|
|
24
29
|
{
|
|
25
30
|
return new DatePropertyEditor(property);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IProperty } from '../IProperty.js';
|
|
2
|
+
import { BasePropertyEditor } from './BasePropertyEditor.js';
|
|
3
|
+
import { ValueType } from '../ValueType.js';
|
|
4
|
+
export declare class FontPropertyEditor extends BasePropertyEditor<HTMLSelectElement> {
|
|
5
|
+
static fontList: string[];
|
|
6
|
+
constructor(property: IProperty);
|
|
7
|
+
parseFontList(): void;
|
|
8
|
+
refreshValue(valueType: ValueType, value: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BasePropertyEditor } from './BasePropertyEditor.js';
|
|
2
|
+
export class FontPropertyEditor extends BasePropertyEditor {
|
|
3
|
+
static fontList;
|
|
4
|
+
constructor(property) {
|
|
5
|
+
super(property);
|
|
6
|
+
let element = document.createElement("select");
|
|
7
|
+
this.element = element;
|
|
8
|
+
if (FontPropertyEditor.fontList) {
|
|
9
|
+
this.parseFontList();
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
}
|
|
12
|
+
else if (window.queryLocalFonts) {
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
window.queryLocalFonts().then(x => {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
FontPropertyEditor.fontList = [...new Set(x.map(y => y.family))];
|
|
17
|
+
this.parseFontList();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
FontPropertyEditor.fontList = ["Verdana", "Arial", "Tahoma", "Trebuchet MS", "Times New Roman", "Georgia", "Garamond", "Courier New", "Brush Script MT"];
|
|
22
|
+
this.parseFontList();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
parseFontList() {
|
|
26
|
+
for (let v of FontPropertyEditor.fontList) {
|
|
27
|
+
let option = document.createElement("option");
|
|
28
|
+
option.value = v;
|
|
29
|
+
option.text = v;
|
|
30
|
+
this.element.appendChild(option);
|
|
31
|
+
}
|
|
32
|
+
this.element.onchange = (e) => this._valueChanged(this.element.value);
|
|
33
|
+
}
|
|
34
|
+
refreshValue(valueType, value) {
|
|
35
|
+
this.element.value = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/elements/services/propertiesService/propertyEditors/SelectPropertyEditor copy.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IProperty } from '../IProperty.js';
|
|
2
|
+
import { BasePropertyEditor } from './BasePropertyEditor.js';
|
|
3
|
+
import { ValueType } from '../ValueType.js';
|
|
4
|
+
export declare class SelectPropertyEditor extends BasePropertyEditor<HTMLSelectElement> {
|
|
5
|
+
constructor(property: IProperty);
|
|
6
|
+
refreshValue(valueType: ValueType, value: any): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BasePropertyEditor } from './BasePropertyEditor.js';
|
|
2
|
+
export class SelectPropertyEditor extends BasePropertyEditor {
|
|
3
|
+
constructor(property) {
|
|
4
|
+
super(property);
|
|
5
|
+
let element = document.createElement("select");
|
|
6
|
+
if (property.type == 'enum') {
|
|
7
|
+
for (let v of property.enumValues) {
|
|
8
|
+
let option = document.createElement("option");
|
|
9
|
+
option.value = v[1];
|
|
10
|
+
option.text = v[0];
|
|
11
|
+
element.appendChild(option);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
for (let v of property.values) {
|
|
16
|
+
let option = document.createElement("option");
|
|
17
|
+
option.value = v;
|
|
18
|
+
option.text = v;
|
|
19
|
+
element.appendChild(option);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
element.onchange = (e) => this._valueChanged(element.value);
|
|
23
|
+
this.element = element;
|
|
24
|
+
}
|
|
25
|
+
refreshValue(valueType, value) {
|
|
26
|
+
this.element.value = value;
|
|
27
|
+
}
|
|
28
|
+
}
|