@plattar/plattar-ar-adapter 1.154.2 → 1.155.1
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/build/es2015/plattar-ar-adapter.js +2060 -1156
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +975 -781
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/ar/configurator-ar.d.ts +29 -0
- package/dist/ar/configurator-ar.js +161 -0
- package/dist/ar/launcher-ar.js +3 -7
- package/dist/ar/model-ar.js +2 -0
- package/dist/ar/product-ar.js +2 -0
- package/dist/ar/raw-ar.js +2 -0
- package/dist/ar/scene-ar.js +2 -0
- package/dist/embed/controllers/configurator-controller.d.ts +4 -2
- package/dist/embed/controllers/configurator-controller.js +171 -179
- package/dist/embed/controllers/plattar-controller.d.ts +21 -1
- package/dist/embed/controllers/plattar-controller.js +138 -67
- package/dist/embed/controllers/product-controller.d.ts +6 -1
- package/dist/embed/controllers/product-controller.js +9 -2
- package/dist/embed/controllers/vto-controller.d.ts +4 -2
- package/dist/embed/controllers/vto-controller.js +190 -194
- package/dist/embed/plattar-embed.d.ts +23 -0
- package/dist/embed/plattar-embed.js +130 -91
- package/dist/util/configurator-state.d.ts +48 -6
- package/dist/util/configurator-state.js +145 -28
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/embed/controllers/viewer-controller.d.ts +0 -14
- package/dist/embed/controllers/viewer-controller.js +0 -193
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
4
|
-
const product_controller_1 = require("./controllers/product-controller");
|
|
5
|
-
const viewer_controller_1 = require("./controllers/viewer-controller");
|
|
6
4
|
const configurator_controller_1 = require("./controllers/configurator-controller");
|
|
7
5
|
const vto_controller_1 = require("./controllers/vto-controller");
|
|
6
|
+
const product_controller_1 = require("./controllers/product-controller");
|
|
8
7
|
/**
|
|
9
8
|
* This tracks the current embed type
|
|
10
9
|
*/
|
|
11
10
|
var EmbedType;
|
|
12
11
|
(function (EmbedType) {
|
|
13
|
-
EmbedType[EmbedType["
|
|
14
|
-
EmbedType[EmbedType["
|
|
12
|
+
EmbedType[EmbedType["Configurator"] = 0] = "Configurator";
|
|
13
|
+
EmbedType[EmbedType["Legacy"] = 1] = "Legacy";
|
|
15
14
|
EmbedType[EmbedType["VTO"] = 2] = "VTO";
|
|
15
|
+
EmbedType[EmbedType["None"] = 3] = "None";
|
|
16
16
|
})(EmbedType || (EmbedType = {}));
|
|
17
17
|
/**
|
|
18
18
|
* This is the primary <plattar-embed /> node that allows easy embedding
|
|
@@ -22,115 +22,154 @@ class PlattarEmbed extends HTMLElement {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
super();
|
|
24
24
|
// this is the current embed type, viewer by default
|
|
25
|
-
this._currentType = EmbedType.
|
|
25
|
+
this._currentType = EmbedType.None;
|
|
26
26
|
this._controller = null;
|
|
27
|
+
this._currentSceneID = null;
|
|
28
|
+
this._observer = null;
|
|
27
29
|
}
|
|
28
30
|
get viewer() {
|
|
29
31
|
return this._controller ? this._controller.element : null;
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Begin observing all changes to this DOM element
|
|
35
|
+
*/
|
|
31
36
|
connectedCallback() {
|
|
32
|
-
|
|
37
|
+
this.create();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* creates a brand new instance of this embed
|
|
41
|
+
*/
|
|
42
|
+
create() {
|
|
43
|
+
// server cannot be changed once its set - defaults to production
|
|
44
|
+
const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
|
|
45
|
+
plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
|
|
46
|
+
if (!this._observer) {
|
|
47
|
+
this._observer = new MutationObserver((mutations) => {
|
|
48
|
+
mutations.forEach((mutation) => {
|
|
49
|
+
if (mutation.type === "attributes") {
|
|
50
|
+
const attributeName = mutation.attributeName ? mutation.attributeName : "none";
|
|
51
|
+
if (this._currentType !== EmbedType.Legacy) {
|
|
52
|
+
this._CreateEmbed(attributeName);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this._OnAttributesUpdated(attributeName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
this._observer.observe(this, {
|
|
61
|
+
attributes: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
|
|
65
|
+
const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
|
|
66
|
+
if (!sceneID && productID) {
|
|
67
|
+
this._currentType = EmbedType.Legacy;
|
|
68
|
+
this._CreateLegacyEmbed();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this._CreateEmbed("none");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Destroys the active instance of this embed and resets internal state to default
|
|
75
|
+
*/
|
|
76
|
+
destroy() {
|
|
77
|
+
if (this._controller) {
|
|
78
|
+
this._controller.removeRenderer();
|
|
79
|
+
this._controller = null;
|
|
80
|
+
}
|
|
81
|
+
this._currentType = EmbedType.None;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* this is only used for backwards-compatible legacy embed types typically
|
|
85
|
+
* embedding products with variations (without a scene-id)
|
|
86
|
+
*/
|
|
87
|
+
_CreateLegacyEmbed() {
|
|
88
|
+
this._controller = new product_controller_1.ProductController(this);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* creates the embed
|
|
92
|
+
* this can also be called when attributes/state changes so embeds can be re-loaded
|
|
93
|
+
*/
|
|
94
|
+
_CreateEmbed(attributeName) {
|
|
95
|
+
const embedType = this.hasAttribute("embed-type") ? this.getAttribute("embed-type") : "configurator";
|
|
96
|
+
const currentEmbed = this._currentType;
|
|
33
97
|
if (embedType) {
|
|
34
98
|
switch (embedType.toLowerCase()) {
|
|
35
|
-
case "viewer":
|
|
36
|
-
this._currentType = EmbedType.Viewer;
|
|
37
|
-
break;
|
|
38
99
|
case "vto":
|
|
39
100
|
this._currentType = EmbedType.VTO;
|
|
40
101
|
break;
|
|
102
|
+
case "viewer":
|
|
41
103
|
case "configurator":
|
|
42
|
-
this._currentType = EmbedType.Configurator;
|
|
43
|
-
break;
|
|
44
104
|
default:
|
|
45
|
-
this._currentType = EmbedType.
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const observer = new MutationObserver((mutations) => {
|
|
49
|
-
mutations.forEach((mutation) => {
|
|
50
|
-
if (mutation.type === "attributes") {
|
|
51
|
-
this._OnAttributesUpdated();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
observer.observe(this, {
|
|
56
|
-
attributes: true
|
|
57
|
-
});
|
|
58
|
-
const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
|
|
59
|
-
plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
|
|
60
|
-
const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
|
|
61
|
-
const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
|
|
62
|
-
// decide which controller to initialise
|
|
63
|
-
if (this._currentType === EmbedType.Viewer) {
|
|
64
|
-
// initialise product if scene-id is missing but product-id is defined
|
|
65
|
-
if (!sceneID && productID) {
|
|
66
|
-
this._controller = new product_controller_1.ProductController(this);
|
|
67
|
-
}
|
|
68
|
-
else if (sceneID) {
|
|
69
|
-
this._controller = new viewer_controller_1.ViewerController(this);
|
|
105
|
+
this._currentType = EmbedType.Configurator;
|
|
70
106
|
}
|
|
71
107
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this._controller = new vto_controller_1.VTOController(this);
|
|
108
|
+
// check if the controller needs to be re-created
|
|
109
|
+
if ((currentEmbed !== this._currentType) && this._controller) {
|
|
110
|
+
this._controller.removeRenderer();
|
|
111
|
+
this._controller = null;
|
|
77
112
|
}
|
|
78
|
-
const
|
|
79
|
-
if
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.startViewer();
|
|
113
|
+
const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
|
|
114
|
+
// if the provided SceneID doesn't match, we need to remove the controller
|
|
115
|
+
if ((sceneID !== this._currentSceneID) && this._controller) {
|
|
116
|
+
this._controller.removeRenderer();
|
|
117
|
+
this._controller = null;
|
|
84
118
|
}
|
|
85
|
-
|
|
86
|
-
|
|
119
|
+
this._currentSceneID = sceneID;
|
|
120
|
+
// scene-id is the absolute minimum in order to initialise the embeds
|
|
121
|
+
if (!this._currentSceneID) {
|
|
122
|
+
return;
|
|
87
123
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
// if the controller was removed due to state-change, we need to re-initialise it
|
|
125
|
+
if (!this._controller) {
|
|
126
|
+
switch (this._currentType) {
|
|
127
|
+
case EmbedType.Configurator:
|
|
128
|
+
this._controller = new configurator_controller_1.ConfiguratorController(this);
|
|
129
|
+
break;
|
|
130
|
+
case EmbedType.VTO:
|
|
131
|
+
this._controller = new vto_controller_1.VTOController(this);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (this._controller) {
|
|
135
|
+
const init = this.hasAttribute("init") ? this.getAttribute("init") : null;
|
|
136
|
+
switch (init) {
|
|
137
|
+
case "viewer":
|
|
138
|
+
this.startViewer();
|
|
139
|
+
break;
|
|
140
|
+
case "qrcode":
|
|
141
|
+
this.startQRCode();
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
94
145
|
}
|
|
95
|
-
else
|
|
96
|
-
this.
|
|
97
|
-
// nothing to do, launched successfully
|
|
98
|
-
}).catch((_err) => {
|
|
99
|
-
this.startViewer();
|
|
100
|
-
});
|
|
146
|
+
else {
|
|
147
|
+
this._OnAttributesUpdated(attributeName);
|
|
101
148
|
}
|
|
102
149
|
}
|
|
103
|
-
initAR() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return this._controller.initAR().then(accept).catch(reject);
|
|
109
|
-
});
|
|
150
|
+
async initAR() {
|
|
151
|
+
if (!this._controller) {
|
|
152
|
+
throw new Error("PlattarEmbed.initAR() - cannot execute as controller has not loaded yet");
|
|
153
|
+
}
|
|
154
|
+
return this._controller.initAR();
|
|
110
155
|
}
|
|
111
|
-
startAR() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this._controller.startAR().then(accept).catch(reject);
|
|
117
|
-
});
|
|
156
|
+
async startAR() {
|
|
157
|
+
if (!this._controller) {
|
|
158
|
+
throw new Error("PlattarEmbed.startAR() - cannot execute as controller has not loaded yet");
|
|
159
|
+
}
|
|
160
|
+
return this._controller.startAR();
|
|
118
161
|
}
|
|
119
|
-
startViewer() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return this._controller.startRenderer().then(accept).catch(reject);
|
|
125
|
-
});
|
|
162
|
+
async startViewer() {
|
|
163
|
+
if (!this._controller) {
|
|
164
|
+
throw new Error("PlattarEmbed.startViewer() - cannot execute as controller has not loaded yet");
|
|
165
|
+
}
|
|
166
|
+
return this._controller.startRenderer();
|
|
126
167
|
}
|
|
127
|
-
startQRCode(options = null) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return this._controller.startQRCode(options).then(accept).catch(reject);
|
|
133
|
-
});
|
|
168
|
+
async startQRCode(options = null) {
|
|
169
|
+
if (!this._controller) {
|
|
170
|
+
throw new Error("PlattarEmbed.startQRCode() - cannot execute as controller has not loaded yet");
|
|
171
|
+
}
|
|
172
|
+
return this._controller.startQRCode(options);
|
|
134
173
|
}
|
|
135
174
|
/**
|
|
136
175
|
* This will remove the currently active Renderer
|
|
@@ -147,9 +186,9 @@ class PlattarEmbed extends HTMLElement {
|
|
|
147
186
|
* This is called by the observer if any of the embed attributes have changed
|
|
148
187
|
* based on the state of the embed, we update the internal structure accordingly
|
|
149
188
|
*/
|
|
150
|
-
_OnAttributesUpdated() {
|
|
189
|
+
_OnAttributesUpdated(attributeName) {
|
|
151
190
|
if (this._controller) {
|
|
152
|
-
this._controller.onAttributesUpdated();
|
|
191
|
+
this._controller.onAttributesUpdated(attributeName);
|
|
153
192
|
}
|
|
154
193
|
}
|
|
155
194
|
}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
+
import { Scene } from "@plattar/plattar-api";
|
|
1
2
|
export interface SceneProductData {
|
|
2
3
|
scene_product_id: string;
|
|
3
4
|
product_variation_id: string;
|
|
4
|
-
meta_data:
|
|
5
|
-
augment: boolean;
|
|
6
|
-
};
|
|
5
|
+
meta_data: SceneProductDataMeta;
|
|
7
6
|
}
|
|
7
|
+
export interface SceneProductDataMeta {
|
|
8
|
+
augment: boolean;
|
|
9
|
+
type: "sceneproduct" | "scenemodel";
|
|
10
|
+
}
|
|
11
|
+
export interface DecodedConfiguratorState {
|
|
12
|
+
readonly scene: Scene;
|
|
13
|
+
readonly state: ConfiguratorState;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Manages a Configuration State of multiple Products with multiple Variations
|
|
17
|
+
* Allows easily changing
|
|
18
|
+
*/
|
|
8
19
|
export declare class ConfiguratorState {
|
|
9
20
|
private readonly _state;
|
|
21
|
+
private readonly _mappedVariationIDValues;
|
|
22
|
+
private readonly _mappedVariationSKUValues;
|
|
10
23
|
constructor(state?: string | null | undefined);
|
|
24
|
+
/**
|
|
25
|
+
* Modifyes the SceneProduct that this Variation SKU belongs to and changes for
|
|
26
|
+
* purposes of Configuration
|
|
27
|
+
*/
|
|
28
|
+
setVariationSKU(productVariationSKU: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Modifyes the SceneProduct that this Variation belongs to and changes for
|
|
31
|
+
* purposes of Configuration
|
|
32
|
+
*/
|
|
33
|
+
setVariationID(productVariationID: string): void;
|
|
11
34
|
/**
|
|
12
35
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
13
36
|
*
|
|
@@ -15,7 +38,15 @@ export declare class ConfiguratorState {
|
|
|
15
38
|
* @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
|
|
16
39
|
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
17
40
|
*/
|
|
18
|
-
setSceneProduct(sceneProductID: string, productVariationID: string, metaData?:
|
|
41
|
+
setSceneProduct(sceneProductID: string, productVariationID: string, metaData?: SceneProductDataMeta | null | undefined): void;
|
|
42
|
+
/**
|
|
43
|
+
* Adds a new SceneModel with meta-data into the Configurator State. Note that the SceneProductDataMeta will
|
|
44
|
+
* override the isSceneModel variable and assign to "true" automatically
|
|
45
|
+
*
|
|
46
|
+
* @param SceneModelID - The SceneModel ID to add
|
|
47
|
+
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
48
|
+
*/
|
|
49
|
+
setSceneModel(SceneModelID: string, metaData?: SceneProductDataMeta | null | undefined): void;
|
|
19
50
|
/**
|
|
20
51
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
21
52
|
*
|
|
@@ -23,7 +54,7 @@ export declare class ConfiguratorState {
|
|
|
23
54
|
* @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
|
|
24
55
|
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
25
56
|
*/
|
|
26
|
-
addSceneProduct(sceneProductID: string, productVariationID: string, metaData?:
|
|
57
|
+
addSceneProduct(sceneProductID: string, productVariationID: string, metaData?: SceneProductDataMeta | null | undefined): void;
|
|
27
58
|
/**
|
|
28
59
|
* Search and return the data index reference for the provided Scene Product ID
|
|
29
60
|
* if not found, will return null
|
|
@@ -40,6 +71,10 @@ export declare class ConfiguratorState {
|
|
|
40
71
|
* Iterate over the internal state data
|
|
41
72
|
*/
|
|
42
73
|
forEach(callback: (data: SceneProductData) => void): void;
|
|
74
|
+
/**
|
|
75
|
+
* Compose and return an array of all internal objects
|
|
76
|
+
*/
|
|
77
|
+
array(): Array<SceneProductData>;
|
|
43
78
|
/**
|
|
44
79
|
* @returns Returns the first reference of data in the stack, otherwise returns null
|
|
45
80
|
*/
|
|
@@ -52,13 +87,20 @@ export declare class ConfiguratorState {
|
|
|
52
87
|
* @returns - ConfiguratorState instance
|
|
53
88
|
*/
|
|
54
89
|
static decode(state: string): ConfiguratorState;
|
|
90
|
+
/**
|
|
91
|
+
* Decodes a previously generated state
|
|
92
|
+
* @param sceneID
|
|
93
|
+
* @param state
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
static decodeState(sceneID?: string | null | undefined, state?: string | null | undefined): Promise<DecodedConfiguratorState>;
|
|
55
97
|
/**
|
|
56
98
|
* Generates a new ConfiguratorState instance from all SceneProducts and default
|
|
57
99
|
* variations from the provided Scene ID
|
|
58
100
|
* @param sceneID - the Scene ID to generate
|
|
59
101
|
* @returns - Promise that resolves into a ConfiguratorState instance
|
|
60
102
|
*/
|
|
61
|
-
static decodeScene(sceneID?: string | null | undefined): Promise<
|
|
103
|
+
static decodeScene(sceneID?: string | null | undefined): Promise<DecodedConfiguratorState>;
|
|
62
104
|
/**
|
|
63
105
|
* Encode and return the internal ConfiguratorState as a Base64 String
|
|
64
106
|
* @returns - Base64 String
|
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfiguratorState = void 0;
|
|
4
4
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
|
+
/**
|
|
6
|
+
* Manages a Configuration State of multiple Products with multiple Variations
|
|
7
|
+
* Allows easily changing
|
|
8
|
+
*/
|
|
5
9
|
class ConfiguratorState {
|
|
6
10
|
constructor(state = null) {
|
|
11
|
+
this._mappedVariationIDValues = new Map();
|
|
12
|
+
this._mappedVariationSKUValues = new Map();
|
|
7
13
|
const defaultState = {
|
|
8
14
|
meta: {
|
|
9
15
|
scene_product_index: 0,
|
|
16
|
+
scene_model_index: 0,
|
|
10
17
|
product_variation_index: 1,
|
|
11
18
|
meta_index: 2,
|
|
12
19
|
},
|
|
@@ -19,6 +26,7 @@ class ConfiguratorState {
|
|
|
19
26
|
// set the meta data
|
|
20
27
|
if (parsedState.meta) {
|
|
21
28
|
defaultState.meta.scene_product_index = parsedState.meta.scene_product_index || 0;
|
|
29
|
+
defaultState.meta.scene_model_index = parsedState.meta.scene_model_index || 0;
|
|
22
30
|
defaultState.meta.product_variation_index = parsedState.meta.product_variation_index || 1;
|
|
23
31
|
defaultState.meta.meta_index = parsedState.meta.meta_index || 2;
|
|
24
32
|
}
|
|
@@ -31,6 +39,30 @@ class ConfiguratorState {
|
|
|
31
39
|
}
|
|
32
40
|
this._state = defaultState;
|
|
33
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Modifyes the SceneProduct that this Variation SKU belongs to and changes for
|
|
44
|
+
* purposes of Configuration
|
|
45
|
+
*/
|
|
46
|
+
setVariationSKU(productVariationSKU) {
|
|
47
|
+
const variationID = this._mappedVariationSKUValues.get(productVariationSKU);
|
|
48
|
+
if (!variationID) {
|
|
49
|
+
console.warn("ConfiguratorState.setVariationSKU() - Variation SKU of " + productVariationSKU + " is not defined in any variations");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.setVariationID(variationID);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Modifyes the SceneProduct that this Variation belongs to and changes for
|
|
56
|
+
* purposes of Configuration
|
|
57
|
+
*/
|
|
58
|
+
setVariationID(productVariationID) {
|
|
59
|
+
const sceneProductID = this._mappedVariationIDValues.get(productVariationID);
|
|
60
|
+
if (!sceneProductID) {
|
|
61
|
+
console.warn("ConfiguratorState.setVariationID() - Variation ID of " + productVariationID + " is not defined in any products");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.setSceneProduct(sceneProductID, productVariationID);
|
|
65
|
+
}
|
|
34
66
|
/**
|
|
35
67
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
36
68
|
*
|
|
@@ -41,6 +73,34 @@ class ConfiguratorState {
|
|
|
41
73
|
setSceneProduct(sceneProductID, productVariationID, metaData = null) {
|
|
42
74
|
this.addSceneProduct(sceneProductID, productVariationID, metaData);
|
|
43
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Adds a new SceneModel with meta-data into the Configurator State. Note that the SceneProductDataMeta will
|
|
78
|
+
* override the isSceneModel variable and assign to "true" automatically
|
|
79
|
+
*
|
|
80
|
+
* @param SceneModelID - The SceneModel ID to add
|
|
81
|
+
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
82
|
+
*/
|
|
83
|
+
setSceneModel(SceneModelID, metaData = null) {
|
|
84
|
+
if (SceneModelID) {
|
|
85
|
+
metaData = metaData || { augment: true, type: "scenemodel" };
|
|
86
|
+
metaData.type = "scenemodel";
|
|
87
|
+
const states = this._state.states;
|
|
88
|
+
const meta = this._state.meta;
|
|
89
|
+
let newData = null;
|
|
90
|
+
const existingData = this.findSceneProductIndex(SceneModelID);
|
|
91
|
+
if (existingData) {
|
|
92
|
+
newData = existingData;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
newData = [];
|
|
96
|
+
// push the new data into the stack
|
|
97
|
+
states.push(newData);
|
|
98
|
+
}
|
|
99
|
+
newData[meta.scene_product_index] = SceneModelID;
|
|
100
|
+
newData[meta.product_variation_index] = null;
|
|
101
|
+
newData[meta.meta_index] = metaData;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
44
104
|
/**
|
|
45
105
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
46
106
|
*
|
|
@@ -50,6 +110,8 @@ class ConfiguratorState {
|
|
|
50
110
|
*/
|
|
51
111
|
addSceneProduct(sceneProductID, productVariationID, metaData = null) {
|
|
52
112
|
if (sceneProductID && productVariationID) {
|
|
113
|
+
metaData = metaData || { augment: true, type: "sceneproduct" };
|
|
114
|
+
metaData.type = "sceneproduct";
|
|
53
115
|
const states = this._state.states;
|
|
54
116
|
const meta = this._state.meta;
|
|
55
117
|
let newData = null;
|
|
@@ -64,9 +126,7 @@ class ConfiguratorState {
|
|
|
64
126
|
}
|
|
65
127
|
newData[meta.scene_product_index] = sceneProductID;
|
|
66
128
|
newData[meta.product_variation_index] = productVariationID;
|
|
67
|
-
|
|
68
|
-
newData[meta.meta_index] = metaData;
|
|
69
|
-
}
|
|
129
|
+
newData[meta.meta_index] = metaData;
|
|
70
130
|
}
|
|
71
131
|
}
|
|
72
132
|
/**
|
|
@@ -98,12 +158,14 @@ class ConfiguratorState {
|
|
|
98
158
|
scene_product_id: found[meta.scene_product_index],
|
|
99
159
|
product_variation_id: found[meta.product_variation_index],
|
|
100
160
|
meta_data: {
|
|
101
|
-
augment: true
|
|
161
|
+
augment: true,
|
|
162
|
+
type: "sceneproduct"
|
|
102
163
|
}
|
|
103
164
|
};
|
|
104
165
|
// include the meta-data
|
|
105
166
|
if (found.length === 3) {
|
|
106
167
|
data.meta_data.augment = found[meta.meta_index].augment || true;
|
|
168
|
+
data.meta_data.type = found[meta.meta_index].type || "sceneproduct";
|
|
107
169
|
}
|
|
108
170
|
return data;
|
|
109
171
|
}
|
|
@@ -122,7 +184,8 @@ class ConfiguratorState {
|
|
|
122
184
|
scene_product_id: productState[meta.scene_product_index],
|
|
123
185
|
product_variation_id: productState[meta.product_variation_index],
|
|
124
186
|
meta_data: {
|
|
125
|
-
augment: true
|
|
187
|
+
augment: true,
|
|
188
|
+
type: "sceneproduct"
|
|
126
189
|
}
|
|
127
190
|
});
|
|
128
191
|
}
|
|
@@ -131,13 +194,24 @@ class ConfiguratorState {
|
|
|
131
194
|
scene_product_id: productState[meta.scene_product_index],
|
|
132
195
|
product_variation_id: productState[meta.product_variation_index],
|
|
133
196
|
meta_data: {
|
|
134
|
-
augment: productState[meta.meta_index].augment || true
|
|
197
|
+
augment: productState[meta.meta_index].augment || true,
|
|
198
|
+
type: productState[meta.meta_index].type || "sceneproduct"
|
|
135
199
|
}
|
|
136
200
|
});
|
|
137
201
|
}
|
|
138
202
|
});
|
|
139
203
|
}
|
|
140
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Compose and return an array of all internal objects
|
|
207
|
+
*/
|
|
208
|
+
array() {
|
|
209
|
+
const array = new Array();
|
|
210
|
+
this.forEach((object) => {
|
|
211
|
+
array.push(object);
|
|
212
|
+
});
|
|
213
|
+
return array;
|
|
214
|
+
}
|
|
141
215
|
/**
|
|
142
216
|
* @returns Returns the first reference of data in the stack, otherwise returns null
|
|
143
217
|
*/
|
|
@@ -157,12 +231,14 @@ class ConfiguratorState {
|
|
|
157
231
|
scene_product_id: found[meta.scene_product_index],
|
|
158
232
|
product_variation_id: found[meta.product_variation_index],
|
|
159
233
|
meta_data: {
|
|
160
|
-
augment: true
|
|
234
|
+
augment: true,
|
|
235
|
+
type: "sceneproduct"
|
|
161
236
|
}
|
|
162
237
|
};
|
|
163
238
|
// include the meta-data
|
|
164
239
|
if (found.length === 3) {
|
|
165
240
|
data.meta_data.augment = found[meta.meta_index].augment || true;
|
|
241
|
+
data.meta_data.type = found[meta.meta_index].type || "sceneproduct";
|
|
166
242
|
}
|
|
167
243
|
return data;
|
|
168
244
|
}
|
|
@@ -180,37 +256,78 @@ class ConfiguratorState {
|
|
|
180
256
|
static decode(state) {
|
|
181
257
|
return new ConfiguratorState(state);
|
|
182
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Decodes a previously generated state
|
|
261
|
+
* @param sceneID
|
|
262
|
+
* @param state
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
static async decodeState(sceneID = null, state = null) {
|
|
266
|
+
if (!sceneID || !state) {
|
|
267
|
+
throw new Error("ConfiguratorState.decodeState(sceneID, state) - sceneID and state must be defined");
|
|
268
|
+
}
|
|
269
|
+
const configState = new ConfiguratorState(state);
|
|
270
|
+
const fscene = new plattar_api_1.Scene(sceneID);
|
|
271
|
+
fscene.include(plattar_api_1.Project);
|
|
272
|
+
fscene.include(plattar_api_1.SceneProduct);
|
|
273
|
+
fscene.include(plattar_api_1.SceneModel);
|
|
274
|
+
fscene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product.include(plattar_api_1.ProductVariation)));
|
|
275
|
+
const scene = await fscene.get();
|
|
276
|
+
return {
|
|
277
|
+
scene: scene,
|
|
278
|
+
state: configState
|
|
279
|
+
};
|
|
280
|
+
}
|
|
183
281
|
/**
|
|
184
282
|
* Generates a new ConfiguratorState instance from all SceneProducts and default
|
|
185
283
|
* variations from the provided Scene ID
|
|
186
284
|
* @param sceneID - the Scene ID to generate
|
|
187
285
|
* @returns - Promise that resolves into a ConfiguratorState instance
|
|
188
286
|
*/
|
|
189
|
-
static decodeScene(sceneID = null) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
287
|
+
static async decodeScene(sceneID = null) {
|
|
288
|
+
if (!sceneID) {
|
|
289
|
+
throw new Error("ConfiguratorState.decodeScene(sceneID) - sceneID must be defined");
|
|
290
|
+
}
|
|
291
|
+
const configState = new ConfiguratorState();
|
|
292
|
+
const fscene = new plattar_api_1.Scene(sceneID);
|
|
293
|
+
fscene.include(plattar_api_1.Project);
|
|
294
|
+
fscene.include(plattar_api_1.SceneProduct);
|
|
295
|
+
fscene.include(plattar_api_1.SceneModel);
|
|
296
|
+
fscene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product.include(plattar_api_1.ProductVariation)));
|
|
297
|
+
const scene = await fscene.get();
|
|
298
|
+
const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
|
|
299
|
+
const sceneModels = scene.relationships.filter(plattar_api_1.SceneModel);
|
|
300
|
+
// add out scene models
|
|
301
|
+
sceneModels.forEach((sceneModel) => {
|
|
302
|
+
configState.setSceneModel(sceneModel.id, {
|
|
303
|
+
augment: sceneModel.attributes.include_in_augment,
|
|
304
|
+
type: "scenemodel"
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
// add out scene products
|
|
308
|
+
sceneProducts.forEach((sceneProduct) => {
|
|
309
|
+
const product = sceneProduct.relationships.find(plattar_api_1.Product);
|
|
310
|
+
if (product) {
|
|
311
|
+
if (product.attributes.product_variation_id) {
|
|
312
|
+
configState.setSceneProduct(sceneProduct.id, product.attributes.product_variation_id, {
|
|
313
|
+
augment: sceneProduct.attributes.include_in_augment,
|
|
314
|
+
type: "sceneproduct"
|
|
315
|
+
});
|
|
203
316
|
}
|
|
204
|
-
// add
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
317
|
+
// add the variation to an acceptible range of values
|
|
318
|
+
const variations = product.relationships.filter(plattar_api_1.ProductVariation);
|
|
319
|
+
variations.forEach((variation) => {
|
|
320
|
+
configState._mappedVariationIDValues.set(variation.id, sceneProduct.id);
|
|
321
|
+
if (variation.attributes.sku) {
|
|
322
|
+
configState._mappedVariationSKUValues.set(variation.attributes.sku, variation.id);
|
|
209
323
|
}
|
|
210
324
|
});
|
|
211
|
-
|
|
212
|
-
}).catch(reject);
|
|
325
|
+
}
|
|
213
326
|
});
|
|
327
|
+
return {
|
|
328
|
+
scene: scene,
|
|
329
|
+
state: configState
|
|
330
|
+
};
|
|
214
331
|
}
|
|
215
332
|
/**
|
|
216
333
|
* Encode and return the internal ConfiguratorState as a Base64 String
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.155.1";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED