@applicaster/zapp-react-native-utils 13.0.0-rc.45 → 13.0.0-rc.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ const defaultPlatforms = {
2
+ tvos: "tvOS",
3
+ android_tv: "Android TV",
4
+ lg_tv: "LG TV",
5
+ samsung_tv: "Samsung TV",
6
+ };
7
+
8
+ const global_defaults = {
9
+ fontSize: 20,
10
+ lineHeight: 40,
11
+ letterSpacing: 0.4,
12
+ };
13
+
14
+ const generateFontConfiguration = (platforms = defaultPlatforms) => {
15
+ const platformEntries = Object.entries(platforms);
16
+ const defaultsEntries = Object.entries(global_defaults);
17
+ const splitCamelCase = (str) => str.replace(/([a-z](?=[A-Z]))/g, "$1_");
18
+
19
+ return platformEntries.reduce((acc, [platformKey, platformValue]) => {
20
+ acc.push(
21
+ ...defaultsEntries.reduce((acc2, [valueKey, defaultValue]) => {
22
+ acc2.push({
23
+ type: "number_input",
24
+ label: `${platformValue} ${splitCamelCase(valueKey).replace(
25
+ "_",
26
+ " "
27
+ )}`,
28
+ key: `${platformKey}_${splitCamelCase(valueKey)}`.toLowerCase(),
29
+ initial_value: defaultValue,
30
+ });
31
+
32
+ return acc2;
33
+ }, [])
34
+ );
35
+
36
+ return acc;
37
+ }, []);
38
+ };
39
+
40
+ const conditional_rule = (key, condition_value) => ({
41
+ key,
42
+ condition_value,
43
+ });
44
+
45
+ const createConditionalConfig = (rules, matchAll = false) => ({
46
+ rules: matchAll ? "all_conditions" : "conditional",
47
+ conditional_fields: rules.map((field) => conditional_rule(...field)),
48
+ });
49
+
50
+ const conditional_horizontal_type = createConditionalConfig([
51
+ ["styles/screen_picker_type", "horizontal"],
52
+ ]);
53
+
54
+ const conditional_vertical_type = createConditionalConfig([
55
+ ["styles/screen_picker_type", "vertical"],
56
+ ]);
57
+
58
+ const conditional_horizontal_type_item_fixed = createConditionalConfig(
59
+ [
60
+ ["styles/screen_picker_type", "horizontal"],
61
+ ["styles/screen_picker_item_size", "fixed"],
62
+ ],
63
+ true
64
+ );
65
+
66
+ const conditional_horizontal_type_item_dynamic = createConditionalConfig(
67
+ [
68
+ ["styles/screen_picker_type", "horizontal"],
69
+ ["screen_picker_horizontal_display_type", "dynamic"],
70
+ ],
71
+ true
72
+ );
73
+
74
+ const conditional_horizontal_display_type_fixed = createConditionalConfig(
75
+ [
76
+ ["styles/screen_picker_type", "horizontal"],
77
+ ["styles/screen_picker_horizontal_display_type", "fixed"],
78
+ ],
79
+ true
80
+ );
81
+
82
+ const conditional_horizontal_asset_on = createConditionalConfig(
83
+ [
84
+ ["styles/screen_picker_type", "horizontal"],
85
+ ["styles/screen_picker_asset_switch", true],
86
+ ],
87
+ true
88
+ );
89
+
90
+ const createVariationFields = ({
91
+ prefix = "screen_picker",
92
+ key,
93
+ type = "number_input",
94
+ label = "",
95
+ variants: [a, b],
96
+ }) => {
97
+ return [
98
+ {
99
+ type,
100
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
101
+ a?.key ?? "vertical"
102
+ }_${key}`,
103
+ label: a?.label ?? label,
104
+ initial_value: a.initial_value,
105
+ ...conditional_vertical_type,
106
+ },
107
+ {
108
+ type,
109
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
110
+ b.key ?? "horizontal"
111
+ }_${key}`,
112
+ label: b?.label ?? label,
113
+ initial_value: b.initial_value,
114
+ ...conditional_horizontal_type,
115
+ },
116
+ ];
117
+ };
118
+
119
+ module.exports = {
120
+ generateFontConfiguration,
121
+ createVariationFields,
122
+ createConditionalConfig,
123
+ conditional_rule,
124
+ conditional_horizontal_type,
125
+ conditional_vertical_type,
126
+ conditional_horizontal_type_item_fixed,
127
+ conditional_horizontal_type_item_dynamic,
128
+ conditional_horizontal_display_type_fixed,
129
+ conditional_horizontal_asset_on,
130
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-rc.45",
3
+ "version": "13.0.0-rc.46",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,9 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-rc.45",
31
+ "@applicaster/applicaster-types": "13.0.0-rc.46",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
- "create-react-context": "^0.2.3",
35
34
  "dayjs": "^1.11.10",
36
35
  "memoizee": "0.4.15",
37
36
  "prop-types": "^15.0.0",
@@ -41,8 +40,8 @@
41
40
  "@applicaster/zapp-pipes-v2-client": "*",
42
41
  "@react-native-community/netinfo": "*",
43
42
  "immer": "*",
44
- "react": "17.0.2",
45
- "react-native": "0.68.6",
43
+ "react": "*",
44
+ "react-native": "*",
46
45
  "uglify-js": "*",
47
46
  "validate-color": "*",
48
47
  "zustand": "*"
@@ -1,3 +1,5 @@
1
+ import { createContext } from "../";
2
+
1
3
  jest.mock("react", () => ({
2
4
  ...jest.requireActual("react"),
3
5
  createContext: jest.fn(() => ({
@@ -6,8 +8,6 @@ jest.mock("react", () => ({
6
8
  })),
7
9
  }));
8
10
 
9
- const { createContext } = require("../index");
10
-
11
11
  const mockedProvider = jest.fn();
12
12
  const mockedWithConsumer = jest.fn();
13
13
  const mockedWithProvider = jest.fn();
@@ -33,7 +33,12 @@ export const getSetterName: (property: string) => string = R.compose(
33
33
  export function createContextSetters(
34
34
  properties: string[],
35
35
  component: any,
36
- options: any = {}
36
+ options: {
37
+ stateValidator?: (
38
+ obj: { property: string; value: unknown },
39
+ oldValue: unknown
40
+ ) => boolean;
41
+ } = {}
37
42
  ) {
38
43
  const { stateValidator = R.T } = options;
39
44
 
@@ -1,5 +1,4 @@
1
1
  import * as React from "react";
2
- import createReactContext from "create-react-context";
3
2
  import * as R from "ramda";
4
3
 
5
4
  import { getSetterName, NOOP } from "./helpers";
@@ -7,33 +6,20 @@ import { createProvider } from "./provider";
7
6
  import { createWithConsumerDecorator } from "./withConsumer";
8
7
  import { createWithProviderDecorator } from "./withProvider";
9
8
 
10
- const reactContextCreator = React.createContext;
11
-
12
- // Depending on the version of React used, the `createContext` function may not be available
13
- // if this is the case, we fall back to a polyfill library
14
- const contextCreatorFn =
15
- reactContextCreator && typeof reactContextCreator === "function"
16
- ? reactContextCreator
17
- : createReactContext;
18
-
19
- /**
20
- * @typedef Context
21
- * @property {Object} Context.Provider react class component to use as context provider
22
- * @property {Function} Context.Consumer react functional component to use as context consumer
23
- * @property {Function} Context.withProvider HOC to apply the context provider
24
- * @property {function} Context.withConsumer HOC to apply the context consumer. passes the context as props
25
- * @property {React.Context} Context.ReactContext React context object
26
- * to the wrapped component
27
- */
28
-
29
9
  /**
30
10
  * Creates a React Context and returns consumer & providers components & decorators to interact
31
11
  * with this context.
32
- * @param {Object} initialContext map of context properties and their initial values
33
- * @param {Function} stateValidator optional predicate to tell whether the state update is valid or not
34
- * @returns {Context} Object containing the context components & decorators {@link Context}
12
+ * @param initialContext map of context properties and their initial values
13
+ * @param stateValidator optional predicate to tell whether the state update is valid or not
14
+ * @returns Object containing the context components & decorators
35
15
  */
36
- export function createContext(initialContext, stateValidator = R.T) {
16
+ export function createContext(
17
+ initialContext: Record<string, any>,
18
+ stateValidator: (
19
+ obj: { property: string; value: unknown },
20
+ oldValue: unknown
21
+ ) => boolean = R.T
22
+ ) {
37
23
  // first we extract the properties name, and create setters name for those
38
24
  const contextPropertiesNames = R.keys(initialContext);
39
25
  const contextSettersNames = R.map(getSetterName, contextPropertiesNames);
@@ -41,7 +27,7 @@ export function createContext(initialContext, stateValidator = R.T) {
41
27
  // we create a React Context with the properties & their setters, assigning a noop function
42
28
  // temporarily (will be overriden by proper setters in the provider component)
43
29
  const ReactContext = R.compose(
44
- contextCreatorFn,
30
+ React.createContext,
45
31
  R.merge(initialContext),
46
32
  R.zipObj(contextSettersNames),
47
33
  R.map(R.always(NOOP))
@@ -1,27 +0,0 @@
1
- jest.mock("create-react-context", () =>
2
- jest.fn(() => ({
3
- Consumer: jest.fn(),
4
- Provider: jest.fn(),
5
- }))
6
- );
7
-
8
- jest.mock("react", () => ({
9
- ...jest.requireActual("react"),
10
- createContext: undefined,
11
- }));
12
-
13
- const { createContext } = require("../index");
14
- const createReactContext = require("create-react-context");
15
-
16
- describe("when react context api is not defined", () => {
17
- it("uses the polyfill", () => {
18
- createContext({ foo: "bar" });
19
-
20
- expect(createReactContext).toHaveBeenCalledWith(
21
- expect.objectContaining({
22
- foo: "bar",
23
- setFoo: expect.any(Function),
24
- })
25
- );
26
- });
27
- });