fontdue-js 2.2.0 → 2.3.0-alpha1
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/components/FontdueProvider/index.d.ts +1 -1
- package/dist/components/Price/index.d.ts +4 -1
- package/dist/components/Price/index.js +21 -10
- package/dist/components/SKUPrice/index.js +8 -6
- package/dist/components/TypeTesters/index.js +1 -0
- package/dist/components/elements/StoreModalFamilyButton/index.js +4 -1
- package/dist/components/elements/StoreModalStyleButton/index.js +8 -3
- package/dist/fontdue.css +12 -2
- package/dist/reducer.d.ts +1 -0
- package/dist/reducer.js +11 -8
- package/dist/utils.js +5 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FontdueProvider_props } from './FontdueProviderClientComponent';
|
|
3
|
-
export { FontdueProvider_props } from './FontdueProviderClientComponent';
|
|
4
3
|
declare const FontdueProvider: ({ children, ...rest }: FontdueProvider_props) => React.JSX.Element;
|
|
4
|
+
export { FontdueProvider_props };
|
|
5
5
|
export default FontdueProvider;
|
|
@@ -19,7 +19,10 @@ export type Price_props = Price_baseProps & {
|
|
|
19
19
|
currency: string;
|
|
20
20
|
} | null | undefined;
|
|
21
21
|
};
|
|
22
|
-
export declare
|
|
22
|
+
export declare function Price({ price, format, invert, // multiply by -1
|
|
23
|
+
subtractFrom, // amount to subtract from
|
|
24
|
+
multiplier, // multiply the result amount?
|
|
25
|
+
isLoading, ...rest }: Price_props): React.JSX.Element;
|
|
23
26
|
type RelayPrice_props = Price_baseProps & {
|
|
24
27
|
price: Price_price$key | null;
|
|
25
28
|
};
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.Price = Price;
|
|
7
|
+
exports.default = exports.PriceFormat = void 0;
|
|
7
8
|
var _react = _interopRequireDefault(require("react"));
|
|
8
9
|
var _reactRelay = require("react-relay");
|
|
9
10
|
var _Price_price;
|
|
@@ -52,7 +53,7 @@ const calculateAmount = _ref => {
|
|
|
52
53
|
}
|
|
53
54
|
return subtracted * multiplier;
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
+
function Price(_ref2) {
|
|
56
57
|
let {
|
|
57
58
|
price,
|
|
58
59
|
format = PriceFormat.Default,
|
|
@@ -65,18 +66,28 @@ const Price = _ref2 => {
|
|
|
65
66
|
isLoading = false,
|
|
66
67
|
...rest
|
|
67
68
|
} = _ref2;
|
|
69
|
+
let priceBeforeDiscount = null;
|
|
70
|
+
let priceFormatted = '-';
|
|
71
|
+
if (price) {
|
|
72
|
+
priceFormatted = formatMoney(calculateAmount({
|
|
73
|
+
amount: price.amount,
|
|
74
|
+
subtractFrom: subtractFrom === null || subtractFrom === void 0 ? void 0 : subtractFrom.amount,
|
|
75
|
+
invert,
|
|
76
|
+
multiplier
|
|
77
|
+
}), format, price.currency);
|
|
78
|
+
priceBeforeDiscount = formatMoney(calculateAmount({
|
|
79
|
+
amount: price.amount,
|
|
80
|
+
subtractFrom: subtractFrom === null || subtractFrom === void 0 ? void 0 : subtractFrom.amount,
|
|
81
|
+
invert,
|
|
82
|
+
multiplier: 1
|
|
83
|
+
}), format, price.currency);
|
|
84
|
+
}
|
|
68
85
|
return /*#__PURE__*/_react.default.createElement("span", _extends({
|
|
69
86
|
className: "price"
|
|
70
87
|
}, rest, {
|
|
71
88
|
"data-loading": isLoading
|
|
72
|
-
}),
|
|
73
|
-
|
|
74
|
-
subtractFrom: subtractFrom === null || subtractFrom === void 0 ? void 0 : subtractFrom.amount,
|
|
75
|
-
invert,
|
|
76
|
-
multiplier
|
|
77
|
-
}), format, price.currency) : '–');
|
|
78
|
-
};
|
|
79
|
-
exports.Price = Price;
|
|
89
|
+
}), priceFormatted !== priceBeforeDiscount ? '+' : null, priceFormatted);
|
|
90
|
+
}
|
|
80
91
|
function RelayPrice(_ref3) {
|
|
81
92
|
let {
|
|
82
93
|
price: priceKey,
|
|
@@ -18,14 +18,15 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
18
18
|
const getSavingsMultiplier = (state, options) => {
|
|
19
19
|
if (options.showCollectionSavings === false) return 1;
|
|
20
20
|
if (!options.sku) return 1;
|
|
21
|
-
const differences = (0, _reducer.collectionSkuIdsDifferences)(state, options.sku.id);
|
|
22
21
|
const baseSkuPrice = state.skuPrices[options.sku.id];
|
|
23
|
-
const collectionWithSavings =
|
|
22
|
+
const [collectionWithSavings, savingsAmount] = (0, _reducer.collectionSkuIdWithDiscount)(state, options.sku.id);
|
|
24
23
|
|
|
25
24
|
// we make it a multiplier since the `collectionSkuIdsDifference`
|
|
26
|
-
// helper doesnt take license multiplication into account
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
// helper doesnt take license multiplication into account
|
|
26
|
+
if (collectionWithSavings) {
|
|
27
|
+
return savingsAmount / baseSkuPrice;
|
|
28
|
+
}
|
|
29
|
+
return 1;
|
|
29
30
|
};
|
|
30
31
|
function SKUPrice(_ref) {
|
|
31
32
|
let {
|
|
@@ -35,6 +36,7 @@ function SKUPrice(_ref) {
|
|
|
35
36
|
} = _ref;
|
|
36
37
|
const [isPending, startTransition] = (0, _react.useTransition)();
|
|
37
38
|
const [sku, refetch] = (0, _reactRelay.useRefetchableFragment)(_SKUPrice_sku !== void 0 ? _SKUPrice_sku : (_SKUPrice_sku = require("../../__generated__/SKUPrice_sku.graphql"), _SKUPrice_sku.hash && _SKUPrice_sku.hash !== "9792a6074c64fb4bb018e42df5045514" && console.error("The definition of 'SKUPrice_sku' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _SKUPrice_sku), skuKey);
|
|
39
|
+
const selected = (0, _reactRedux.useSelector)((0, _reducer.isSelected)(sku.id));
|
|
38
40
|
const savingsMultiplier = (0, _reactRedux.useSelector)(state => getSavingsMultiplier(state, {
|
|
39
41
|
showCollectionSavings,
|
|
40
42
|
sku
|
|
@@ -60,7 +62,7 @@ function SKUPrice(_ref) {
|
|
|
60
62
|
if (!(sku !== null && sku !== void 0 && sku.price)) return null;
|
|
61
63
|
return /*#__PURE__*/_react.default.createElement(_Price.default, _extends({}, rest, {
|
|
62
64
|
price: sku.price,
|
|
63
|
-
multiplier: savingsMultiplier,
|
|
65
|
+
multiplier: selected ? 1 : savingsMultiplier,
|
|
64
66
|
isLoading: isPending
|
|
65
67
|
}));
|
|
66
68
|
}
|
|
@@ -90,6 +90,7 @@ function TypeTestersComponent(_ref) {
|
|
|
90
90
|
}, {});
|
|
91
91
|
if (!testers) return null;
|
|
92
92
|
return /*#__PURE__*/_react.default.createElement(_TypeTesterContext.default, {
|
|
93
|
+
key: collection.id,
|
|
93
94
|
defaultMode: defaultMode ?? (autofit ? 'local' : 'group'),
|
|
94
95
|
testers: testers
|
|
95
96
|
}, config.toolsPosition === 'floating' && /*#__PURE__*/_react.default.createElement(_TypeTesterFloatingToolbar.default, {
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
9
|
var _Button = _interopRequireDefault(require("../../elements/Button"));
|
|
10
|
+
var _Icons = require("../../Icons");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
13
|
const StoreModalFamilyButton = _ref => {
|
|
@@ -33,7 +34,9 @@ const StoreModalFamilyButton = _ref => {
|
|
|
33
34
|
className: "store-modal__family-button__name"
|
|
34
35
|
}, name), /*#__PURE__*/_react.default.createElement("div", {
|
|
35
36
|
className: "store-modal__family-button__label"
|
|
36
|
-
}, label), /*#__PURE__*/_react.default.createElement("div", {
|
|
37
|
+
}, label), selected ? /*#__PURE__*/_react.default.createElement("div", {
|
|
38
|
+
className: "store-modal__family-button__checked"
|
|
39
|
+
}, /*#__PURE__*/_react.default.createElement(_Icons.Check, null)) : /*#__PURE__*/_react.default.createElement("div", {
|
|
37
40
|
className: "store-modal__family-button__price"
|
|
38
41
|
}, price)));
|
|
39
42
|
};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
9
|
+
var _Icons = require("../../Icons");
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
11
12
|
const StoreModalStyleButton = _ref => {
|
|
@@ -21,11 +22,15 @@ const StoreModalStyleButton = _ref => {
|
|
|
21
22
|
return /*#__PURE__*/_react.default.createElement(_Button.default, _extends({}, rest, {
|
|
22
23
|
"data-selected": selected,
|
|
23
24
|
"data-clickable": Boolean(rest.onClick)
|
|
24
|
-
}), /*#__PURE__*/_react.default.createElement("
|
|
25
|
-
className: "store-modal__style-
|
|
25
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
26
|
+
className: "store-modal__style-button__container"
|
|
26
27
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
27
28
|
className: "store-modal__style-button__aa"
|
|
28
|
-
}, aa),
|
|
29
|
+
}, aa), ' ', /*#__PURE__*/_react.default.createElement("span", {
|
|
30
|
+
className: "store-modal__style-button__style-name"
|
|
31
|
+
}, name), selected ? /*#__PURE__*/_react.default.createElement("div", {
|
|
32
|
+
className: "store-modal__style-button__checked"
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_Icons.Check, null)) : /*#__PURE__*/_react.default.createElement("div", {
|
|
29
34
|
className: "store-modal__style-button__price"
|
|
30
35
|
}, price)));
|
|
31
36
|
};
|
package/dist/fontdue.css
CHANGED
|
@@ -1447,6 +1447,10 @@ body[data-fontdue-store-modal=open] {
|
|
|
1447
1447
|
margin-bottom: 20px;
|
|
1448
1448
|
}
|
|
1449
1449
|
|
|
1450
|
+
.store-modal__family-button__checked .icon {
|
|
1451
|
+
font-size: 20px;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1450
1454
|
.store-modal__index-item__button {
|
|
1451
1455
|
background: none;
|
|
1452
1456
|
color: inherit;
|
|
@@ -1865,8 +1869,10 @@ body[data-fontdue-store-modal=open] {
|
|
|
1865
1869
|
color: color(red);
|
|
1866
1870
|
}
|
|
1867
1871
|
|
|
1868
|
-
.store-modal__style-
|
|
1869
|
-
display:
|
|
1872
|
+
.store-modal__style-button__container {
|
|
1873
|
+
display: grid;
|
|
1874
|
+
grid-template-columns: minmax(0, max-content) auto max-content;
|
|
1875
|
+
grid-column-gap: 10px;
|
|
1870
1876
|
align-items: baseline;
|
|
1871
1877
|
}
|
|
1872
1878
|
|
|
@@ -1880,6 +1886,10 @@ body[data-fontdue-store-modal=open] {
|
|
|
1880
1886
|
margin-left: auto;
|
|
1881
1887
|
}
|
|
1882
1888
|
|
|
1889
|
+
.store-modal__style-button__checked .icon {
|
|
1890
|
+
font-size: 20px;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1883
1893
|
.empty-cart__message {
|
|
1884
1894
|
font-size: 20px;
|
|
1885
1895
|
margin-bottom: 60px;
|
package/dist/reducer.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export type FontdueAction = {
|
|
|
83
83
|
} | {
|
|
84
84
|
type: 'STORE_MODAL_BACK';
|
|
85
85
|
};
|
|
86
|
+
export declare const collectionSkuIdWithDiscount: (state: FontdueState, skuId: string) => [string, number] | [null, null];
|
|
86
87
|
declare const reducer: Reducer<FontdueState, FontdueAction>;
|
|
87
88
|
export declare function createDefaultStore(config: Config | undefined): import("redux").Store<FontdueState, FontdueAction>;
|
|
88
89
|
export default reducer;
|
package/dist/reducer.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.collectionSkuIdWithDiscount = void 0;
|
|
6
7
|
Object.defineProperty(exports, "collectionSkuIdsDifferences", {
|
|
7
8
|
enumerable: true,
|
|
8
9
|
get: function () {
|
|
@@ -77,15 +78,16 @@ const selectLicenseOption = (state, action) => {
|
|
|
77
78
|
})
|
|
78
79
|
};
|
|
79
80
|
};
|
|
80
|
-
const collectionSkuIdsWithDiscount = (state, skuId) => {
|
|
81
|
-
const differences = (0, _utils.collectionSkuIdsDifferences)(state, skuId);
|
|
82
|
-
return Object.keys(differences).filter(collectionSkuId => differences[collectionSkuId] <= state.skuPrices[skuId]);
|
|
83
|
-
};
|
|
84
81
|
const collectionSkuIdWithDiscount = (state, skuId) => {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
const differences = (0, _utils.collectionSkuIdsDifferences)(state, skuId);
|
|
83
|
+
const collectionId = Object.keys(differences).filter(collSkuId => differences[collSkuId] <= state.skuPrices[skuId]).reduce((smallest, key) => {
|
|
84
|
+
if (!smallest || differences[key] < differences[smallest]) return key;
|
|
85
|
+
return smallest;
|
|
86
|
+
}, null);
|
|
87
|
+
if (collectionId) return [collectionId, differences[collectionId]];
|
|
88
|
+
return [null, null];
|
|
88
89
|
};
|
|
90
|
+
exports.collectionSkuIdWithDiscount = collectionSkuIdWithDiscount;
|
|
89
91
|
const selectedCollectionSkuIdContainingSkuId = (state, skuId) => Object.keys(state.selectedSkuIds).filter(id => state.selectedSkuIds[id] === true).find(selectedSkuId => (0, _utils.collContainsSkuId)(state.collectionStyleSkus[selectedSkuId], skuId));
|
|
90
92
|
const setKeysFalse = (acc, key) => {
|
|
91
93
|
acc[key] = false;
|
|
@@ -115,7 +117,8 @@ const selectSkuId = (state, action) => {
|
|
|
115
117
|
if (selected) {
|
|
116
118
|
// check if selecting any collections instead of this sku
|
|
117
119
|
// would reduce the selection price
|
|
118
|
-
|
|
120
|
+
const [collectionSkuId, _amount] = collectionSkuIdWithDiscount(state, skuId);
|
|
121
|
+
actualSkuId = collectionSkuId || actualSkuId;
|
|
119
122
|
} else if (state.selectedSkuIds[skuId] === false) {
|
|
120
123
|
// we're clicking "deselect" on an item that's not actually selected,
|
|
121
124
|
// it's a member of a collection which is selected. in this case
|
package/dist/utils.js
CHANGED
|
@@ -34,10 +34,14 @@ const isSelected = skuIdOrStyleId => state => {
|
|
|
34
34
|
const collectionSkuIds = Object.keys(state.collectionStyleSkus).filter(collSkuId => collContainsSkuId(state.collectionStyleSkus[collSkuId], skuIdOrStyleId));
|
|
35
35
|
return state.selectedSkuIds[skuIdOrStyleId] === true || collectionSkuIds.some(collSkuId => state.selectedSkuIds[collSkuId] === true);
|
|
36
36
|
};
|
|
37
|
+
|
|
38
|
+
// find any collection ancestors that contain this skuId,
|
|
39
|
+
// then for each collection, sum the price of selected skus,
|
|
40
|
+
// and return the delta between the collection price and the sum.
|
|
37
41
|
exports.isSelected = isSelected;
|
|
38
42
|
const collectionSkuIdsDifferences = (state, skuId) => Object.keys(state.collectionStyleSkus).filter(collectionSkuId => {
|
|
39
43
|
const coll = state.collectionStyleSkus[collectionSkuId];
|
|
40
|
-
return collContainsSkuId(coll, skuId);
|
|
44
|
+
return skuId === collectionSkuId || collContainsSkuId(coll, skuId);
|
|
41
45
|
}).reduce((acc, collectionSkuId) => {
|
|
42
46
|
const coll = state.collectionStyleSkus[collectionSkuId];
|
|
43
47
|
const selectedSkuIdsInColl = Object.keys(state.selectedSkuIds).filter(selectedSkuId => state.selectedSkuIds[selectedSkuId] === true && collContainsSkuId(coll, selectedSkuId));
|
package/package.json
CHANGED