@bigbinary/neeto-commons-frontend 2.0.36 → 2.0.38

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/README.md CHANGED
@@ -47,6 +47,9 @@ Category
47
47
  - [useLocalStorage](./docs/react/hooks.md#uselocalstorage)
48
48
  - [useOnClickOutside](./docs/react/hooks.md#useonclickoutside)
49
49
  - [useFieldSubmit](./docs/react/hooks.md#usefieldsubmit)
50
+ - [useDisplayErrorPage](./docs/react/hooks.md#usedisplayerrorpage)
51
+ - [useErrorDisplayStore](./docs/react/hooks.md#useerrordisplaystore)
52
+ - [useHotKeys](./docs/react/hooks.md#useHotKeys)
50
53
  - [PrivateRoute](./docs/react/components.md#privateroute)
51
54
  - [HoneybadgerErrorBoundary](./docs/react/components.md#honeybadgererrorboundary)
52
55
  - [Sidebar](./docs/react/components.md#sidebar)
@@ -60,11 +63,13 @@ Category
60
63
  - [BrowserSupport](./docs/react/components.md#browsersupport)
61
64
  - [IpRestriction](./docs/react/components.md#iprestriction)
62
65
  - [PublishBlock](./docs/react/components.md#publishblock)
66
+ - [KeyboardShortcutsPane](./docs/react/components.md#keyboardshortcutspane)
63
67
  - [withImmutableActions](./docs/react/utils.md#withimmutableactions)
64
68
  - [withTitle](./docs/react/utils.md#withtitle)
65
69
  - [registerBrowserNotifications](./docs/react/utils.md#registerbrowsernotifications)
66
70
  - [destroyBrowserSubscription](./docs/react/utils.md#destroybrowsersubscription)
67
71
  - [handleMetaClick](./docs/react/utils.md#handlemetaclick)
72
+ - [isMetaKeyPressed](./docs/react/utils.md#ismetakeypressed)
68
73
 
69
74
  </td>
70
75
  <td style="vertical-align: top;">
package/configs/babel.js CHANGED
@@ -33,6 +33,7 @@ module.exports = function (api) {
33
33
  isTestEnv
34
34
  ? "babel-plugin-dynamic-import-node" // tests run in node environment
35
35
  : "@babel/plugin-syntax-dynamic-import",
36
+ ["istanbul", { useInlineSourceMaps: false }],
36
37
  isProductionEnv && [
37
38
  "babel-plugin-transform-react-remove-prop-types",
38
39
  { removeImport: true },
@@ -1,62 +1,78 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
 
4
- const { mergeDeepLeft } = require("ramda");
4
+ const { mergeDeepLeft, mergeLeft, keys } = require("ramda");
5
5
 
6
6
  const loadJS = jsPath => {
7
7
  try {
8
- return require(path.resolve(__dirname, "../../../..", jsPath));
8
+ return require(jsPath);
9
9
  } catch {
10
10
  return {};
11
11
  }
12
12
  };
13
13
 
14
- const buildPathGroupsBasedOnWebpackAliases = ({
15
- customJSRoot = "app/javascript/",
16
- customAliasPath = "config/webpack/resolve.js",
17
- }) => {
18
- const rootOfProject = `${__dirname}/../../../../../../`;
14
+ const doesFileExist = filePath =>
15
+ fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();
16
+
17
+ const generateAllPathsInsideDir = dirPath => {
18
+ const files = fs.readdirSync(dirPath, { withFileTypes: true });
19
19
 
20
- const isFile = filePath =>
21
- fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();
20
+ return files.flatMap(file => {
21
+ const filePath = path.join(dirPath, file.name);
22
22
 
23
- const isRailsProject = isFile(`${rootOfProject}Gemfile`);
23
+ return file.isDirectory() ? generateAllPathsInsideDir(filePath) : filePath;
24
+ });
25
+ };
24
26
 
25
- const emptyPathGroups = [];
27
+ const generatePathGroupsFromAssets = assetsPath => {
28
+ if (!fs.existsSync(assetsPath)) return [];
26
29
 
27
- if (!isRailsProject) return emptyPathGroups;
30
+ return generateAllPathsInsideDir(assetsPath).map(absPath => ({
31
+ pattern: absPath.replace(assetsPath, "").split(".")[0],
32
+ group: "internal",
33
+ }));
34
+ };
28
35
 
29
- const projectResolve = loadJS(rootOfProject + customAliasPath);
36
+ const buildPathGroupsBasedOnWebpackAliases = ({
37
+ customAliasPath = "config/webpack/resolve.js",
38
+ }) => {
39
+ const rootOfProject = path.join(__dirname, "../../../../../../");
40
+ const projectResolve = loadJS(path.join(rootOfProject, customAliasPath));
30
41
  const commonResolve = loadJS(
31
- `${rootOfProject}node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js`
42
+ path.join(
43
+ rootOfProject,
44
+ "node_modules/@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js"
45
+ )
32
46
  );
33
- const { alias } = mergeDeepLeft(projectResolve, commonResolve);
34
-
35
- const railsJSFilesRoot = rootOfProject + customJSRoot;
36
-
37
- const pathGroups = Object.entries(alias).map(([name, path]) => {
38
- // sometimes alias might be already resolved to full absolute path
39
- const isAlreadyAnAbsolutePath =
40
- path.includes("cypress-tests/") || path.includes("app/");
41
47
 
42
- const absolutePath = isAlreadyAnAbsolutePath
43
- ? path
44
- : `${railsJSFilesRoot}${path}`;
48
+ const { dependencies = [], devDependencies = [] } = loadJS(
49
+ path.join(rootOfProject, "package.json")
50
+ );
51
+ const packages = keys(mergeLeft(dependencies, devDependencies));
52
+ const { alias = {}, extensions = [] } = mergeDeepLeft(
53
+ projectResolve,
54
+ commonResolve
55
+ );
45
56
 
46
- const wildCard =
47
- isFile(`${absolutePath}.js`) || isFile(`${absolutePath}.jsx`)
48
- ? ""
49
- : "/**";
57
+ const pathGroups = Object.entries(alias).flatMap(([pattern, aliasPath]) => {
58
+ const group = packages.includes(aliasPath) ? "external" : "internal";
59
+ const isFile = ["", ...extensions].some(extension =>
60
+ doesFileExist(`${aliasPath}${extension}`)
61
+ );
50
62
 
51
- let group = "internal";
52
- if (name === "neetoui") {
53
- group = "external";
54
- }
63
+ if (isFile) return { pattern, group };
55
64
 
56
- return { pattern: `${name}${wildCard}`, group };
65
+ return [
66
+ { pattern, group },
67
+ { pattern: `${pattern}/**`, group },
68
+ ];
57
69
  });
58
70
 
59
- return pathGroups;
71
+ const pathGroupsFromAssets = generatePathGroupsFromAssets(
72
+ path.join(rootOfProject, "app/assets/")
73
+ );
74
+
75
+ return pathGroups.concat(pathGroupsFromAssets);
60
76
  };
61
77
 
62
78
  module.exports = { buildPathGroupsBasedOnWebpackAliases };
@@ -0,0 +1,49 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const { mergeDeepLeft, mergeLeft, keys } = require("ramda");
5
+
6
+ const rootOfTheProject = path.join(__dirname, "../../../../../../../");
7
+
8
+ const loadJS = jsPath => {
9
+ try {
10
+ return require(path.join(rootOfTheProject, jsPath));
11
+ } catch {
12
+ return {};
13
+ }
14
+ };
15
+
16
+ const doesFileExist = filePath =>
17
+ fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();
18
+
19
+ const buildPathGroupsBasedOnWebpackAliases = ({
20
+ customAliasPath = "resolve.js",
21
+ }) => {
22
+ const projectResolve = loadJS(customAliasPath);
23
+ const commonResolve = loadJS(
24
+ "node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/webpack/resolve.js"
25
+ );
26
+
27
+ const { dependencies = [], devDependencies = [] } = loadJS("package.json");
28
+ const packages = keys(mergeLeft(dependencies, devDependencies));
29
+ const { alias = {}, extensions = [] } = mergeDeepLeft(
30
+ projectResolve,
31
+ commonResolve
32
+ );
33
+
34
+ return Object.entries(alias).flatMap(([pattern, aliasPath]) => {
35
+ const group = packages.includes(aliasPath) ? "external" : "internal";
36
+ const isFile = ["", ...extensions].some(extension =>
37
+ doesFileExist(`${aliasPath}${extension}`)
38
+ );
39
+
40
+ if (isFile) return { pattern, group };
41
+
42
+ return [
43
+ { pattern, group },
44
+ { pattern: `${pattern}/**`, group },
45
+ ];
46
+ });
47
+ };
48
+
49
+ module.exports = { buildPathGroupsBasedOnWebpackAliases };
@@ -0,0 +1,18 @@
1
+ const { assocPath } = require("ramda");
2
+
3
+ const commonConfig = require("../../../eslint/imports/order");
4
+ const { buildPathGroupsBasedOnWebpackAliases } = require("../helpers");
5
+
6
+ const pathGroups = buildPathGroupsBasedOnWebpackAliases({});
7
+ const pathGroupForKeepingReactImportsAtTop = {
8
+ pattern: "react+(-native|)",
9
+ group: "external",
10
+ position: "before",
11
+ };
12
+ pathGroups.push(pathGroupForKeepingReactImportsAtTop);
13
+
14
+ module.exports = assocPath(
15
+ ["rules", "import/order", 1, "pathGroups"],
16
+ pathGroups,
17
+ commonConfig
18
+ );
@@ -0,0 +1,23 @@
1
+ const { mergeLeft } = require("ramda");
2
+
3
+ const commonConfiguration = require("../../eslint");
4
+
5
+ const nanosConfiguration = {
6
+ extends: [
7
+ "plugin:@bigbinary/neeto/recommended",
8
+ "plugin:cypress/recommended",
9
+ "plugin:json/recommended",
10
+ "eslint:recommended",
11
+ "plugin:react/recommended",
12
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/globals",
13
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/eslint/imports/order",
14
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/overrides",
15
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/enforced",
16
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/react",
17
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/promise",
18
+ "./node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/eslint/neeto",
19
+ "prettier",
20
+ ],
21
+ };
22
+
23
+ module.exports = mergeLeft(nanosConfiguration, commonConfiguration);
@@ -0,0 +1,92 @@
1
+ const path = require("path");
2
+
3
+ const { mergeDeepLeft } = require("ramda");
4
+
5
+ const rootOfTheProject = path.join(__dirname, "../../../../../../");
6
+ const pathToTranslationFile = "src/translations/en.json";
7
+ const pathToResolveFile = "resolve.js";
8
+ const pathToJsConfigFile = "jsconfig.json";
9
+
10
+ const loadJS = jsPath => {
11
+ try {
12
+ return require(path.join(rootOfTheProject, jsPath));
13
+ } catch {
14
+ return {};
15
+ }
16
+ };
17
+
18
+ const commonResolve = loadJS(
19
+ "node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/webpack/resolve.js"
20
+ );
21
+ const projectResolve = loadJS(pathToResolveFile);
22
+ const en = loadJS(pathToTranslationFile);
23
+ const resolve = mergeDeepLeft(projectResolve, commonResolve);
24
+
25
+ module.exports = {
26
+ rules: {
27
+ "@bigbinary/neeto/file-name-and-export-name-standards": [
28
+ "warn",
29
+ {
30
+ basePath: path.join(rootOfTheProject, "src"),
31
+ default: {
32
+ filenameCase: "camelCase",
33
+ exportnameCase: "camelCase",
34
+ },
35
+ configs: [
36
+ {
37
+ filenameCase: "camelCase",
38
+ exportnameCase: "CONSTANT_CASE",
39
+ includes: ["/**/constants.{js,jsx}", "/**/constants/**"],
40
+ },
41
+ {
42
+ filenameCase: "camelCase",
43
+ includes: ["/**/utils.{js,jsx}", "/**/utils/**"],
44
+ },
45
+ {
46
+ filenameCase: "snake_case",
47
+ exportnameCase: "camelCase",
48
+ includes: "/apis/**",
49
+ },
50
+ {
51
+ filenameCase: "camelCase",
52
+ exportnameCase: "camelCase",
53
+ includes: "/channels/**",
54
+ },
55
+ {
56
+ filenameCase: "camelCase",
57
+ exportnameCase: "camelCase",
58
+ includes: "/**/hooks/**",
59
+ },
60
+ {
61
+ filenameCase: "camelCase",
62
+ includes: "/lib/**",
63
+ },
64
+ {
65
+ filenameCase: "camelCase",
66
+ exportnameCase: "camelCase",
67
+ includes: "/**/stores/**",
68
+ },
69
+ {
70
+ filenameCase: "PascalCase",
71
+ exportnameCase: "PascalCase",
72
+ includes: ["/components/**", "/*.jsx"],
73
+ },
74
+ ],
75
+ },
76
+ ],
77
+ "@bigbinary/neeto/no-axios-import-outside-apis": ["error", resolve.alias],
78
+ "@bigbinary/neeto/no-missing-localization": [
79
+ "error",
80
+ { name: "en.json", lng: "en", content: en },
81
+ ],
82
+ "@bigbinary/neeto/prefix-neeto-ui-import-alias": ["error", resolve.alias],
83
+ "@bigbinary/neeto/use-webpack-alias": ["error", resolve.alias],
84
+ "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": [
85
+ "error",
86
+ {
87
+ jsconfigFilePath: path.join(rootOfTheProject, pathToJsConfigFile),
88
+ aliasFilePath: path.join(rootOfTheProject, pathToResolveFile),
89
+ },
90
+ ],
91
+ },
92
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ important: true,
3
+ purge: {
4
+ enabled: process.env.NODE_ENV === "production",
5
+ content: [
6
+ "./{src,example}/**/*.{js,jsx}",
7
+ "./node_modules/@bigbinary/**/*.js",
8
+ ],
9
+ defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || [],
10
+ },
11
+ };
@@ -0,0 +1,42 @@
1
+ const path = require("path");
2
+
3
+ const absolutePath = basePath =>
4
+ path.join(__dirname, "../../../../../../", basePath);
5
+
6
+ module.exports = {
7
+ alias: {
8
+ apis: absolutePath("src/apis"),
9
+ assets: absolutePath("src/assets"),
10
+ components: absolutePath("src/components"),
11
+ hooks: absolutePath("src/hooks"),
12
+ reducers: absolutePath("src/reducers"),
13
+ routes: absolutePath("src/routes"),
14
+ stores: absolutePath("src/stores"),
15
+ translations: absolutePath("src/translations"),
16
+ utils: absolutePath("src/utils"),
17
+ src: absolutePath("src"),
18
+ neetoui: "@bigbinary/neetoui",
19
+ neetocommons: "@bigbinary/neeto-commons-frontend",
20
+ neetoicons: "@bigbinary/neeto-icons",
21
+ neetoteam: "@bigbinary/neeto-team-members-frontend",
22
+ neetoeditor: "@bigbinary/neeto-editor",
23
+ neetofilters: "@bigbinary/neeto-filters-frontend",
24
+ },
25
+ extensions: [
26
+ ".ts",
27
+ ".mjs",
28
+ ".js",
29
+ ".jsx",
30
+ ".sass",
31
+ ".scss",
32
+ ".css",
33
+ ".module.sass",
34
+ ".module.scss",
35
+ ".module.css",
36
+ ".png",
37
+ ".svg",
38
+ ".gif",
39
+ ".jpeg",
40
+ ".jpg",
41
+ ],
42
+ };