Skip to content
This repository was archived by the owner on Jun 3, 2022. It is now read-only.

Commit 683065a

Browse files
committed
Merge branch 'release/v0.5.8' into stable
2 parents 4d2ccaa + 1337d79 commit 683065a

29 files changed

+537
-91
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 0.5.8
2+
3+
### Bug Fixes
4+
5+
* [Renames defaultValue to initialValue throughout.](https://github.com/material-foundation/material-remixer-js/commit/bf4c7bfb5427e070aeb7b26fb8e66643696fffa6)
6+
* [Updates webpack config source mapping.](https://github.com/material-foundation/material-remixer-js/commit/7cb0c9b37ee614c1e3fa1ecc74cd196e4fec83e4)
7+
* [Fixes title when deserializing variable.](https://github.com/material-foundation/material-remixer-js/commit/46f241031fb91a1732721f4772bbeb2737ac0b1c)
8+
* [Updates localStorage schema](https://github.com/material-foundation/material-remixer-js/commit/a6ca1b2341af96635ef184ba1992ea1d745dbe00)
9+
* [Fixes Variable.clone() wrongly setting selectedValue to initialValue.](https://github.com/material-foundation/material-remixer-js/commit/19ef8e4af6b3eafe997a7d561740f6915a50202e)
10+
* [Updates overlay title bar background color.](https://github.com/material-foundation/material-remixer-js/commit/130026e9a356db0185ebee70b8f964f2248aa39b)
11+
* [Cleans up remote controller class.](https://github.com/material-foundation/material-remixer-js/commit/715812d56d61aa8daeadbba20abc72ed9eed0030)
12+
* [Makes deserialize publicly available.](https://github.com/material-foundation/material-remixer-js/commit/ded22f9c3da46bdc87250f141d5a1b15551d8057)
13+
14+
### New Features
15+
16+
* [Updates MDL controls to allow remote updates.](https://github.com/material-foundation/material-remixer-js/commit/823d8e29320b790bc5331ce6b9b0f27ca1b0ce54)
17+
* [Adds ability to sync with remote controller.](https://github.com/material-foundation/material-remixer-js/commit/7a4847dc9e169f1742a94cb09941006f58a61a6c)
18+
119
## 0.5.7
220

321
* [Updates webpack configuration.](https://github.com/material-foundation/material-remixer-js/commit/fffca3cf29960defe0b280cbe60f37308dc1aaf5)

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
},
3232
"devDependencies": {
3333
"@types/chai": "^3.4.34",
34+
"@types/lodash.throttle": "^4.1.0",
3435
"@types/mocha": "^2.2.33",
3536
"@types/react": "^0.14.50",
3637
"@types/react-addons-test-utils": "^0.14.15",
3738
"@types/react-dom": "^0.14.19",
3839
"@types/sinon": "^1.16.32",
3940
"@types/sinon-chai": "^2.7.27",
4041
"@types/tinycolor2": "^1.1.0",
42+
"@types/uuid": "^2.0.29",
4143
"chai": "^3.5.0",
4244
"codecov.io": "^0.1.6",
4345
"copyfiles": "^1.0.0",
@@ -73,9 +75,12 @@
7375
"webpack-dev-server": "^2.2.0-rc.0"
7476
},
7577
"dependencies": {
78+
"firebase": "^3.6.5",
79+
"lodash.throttle": "^4.1.1",
7680
"material-design-lite": "^1.2.1",
7781
"react": "^15.4.0",
7882
"react-dom": "^15.4.0",
79-
"tinycolor2": "^1.4.1"
83+
"tinycolor2": "^1.4.1",
84+
"uuid": "^3.0.1"
8085
}
8186
}

src/core/Remixer.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Messaging } from "../lib/Messaging";
2222
import { NumberVariable } from "./variables/NumberVariable";
2323
import { IRangeVariableParams, RangeVariable } from "./variables/RangeVariable";
2424
import { IVariableCallback, IVariableKeyMap, Variable } from "./variables/Variable";
25+
import { Remote } from "../lib/Remote";
2526
import { StringVariable } from "./variables/StringVariable";
2627

2728
import "../ui/styles/iframe.less";
@@ -81,7 +82,7 @@ class Remixer {
8182
if (!this._frameElement) {
8283
let frame = document.createElement("IFRAME") as HTMLFrameElement;
8384
frame.id = CSS.RMX_OVERLAY_FRAME;
84-
frame.setAttribute("sandbox", "allow-scripts allow-same-origin");
85+
frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-popups");
8586
document.getElementsByTagName("body")[0].appendChild(frame);
8687

8788
// Until `srcdoc` is fully compatible with all browsers, lets simply
@@ -110,10 +111,16 @@ class Remixer {
110111
* Appends the HTML iFrame to body of client app. Attaches key listener to
111112
* toggle Overlay visibility.
112113
* @static
114+
* @param {{}} remoteConfig The optional firebase configuration. Provide this
115+
* configuration if you wish to use the remote
116+
* controller.
113117
*/
114-
static start(): void {
118+
static start(remoteConfig?: {}): void {
115119
this._sharedInstance.appendFrameToBody();
116120
this._sharedInstance.addKeyListener();
121+
if (remoteConfig) {
122+
Remote.initializeRemote(remoteConfig);
123+
}
117124
}
118125

119126
/**
@@ -238,13 +245,14 @@ class Remixer {
238245
let existingVariable = this.getVariable(key);
239246
if (existingVariable) {
240247
// Variable with key already exists, so only add callback.
241-
// TODO(cjcox:) Determin what to do if variable key already exists.
248+
// TODO(cjcox:) Determine what to do if variable key already exists.
242249
} else {
243250
this._sharedInstance._variables[key] = variable;
244251
let storedVariable = LocalStorage.getVariable(key);
245252
if (storedVariable) {
246253
// Update variable if exists in storage.
247254
this.updateVariable(variable, storedVariable.selectedValue);
255+
Remote.saveVariable(variable, false);
248256
} else {
249257
// Save variable first time.
250258
this.saveVariable(variable);
@@ -281,21 +289,52 @@ class Remixer {
281289
}
282290

283291
/**
284-
* Updates the selected value of a given Variable from the Remixer shared instance.
292+
* Updates the selected value of a given Variable from the Remixer shared
293+
* instance.
285294
* @static
286295
* @param {Variable} variable The Variable to update.
287296
* @param {any} selectedValue The new selected value.
288297
*/
289298
static updateVariable(variable: Variable, selectedValue: any): void {
290-
variable.selectedValue = selectedValue;
299+
if (variable.selectedValue !== selectedValue) {
300+
variable.selectedValue = selectedValue;
301+
}
302+
}
303+
304+
/**
305+
* Clones and updates the selected value of a given Variable from the Remixer
306+
* shared instance. Allows immutability update required for React rendering.
307+
* @static
308+
* @param {Variable} variable The variable to clone and update.
309+
* @param {any} selectedValue The new selected value.
310+
*/
311+
static cloneAndUpdateVariable(variable: Variable, selectedValue: any): void {
312+
if (variable.selectedValue !== selectedValue) {
313+
let clonedVariable = variable.clone();
314+
this.attachedInstance._variables[variable.key] = clonedVariable;
315+
this.updateVariable(clonedVariable, selectedValue);
316+
}
291317
}
292318

293319
/**
294-
* Saves the Variable to local storage.
320+
* Saves the Variable to both local storage and remote.
321+
* @static
295322
* @param {Variable} variable The Variable to save.
296323
*/
297324
static saveVariable(variable: Variable): void {
298325
LocalStorage.saveVariable(variable);
326+
327+
// Save remotely. If remote sharing is disabled, a call to this method
328+
// will simply be a no-op.
329+
Remote.saveVariable(variable);
330+
}
331+
332+
/**
333+
* Returns the current remote controller class.
334+
* @return {Remote}
335+
*/
336+
get remote(): Remote {
337+
return Remote.attachedInstance;
299338
}
300339
}
301340

src/core/__tests__/BooleanVariable_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ chai.use(sinonChai);
1313
describe("BooleanVariable", () => {
1414
const key: string = "test variable";
1515
const sanitizedKey: string = "test_variable";
16-
const defaultValue: boolean = true;
16+
const initialValue: boolean = true;
1717
let callbackSpy: sinon.SinonSpy;
1818
let variable: BooleanVariable;
1919

2020
beforeEach(() => {
2121
callbackSpy = sinon.spy();
22-
variable = remixer.addBooleanVariable(key, defaultValue, callbackSpy);
22+
variable = remixer.addBooleanVariable(key, initialValue, callbackSpy);
2323
});
2424

2525
it("should create a new variable", () => {

src/core/__tests__/ColorVariable_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(sinonChai);
1313
describe("ColorVariable", () => {
1414
const key: string = "test variable";
1515
const sanitizedKey: string = "test_variable";
16-
const defaultValue: string = "#4285F4";
16+
const initialValue: string = "#4285F4";
1717
const limitedToValues: string[] = ["#4285F4", "#0F9D58", "#DB4437"];
1818
let callbackSpy: sinon.SinonSpy;
1919
let variable: ColorVariable;
@@ -22,7 +22,7 @@ describe("ColorVariable", () => {
2222
callbackSpy = sinon.spy();
2323
variable = remixer.addColorVariable(
2424
key,
25-
defaultValue,
25+
initialValue,
2626
limitedToValues,
2727
callbackSpy,
2828
);

src/core/__tests__/NumberVariable_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(sinonChai);
1313
describe("NumberVariable", () => {
1414
const key: string = "test variable";
1515
const sanitizedKey: string = "test_variable";
16-
const defaultValue: number = 20;
16+
const initialValue: number = 20;
1717
const limitedToValues: number[] = [10, 20, 30, 40];
1818
let callbackSpy: sinon.SinonSpy;
1919
let variable: NumberVariable;
@@ -22,7 +22,7 @@ describe("NumberVariable", () => {
2222
callbackSpy = sinon.spy();
2323
variable = remixer.addNumberVariable(
2424
key,
25-
defaultValue,
25+
initialValue,
2626
limitedToValues,
2727
callbackSpy,
2828
);

src/core/__tests__/RangeVariable_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(sinonChai);
1313
describe("RangeVariable", () => {
1414
const key: string = "test variable";
1515
const sanitizedKey: string = "test_variable";
16-
const defaultValue: number = 1;
16+
const initialValue: number = 1;
1717
const minValue: number = 0;
1818
const maxValue: number = 1;
1919
const increment: number = 0.1;
@@ -24,7 +24,7 @@ describe("RangeVariable", () => {
2424
callbackSpy = sinon.spy();
2525
variable = remixer.addRangeVariable(
2626
key,
27-
defaultValue,
27+
initialValue,
2828
minValue,
2929
maxValue,
3030
increment,

src/core/__tests__/StringVariable_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ chai.use(sinonChai);
1313
describe("StringVariable", () => {
1414
const key: string = "test variable";
1515
const sanitizedKey: string = "test_variable";
16-
const defaultValue: string = "B";
16+
const initialValue: string = "B";
1717
const limitedToValues: string[] = ["A", "B", "C", "D"];
1818
let callbackSpy: sinon.SinonSpy;
1919
let variable: StringVariable;
@@ -22,7 +22,7 @@ describe("StringVariable", () => {
2222
callbackSpy = sinon.spy();
2323
variable = remixer.addStringVariable(
2424
key,
25-
defaultValue,
25+
initialValue,
2626
limitedToValues,
2727
callbackSpy,
2828
);

src/core/variables/BooleanVariable.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { IVariableCallback, IVariableParams, Variable } from "./Variable";
2424
* @extends IVariableParams
2525
*/
2626
interface IBooleanVariableParams extends IVariableParams {
27-
defaultValue: boolean;
27+
initialValue: boolean;
2828
selectedValue: boolean;
2929
}
3030

@@ -40,16 +40,16 @@ export class BooleanVariable extends Variable implements IBooleanVariableParams
4040
* Creates an instance of a BooleanVariable.
4141
* @constructor
4242
* @param {string} key A unique key for the Variable.
43-
* @param {boolean} defaultValue The default value.
43+
* @param {boolean} initialValue The initial selected value.
4444
* @param {IVariableCallback} callback The callback to invoke when updated.
4545
* @return {BooleanVariable}
4646
*/
4747
constructor(
4848
key: string,
49-
defaultValue: boolean,
49+
initialValue: boolean,
5050
callback?: IVariableCallback,
5151
) {
52-
super(key, DataType.BOOLEAN, defaultValue, callback);
52+
super(key, DataType.BOOLEAN, initialValue, callback);
5353
this.controlType = ControlType.SWITCH;
5454
}
5555

@@ -58,7 +58,7 @@ export class BooleanVariable extends Variable implements IBooleanVariableParams
5858
* @return {BooleanVariable} Returns the cloned variable.
5959
*/
6060
clone() {
61-
let cloned = new BooleanVariable(this.key, this.defaultValue, null);
61+
let cloned = new BooleanVariable(this.key, this.selectedValue, null);
6262
cloned.title = this.title;
6363
cloned._callbacks = this._callbacks.slice();
6464
return cloned;
@@ -71,7 +71,6 @@ export class BooleanVariable extends Variable implements IBooleanVariableParams
7171
*/
7272
serialize(): ISerializableData {
7373
let data = super.serialize();
74-
data.defaultValue = this.defaultValue;
7574
data.selectedValue = this.selectedValue;
7675
return data;
7776
}
@@ -83,6 +82,8 @@ export class BooleanVariable extends Variable implements IBooleanVariableParams
8382
* @return {BooleanVariable} A new initialized BooleanVariable.
8483
*/
8584
static deserialize(data: ISerializableData): BooleanVariable {
86-
return new BooleanVariable(data.key, data.selectedValue);
85+
let variable = new BooleanVariable(data.key, data.selectedValue);
86+
variable.title = data.title;
87+
return variable;
8788
}
8889
}

src/core/variables/ColorVariable.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { IVariableCallback, IVariableListParams, Variable } from "./Variable";
2626
* @extends IVariableListParams
2727
*/
2828
interface IColorVariableParams extends IVariableListParams {
29-
defaultValue: string;
29+
initialValue: string;
3030
selectedValue: string;
3131
limitedToValues?: string[];
3232
}
@@ -43,18 +43,18 @@ export class ColorVariable extends Variable implements IColorVariableParams {
4343
* Creates an instance of a ColorVariable.
4444
* @constructor
4545
* @param {string} key A unique key for the Variable.
46-
* @param {string} defaultValue The default value.
46+
* @param {string} initialValue The initial selected value.
4747
* @param {string[]} limitedToValues The array of allowed values.
4848
* @param {IVariableCallback} callback The callback to invoke when updated.
4949
* @return {ColorVariable}
5050
*/
5151
constructor(
5252
key: string,
53-
defaultValue: string,
53+
initialValue: string,
5454
limitedToValues?: string[],
5555
callback?: IVariableCallback,
5656
) {
57-
super(key, DataType.COLOR, defaultValue, callback);
57+
super(key, DataType.COLOR, initialValue, callback);
5858
this.limitedToValues = limitedToValues ? limitedToValues : [];
5959
this.controlType = (this.limitedToValues.length > 0) ?
6060
ControlType.COLOR_LIST : ControlType.COLOR_INPUT;
@@ -77,7 +77,7 @@ export class ColorVariable extends Variable implements IColorVariableParams {
7777
clone() {
7878
let cloned = new ColorVariable(
7979
this.key,
80-
this.defaultValue,
80+
this.selectedValue,
8181
this.limitedToValues,
8282
);
8383
cloned.title = this.title;
@@ -117,6 +117,8 @@ export class ColorVariable extends Variable implements IColorVariableParams {
117117
let limitedToValues = data.limitedToValues.map((color: string) => {
118118
return TinyColor(color).toHexString();
119119
});
120-
return new ColorVariable(data.key, selectedValue, limitedToValues);
120+
let variable = new ColorVariable(data.key, selectedValue, limitedToValues);
121+
variable.title = data.title;
122+
return variable;
121123
}
122124
}

0 commit comments

Comments
 (0)