@contrail/documents 1.0.1 → 1.0.3

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.
@@ -0,0 +1,20 @@
1
+ import { Document } from '../types/document';
2
+ export interface ComponentDefinition {
3
+ slug: string;
4
+ defaultTemplate: Document;
5
+ }
6
+ export declare const ITEM_COLOR_VIEW_TEMPLATE: Document;
7
+ export declare const ITEM_COLOR_VIEW_STATIC_THUMBNAIL_TEMPLATE: Document;
8
+ export declare const ITEM_COLOR_VIEW: {
9
+ slug: string;
10
+ defaultTemplate: Document;
11
+ };
12
+ export declare const ITEM_COLOR_STATIC_THUMBNAIL_VIEW: {
13
+ slug: string;
14
+ defaultTemplate: Document;
15
+ };
16
+ export declare class ComponentRegistry {
17
+ private static componentDefinitionMap;
18
+ static getComponentDefinition(slug: string): ComponentDefinition;
19
+ private static initMap;
20
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentRegistry = exports.ITEM_COLOR_STATIC_THUMBNAIL_VIEW = exports.ITEM_COLOR_VIEW = exports.ITEM_COLOR_VIEW_STATIC_THUMBNAIL_TEMPLATE = exports.ITEM_COLOR_VIEW_TEMPLATE = void 0;
4
+ exports.ITEM_COLOR_VIEW_TEMPLATE = {
5
+ elements: [{
6
+ type: "image",
7
+ size: { width: 125, height: 125 },
8
+ propertyBindings: { url: 'thumbnail.downloadUrl' }
9
+ }, {
10
+ type: "text",
11
+ position: { x: 0, y: 126 },
12
+ style: {
13
+ font: {
14
+ size: 8,
15
+ }
16
+ },
17
+ propertyBindings: { text: 'itemColor.item.name' }
18
+ }, {
19
+ type: "text",
20
+ position: { x: 0, y: 137 },
21
+ style: {
22
+ font: {
23
+ size: 8,
24
+ }
25
+ },
26
+ propertyBindings: { text: 'itemColor.item.styleNumber' }
27
+ }, {
28
+ type: "text",
29
+ position: { x: 0, y: 148 },
30
+ style: {
31
+ font: {
32
+ size: 10,
33
+ },
34
+ color: 'rgba(0,0,0,.5)',
35
+ },
36
+ propertyBindings: { text: 'itemColor.name' }
37
+ }
38
+ ]
39
+ };
40
+ exports.ITEM_COLOR_VIEW_STATIC_THUMBNAIL_TEMPLATE = {
41
+ elements: [{
42
+ type: "image",
43
+ size: { width: 125, height: 125 },
44
+ propertyBindings: { url: 'itemColor.thumbnail' }
45
+ }, {
46
+ type: "text",
47
+ position: { x: 0, y: 126 },
48
+ style: {
49
+ font: {
50
+ size: 8,
51
+ }
52
+ },
53
+ propertyBindings: { text: 'itemColor.item.name' }
54
+ }, {
55
+ type: "text",
56
+ position: { x: 0, y: 137 },
57
+ style: {
58
+ font: {
59
+ size: 8,
60
+ }
61
+ },
62
+ propertyBindings: { text: 'itemColor.item.styleNumber' }
63
+ }, {
64
+ type: "text",
65
+ position: { x: 0, y: 148 },
66
+ style: {
67
+ font: {
68
+ size: 10,
69
+ },
70
+ color: 'rgba(0,0,0,.5)',
71
+ },
72
+ propertyBindings: { text: 'itemColor.name' }
73
+ }
74
+ ]
75
+ };
76
+ exports.ITEM_COLOR_VIEW = {
77
+ slug: 'item-color-view',
78
+ defaultTemplate: exports.ITEM_COLOR_VIEW_TEMPLATE,
79
+ };
80
+ exports.ITEM_COLOR_STATIC_THUMBNAIL_VIEW = {
81
+ slug: 'item-color-static-thumbnail-view',
82
+ defaultTemplate: exports.ITEM_COLOR_VIEW_STATIC_THUMBNAIL_TEMPLATE,
83
+ };
84
+ class ComponentRegistry {
85
+ static getComponentDefinition(slug) {
86
+ if (!this.componentDefinitionMap) {
87
+ this.initMap();
88
+ }
89
+ return this.componentDefinitionMap.get(slug);
90
+ }
91
+ static initMap() {
92
+ this.componentDefinitionMap = new Map();
93
+ this.componentDefinitionMap.set('item-color-view', exports.ITEM_COLOR_VIEW);
94
+ this.componentDefinitionMap.set('item-color-static-thumbnail-view', exports.ITEM_COLOR_STATIC_THUMBNAIL_VIEW);
95
+ }
96
+ }
97
+ exports.ComponentRegistry = ComponentRegistry;
@@ -0,0 +1 @@
1
+ export * from './components';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./components"), exports);
@@ -0,0 +1,8 @@
1
+ import { DocumentElement } from './types/document-element';
2
+ export declare class DocumentElementFactory {
3
+ private static initNewElement;
4
+ static createTextElement(text: string): DocumentElement;
5
+ static createShapeElement(type: string): DocumentElement;
6
+ static createImageElement(options: DocumentElement): DocumentElement;
7
+ static createComponent(componentType: string, model: any, modelBindings: any, options?: DocumentElement): DocumentElement;
8
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentElementFactory = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const components_1 = require("./components/components");
6
+ const document_element_property_binding_handler_1 = require("./document-element-property-binding-handler");
7
+ class DocumentElementFactory {
8
+ static initNewElement(type) {
9
+ const element = {
10
+ id: uuid_1.v4(),
11
+ position: { x: 300, y: 300 },
12
+ type,
13
+ size: {
14
+ width: 0,
15
+ height: 0,
16
+ },
17
+ style: {
18
+ font: {
19
+ size: 0,
20
+ family: '',
21
+ weight: '',
22
+ style: '',
23
+ },
24
+ text: {
25
+ decoration: '',
26
+ },
27
+ color: '',
28
+ },
29
+ text: '',
30
+ url: '',
31
+ };
32
+ return element;
33
+ }
34
+ static createTextElement(text) {
35
+ const element = this.initNewElement('text');
36
+ element.text = text;
37
+ element.size = { width: 65, height: 20 };
38
+ element.style = {
39
+ color: '#000000'
40
+ };
41
+ return element;
42
+ }
43
+ static createShapeElement(type) {
44
+ const element = this.initNewElement('shape');
45
+ element.type = type;
46
+ return element;
47
+ }
48
+ static createImageElement(options) {
49
+ let element = this.initNewElement('image');
50
+ element = Object.assign(element, options);
51
+ return element;
52
+ }
53
+ static createComponent(componentType, model, modelBindings, options) {
54
+ let element = this.initNewElement('component');
55
+ if (options) {
56
+ element = Object.assign(element, options);
57
+ }
58
+ const componentDefinition = components_1.ComponentRegistry.getComponentDefinition(componentType);
59
+ const elements = JSON.parse(JSON.stringify(componentDefinition.defaultTemplate.elements));
60
+ document_element_property_binding_handler_1.DocumentElementPropertyBindingHandler.bindPropertiesToElements(elements, model);
61
+ element.elements = elements;
62
+ element.modelBindings = modelBindings;
63
+ return element;
64
+ }
65
+ }
66
+ exports.DocumentElementFactory = DocumentElementFactory;
@@ -0,0 +1,5 @@
1
+ import { DocumentElement } from './types/document-element';
2
+ export declare class DocumentElementPropertyBindingHandler {
3
+ static bindPropertiesToElements(elements: Array<DocumentElement>, model: any): void;
4
+ static bindPropertiesToElement(element: DocumentElement, model: any): void;
5
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentElementPropertyBindingHandler = void 0;
4
+ const util_1 = require("@contrail/util");
5
+ class DocumentElementPropertyBindingHandler {
6
+ static bindPropertiesToElements(elements, model) {
7
+ elements.map(el => {
8
+ this.bindPropertiesToElement(el, model);
9
+ });
10
+ }
11
+ static bindPropertiesToElement(element, model) {
12
+ const localModel = Object.assign({}, model);
13
+ if (!element.propertyBindings) {
14
+ return;
15
+ }
16
+ if (element.modelBindings) {
17
+ }
18
+ for (const propertyKey of Object.keys(element.propertyBindings)) {
19
+ const modelIndex = element.propertyBindings[propertyKey];
20
+ const propertyValue = util_1.ObjectUtil.getByPath(localModel, modelIndex) || '';
21
+ element[propertyKey] = propertyValue;
22
+ }
23
+ if (element.elements) {
24
+ this.bindPropertiesToElements(element.elements, localModel);
25
+ }
26
+ }
27
+ }
28
+ exports.DocumentElementPropertyBindingHandler = DocumentElementPropertyBindingHandler;
package/lib/index.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export * from './types';
2
+ export * from './components';
3
+ export * from './document-element-factory';
4
+ export * from './document-element-property-binding-handler';
package/lib/index.js CHANGED
@@ -11,3 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./types"), exports);
14
+ __exportStar(require("./components"), exports);
15
+ __exportStar(require("./document-element-factory"), exports);
16
+ __exportStar(require("./document-element-property-binding-handler"), exports);
@@ -2,6 +2,7 @@ import { PositionDefinition, SizeDefinition } from "./common";
2
2
  import { DocumentElement } from "./document-element";
3
3
  export interface DocumentElementEvent {
4
4
  element: DocumentElement;
5
+ selectedElements?: Array<DocumentElement>;
5
6
  renderedElementPosition?: PositionDefinition;
6
7
  renderedElementSize?: SizeDefinition;
7
8
  eventType?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -40,6 +40,7 @@
40
40
  "testEnvironment": "node"
41
41
  },
42
42
  "dependencies": {
43
+ "@contrail/util": "^1.0.9",
43
44
  "reflect-metadata": "^0.1.13"
44
45
  }
45
46
  }