@mgdis/core-ui-helpers 1.2.2 → 1.3.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.
Files changed (149) hide show
  1. package/dist/angular/index.cjs +27 -0
  2. package/dist/angular/index.cjs.map +1 -0
  3. package/dist/angular/index.d.ts +21 -0
  4. package/dist/angular/index.js +25 -0
  5. package/dist/angular/index.js.map +1 -0
  6. package/dist/angular/index.umd.js +33 -0
  7. package/dist/angular/index.umd.js.map +1 -0
  8. package/dist/locale/index.cjs +190 -0
  9. package/dist/locale/index.cjs.map +1 -0
  10. package/dist/locale/index.d.ts +110 -0
  11. package/dist/locale/index.js +181 -0
  12. package/dist/locale/index.js.map +1 -0
  13. package/dist/locale/index.umd.js +196 -0
  14. package/dist/locale/index.umd.js.map +1 -0
  15. package/dist/playwright/index.cjs +137 -0
  16. package/dist/playwright/index.cjs.map +1 -0
  17. package/dist/playwright/index.d.ts +39 -0
  18. package/dist/playwright/index.js +133 -0
  19. package/dist/playwright/index.js.map +1 -0
  20. package/dist/playwright/index.umd.js +143 -0
  21. package/dist/playwright/index.umd.js.map +1 -0
  22. package/dist/stencil/index.cjs +363 -0
  23. package/dist/stencil/index.cjs.map +1 -0
  24. package/dist/stencil/index.d.ts +222 -0
  25. package/dist/stencil/index.js +357 -0
  26. package/dist/stencil/index.js.map +1 -0
  27. package/dist/stencil/index.umd.js +369 -0
  28. package/dist/stencil/index.umd.js.map +1 -0
  29. package/dist/storybook/index.cjs +2335 -0
  30. package/dist/storybook/index.cjs.map +1 -0
  31. package/dist/storybook/index.d.ts +85 -0
  32. package/dist/storybook/index.js +2329 -0
  33. package/dist/storybook/index.js.map +1 -0
  34. package/dist/storybook/index.umd.js +2341 -0
  35. package/dist/storybook/index.umd.js.map +1 -0
  36. package/dist/tests/index.cjs +315 -0
  37. package/dist/tests/index.cjs.map +1 -0
  38. package/dist/tests/index.d.ts +100 -0
  39. package/dist/tests/index.js +309 -0
  40. package/dist/tests/index.js.map +1 -0
  41. package/dist/tests/index.umd.js +321 -0
  42. package/dist/tests/index.umd.js.map +1 -0
  43. package/dist/utils/index.cjs +441 -0
  44. package/dist/utils/index.cjs.map +1 -0
  45. package/dist/utils/index.d.ts +265 -0
  46. package/dist/utils/index.js +417 -0
  47. package/dist/utils/index.js.map +1 -0
  48. package/dist/utils/index.umd.js +447 -0
  49. package/dist/utils/index.umd.js.map +1 -0
  50. package/dist/vue/index.cjs +1935 -0
  51. package/dist/vue/index.cjs.map +1 -0
  52. package/dist/vue/index.d.ts +35 -0
  53. package/dist/vue/index.js +1933 -0
  54. package/dist/vue/index.js.map +1 -0
  55. package/dist/vue/index.umd.js +1941 -0
  56. package/dist/vue/index.umd.js.map +1 -0
  57. package/package.json +4 -1
  58. package/CHANGELOG.md +0 -101
  59. package/json-doc.test.json +0 -264
  60. package/rollup.config.mjs +0 -61
  61. package/src/angular/index.spec.ts +0 -8
  62. package/src/angular/index.ts +0 -1
  63. package/src/angular/mg-angular-logger/index.ts +0 -1
  64. package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +0 -3
  65. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +0 -40
  66. package/src/angular/mg-angular-logger/mg-angular-logger.ts +0 -24
  67. package/src/locale/index.spec.ts +0 -24
  68. package/src/locale/index.ts +0 -1
  69. package/src/locale/locale.spec.ts +0 -291
  70. package/src/locale/locale.ts +0 -201
  71. package/src/playwright/config/index.ts +0 -43
  72. package/src/playwright/index.spec.ts +0 -16
  73. package/src/playwright/index.ts +0 -4
  74. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +0 -48
  75. package/src/playwright/utils/index.ts +0 -1
  76. package/src/playwright/utils/utils.spec.ts +0 -50
  77. package/src/playwright/utils/utils.ts +0 -77
  78. package/src/stencil/ide/__snapshots__/cem.spec.ts.snap +0 -248
  79. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +0 -414
  80. package/src/stencil/ide/cem.spec.ts +0 -35
  81. package/src/stencil/ide/cem.ts +0 -96
  82. package/src/stencil/ide/ide.spec.ts +0 -29
  83. package/src/stencil/ide/ide.ts +0 -221
  84. package/src/stencil/ide/index.ts +0 -2
  85. package/src/stencil/index.spec.ts +0 -16
  86. package/src/stencil/index.ts +0 -2
  87. package/src/stencil/normalize-boolean-attributes/index.ts +0 -1
  88. package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.spec.ts +0 -63
  89. package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.ts +0 -40
  90. package/src/storybook/index.spec.ts +0 -19
  91. package/src/storybook/index.ts +0 -1
  92. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +0 -329
  93. package/src/storybook/stencil/index.ts +0 -1
  94. package/src/storybook/stencil/stencil-shim.d.ts +0 -1
  95. package/src/storybook/stencil/stencil.conf.ts +0 -4
  96. package/src/storybook/stencil/stencil.spec.ts +0 -170
  97. package/src/storybook/stencil/stencil.ts +0 -377
  98. package/src/tests/index.spec.ts +0 -20
  99. package/src/tests/index.ts +0 -1
  100. package/src/tests/unit/__snapshots__/unit.spec.ts.snap +0 -52
  101. package/src/tests/unit/index.ts +0 -1
  102. package/src/tests/unit/unit.conf.ts +0 -16
  103. package/src/tests/unit/unit.spec.ts +0 -206
  104. package/src/tests/unit/unit.ts +0 -333
  105. package/src/utils/attributes/class-list/class-list.spec.ts +0 -36
  106. package/src/utils/attributes/class-list/class-list.ts +0 -51
  107. package/src/utils/attributes/class-list/index.ts +0 -1
  108. package/src/utils/attributes/id/id.spec.ts +0 -54
  109. package/src/utils/attributes/id/id.ts +0 -47
  110. package/src/utils/attributes/id/index.ts +0 -1
  111. package/src/utils/attributes/index.ts +0 -3
  112. package/src/utils/attributes/to-kebab-case/index.ts +0 -1
  113. package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +0 -29
  114. package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +0 -23
  115. package/src/utils/components/__snapshots__/components.spec.ts.snap +0 -313
  116. package/src/utils/components/components.conf.ts +0 -11
  117. package/src/utils/components/components.spec.ts +0 -192
  118. package/src/utils/components/components.ts +0 -152
  119. package/src/utils/components/index.ts +0 -2
  120. package/src/utils/date/date.spec.ts +0 -12
  121. package/src/utils/date/date.ts +0 -20
  122. package/src/utils/date/index.ts +0 -1
  123. package/src/utils/elements/elements.spec.ts +0 -17
  124. package/src/utils/elements/elements.ts +0 -18
  125. package/src/utils/elements/index.ts +0 -1
  126. package/src/utils/index.spec.ts +0 -84
  127. package/src/utils/index.ts +0 -8
  128. package/src/utils/number/index.ts +0 -1
  129. package/src/utils/number/number.spec.ts +0 -14
  130. package/src/utils/number/number.ts +0 -6
  131. package/src/utils/object/index.ts +0 -2
  132. package/src/utils/object/object.conf.ts +0 -4
  133. package/src/utils/object/object.spec.ts +0 -110
  134. package/src/utils/object/object.ts +0 -27
  135. package/src/utils/string/index.ts +0 -1
  136. package/src/utils/string/string.spec.ts +0 -54
  137. package/src/utils/string/string.ts +0 -39
  138. package/src/utils/windows/index.ts +0 -1
  139. package/src/utils/windows/windows.spec.ts +0 -69
  140. package/src/utils/windows/windows.ts +0 -50
  141. package/src/vue/index.spec.ts +0 -8
  142. package/src/vue/index.ts +0 -1
  143. package/src/vue/mg-model/index.ts +0 -1
  144. package/src/vue/mg-model/mg-model.conf.ts +0 -6
  145. package/src/vue/mg-model/mg-model.spec.ts +0 -50
  146. package/src/vue/mg-model/mg-model.ts +0 -55
  147. package/tsconfig.json +0 -17
  148. package/typedoc.json +0 -14
  149. package/vitest.config.mts +0 -13
@@ -1 +0,0 @@
1
- export * from './date';
@@ -1,17 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { isTagName } from './elements';
3
-
4
- describe('elements', () => {
5
- describe('isTagName', () => {
6
- test.each([
7
- { querySelector: 'h1', expected: true },
8
- { querySelector: 'span', expected: false },
9
- { querySelector: 'blu', expected: false },
10
- ])('Should test if all otems are string: %s', ({ querySelector, expected }) => {
11
- const div = document.createElement('div');
12
- div.innerHTML = '<h1></h1><span></span>';
13
- const elm = div.querySelector(querySelector);
14
- expect(isTagName(elm as HTMLElement, ['h1'])).toEqual(expected);
15
- });
16
- });
17
- });
@@ -1,18 +0,0 @@
1
- /**
2
- * Check if element belongs to the given tagNames list
3
- * @param element - element to check
4
- * @param tagNames - allowed tag names list
5
- * @returns `true` if element tagName is in the tagNames list
6
- */
7
- export const isTagName = (element: Element, tagNames: string[]): boolean =>
8
- tagNames.includes(element?.tagName.toLowerCase());
9
-
10
- /**
11
- * CSS selector to select focusable elements.
12
- * @example
13
- * ```ts
14
- * const allFocusableElements: HTMLElement[] = Array.from(this.element.querySelectorAll(focusableElements));
15
- * ```
16
- */
17
- export const focusableElements =
18
- 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier], mg-button';
@@ -1 +0,0 @@
1
- export * from './elements';
@@ -1,84 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import {
3
- allItemsAreString,
4
- ClassList,
5
- cleanString,
6
- createID,
7
- Cursor,
8
- dateRegExp,
9
- dateToString,
10
- focusableElements,
11
- formatID,
12
- getObjectValueFromKey,
13
- getChildWindows,
14
- getParentWindows,
15
- getWindows,
16
- isObject,
17
- isTagName,
18
- isValideID,
19
- isValidNumber,
20
- isValidString,
21
- nextTick,
22
- Page,
23
- Paginate,
24
- toKebabCase,
25
- toString,
26
- } from './';
27
-
28
- describe('utils', () => {
29
- describe('attributes', () => {
30
- test('import', () => {
31
- expect(ClassList).toBeDefined();
32
- expect(createID).toBeDefined();
33
- expect(formatID).toBeDefined();
34
- expect(isValideID).toBeDefined();
35
- expect(toKebabCase).toBeDefined();
36
- });
37
- });
38
- describe('components', () => {
39
- test('import', () => {
40
- expect(nextTick).toBeDefined();
41
- expect(Cursor).toBeDefined();
42
- expect(Page).toBeDefined();
43
- expect(Paginate).toBeDefined();
44
- });
45
- });
46
- describe('date', () => {
47
- test('import', () => {
48
- expect(dateRegExp).toBeDefined();
49
- expect(dateToString).toBeDefined();
50
- });
51
- });
52
- describe('elements', () => {
53
- test('import', () => {
54
- expect(focusableElements).toBeDefined();
55
- expect(isTagName).toBeDefined();
56
- });
57
- });
58
- describe('number', () => {
59
- test('import', () => {
60
- expect(isValidNumber).toBeDefined();
61
- });
62
- });
63
- describe('object', () => {
64
- test('import', () => {
65
- expect(isObject).toBeDefined();
66
- expect(getObjectValueFromKey).toBeDefined();
67
- });
68
- });
69
- describe('string', () => {
70
- test('import', () => {
71
- expect(allItemsAreString).toBeDefined();
72
- expect(isValidString).toBeDefined();
73
- expect(toString).toBeDefined();
74
- expect(cleanString).toBeDefined();
75
- });
76
- });
77
- describe('windows', () => {
78
- test('import', () => {
79
- expect(getWindows).toBeDefined();
80
- expect(getParentWindows).toBeDefined();
81
- expect(getChildWindows).toBeDefined();
82
- });
83
- });
84
- });
@@ -1,8 +0,0 @@
1
- export * from './attributes';
2
- export * from './components';
3
- export * from './date';
4
- export * from './elements';
5
- export * from './number';
6
- export * from './object';
7
- export * from './string';
8
- export * from './windows';
@@ -1 +0,0 @@
1
- export * from './number';
@@ -1,14 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { isValidNumber } from './number';
3
-
4
- describe('number', () => {
5
- describe('isValidNumber', () => {
6
- test.each(['', ' ', null, undefined, '1', {}, []])('Should return "false" for invalid values', (value) => {
7
- expect(isValidNumber(value)).toEqual(false);
8
- });
9
-
10
- test.each([1, 1.0])('Should return "true" for valid value', (value) => {
11
- expect(isValidNumber(value)).toEqual(true);
12
- });
13
- });
14
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * Validate number
3
- * @param value - value to check
4
- * @returns `true` if number is valid
5
- */
6
- export const isValidNumber = (value: unknown): value is number => typeof value === 'number' && !Number.isNaN(value);
@@ -1,2 +0,0 @@
1
- export * from './object';
2
- export * from './object.conf';
@@ -1,4 +0,0 @@
1
- /**
2
- * Define json object type
3
- */
4
- export type ObjectType = Record<string, unknown>;
@@ -1,110 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { getObjectValueFromKey, isObject } from './object';
3
-
4
- describe('object', () => {
5
- describe('isObject', () => {
6
- test.each([{}, new Date()])('Should validate an object', (value) => {
7
- const res = isObject(value);
8
- expect(res).toEqual(true);
9
- });
10
-
11
- test.each([undefined, null, '', 'batman', []])('Should NOT validate %s', (value) => {
12
- const res = isObject(value);
13
- expect(res).toEqual(false);
14
- });
15
- });
16
-
17
- describe('getObjectValueFromKey', () => {
18
- test.each([
19
- {
20
- object: { batman: 'hero' },
21
- key: undefined,
22
- result: undefined,
23
- },
24
- {
25
- object: { batman: 'hero' },
26
- key: { filter: 'batman' },
27
- result: undefined,
28
- },
29
- {
30
- object: { batman: 'hero' },
31
- key: { filter: 'batman.test' },
32
- defaultValue: 0,
33
- result: 0,
34
- },
35
- {
36
- object: 'batman',
37
- key: 'batman',
38
- result: undefined,
39
- },
40
- {
41
- object: null,
42
- key: 'batman',
43
- result: undefined,
44
- },
45
- {
46
- object: undefined,
47
- key: 'batman',
48
- result: undefined,
49
- },
50
- {
51
- value: { heroes: { batman: 'hero' } },
52
- key: 'heroes.robin',
53
- result: undefined,
54
- },
55
- {
56
- object: {},
57
- key: 'batman',
58
- result: undefined,
59
- },
60
- {
61
- object: { batman: 'hero' },
62
- key: { filter: 'batman' },
63
- defaultValue: { batman: 'hero' },
64
- result: { batman: 'hero' },
65
- },
66
- {
67
- object: { hero: undefined },
68
- key: { filter: 'hero' },
69
- defaultValue: 'batman',
70
- result: 'batman',
71
- },
72
- {
73
- object: { hero: { batman: undefined } },
74
- key: { filter: 'hero.batman' },
75
- defaultValue: 'talk',
76
- result: 'talk',
77
- },
78
- {
79
- object: {},
80
- key: 'batman',
81
- defaultValue: {},
82
- result: {},
83
- },
84
- {
85
- object: 'batman',
86
- key: 'batman',
87
- defaultValue: 'batman',
88
- result: 'batman',
89
- },
90
- {
91
- value: { batman: undefined },
92
- key: 'batman',
93
- result: undefined,
94
- },
95
- {
96
- value: { batman: 'hero' },
97
- key: 'batman',
98
- result: 'hero',
99
- },
100
- {
101
- value: { heroes: { batman: 'hero' } },
102
- key: 'heroes.batman',
103
- result: 'hero',
104
- },
105
- ])('Should parse object %', ({ value, key, defaultValue, result }) => {
106
- const res = getObjectValueFromKey(value, key as string, defaultValue);
107
- expect(res).toEqual(result);
108
- });
109
- });
110
- });
@@ -1,27 +0,0 @@
1
- /**
2
- * Check if a value is of object type.
3
- * @param object - The value to validate.
4
- * @returns `true` if the value is a valid object (non-null and not an array), otherwise `false`.
5
- */
6
- export const isObject = <T>(object: unknown): object is T =>
7
- typeof object === 'object' && !Array.isArray(object) && object !== null;
8
-
9
- /**
10
- * Get object value from key
11
- * @param object - object to query
12
- * @param path - path of the property to get. Nested keys are allowed with `.` separators (eg: 'key0.key1.key2' = object[key0][key1][key2])
13
- * @param defaultValue - The value returned for `undefined` resolved values
14
- * @returns object value
15
- */
16
- export const getObjectValueFromKey = <T, R>(object: T, path: string, defaultValue?: R): R | undefined => {
17
- const separator = '.';
18
- if (!isObject<Record<string, R>>(object) || typeof path !== 'string') {
19
- return defaultValue;
20
- }
21
- const [current, ...next] = path.split(separator);
22
- if (next.length) {
23
- return getObjectValueFromKey(object[current as keyof T], next.join(separator), defaultValue);
24
- } else {
25
- return object[current as keyof T] ?? defaultValue;
26
- }
27
- };
@@ -1 +0,0 @@
1
- export * from './string';
@@ -1,54 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { allItemsAreString, cleanString, isValidString, toString } from './string';
3
-
4
- describe('string', () => {
5
- describe('allItemsAreString', () => {
6
- test.each([
7
- { items: ['blu', 'bli', 'blo', 'bla'], expected: true },
8
- { items: ['blu', 'bli', 'blo', { value: 'bla' }], expected: false },
9
- ])('Should test if all otems are string: %s', ({ items, expected }) => {
10
- expect(allItemsAreString(items as string[])).toEqual(expected);
11
- });
12
- });
13
-
14
- describe('isValidString', () => {
15
- test.each(['', ' ', null, undefined, 1, {}, []])('Should return "false" for invalid values', (value) => {
16
- expect(isValidString(value)).toEqual(false);
17
- });
18
-
19
- test.each(['batman', 'batman '])('Should return "true" for valid value', (value) => {
20
- expect(isValidString(value)).toEqual(true);
21
- });
22
- });
23
-
24
- describe('toString', () => {
25
- test.each([undefined, null, 1, 'string', '', [undefined], [{ value: null }], {}, ['string'], { hello: 'batman' }])(
26
- 'Should return stringified value, original %s',
27
- (value) => {
28
- expect(toString(value)).toEqual(
29
- typeof value === 'object' || (Array.isArray(value) && typeof value !== 'string')
30
- ? JSON.stringify(value)
31
- : `${value}`
32
- );
33
- }
34
- );
35
- });
36
-
37
- describe('cleanString', () => {
38
- test.each([
39
- { string: 'batman', expected: 'batman' },
40
- { string: 'BATMAN', expected: 'batman' },
41
- { string: 'Batman', expected: 'batman' },
42
- { string: ' batman ', expected: ' batman ' },
43
- { string: ' batman', expected: ' batman' },
44
- { string: 'batman ', expected: 'batman ' },
45
- { string: 'âäàçéèêñù', expected: 'aaaceeenu' },
46
- ])('Should format string properly', ({ string, expected }) => {
47
- expect(cleanString(string)).toEqual(expected);
48
- });
49
-
50
- test('Should return orignal value when param is NOT a string', () => {
51
- expect(cleanString(undefined as unknown as string)).toEqual(undefined);
52
- });
53
- });
54
- });
@@ -1,39 +0,0 @@
1
- /**
2
- * Typeguard function to check if all array items are strings.
3
- * @param items - items to check
4
- * @returns `true` if all items are strings
5
- */
6
- export const allItemsAreString = (items: unknown): items is string[] =>
7
- Array.isArray(items) && items.every((item) => typeof item === 'string');
8
-
9
- /**
10
- * Validate string
11
- * @param value - value to check
12
- * @returns `true` if string is valid
13
- */
14
- export const isValidString = (value: unknown): value is string => typeof value === 'string' && value.trim() !== '';
15
-
16
- /**
17
- * Stringify value
18
- * @param value - value to stringify
19
- * @returns stringified value
20
- */
21
- export const toString = (value: unknown): string => (typeof value === 'object' ? JSON.stringify(value) : String(value));
22
-
23
- /**
24
- * Cleans string characters by removing special characters and converting to lowercase.
25
- * @param text - text to clean
26
- * @returns cleaned string
27
- * @example
28
- * ```ts
29
- * cleanString('âäàçéèêñù') // 'aaaceeenu'
30
- * cleanString('BATMAN') // 'batman'
31
- * ```
32
- */
33
- export const cleanString = (text: string): string =>
34
- typeof text === 'string'
35
- ? text
36
- .toLocaleLowerCase()
37
- .normalize('NFD')
38
- .replaceAll(/[\u0300-\u036f]/g, '')
39
- : text;
@@ -1 +0,0 @@
1
- export * from './windows';
@@ -1,69 +0,0 @@
1
- import { describe, expect, test, afterEach, vi } from 'vitest';
2
- import { getWindows } from './windows';
3
-
4
- describe('windows', () => {
5
- describe('getWindows', () => {
6
- const mockWindowFramesLength = vi.fn();
7
- const mockWindowIndexZero = vi.fn();
8
- Object.defineProperty(window, 'frames', {
9
- value: {
10
- get length() {
11
- return mockWindowFramesLength();
12
- },
13
- get 0() {
14
- return mockWindowIndexZero();
15
- },
16
- },
17
- });
18
-
19
- afterEach(() => {
20
- vi.clearAllMocks();
21
- });
22
-
23
- test('Should return the window in an array', () => {
24
- mockWindowFramesLength.mockReturnValue(0);
25
- const localWindow: Window = window;
26
- const windows: Window[] = getWindows(localWindow);
27
- expect(windows).toHaveLength(1);
28
- expect(windows[0]).toEqual(localWindow);
29
- });
30
-
31
- test('Should return the window with a parent', () => {
32
- mockWindowFramesLength.mockReturnValue(0);
33
- const spyWindowSelf = vi
34
- .spyOn(window, 'self', 'get')
35
- .mockImplementationOnce(() => ({}) as Window & typeof globalThis);
36
- const spyWindowParent = vi.spyOn(window, 'parent', 'get').mockImplementationOnce(() => window);
37
-
38
- const windows = getWindows(window);
39
- expect(windows).toHaveLength(2);
40
- expect(spyWindowSelf).toBeCalledTimes(2);
41
- expect(spyWindowParent).toBeCalledTimes(2);
42
- });
43
-
44
- test('Should return the window with a child', () => {
45
- mockWindowFramesLength.mockReturnValueOnce(1).mockReturnValueOnce(1).mockReturnValue(0);
46
- mockWindowIndexZero.mockReturnValueOnce(window);
47
- const windows = getWindows(window);
48
- expect(windows).toHaveLength(2);
49
- });
50
-
51
- test('Should throw an error when cannot access top parent window', () => {
52
- mockWindowFramesLength.mockReturnValue(0);
53
- const spyConsole = vi.spyOn(console, 'error');
54
- const spyWindowSelf = vi
55
- .spyOn(window, 'self', 'get')
56
- .mockImplementationOnce(() => ({}) as Window & typeof globalThis);
57
- const spyWindowParent = vi.spyOn(window, 'parent', 'get').mockImplementationOnce(() => {
58
- throw new Error('non');
59
- });
60
- const localWindow: Window = window;
61
- const windows: Window[] = getWindows(localWindow);
62
- expect(windows).toHaveLength(1);
63
- expect(windows[0]).toEqual(localWindow);
64
- expect(spyConsole).toBeCalledTimes(1);
65
- expect(spyWindowSelf).toBeCalledTimes(1);
66
- expect(spyWindowParent).toBeCalledTimes(1);
67
- });
68
- });
69
- });
@@ -1,50 +0,0 @@
1
- /**
2
- * Get windows
3
- * @param localWindow - the window we are lookink for other windows
4
- * @returns The list of windows found
5
- */
6
- export const getWindows = (localWindow: Window): Window[] => {
7
- const parentWindows = getParentWindows(localWindow);
8
- const childWindows = getChildWindows(localWindow);
9
- return [localWindow, ...parentWindows, ...childWindows];
10
- };
11
-
12
- /**
13
- * Get parent windows
14
- * @param localWindow - the window we are lookink for parents
15
- * @param windows - The list of allready found windows
16
- * @returns The list of windows found
17
- */
18
- export const getParentWindows = (localWindow: Window, windows: Window[] = []): Window[] => {
19
- // Check if is in iframe
20
- if (localWindow.self !== localWindow.top) {
21
- // Check if we have permission to access parent
22
- try {
23
- const parentWindow: Window = localWindow.parent;
24
- if (parentWindow) {
25
- windows.push(parentWindow);
26
- return getParentWindows(parentWindow, windows);
27
- } else return windows;
28
- } catch (err) {
29
- console.error('Different hosts between iframes:', err);
30
- return windows;
31
- }
32
- }
33
- return windows;
34
- };
35
-
36
- /**
37
- * Get child windows
38
- * @param localWindow - the window we are lookink for children
39
- * @param windows - The list of allready found windows
40
- * @returns The list of windows found
41
- */
42
- export const getChildWindows = (localWindow: Window, windows: Window[] = []): Window[] => {
43
- if (localWindow.frames.length > 0) {
44
- for (const childWindow of Array.from(localWindow.frames)) {
45
- windows.push(childWindow);
46
- getChildWindows(childWindow, windows);
47
- }
48
- }
49
- return windows;
50
- };
@@ -1,8 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { mgModel } from '.';
3
-
4
- describe('VUE', () => {
5
- test('import', () => {
6
- expect(mgModel).toBeDefined();
7
- });
8
- });
package/src/vue/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './mg-model';
@@ -1 +0,0 @@
1
- export * from './mg-model';
@@ -1,6 +0,0 @@
1
- import { type Directive } from 'vue';
2
-
3
- export interface App {
4
- directive(name: string): Directive | undefined;
5
- directive(name: string, directive: Directive): this;
6
- }
@@ -1,50 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { createLocalVue } from '@vue/test-utils';
3
- import { mgModel } from '.';
4
-
5
- const localVue = createLocalVue();
6
-
7
- describe('mg-model', () => {
8
- test('nominal', () => {
9
- mgModel.install(localVue);
10
- const directive = localVue.directive('mg-model');
11
-
12
- expect(directive.bind).toBeDefined();
13
- expect(directive.componentUpdated).toBeDefined();
14
- expect(directive.unbind).toBeDefined();
15
-
16
- const el = document.createElement('div');
17
- const vnode = { context: {} };
18
- const binding = { value: 'blu', expression: 'blu' };
19
-
20
- directive.bind(el, binding, vnode);
21
- expect(el.value).toEqual('blu');
22
-
23
- expect(vnode.context[binding.expression]).not.toBeDefined();
24
- el.dispatchEvent(new CustomEvent('value-change', { bubbles: true }));
25
- expect(vnode.context[binding.expression]).toEqual(el.value);
26
-
27
- directive.componentUpdated(el, { value: 'bla' });
28
- expect(el.value).toEqual('bla');
29
-
30
- directive.unbind(el);
31
- el.dispatchEvent(new CustomEvent('value-change', { bubbles: true }));
32
- expect(vnode.context[binding.expression]).not.toEqual(el.value);
33
- });
34
- test('without binding values', () => {
35
- mgModel.install(localVue);
36
- const directive = localVue.directive('mg-model');
37
-
38
- const el = document.createElement('div');
39
- const vnode = { context: {} };
40
-
41
- directive.bind(el, {}, vnode);
42
- expect(el.value).toEqual('');
43
-
44
- directive.bind(el, { value: 'blu' }, vnode);
45
- expect(el.value).toEqual('blu');
46
-
47
- directive.componentUpdated(el, {});
48
- expect(el.value).toEqual('');
49
- });
50
- });
@@ -1,55 +0,0 @@
1
- import set from 'lodash/set';
2
- import { type Directive, type VNode } from 'vue';
3
- import { type App } from './mg-model.conf';
4
-
5
- const wm = new WeakMap();
6
-
7
- /**
8
- * Custom `v-mg-model` directive
9
- *
10
- * @remarks
11
- * Packages requirements
12
- * - "\@mgdis/mg-components": \>=3
13
- * - "vue": \>=2
14
- * - "lodash"
15
- *
16
- * @example
17
- * ```js
18
- * // src/main.js
19
- * import Vue from 'vue';
20
- * import App from './App.vue';
21
- * import { mgModel } from '@mgdis/core-ui-helpers/dist/vue';
22
- *
23
- * Vue.use(mgModel);
24
- *
25
- * new Vue({
26
- * render: (h) => h(App),
27
- * }).$mount('#app');
28
- * ```
29
- */
30
- export const mgModel = {
31
- install(Vue: App) {
32
- Vue.directive('mg-model', <Directive<HTMLInputElement, string>>{
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- bind(el: HTMLInputElement, binding: any, vnode: VNode) {
35
- const valueChangeHandler = (event: Event) =>
36
- set(
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- vnode.context as any,
39
- binding.expression,
40
- (event as unknown as { target: EventTarget & { value: unknown } }).target.value
41
- );
42
- wm.set(el, valueChangeHandler);
43
- el.value = binding.value ?? '';
44
- el.addEventListener('value-change', valueChangeHandler);
45
- },
46
- componentUpdated(el, binding) {
47
- el.value = binding.value ?? '';
48
- },
49
- unbind(el: HTMLElement) {
50
- const valueChangeHandler = wm.get(el);
51
- el.removeEventListener('value-change', valueChangeHandler);
52
- },
53
- });
54
- },
55
- };