@sleeperhq/mini-core 1.3.4 → 1.4.0

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/bin/build_mini.js CHANGED
@@ -47,7 +47,8 @@ const getCommands = (projectName) => {
47
47
  --bundle-output "${bundleOutputPath[platform]}" \
48
48
  --sourcemap-output "${sourcemapOutputPath[platform]}" \
49
49
  --minify false \
50
- --assets-dest "${assetsDestPath[platform]}"`;
50
+ --assets-dest "${assetsDestPath[platform]}" \
51
+ --webpackConfig ./node_modules/@sleeperhq/mini-core/webpack.config.js`;
51
52
  };
52
53
 
53
54
  // Exposed
@@ -1,5 +1,6 @@
1
- import { NavigationTabId } from './types';
2
- export type SleeperActions = {
3
- navigate: (navTabType: NavigationTabId, args?: any) => void;
4
- requestLocation: () => void;
5
- };
1
+ import { NavigationTabId, ToastConfig } from './types';
2
+ export type SleeperActions = {
3
+ navigate: (navTabType: NavigationTabId, args?: any) => void;
4
+ requestLocation: () => void;
5
+ showToast: (toastData: ToastConfig) => void;
6
+ };
@@ -0,0 +1,3 @@
1
+ import { AppIconSwitch } from '../types/components/ui_2/app_icon_switch';
2
+ export type { SwitchOption, Props as SwitchProps } from '../types/components/ui_2/app_icon_switch';
3
+ export default AppIconSwitch;
@@ -0,0 +1,18 @@
1
+ import { StyleProp, ViewStyle } from 'react-native';
2
+ export type SwitchOption = {
3
+ colorToggleActive: string;
4
+ colorIconActive: string;
5
+ colorIconInactive: string;
6
+ iconStyle?: any;
7
+ icon: any;
8
+ };
9
+ export type Props = {
10
+ options: [SwitchOption, SwitchOption];
11
+ value?: number;
12
+ onChange?: (value: number) => void;
13
+ height?: number;
14
+ width?: number;
15
+ containerStyle?: StyleProp<ViewStyle>;
16
+ toggleStyle?: StyleProp<ViewStyle>;
17
+ };
18
+ export declare const AppIconSwitch: any;
@@ -1,4 +1,5 @@
1
1
  import { League, Roster, User, MatchupLeg, LeagueTransaction, Draft, DraftPick, RosterDraftPick, Player, Topic } from './shared/graphql.d';
2
+ import type { ToastConfig as ToastConfigOriginal } from './utils/toast_helper';
2
3
  export type NavigationTabId = 'LeaguesIndexScreen' | 'LeaguesDetailScreen' | 'ScoreIndexScreen' | 'ScoreDetailScreen' | 'PicksIndexScreen' | 'FeedIndexScreen' | 'WebviewScreen' | 'ManageChannelsScreen' | 'InboxIndexScreen' | 'MinisIndexScreen' | 'ManageChannelsScreen' | 'InboxIndexScreen' | 'MinisIndexScreen';
3
4
  export * from './shared/graphql.d';
4
5
  export type LeagueId = string;
@@ -77,3 +78,6 @@ export type Location = {
77
78
  hasPermission: 'pending' | 'yes' | 'no';
78
79
  };
79
80
  export type VersionMap = Record<string, Mini>;
81
+ export type ToastConfig = Omit<ToastConfigOriginal, 'icon'> & {
82
+ icon?: 'success' | 'error';
83
+ };
@@ -0,0 +1,9 @@
1
+ import { TextStyle, ViewStyle } from 'react-native';
2
+ export type ToastConfig = {
3
+ text: string;
4
+ icon?: string;
5
+ time?: number;
6
+ style?: ViewStyle;
7
+ slideTop?: boolean;
8
+ textStyle?: TextStyle;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -33,37 +33,43 @@
33
33
  "registry": "https://registry.npmjs.org/",
34
34
  "access": "public"
35
35
  },
36
- "peerDependencies": {
36
+ "dependencies": {
37
37
  "@callstack/repack": "blitzstudios/repack.git#callstack-repack-v2.6.3-gitpkg",
38
+ "@callstack/repack-dev-server": "blitzstudios/repack.git#callstack-repack-dev-server-v1.0.7-gitpkg",
39
+ "@react-native-community/cli": "6.4.0",
40
+ "@react-native-community/cli-types": "6.0.0",
38
41
  "@react-native-community/netinfo": "9.3.7",
39
42
  "axios": "0.15.3",
40
- "lodash": "4.17.21",
43
+ "babel-loader": "^8.2.5",
44
+ "react-native-fast-image": "8.5.11",
45
+ "react-native-interactable": "0.1.10",
46
+ "react-native-linear-gradient": "2.5.6",
47
+ "react-native-rename": "^3.2.12",
48
+ "react-refresh": "0.8.3",
49
+ "react-test-renderer": "17.0.2",
50
+ "terser-webpack-plugin": "^5.3.3",
51
+ "webpack": "^5.73.0"
52
+ },
53
+ "peerDependencies": {
41
54
  "react": "17.0.2",
42
55
  "react-native": "0.66.5",
43
- "react-native-linear-gradient": "2.5.6",
44
- "react-native-rename": "3.2.12",
45
- "react-native-svg": "13.7.0",
46
- "react-native-tcp-socket": "6.0.6",
47
- "react-native-webview": "11.23.1"
56
+ "react-native-svg": "13.7.0"
48
57
  },
49
58
  "devDependencies": {
50
59
  "@babel/core": "^7.12.9",
51
60
  "@babel/preset-typescript": "^7.16.7",
52
61
  "@babel/runtime": "^7.12.5",
53
62
  "@react-native-community/eslint-config": "^2.0.0",
54
- "@types/lodash": "^4.14.182",
55
- "@types/react-native": "0.66.5",
63
+ "@types/react-native": "0.67.7",
56
64
  "@typescript-eslint/eslint-plugin": "^5.31.0",
57
65
  "@typescript-eslint/parser": "^5.31.0",
58
66
  "babel-jest": "^26.6.3",
59
- "babel-loader": "^8.2.5",
60
67
  "eslint": "7.14.0",
61
68
  "jest": "^26.6.3",
69
+ "lodash": "4.17.21",
62
70
  "metro-react-native-babel-preset": "^0.66.2",
63
- "react-test-renderer": "17.0.2",
64
- "terser-webpack-plugin": "^5.3.3",
65
- "typescript": "^4.7.2",
66
- "webpack": "^5.73.0"
71
+ "react-native-tcp-socket": "6.0.6",
72
+ "typescript": "^4.7.2"
67
73
  },
68
74
  "resolutions": {
69
75
  "react-devtools-core": "~4.25.0",
@@ -3,6 +3,7 @@ import {TextProps, View} from 'react-native';
3
3
  import {Federated} from '@callstack/repack/client';
4
4
  import type {ButtonProps} from '../../declarations/button';
5
5
  import type {JerseyProps} from '../../declarations/jersey';
6
+ import type {SwitchProps} from '../../declarations/switch';
6
7
 
7
8
  const _SleeperModule = React.lazy(() =>
8
9
  Federated.importModule('sleeper', 'index').catch(() => ({
@@ -31,6 +32,14 @@ const Text = (props: TextProps) => {
31
32
  );
32
33
  };
33
34
 
35
+ const Switch = (props: SwitchProps) => {
36
+ return (
37
+ <React.Suspense fallback={<View />}>
38
+ <_SleeperModule component="Switch" {...props} />
39
+ </React.Suspense>
40
+ );
41
+ };
42
+
34
43
  const Jersey = (props: JerseyProps) => {
35
44
  return (
36
45
  <React.Suspense fallback={<View />}>
@@ -39,5 +48,5 @@ const Jersey = (props: JerseyProps) => {
39
48
  );
40
49
  };
41
50
 
42
- export type {ButtonProps, TextProps, JerseyProps};
43
- export {Button, Text, Jersey};
51
+ export type {ButtonProps, TextProps, JerseyProps, SwitchProps};
52
+ export {Button, Text, Jersey, Switch};
@@ -251,7 +251,7 @@ const DevServer = props => {
251
251
  let isInitialized = !!_dataRef.current?.dist;
252
252
 
253
253
  // Non-staging builds also require a version map to be defined.
254
- if (!_dataRef.current?.isStaging) {
254
+ if (!_dataRef.current?.isStaging && !config.dev) {
255
255
  isInitialized = !!_versionMap.current;
256
256
  }
257
257
 
@@ -0,0 +1,307 @@
1
+ const path = require('path');
2
+ const TerserPlugin = require('../../../node_modules/terser-webpack-plugin');
3
+ const Repack = require('../../../node_modules/@callstack/repack');
4
+ const config = require('../../../app.json');
5
+ const {dependencies} = require('../../../package.json');
6
+
7
+ const sharedDeps = Object.keys(dependencies).reduce((acc, key) => {
8
+ acc[key] = {singleton: true, eager: true, requiredVersion: dependencies[key]};
9
+ return acc;
10
+ }, {});
11
+
12
+ const {samples, selectedSample} = config;
13
+ const sampleClassPath = `../../../src/${samples[selectedSample]}`;
14
+ const sampleClassPathLocal = `./src/${samples[selectedSample]}`
15
+
16
+ /**
17
+ * More documentation, installation, usage, motivation and differences with Metro is available at:
18
+ * https://github.com/callstack/repack/blob/main/README.md
19
+ *
20
+ * The API documentation for the functions and plugins used in this file is available at:
21
+ * https://re-pack.netlify.app/
22
+ */
23
+
24
+ /**
25
+ * Webpack configuration.
26
+ * You can also export a static object or a function returning a Promise.
27
+ *
28
+ * @param env Environment options passed from either Webpack CLI or React Native CLI
29
+ * when running with `react-native start/bundle`.
30
+ */
31
+ module.exports = env => {
32
+ const {
33
+ mode = 'development',
34
+ context = __dirname,
35
+ entry = './index.tsx',
36
+ platform,
37
+ minimize = mode === 'production',
38
+ devServer = undefined,
39
+ bundleFilename = undefined,
40
+ sourceMapFilename = undefined,
41
+ assetsPath = undefined,
42
+ reactNativePath = require.resolve('react-native'),
43
+ } = env;
44
+
45
+ if (!platform) {
46
+ throw new Error('Missing platform');
47
+ }
48
+
49
+ const dev = mode === 'development';
50
+
51
+ /**
52
+ * Using Module Federation might require disabling hmr.
53
+ * Uncomment below to set `devServer.hmr` to `false`.
54
+ *
55
+ * Keep in mind that `devServer` object is not available
56
+ * when running `webpack-bundle` command. Be sure
57
+ * to check its value to avoid accessing undefined value,
58
+ * otherwise an error might occur.
59
+ */
60
+ // if (devServer) {
61
+ // devServer.hmr = false;
62
+ // }
63
+
64
+ /**
65
+ * Depending on your Babel configuration you might want to keep it.
66
+ * If you don't use `env` in your Babel config, you can remove it.
67
+ *
68
+ * Keep in mind that if you remove it you should set `BABEL_ENV` or `NODE_ENV`
69
+ * to `development` or `production`. Otherwise your production code might be compiled with
70
+ * in development mode by Babel.
71
+ */
72
+ process.env.BABEL_ENV = mode;
73
+
74
+ return {
75
+ mode,
76
+ /**
77
+ * This should be always `false`, since the Source Map configuration is done
78
+ * by `SourceMapDevToolPlugin`.
79
+ */
80
+ devtool: false,
81
+ context,
82
+ /**
83
+ * `getInitializationEntries` will return necessary entries with setup and initialization code.
84
+ * If you don't want to use Hot Module Replacement, set `hmr` option to `false`. By default,
85
+ * HMR will be enabled in development mode.
86
+ */
87
+ entry: [
88
+ ...Repack.getInitializationEntries(reactNativePath, {
89
+ hmr: devServer && devServer.hmr,
90
+ }),
91
+ entry,
92
+ ],
93
+ resolve: {
94
+ /**
95
+ * `getResolveOptions` returns additional resolution configuration for React Native.
96
+ * If it's removed, you won't be able to use `<file>.<platform>.<ext>` (eg: `file.ios.js`)
97
+ * convention and some 3rd-party libraries that specify `react-native` field
98
+ * in their `package.json` might not work correctly.
99
+ */
100
+ ...Repack.getResolveOptions(platform),
101
+
102
+ /**
103
+ * Uncomment this to ensure all `react-native*` imports will resolve to the same React Native
104
+ * dependency. You might need it when using workspaces/monorepos or unconventional project
105
+ * structure. For simple/typical project you won't need it.
106
+ */
107
+ // alias: {
108
+ // 'react-native': reactNativePath,
109
+ // },
110
+ alias: {
111
+ app: path.resolve(__dirname, sampleClassPath),
112
+ },
113
+ },
114
+ /**
115
+ * Configures output.
116
+ * It's recommended to leave it as it is unless you know what you're doing.
117
+ * By default Webpack will emit files into the directory specified under `path`. In order for the
118
+ * React Native app use them when bundling the `.ipa`/`.apk`, they need to be copied over with
119
+ * `Repack.OutputPlugin`, which is configured by default inside `Repack.RepackPlugin`.
120
+ */
121
+ output: {
122
+ clean: true,
123
+ path: path.join(__dirname, '..', '..', '..', 'build', platform),
124
+ filename: dev
125
+ ? 'index.bundle'
126
+ : platform === 'android'
127
+ ? 'index.android.bundle'
128
+ : 'index.ios.bundle',
129
+ chunkFilename: '[name].chunk.bundle',
130
+ publicPath: Repack.getPublicPath({platform, devServer}),
131
+ },
132
+ /**
133
+ * Configures optimization of the built bundle.
134
+ */
135
+ optimization: {
136
+ /** Enables minification based on values passed from React Native CLI or from fallback. */
137
+ minimize,
138
+ /** Configure minimizer to process the bundle. */
139
+ minimizer: [
140
+ new TerserPlugin({
141
+ test: /\.(js)?bundle(\?.*)?$/i,
142
+ /**
143
+ * Prevents emitting text file with comments, licenses etc.
144
+ * If you want to gather in-file licenses, feel free to remove this line or configure it
145
+ * differently.
146
+ */
147
+ extractComments: false,
148
+ terserOptions: {
149
+ format: {
150
+ comments: false,
151
+ },
152
+ },
153
+ }),
154
+ ],
155
+ chunkIds: 'named',
156
+ },
157
+ module: {
158
+ /**
159
+ * This rule will process all React Native related dependencies with Babel.
160
+ * If you have a 3rd-party dependency that you need to transpile, you can add it to the
161
+ * `include` list.
162
+ *
163
+ * You can also enable persistent caching with `cacheDirectory` - please refer to:
164
+ * https://github.com/babel/babel-loader#options
165
+ */
166
+ rules: [
167
+ {
168
+ test: /\.[jt]sx?$/,
169
+ include: [
170
+ /node_modules(.*[/\\])+react/,
171
+ /node_modules(.*[/\\])+@react-native/,
172
+ /node_modules(.*[/\\])+@react-navigation/,
173
+ /node_modules(.*[/\\])+@react-native-community/,
174
+ /node_modules(.*[/\\])+@expo/,
175
+ /node_modules(.*[/\\])+pretty-format/,
176
+ /node_modules(.*[/\\])+metro/,
177
+ /node_modules(.*[/\\])+he/,
178
+ /node_modules(.*[/\\])+abort-controller/,
179
+ /node_modules(.*[/\\])+@callstack\/repack/,
180
+ /node_modules(.*[/\\])+@sleeperhq\/mini-core/,
181
+ ],
182
+ use: {
183
+ loader: 'babel-loader',
184
+ options: {
185
+ presets: [
186
+ 'module:metro-react-native-babel-preset',
187
+ '@babel/preset-typescript',
188
+ ],
189
+ babelrc: false,
190
+ cacheDirectory: true,
191
+ },
192
+ },
193
+ },
194
+ /**
195
+ * Here you can adjust loader that will process your files.
196
+ *
197
+ * You can also enable persistent caching with `cacheDirectory` - please refer to:
198
+ * https://github.com/babel/babel-loader#options
199
+ */
200
+ {
201
+ test: /\.[jt]sx?$/,
202
+ exclude: /node_modules/,
203
+ use: {
204
+ loader: 'babel-loader',
205
+ options: {
206
+ presets: [
207
+ 'module:metro-react-native-babel-preset',
208
+ '@babel/preset-typescript',
209
+ ],
210
+ // sourceType: "unambiguous",
211
+ /** Add React Refresh transform only when HMR is enabled. */
212
+ plugins:
213
+ devServer && devServer.hmr
214
+ ? ['module:react-refresh/babel']
215
+ : undefined,
216
+ babelrc: false,
217
+ comments: true, // necessary for named chunks
218
+ cacheDirectory: true,
219
+ },
220
+ },
221
+ },
222
+ /**
223
+ * This loader handles all static assets (images, video, audio and others), so that you can
224
+ * use (reference) them inside your application.
225
+ *
226
+ * If you wan to handle specific asset type manually, filter out the extension
227
+ * from `ASSET_EXTENSIONS`, for example:
228
+ * ```
229
+ * Repack.ASSET_EXTENSIONS.filter((ext) => ext !== 'svg')
230
+ * ```
231
+ */
232
+ {
233
+ test: Repack.getAssetExtensionsRegExp(Repack.SCALABLE_ASSETS),
234
+ use: {
235
+ loader: '@callstack/repack/assets-loader',
236
+ options: {
237
+ // In order to support single file bundle uploads through our submission process,
238
+ // we need to encode image dependencies directly into the main bundle file as base64.
239
+ inline: true,
240
+ platform,
241
+ devServerEnabled: Boolean(devServer),
242
+ scalableAssetExtensions: Repack.SCALABLE_ASSETS,
243
+ },
244
+ },
245
+ },
246
+ {
247
+ test: Repack.getAssetExtensionsRegExp(Repack.NON_SCALABLE_ASSETS),
248
+ use: {
249
+ loader: '@callstack/repack/assets-loader',
250
+ options: {
251
+ inline: false, // all other assets must be uploaded separately, as they cannot be inlined.
252
+ platform,
253
+ devServerEnabled: Boolean(devServer),
254
+ scalableAssetExtensions: Repack.SCALABLE_ASSETS,
255
+ },
256
+ },
257
+ },
258
+ ],
259
+ },
260
+ plugins: [
261
+ /**
262
+ * Configure other required and additional plugins to make the bundle
263
+ * work in React Native and provide good development experience with
264
+ * sensible defaults.
265
+ *
266
+ * `Repack.RepackPlugin` provides some degree of customization, but if you
267
+ * need more control, you can replace `Repack.RepackPlugin` with plugins
268
+ * from `Repack.plugins`.
269
+ */
270
+ new Repack.RepackPlugin({
271
+ context,
272
+ mode,
273
+ platform,
274
+ devServer,
275
+ output: {
276
+ bundleFilename,
277
+ sourceMapFilename,
278
+ assetsPath,
279
+ },
280
+ extraChunks: [
281
+ {
282
+ include: new RegExp('.*'),
283
+ type: 'remote',
284
+ outputPath: path.join(__dirname, '..', '..', '..', 'dist', config.name, platform),
285
+ },
286
+ ],
287
+ listenerIP: config.remoteIP,
288
+ }),
289
+
290
+ new Repack.plugins.ModuleFederationPlugin({
291
+ name: config.name,
292
+ exposes: {
293
+ app: sampleClassPathLocal,
294
+ },
295
+ shared: {
296
+ // Adding this here fixes the named chunks problem.
297
+ // It also makes sure any third party javascript packages are included in the container,
298
+ // not exported to a separate chunk.
299
+ // The only separate chunk is the exposed stuff.
300
+ ...sharedDeps,
301
+ // if we don't do the above, then instead each package that is not included in this list will
302
+ // split off into a seperate chunk, and named chunks will break (assume that's a bug that we can fix).
303
+ },
304
+ }),
305
+ ],
306
+ };
307
+ };
@@ -1,31 +0,0 @@
1
- export declare const NAVIGATION_TYPE: {
2
- readonly DM: "DM";
3
- readonly INBOX: "INBOX";
4
- readonly MY_FEED: "MY_FEED";
5
- readonly FRIENDS: "FRIENDS";
6
- readonly LEAGUE: "LEAGUE";
7
- readonly ASYNC_SPORT: "ASYNC_SPORT";
8
- readonly CREATE_LEAGUE: "CREATE_LEAGUE";
9
- readonly LEAGUE_SYNC: "LEAGUE_SYNC";
10
- readonly DRAFTBOARDS: "DRAFTBOARDS";
11
- readonly SOLO_OVER_UNDER: "SOLO_OVER_UNDER";
12
- readonly CHANNEL: "CHANNEL";
13
- readonly MANAGE_CHANNELS: "MANAGE_CHANNELS";
14
- };
15
- export declare const NAVIGATION_ID: {
16
- readonly DRAFTBOARDS: 1;
17
- readonly CREATE_DM: 2;
18
- readonly DM_SCREEN: 3;
19
- readonly CREATE_LEAGUE: 4;
20
- readonly MY_FEED: 5;
21
- readonly MENTIONS: 6;
22
- readonly FRIENDS: 7;
23
- };
24
- export declare const NAVIGATION_TAB_ID: {
25
- readonly FantasyTab: "FantasyTab";
26
- readonly ScoresTab: "ScoresTab";
27
- readonly GamesTab: "GamesTab";
28
- readonly FeedTab: "FeedTab";
29
- readonly InboxTab: "InboxTab";
30
- readonly MinisTab: "MinisTab";
31
- };