piral-core 0.15.0-alpha.3905 → 0.15.0-alpha.3933

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.
@@ -1,9 +1,8 @@
1
1
  import { isfunc } from 'piral-base';
2
- import { none } from './helpers';
3
2
  export const defaultLayouts = ['desktop', 'tablet', 'mobile'];
4
3
  export const defaultBreakpoints = ['(min-width: 991px)', '(min-width: 481px)', '(max-width: 480px)'];
5
4
  const mm = typeof window === 'undefined' || !isfunc(window.matchMedia)
6
- ? () => ({ matches: none })
5
+ ? () => ({ matches: undefined })
7
6
  : (q) => window.matchMedia(q);
8
7
  export function getCurrentLayout(breakpoints, layouts, defaultLayout) {
9
8
  const query = breakpoints.findIndex((q) => mm(q).matches);
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,CAAC,MAAM,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,MAAM,UAAU,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC"}
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC,MAAM,CAAC,MAAM,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,MAAM,UAAU,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC"}
@@ -2,11 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCurrentLayout = exports.defaultBreakpoints = exports.defaultLayouts = void 0;
4
4
  const piral_base_1 = require("piral-base");
5
- const helpers_1 = require("./helpers");
6
5
  exports.defaultLayouts = ['desktop', 'tablet', 'mobile'];
7
6
  exports.defaultBreakpoints = ['(min-width: 991px)', '(min-width: 481px)', '(max-width: 480px)'];
8
7
  const mm = typeof window === 'undefined' || !(0, piral_base_1.isfunc)(window.matchMedia)
9
- ? () => ({ matches: helpers_1.none })
8
+ ? () => ({ matches: undefined })
10
9
  : (q) => window.matchMedia(q);
11
10
  function getCurrentLayout(breakpoints, layouts, defaultLayout) {
12
11
  const query = breakpoints.findIndex((q) => mm(q).matches);
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AACpC,uCAAiC;AAGpB,QAAA,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE9D,QAAA,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAI,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,SAAgB,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC;AAJD,4CAIC"}
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/utils/media.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAGvB,QAAA,cAAc,GAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE9D,QAAA,kBAAkB,GAAsB,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAExH,MAAM,EAAE,GACN,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,IAAA,mBAAM,EAAC,MAAM,CAAC,UAAU,CAAC;IACzD,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1C,SAAgB,gBAAgB,CAAI,WAA0B,EAAE,OAAiB,EAAE,aAAgB;IACjG,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC;AACvD,CAAC;AAJD,4CAIC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-alpha.3905",
3
+ "version": "0.15.0-alpha.3933",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -48,8 +48,8 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@dbeining/react-atom": "^4.0.0",
51
- "piral-base": "0.15.0-alpha.3905",
52
- "piral-debug-utils": "0.15.0-alpha.3905"
51
+ "piral-base": "0.15.0-alpha.3933",
52
+ "piral-debug-utils": "0.15.0-alpha.3933"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0",
@@ -79,5 +79,5 @@
79
79
  "@libre/atom",
80
80
  "@dbeining/react-atom"
81
81
  ],
82
- "gitHead": "533d09963cfd8c901df797958ca386dbae0286e1"
82
+ "gitHead": "520a272d09f02543153f1d8b2ae23a3ae10acd6f"
83
83
  }
@@ -1,9 +1,30 @@
1
1
  import * as React from 'react';
2
2
  import { Atom, swap, deref } from '@dbeining/react-atom';
3
- import { showPortal, destroyPortal } from './portal';
3
+ import { showPortal, destroyPortal, hidePortal, updatePortal } from './portal';
4
4
 
5
5
  describe('Piral-Core portal actions', () => {
6
- it('showPortal adds a portal', () => {
6
+ it('destroyPortal removes a portal', () => {
7
+ const children = React.createElement('div');
8
+ const portal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
9
+
10
+ const state = Atom.of({
11
+ portals: { test: { portal } },
12
+ });
13
+
14
+ const ctx: any = {
15
+ state,
16
+ dispatch(update) {
17
+ swap(state, update);
18
+ },
19
+ };
20
+
21
+ destroyPortal(ctx, 'test');
22
+ const { portals } = deref(ctx.state);
23
+ expect(portals).not.toBeNull();
24
+ expect(portals.test).toBeUndefined();
25
+ });
26
+
27
+ it('hidePortal hides a portal', () => {
7
28
  const children = React.createElement('div');
8
29
  const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
9
30
  const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
@@ -19,18 +40,20 @@ describe('Piral-Core portal actions', () => {
19
40
  },
20
41
  };
21
42
 
22
- showPortal(ctx, 'test', newPortal);
43
+ hidePortal(ctx, 'test', newPortal);
23
44
  const { portals } = deref(ctx.state);
24
45
  expect(portals).not.toBeNull();
25
46
  expect(portals.test).not.toBeNull();
26
47
  });
27
48
 
28
- it('destroyPortal removes a portal', () => {
49
+ it('updatePortal updates a portal', () => {
29
50
  const children = React.createElement('div');
30
- const portal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
51
+ const current: React.ReactPortal = { key: 'current', children: { children }, type: 'div', props: null };
52
+ const next: React.ReactPortal = { key: 'next', children: { children }, type: 'div', props: null };
53
+ const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
31
54
 
32
55
  const state = Atom.of({
33
- portals: { test: { portal } },
56
+ portals: { p1: { portal } },
34
57
  });
35
58
 
36
59
  const ctx: any = {
@@ -40,9 +63,31 @@ describe('Piral-Core portal actions', () => {
40
63
  },
41
64
  };
42
65
 
43
- destroyPortal(ctx, 'test');
66
+ updatePortal(ctx, 'test', current, next);
44
67
  const { portals } = deref(ctx.state);
45
68
  expect(portals).not.toBeNull();
46
- expect(portals.test).toBeUndefined();
69
+ expect(portals.test).not.toBeNull();
70
+ });
71
+
72
+ it('showPortal adds a portal', () => {
73
+ const children = React.createElement('div');
74
+ const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
75
+ const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
76
+
77
+ const state = Atom.of({
78
+ portals: { p1: { portal } },
79
+ });
80
+
81
+ const ctx: any = {
82
+ state,
83
+ dispatch(update) {
84
+ swap(state, update);
85
+ },
86
+ };
87
+
88
+ showPortal(ctx, 'test', newPortal);
89
+ const { portals } = deref(ctx.state);
90
+ expect(portals).not.toBeNull();
91
+ expect(portals.test).not.toBeNull();
47
92
  });
48
93
  });
@@ -43,7 +43,7 @@ const state = {
43
43
 
44
44
  (hooks as any).useGlobalState = (select: any) => select(state);
45
45
 
46
- (routes as any).PiralRoutes = ({}) => <StubDashboard />;
46
+ (routes as any).PiralRoutes = ({ }) => <StubDashboard />;
47
47
 
48
48
  describe('Portal Module', () => {
49
49
  it('renders the dashboard / content in layout if loaded without error', () => {
@@ -42,7 +42,7 @@ const PiralProvider: React.FC = ({ children }) => {
42
42
  /**
43
43
  * The props for the PiralView component.
44
44
  */
45
- export interface PiralViewProps {}
45
+ export interface PiralViewProps { }
46
46
 
47
47
  /**
48
48
  * The component responsible for the generic view of the application.
@@ -11,4 +11,9 @@ describe('Piral-Core createInstance module', () => {
11
11
  const instance = createInstance({ async: true });
12
12
  expect(instance.options.strategy).toBe(blazingStrategy);
13
13
  });
14
+
15
+ it('createInstance with empty actions uses the standard strategy', () => {
16
+ const instance = createInstance({ actions: {} });
17
+ expect(instance.options.strategy).toBe(standardStrategy);
18
+ })
14
19
  });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { useGlobalState } from './globalState';
5
+
6
+ jest.mock('react', () => {
7
+ const { Atom } = require('@libre/atom');
8
+ const state = Atom.of({
9
+ foo: 5,
10
+ bar: {
11
+ qxz: 'hello',
12
+ },
13
+ list: [1, 2, 3],
14
+ });
15
+ return {
16
+ createContext: jest.fn(),
17
+ useContext: () => ({ state }),
18
+ useState: (v) => [v, jest.fn()],
19
+ useMemo: (f) => f(),
20
+ useLayoutEffect: (f) => f(),
21
+ };
22
+ });
23
+
24
+ describe('Media Module', () => {
25
+ it('in here window should be undefined', () => {
26
+ expect(typeof window).toBe('undefined');
27
+ const result = useGlobalState((m) => (m as any).foo);
28
+ expect(result).toBe(5);
29
+ });
30
+
31
+ it('gets full state object', () => {
32
+ const result = useGlobalState();
33
+ expect(result).toEqual({
34
+ foo: 5,
35
+ bar: {
36
+ qxz: 'hello',
37
+ },
38
+ list: [1, 2, 3],
39
+ });
40
+ });
41
+ });
@@ -9,4 +9,4 @@ describe('Util Extension.', () => {
9
9
  const node = mount(<Extension piral={undefined} params={{ title: 'Foo' }} />);
10
10
  expect(node.find('b').length).toBe(1);
11
11
  });
12
- });
12
+ });
@@ -1,6 +1,11 @@
1
- import { generateId } from './guid';
1
+ import { buildName, generateId } from './guid';
2
2
 
3
3
  describe('Guid Utility Module', () => {
4
+ it('buildName returns name with its prefix', () => {
5
+ const result = buildName('Ma', 'Majd');
6
+ expect(result).toEqual('Ma://Majd');
7
+ });
8
+
4
9
  it('Generates two consecutive different guids', () => {
5
10
  const guid1 = generateId();
6
11
  const guid2 = generateId();
@@ -8,9 +8,61 @@ import {
8
8
  prependItems,
9
9
  appendItems,
10
10
  updateKey,
11
+ replaceOrAddItem,
12
+ includeItem,
13
+ tryParseJson,
14
+ removeNested,
11
15
  } from './helpers';
12
16
 
13
17
  describe('Helpers Module', () => {
18
+ it('removeNested removes keys values', () => {
19
+ const obj = { d: 'test', z: ['test arr'] };
20
+ const result = removeNested(obj, () => true);
21
+ const expectedResult = { d: {}, z: {} };
22
+ expect(result).toEqual(expectedResult);
23
+ });
24
+
25
+ it('removeNested removes keys values with nested arrays', () => {
26
+ const obj = { z: [['test arr'], ['test arr2']] };
27
+ const result = removeNested(obj, () => true);
28
+ const expectedResult = { z: { '0': [], '1': [] } };
29
+ expect(result).toEqual(expectedResult);
30
+ });
31
+
32
+ it('removeNested splits keys values', () => {
33
+ const obj = { d: 'test', z: ['test arr'] };
34
+ const result = removeNested(obj, () => false);
35
+ const expectedResult = { d: { '0': 't', '1': 'e', '2': 's', '3': 't' }, z: { '0': 'test arr' } };
36
+ expect(result).toEqual(expectedResult);
37
+ });
38
+
39
+ it('tryParseJson parses a JSON string', () => {
40
+ const content = '{"result":true, "count":42}';
41
+ const result = tryParseJson(content);
42
+ expect(result).toEqual({ result: true, count: 42 });
43
+ });
44
+
45
+ it('tryParseJson return empty object if the content is not valid', () => {
46
+ const content = '"result":true, "count":42';
47
+ const result = tryParseJson(content);
48
+ expect(result).toEqual({});
49
+ });
50
+
51
+ it('includeItem adds an item to array', () => {
52
+ const result = includeItem([1, 2, 3], 4);
53
+ expect(result).toEqual([1, 2, 3, 4]);
54
+ });
55
+
56
+ it('replaceOrAddItem replaces the first item', () => {
57
+ const result = replaceOrAddItem([1, 2, 3], 4, () => true);
58
+ expect(result).toEqual([4, 2, 3]);
59
+ });
60
+
61
+ it('replaceOrAddItem adds the item the end', () => {
62
+ const result = replaceOrAddItem([1, 2, 3], 4, () => false);
63
+ expect(result).toEqual([1, 2, 3, 4]);
64
+ });
65
+
14
66
  it('prependItem works with an existing array', () => {
15
67
  const result = prependItem([1, 2, 3], 4);
16
68
  expect(result).toEqual([4, 1, 2, 3]);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ import { getCurrentLayout } from './media';
5
+
6
+ describe('Media Module', () => {
7
+ it('in here window should be undefined', () => {
8
+ expect(typeof window).toBe('undefined');
9
+ const breakpoints = ['min-width: 200px', 'max-width: 199px'];
10
+ const result = getCurrentLayout(breakpoints, ['foo', 'bar'], 'qxz');
11
+ expect(result).toBe('qxz');
12
+ });
13
+ });
@@ -1,5 +1,4 @@
1
1
  import { isfunc } from 'piral-base';
2
- import { none } from './helpers';
3
2
  import { LayoutTypes, LayoutBreakpoints } from '../types';
4
3
 
5
4
  export const defaultLayouts: LayoutTypes = ['desktop', 'tablet', 'mobile'];
@@ -8,7 +7,7 @@ export const defaultBreakpoints: LayoutBreakpoints = ['(min-width: 991px)', '(mi
8
7
 
9
8
  const mm =
10
9
  typeof window === 'undefined' || !isfunc(window.matchMedia)
11
- ? () => ({ matches: none })
10
+ ? () => ({ matches: undefined })
12
11
  : (q: string) => window.matchMedia(q);
13
12
 
14
13
  export function getCurrentLayout<T>(breakpoints: Array<string>, layouts: Array<T>, defaultLayout: T) {