fontdue-js 0.1.0-alpha21 → 0.1.0-alpha24

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.
Files changed (59) hide show
  1. package/dist/__generated__/CartOrderApplyCouponMutation.graphql.js +9 -2
  2. package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.js +9 -2
  3. package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.js +9 -2
  4. package/dist/__generated__/CartOrderUpdateMutation.graphql.js +9 -2
  5. package/dist/__generated__/CartQuery.graphql.js +9 -2
  6. package/dist/__generated__/CartStateApplyCouponMutation.graphql.js +9 -2
  7. package/dist/__generated__/CartStateRemoveDiscountMutation.graphql.js +9 -2
  8. package/dist/__generated__/CartStateUpdateMutation.graphql.js +9 -2
  9. package/dist/__generated__/CartTotals_order.graphql.d.ts +1 -0
  10. package/dist/__generated__/CartTotals_order.graphql.js +7 -1
  11. package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.js +9 -2
  12. package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.js +9 -2
  13. package/dist/__generated__/PrecartAddToCartMutation.graphql.js +9 -2
  14. package/dist/__generated__/StoreModalCartQuery.graphql.js +9 -2
  15. package/dist/__generated__/StoreModalReviewCompleteOrderMutation.graphql.js +9 -2
  16. package/dist/__generated__/StoreModalReviewQuery.graphql.js +9 -2
  17. package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.js +9 -2
  18. package/dist/__generated__/TypeTesterData_typeTester.graphql.d.ts +1 -0
  19. package/dist/__generated__/TypeTesterData_typeTester.graphql.js +48 -40
  20. package/dist/__generated__/TypeTesterFloatingToolbar_testers.graphql.d.ts +16 -0
  21. package/dist/__generated__/TypeTesterFloatingToolbar_testers.graphql.js +44 -0
  22. package/dist/__generated__/TypeTestersIDQuery.graphql.js +62 -14
  23. package/dist/__generated__/TypeTestersSlugQuery.graphql.js +62 -14
  24. package/dist/__generated__/TypeTesters_collection.graphql.d.ts +7 -1
  25. package/dist/__generated__/TypeTesters_collection.graphql.js +32 -4
  26. package/dist/components/Cart/CartTotals.js +3 -3
  27. package/dist/components/Icons/Align.d.ts +4 -0
  28. package/dist/components/Icons/Align.js +63 -0
  29. package/dist/components/TypeTester/TypeTesterAlignButtons.d.ts +8 -0
  30. package/dist/components/TypeTester/TypeTesterAlignButtons.js +39 -0
  31. package/dist/components/TypeTester/TypeTesterContent.d.ts +6 -2
  32. package/dist/components/TypeTester/TypeTesterContent.js +22 -6
  33. package/dist/components/TypeTester/TypeTesterContext.d.ts +51 -7
  34. package/dist/components/TypeTester/TypeTesterContext.js +119 -9
  35. package/dist/components/TypeTester/TypeTesterFeatures.d.ts +1 -2
  36. package/dist/components/TypeTester/TypeTesterFeatures.js +86 -19
  37. package/dist/components/TypeTester/TypeTesterFeaturesButton.js +1 -1
  38. package/dist/components/TypeTester/TypeTesterFloatingToolbar.d.ts +8 -0
  39. package/dist/components/TypeTester/TypeTesterFloatingToolbar.js +88 -0
  40. package/dist/components/TypeTester/TypeTesterStandalone.d.ts +4 -0
  41. package/dist/components/TypeTester/TypeTesterStandalone.js +19 -7
  42. package/dist/components/TypeTester/TypeTesterState.d.ts +4 -5
  43. package/dist/components/TypeTester/TypeTesterState.js +63 -67
  44. package/dist/components/TypeTester/TypeTesterStyleSelect.js +4 -2
  45. package/dist/components/TypeTester/TypeTesterStyleSelectData.d.ts +1 -1
  46. package/dist/components/TypeTester/TypeTesterStyleSelectData.js +3 -1
  47. package/dist/components/TypeTester/TypeTesterToolbar.d.ts +9 -0
  48. package/dist/components/TypeTester/TypeTesterToolbar.js +57 -0
  49. package/dist/components/TypeTester/index.d.ts +8 -5
  50. package/dist/components/TypeTester/index.js +51 -52
  51. package/dist/components/TypeTester/types.d.ts +1 -0
  52. package/dist/components/TypeTester/useTypeTesterStyler.d.ts +3 -1
  53. package/dist/components/TypeTester/useTypeTesterStyler.js +5 -3
  54. package/dist/components/TypeTesterData/index.js +2 -1
  55. package/dist/components/TypeTesters/index.d.ts +3 -0
  56. package/dist/components/TypeTesters/index.js +66 -18
  57. package/fontdue.css +53 -4
  58. package/fontdue.css.map +1 -1
  59. package/package.json +1 -1
@@ -51,7 +51,7 @@ const CartTotals = ({
51
51
  "data-has-discount": Boolean(order.discount),
52
52
  "data-hide-total": hideTotal
53
53
  }, /*#__PURE__*/_react.default.createElement(PriceBlock, {
54
- label: "Pre-tax total:",
54
+ label: "Subtotal:",
55
55
  price: order.subtotal,
56
56
  "data-line": "subtotal"
57
57
  }), order.discount && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(PriceBlock, {
@@ -79,13 +79,13 @@ const CartTotals = ({
79
79
  price: order.taxes,
80
80
  "data-line": "taxes"
81
81
  }), /*#__PURE__*/_react.default.createElement(PriceBlock, {
82
- label: "Total:",
82
+ label: "Total".concat(order.gstIncluded ? ' including GST' : '', ":"),
83
83
  price: order.total,
84
84
  "data-line": "total"
85
85
  }));
86
86
 
87
87
  var _default = (0, _reactRelay.createFragmentContainer)(CartTotals, {
88
- order: _CartTotals_order !== void 0 ? _CartTotals_order : (_CartTotals_order = require("../../__generated__/CartTotals_order.graphql"), _CartTotals_order.hash && _CartTotals_order.hash !== "e4a0587e58d04c9f6ab6753a7d767740" && console.error("The definition of 'CartTotals_order' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _CartTotals_order)
88
+ order: _CartTotals_order !== void 0 ? _CartTotals_order : (_CartTotals_order = require("../../__generated__/CartTotals_order.graphql"), _CartTotals_order.hash && _CartTotals_order.hash !== "b4e8ff4b5b5525af89e9f80a08a657e5" && console.error("The definition of 'CartTotals_order' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _CartTotals_order)
89
89
  });
90
90
 
91
91
  exports.default = _default;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function AlignCenter(): JSX.Element;
3
+ export declare function AlignLeft(): JSX.Element;
4
+ export declare function AlignRight(): JSX.Element;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AlignCenter = AlignCenter;
7
+ exports.AlignLeft = AlignLeft;
8
+ exports.AlignRight = AlignRight;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function AlignCenter() {
15
+ return /*#__PURE__*/_react.default.createElement("span", {
16
+ className: "icon",
17
+ "data-label": "AlignCenter"
18
+ }, /*#__PURE__*/_react.default.createElement("svg", {
19
+ xmlns: "http://www.w3.org/2000/svg",
20
+ width: "18",
21
+ height: "13",
22
+ fill: "none",
23
+ viewBox: "0 0 18 13"
24
+ }, /*#__PURE__*/_react.default.createElement("path", {
25
+ fillRule: "evenodd",
26
+ d: "M0 4h18v1H0V4zM2 0h14.078v1H2V0zM2.067 8H16v1H2.067V8zM3 12h12.079v1H3v-1z",
27
+ clipRule: "evenodd"
28
+ })));
29
+ }
30
+
31
+ function AlignLeft() {
32
+ return /*#__PURE__*/_react.default.createElement("span", {
33
+ className: "icon",
34
+ "data-label": "AlignLeft"
35
+ }, /*#__PURE__*/_react.default.createElement("svg", {
36
+ xmlns: "http://www.w3.org/2000/svg",
37
+ width: "19",
38
+ height: "13",
39
+ fill: "none",
40
+ viewBox: "0 0 19 13"
41
+ }, /*#__PURE__*/_react.default.createElement("path", {
42
+ fillRule: "evenodd",
43
+ d: "M0 0h14.079v1H0V0zM0 4h18.078v1H0V4zM0 8h16.078v1H0V8zM0 12h14.079v1H0v-1z",
44
+ clipRule: "evenodd"
45
+ })));
46
+ }
47
+
48
+ function AlignRight() {
49
+ return /*#__PURE__*/_react.default.createElement("span", {
50
+ className: "icon",
51
+ "data-label": "AlignRight"
52
+ }, /*#__PURE__*/_react.default.createElement("svg", {
53
+ xmlns: "http://www.w3.org/2000/svg",
54
+ width: "19",
55
+ height: "13",
56
+ fill: "none",
57
+ viewBox: "0 0 19 13"
58
+ }, /*#__PURE__*/_react.default.createElement("path", {
59
+ fillRule: "evenodd",
60
+ d: "M3 0h15v1H3V0zM3.47 12H18v1H3.47v-1zM.067 4H18v1H.067V4zM2.067 8H18v1H2.067V8z",
61
+ clipRule: "evenodd"
62
+ })));
63
+ }
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { Alignment } from './types';
3
+ interface TypeTesterAlignButtons_props {
4
+ alignment: Alignment;
5
+ setAlignment: (value: Alignment) => void;
6
+ }
7
+ declare const TypeTesterAlignButtons: React.FC<TypeTesterAlignButtons_props>;
8
+ export default TypeTesterAlignButtons;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _Align = require("../Icons/Align");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const TypeTesterAlignButtons = ({
15
+ alignment,
16
+ setAlignment
17
+ }) => {
18
+ return /*#__PURE__*/_react.default.createElement("div", {
19
+ className: "type-tester__align-buttons"
20
+ }, /*#__PURE__*/_react.default.createElement("button", {
21
+ type: "button",
22
+ className: "type-tester__align-buttons__button",
23
+ "data-active": alignment === 'left',
24
+ onClick: () => setAlignment('left')
25
+ }, /*#__PURE__*/_react.default.createElement(_Align.AlignLeft, null)), /*#__PURE__*/_react.default.createElement("button", {
26
+ type: "button",
27
+ className: "type-tester__align-buttons__button",
28
+ "data-active": alignment === 'center',
29
+ onClick: () => setAlignment('center')
30
+ }, /*#__PURE__*/_react.default.createElement(_Align.AlignCenter, null)), /*#__PURE__*/_react.default.createElement("button", {
31
+ type: "button",
32
+ className: "type-tester__align-buttons__button",
33
+ "data-active": alignment === 'right',
34
+ onClick: () => setAlignment('right')
35
+ }, /*#__PURE__*/_react.default.createElement(_Align.AlignRight, null)));
36
+ };
37
+
38
+ var _default = TypeTesterAlignButtons;
39
+ exports.default = _default;
@@ -1,6 +1,9 @@
1
1
  import React from 'react';
2
2
  import { UseTypeTesterStylerProps } from './useTypeTesterStyler';
3
- import { Content } from './types';
3
+ import { Alignment, Content } from './types';
4
+ export interface TypeTesterContentRef {
5
+ focus: () => void;
6
+ }
4
7
  interface TypeTesterContentProps extends UseTypeTesterStylerProps {
5
8
  content: Content;
6
9
  setContent: (value: Content) => void;
@@ -8,6 +11,7 @@ interface TypeTesterContentProps extends UseTypeTesterStylerProps {
8
11
  setFocused: (value: boolean) => void;
9
12
  direction: string | null;
10
13
  autofitOnChange: boolean;
14
+ alignment: Alignment;
11
15
  }
12
- declare const TypeTesterContent: React.FunctionComponent<TypeTesterContentProps>;
16
+ declare const TypeTesterContent: React.ForwardRefExoticComponent<TypeTesterContentProps & React.RefAttributes<TypeTesterContentRef>>;
13
17
  export default TypeTesterContent;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _useTypeTesterStyler = _interopRequireDefault(require("./useTypeTesterStyler"));
11
11
 
@@ -13,30 +13,46 @@ var _draftJs = require("draft-js");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
16
20
  function _extends() { _extends = Object.assign || 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); }
17
21
 
18
- const TypeTesterContent = ({
22
+ const TypeTesterContent = /*#__PURE__*/_react.default.forwardRef(({
19
23
  content,
20
24
  setContent,
21
25
  setFocused,
22
26
  direction,
27
+ alignment,
23
28
  ...props
24
- }) => {
29
+ }, ref) => {
30
+ const editorRef = (0, _react.useRef)(null);
31
+ (0, _react.useImperativeHandle)(ref, () => ({
32
+ focus: () => {
33
+ var _editorRef$current;
34
+
35
+ (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.focus();
36
+ }
37
+ }));
25
38
  const style = (0, _useTypeTesterStyler.default)({ ...props,
26
- content
39
+ content,
40
+ alignment
27
41
  });
28
42
  return /*#__PURE__*/_react.default.createElement("div", _extends({}, style, {
29
43
  className: "type-tester__text__container"
30
44
  }), /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
45
+ ref: editorRef,
31
46
  editorState: content,
32
47
  onChange: value => setContent(value),
33
48
  onBlur: () => setFocused(false),
34
49
  onFocus: () => setFocused(true),
35
50
  spellCheck: false,
36
51
  stripPastedStyles: true,
37
- textDirectionality: direction === 'rtl' ? 'RTL' : 'LTR'
52
+ textDirectionality: direction === 'rtl' ? 'RTL' : 'LTR',
53
+ textAlignment: alignment
38
54
  }));
39
- };
55
+ });
40
56
 
41
57
  var _default = TypeTesterContent;
42
58
  exports.default = _default;
@@ -1,28 +1,72 @@
1
1
  import React, { Dispatch } from 'react';
2
- import { Content, Features, Size, TypeTesterMode } from './types';
2
+ import { Content, Features, Size, Alignment, TypeTesterMode } from './types';
3
+ interface TypeTesterState {
4
+ content: Content;
5
+ contentEdited: boolean;
6
+ features: Features;
7
+ size: Size;
8
+ lineHeight: number;
9
+ focused: boolean;
10
+ featuresOpen: boolean;
11
+ autofit: boolean;
12
+ alignment: Alignment;
13
+ }
14
+ export interface TypeTestersState {
15
+ [id: string]: TypeTesterState;
16
+ }
17
+ export interface TypeTestersInitialState {
18
+ [id: string]: {
19
+ content: string | null;
20
+ size: number | null;
21
+ lineHeight: number | null;
22
+ autofit: boolean;
23
+ alignment: Alignment;
24
+ };
25
+ }
3
26
  interface TypeTesterContextState {
4
27
  mode: TypeTesterMode;
5
- content: Content | null;
6
- features: Features | null;
7
- size: Size | null;
28
+ globalFeaturesOpen: boolean;
29
+ testers: TypeTestersState;
8
30
  }
9
31
  declare type TypeTesterContextAction = {
10
32
  type: 'TOGGLE_MODE';
33
+ } | {
34
+ type: 'TOGGLE_GLOBAL_FEATURES_OPEN';
11
35
  } | {
12
36
  type: 'SET_CONTENT';
13
- value: Content | null;
37
+ id: string;
38
+ value: Content;
14
39
  } | {
15
40
  type: 'SET_SIZE';
16
- value: Size | null;
41
+ id: string;
42
+ value: Size;
17
43
  } | {
18
44
  type: 'SET_FEATURES';
19
- value: Features | null;
45
+ id: string;
46
+ value: Features;
47
+ } | {
48
+ type: 'SET_FEATURES_OPEN';
49
+ id: string;
50
+ value: boolean;
51
+ } | {
52
+ type: 'SET_FOCUSED';
53
+ id: string;
54
+ value: boolean;
55
+ } | {
56
+ type: 'SET_LINE_HEIGHT';
57
+ id: string;
58
+ value: number;
59
+ } | {
60
+ type: 'SET_ALIGNMENT';
61
+ id: string;
62
+ value: Alignment;
20
63
  };
21
64
  export declare const TypeTesterContext: React.Context<TypeTesterContextState & {
22
65
  dispatch: Dispatch<TypeTesterContextAction>;
23
66
  }>;
24
67
  export interface TypeTesterContextProps {
25
68
  defaultMode?: 'group' | 'local';
69
+ testers: TypeTestersInitialState;
26
70
  }
27
71
  declare const TypeTesterContextComponent: React.FunctionComponent<TypeTesterContextProps>;
28
72
  export default TypeTesterContextComponent;
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = exports.TypeTesterContext = void 0;
7
7
 
8
+ var _draftJs = require("draft-js");
9
+
8
10
  var _react = _interopRequireWildcard(require("react"));
9
11
 
10
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -14,39 +16,147 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
14
16
  const TypeTesterContext = /*#__PURE__*/(0, _react.createContext)({});
15
17
  exports.TypeTesterContext = TypeTesterContext;
16
18
 
19
+ const updateTester = (state, id, newState) => {
20
+ const testers = state.testers;
21
+
22
+ if (state.mode === 'local') {
23
+ return { ...state,
24
+ testers: { ...testers,
25
+ [id]: { ...testers[id],
26
+ ...newState
27
+ }
28
+ }
29
+ };
30
+ }
31
+
32
+ if (state.mode === 'group') {
33
+ // affect all testers
34
+ const newTesters = Object.keys(testers).reduce((acc, tid) => {
35
+ let content = testers[tid].content;
36
+
37
+ if (newState.content) {
38
+ if (id === tid) {
39
+ // for the currently edited tester, we need to use the new content
40
+ // as-is to maintain the selection state
41
+ content = newState.content;
42
+ } else {
43
+ var _testers$id$content;
44
+
45
+ if (((_testers$id$content = testers[id].content) === null || _testers$id$content === void 0 ? void 0 : _testers$id$content.getCurrentContent()) !== newState.content.getCurrentContent()) {
46
+ // but we can't use the `content` state as-is for other testers, because
47
+ // the selection state seems to be globally tied to the browser selection,
48
+ // so the cursor jumps to the other tester. we have to make a new
49
+ // EditorState with a copy of the content
50
+ content = _draftJs.EditorState.createWithContent(newState.content.getCurrentContent());
51
+ }
52
+ }
53
+ }
54
+
55
+ acc[tid] = { ...testers[tid],
56
+ ...newState,
57
+ content
58
+ };
59
+ return acc;
60
+ }, {});
61
+ return { ...state,
62
+ testers: newTesters
63
+ };
64
+ }
65
+
66
+ return state;
67
+ };
68
+
17
69
  const groupReducer = (state, action) => {
70
+ const {
71
+ testers
72
+ } = state;
73
+
18
74
  switch (action.type) {
19
75
  case 'TOGGLE_MODE':
20
76
  return { ...state,
21
77
  mode: state.mode === 'group' ? 'local' : 'group'
22
78
  };
23
79
 
24
- case 'SET_CONTENT':
80
+ case 'TOGGLE_GLOBAL_FEATURES_OPEN':
25
81
  return { ...state,
26
- content: action.value
82
+ globalFeaturesOpen: !state.globalFeaturesOpen
27
83
  };
28
84
 
85
+ case 'SET_CONTENT':
86
+ return updateTester(state, action.id, {
87
+ content: action.value,
88
+ contentEdited: true
89
+ });
90
+
29
91
  case 'SET_SIZE':
30
- return { ...state,
92
+ return updateTester(state, action.id, {
31
93
  size: action.value
32
- };
94
+ });
33
95
 
34
96
  case 'SET_FEATURES':
35
- return { ...state,
97
+ return updateTester(state, action.id, {
36
98
  features: action.value
99
+ });
100
+
101
+ case 'SET_LINE_HEIGHT':
102
+ return updateTester(state, action.id, {
103
+ lineHeight: action.value
104
+ });
105
+
106
+ case 'SET_ALIGNMENT':
107
+ return updateTester(state, action.id, {
108
+ alignment: action.value
109
+ });
110
+
111
+ case 'SET_FOCUSED':
112
+ return { ...state,
113
+ testers: { ...testers,
114
+ [action.id]: { ...testers[action.id],
115
+ focused: action.value
116
+ }
117
+ }
118
+ };
119
+
120
+ case 'SET_FEATURES_OPEN':
121
+ return { ...state,
122
+ testers: { ...testers,
123
+ [action.id]: { ...testers[action.id],
124
+ featuresOpen: action.value
125
+ }
126
+ }
37
127
  };
38
128
  }
39
129
  };
40
130
 
41
131
  const TypeTesterContextComponent = ({
42
132
  children,
133
+ testers: initialTestersState,
43
134
  defaultMode = 'group'
44
135
  }) => {
136
+ const testers = Object.keys(initialTestersState).reduce((acc, id) => {
137
+ var _initialState$content, _initialState$size, _initialState$lineHei;
138
+
139
+ const initialState = initialTestersState[id];
140
+
141
+ const content = _draftJs.EditorState.createWithContent(_draftJs.ContentState.createFromText((_initialState$content = initialState.content) !== null && _initialState$content !== void 0 ? _initialState$content : ''));
142
+
143
+ acc[id] = {
144
+ content,
145
+ contentEdited: false,
146
+ size: (_initialState$size = initialState.size) !== null && _initialState$size !== void 0 ? _initialState$size : 72,
147
+ lineHeight: (_initialState$lineHei = initialState.lineHeight) !== null && _initialState$lineHei !== void 0 ? _initialState$lineHei : 1,
148
+ autofit: initialState.autofit,
149
+ features: [],
150
+ featuresOpen: false,
151
+ focused: false,
152
+ alignment: initialState.alignment
153
+ };
154
+ return acc;
155
+ }, {});
45
156
  const [value, dispatch] = (0, _react.useReducer)(groupReducer, {
46
- content: null,
47
- size: null,
48
- features: null,
49
- mode: defaultMode
157
+ mode: defaultMode,
158
+ globalFeaturesOpen: false,
159
+ testers
50
160
  });
51
161
  return /*#__PURE__*/_react.default.createElement(TypeTesterContext.Provider, {
52
162
  value: { ...value,
@@ -1,10 +1,9 @@
1
1
  import { TypeTesterFeatures_fontStyle } from '../../__generated__/TypeTesterFeatures_fontStyle.graphql';
2
2
  import { TypeTesterConfig } from '.';
3
3
  interface TypeTesterFeatures_props {
4
+ id: string;
4
5
  fontStyle: TypeTesterFeatures_fontStyle;
5
6
  features: ReadonlyArray<string>;
6
- showFeatures: ReadonlyArray<string>;
7
- toggleFeature: (feature: string) => void;
8
7
  config: TypeTesterConfig;
9
8
  }
10
9
  declare const _default: import("react-relay").Container<TypeTesterFeatures_props>;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactRelay = require("react-relay");
11
11
 
@@ -13,10 +13,43 @@ var _features = _interopRequireDefault(require("./features"));
13
13
 
14
14
  var _TypeTesterBullet = _interopRequireDefault(require("../TypeTester/TypeTesterBullet"));
15
15
 
16
+ var _TypeTesterState = _interopRequireDefault(require("./TypeTesterState"));
17
+
16
18
  var _TypeTesterFeatures_stylisticSetName, _TypeTesterFeatures_fontStyle;
17
19
 
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ function useHeightAnimation(isOpen = false, duration = 350) {
27
+ const contentRef = (0, _react.useRef)(null); // Inner wrapper that keeps the height if the outer animated is closed
28
+
29
+ const [height, setHeight] = (0, _react.useState)(isOpen ? 'auto' : 0);
30
+ (0, _react.useEffect)(() => {
31
+ var _contentRef$current;
32
+
33
+ const contentRect = (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.getBoundingClientRect();
34
+ if (!contentRect) return;
35
+ setHeight("".concat(contentRect.height, "px"));
36
+ const first = setTimeout(() => setHeight(isOpen ? "".concat(contentRect.height, "px") : 0));
37
+ const second = setTimeout(() => {
38
+ if (isOpen) {
39
+ setHeight('auto');
40
+ }
41
+ }, duration);
42
+ return () => {
43
+ clearTimeout(first);
44
+ clearTimeout(second);
45
+ };
46
+ }, [isOpen]);
47
+ return {
48
+ height,
49
+ contentRef
50
+ };
51
+ }
52
+
20
53
  const shouldIncludeFeature = (supportedFeatures, feature) => supportedFeatures.indexOf(feature) >= 0;
21
54
 
22
55
  const getStylisticSetName = (feature, stylisticSetNames) => stylisticSetNames.find(({
@@ -40,31 +73,65 @@ const getFeatureName = (feature, stylisticSetNames) => {
40
73
  _TypeTesterFeatures_stylisticSetName !== void 0 ? _TypeTesterFeatures_stylisticSetName : (_TypeTesterFeatures_stylisticSetName = require("../../__generated__/TypeTesterFeatures_stylisticSetName.graphql"), _TypeTesterFeatures_stylisticSetName.hash && _TypeTesterFeatures_stylisticSetName.hash !== "8420321d8ddf9b3846450d609586db21" && console.error("The definition of 'TypeTesterFeatures_stylisticSetName' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _TypeTesterFeatures_stylisticSetName);
41
74
 
42
75
  const TypeTesterFeatures = ({
76
+ id,
43
77
  fontStyle,
44
- showFeatures,
45
- features,
46
- toggleFeature,
78
+ features: showFeatures,
47
79
  config
48
80
  }) => {
49
- var _config$openTypeFeatu, _config$openTypeFeatu2;
50
-
51
- const renderFeature = feature => /*#__PURE__*/_react.default.createElement("button", {
52
- key: feature,
53
- className: "type-tester__features__button",
54
- type: "button",
55
- onClick: () => toggleFeature(feature)
56
- }, /*#__PURE__*/_react.default.createElement(_TypeTesterBullet.default, {
57
- checked: features.indexOf(feature) >= 0,
58
- config: config
59
- }), ' ', /*#__PURE__*/_react.default.createElement("span", {
60
- className: "type-tester__features__name"
61
- }, getFeatureName(feature, fontStyle.fontFeatures.stylisticSetNames)));
81
+ var _config$openTypeFeatu, _config$openTypeFeatu2, _config$openTypeFeatu3, _config$openTypeFeatu4;
82
+
83
+ const {
84
+ features,
85
+ toggleFeature,
86
+ featuresOpen
87
+ } = (0, _TypeTesterState.default)({
88
+ id
89
+ });
90
+
91
+ const renderFeature = feature => {
92
+ var _fontStyle$fontFeatur;
93
+
94
+ return /*#__PURE__*/_react.default.createElement("button", {
95
+ key: feature,
96
+ className: "type-tester__features__button",
97
+ type: "button",
98
+ onClick: () => toggleFeature(feature)
99
+ }, /*#__PURE__*/_react.default.createElement(_TypeTesterBullet.default, {
100
+ checked: features.indexOf(feature) >= 0,
101
+ config: config
102
+ }), ' ', /*#__PURE__*/_react.default.createElement("span", {
103
+ className: "type-tester__features__name"
104
+ }, getFeatureName(feature, (_fontStyle$fontFeatur = fontStyle.fontFeatures) === null || _fontStyle$fontFeatur === void 0 ? void 0 : _fontStyle$fontFeatur.stylisticSetNames)));
105
+ };
106
+
107
+ let featuresColumns;
62
108
 
63
109
  if ((_config$openTypeFeatu = config.openTypeFeatures) !== null && _config$openTypeFeatu !== void 0 && (_config$openTypeFeatu2 = _config$openTypeFeatu.columns) !== null && _config$openTypeFeatu2 !== void 0 && _config$openTypeFeatu2.length) {
64
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, config.openTypeFeatures.columns.map(column => /*#__PURE__*/_react.default.createElement("div", null, column.filter(feature => shouldIncludeFeature(fontStyle.fontFeatures.supportedFeatures, feature)).map(renderFeature))));
110
+ featuresColumns = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, config.openTypeFeatures.columns.map((column, i) => /*#__PURE__*/_react.default.createElement("div", {
111
+ key: i
112
+ }, column.filter(feature => shouldIncludeFeature(fontStyle.fontFeatures.supportedFeatures, feature)).map(renderFeature))));
113
+ } else {
114
+ featuresColumns = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showFeatures.filter(feature => shouldIncludeFeature(fontStyle.fontFeatures.supportedFeatures, feature)).map(renderFeature));
65
115
  }
66
116
 
67
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, showFeatures.filter(feature => shouldIncludeFeature(fontStyle.fontFeatures.supportedFeatures, feature)).map(renderFeature));
117
+ const {
118
+ height: featuresHeight,
119
+ contentRef: featuresContentRef
120
+ } = useHeightAnimation(featuresOpen, 300);
121
+ return /*#__PURE__*/_react.default.createElement("div", {
122
+ className: "type-tester__features-container",
123
+ onMouseDown: e => e.preventDefault(),
124
+ "data-open": featuresOpen,
125
+ style: {
126
+ height: featuresHeight,
127
+ overflow: featuresHeight === 'auto' ? 'visible' : 'hidden',
128
+ transition: "height 300ms ease-out"
129
+ }
130
+ }, /*#__PURE__*/_react.default.createElement("div", {
131
+ ref: featuresContentRef,
132
+ className: "type-tester__features",
133
+ "data-columns": (_config$openTypeFeatu3 = config.openTypeFeatures) !== null && _config$openTypeFeatu3 !== void 0 && (_config$openTypeFeatu4 = _config$openTypeFeatu3.columns) !== null && _config$openTypeFeatu4 !== void 0 && _config$openTypeFeatu4.length ? 'set' : 'auto'
134
+ }, featuresColumns));
68
135
  };
69
136
 
70
137
  var _default = (0, _reactRelay.createFragmentContainer)(TypeTesterFeatures, {
@@ -23,7 +23,7 @@ const TypeTesterFeaturesButton = ({
23
23
  }, /*#__PURE__*/_react.default.createElement("button", {
24
24
  className: "type-tester__features-button__button",
25
25
  type: "button",
26
- onClick: toggleFeaturesOpen
26
+ onClick: () => toggleFeaturesOpen()
27
27
  }, /*#__PURE__*/_react.default.createElement("span", {
28
28
  className: "type-tester__features-button__text"
29
29
  }, "OT Features"), ' ', featuresOpen ? /*#__PURE__*/_react.default.createElement(_CarrotUp.default, null) : /*#__PURE__*/_react.default.createElement(_CarrotDown.default, null)));
@@ -0,0 +1,8 @@
1
+ import { TypeTesterFloatingToolbar_testers } from '__generated__/TypeTesterFloatingToolbar_testers.graphql';
2
+ interface TypeTesterFloatingToolbar_props {
3
+ testers: TypeTesterFloatingToolbar_testers;
4
+ features: readonly string[] | null | undefined;
5
+ onToolbarOpenClose?: (open: boolean) => void;
6
+ }
7
+ declare const _default: import("react-relay").Container<TypeTesterFloatingToolbar_props>;
8
+ export default _default;