@mgdis/core-ui-helpers 1.1.1 → 1.2.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 (37) hide show
  1. package/.turbo/turbo-build.log +16 -16
  2. package/CHANGELOG.md +18 -0
  3. package/dist/playwright/index.cjs +11 -5
  4. package/dist/playwright/index.cjs.map +1 -1
  5. package/dist/playwright/index.d.ts +7 -3
  6. package/dist/playwright/index.js +11 -5
  7. package/dist/playwright/index.js.map +1 -1
  8. package/dist/playwright/index.umd.js +11 -5
  9. package/dist/playwright/index.umd.js.map +1 -1
  10. package/dist/stencil/index.cjs +153 -1682
  11. package/dist/stencil/index.cjs.map +1 -1
  12. package/dist/stencil/index.d.ts +113 -2
  13. package/dist/stencil/index.js +152 -1683
  14. package/dist/stencil/index.js.map +1 -1
  15. package/dist/stencil/index.umd.js +352 -1881
  16. package/dist/stencil/index.umd.js.map +1 -1
  17. package/dist/storybook/index.cjs +168 -1705
  18. package/dist/storybook/index.cjs.map +1 -1
  19. package/dist/storybook/index.js +168 -1705
  20. package/dist/storybook/index.js.map +1 -1
  21. package/dist/storybook/index.umd.js +168 -1705
  22. package/dist/storybook/index.umd.js.map +1 -1
  23. package/json-doc.test.json +13 -2
  24. package/package.json +12 -12
  25. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +3 -3
  26. package/src/playwright/utils/utils.ts +10 -5
  27. package/src/stencil/ide/__snapshots__/cem.spec.ts.snap +248 -0
  28. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +11 -124
  29. package/src/stencil/ide/cem.spec.ts +35 -0
  30. package/src/stencil/ide/cem.ts +96 -0
  31. package/src/stencil/ide/ide.ts +33 -26
  32. package/src/stencil/ide/index.ts +1 -0
  33. package/src/stencil/index.ts +1 -0
  34. package/src/stencil/normalize-boolean-attributes/index.ts +1 -0
  35. package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.spec.ts +63 -0
  36. package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.ts +40 -0
  37. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +1 -1
@@ -97,7 +97,8 @@
97
97
  }
98
98
  ],
99
99
  "optional": false,
100
- "required": true
100
+ "required": true,
101
+ "default": "false"
101
102
  },
102
103
  {
103
104
  "name": "objecttype",
@@ -125,6 +126,11 @@
125
126
  "docsTags": [],
126
127
  "values": [
127
128
  {
129
+ "value": "blu",
130
+ "type": "string"
131
+ },
132
+ {
133
+ "value": "bli",
128
134
  "type": "string"
129
135
  }
130
136
  ],
@@ -224,7 +230,12 @@
224
230
  "docs": ""
225
231
  }
226
232
  ],
227
- "parts": [],
233
+ "parts": [
234
+ {
235
+ "name": "icon",
236
+ "docs": "docs"
237
+ }
238
+ ],
228
239
  "dependents": ["my-internal-comp"],
229
240
  "dependencies": ["my-second-comp"],
230
241
  "dependencyGraph": {}
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@mgdis/core-ui-helpers",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
- "@playwright/test": "1.59.1",
7
- "@stencil/core": "4.40.1",
6
+ "@playwright/test": "1.60.0",
7
+ "@stencil/core": "4.43.5",
8
8
  "lodash": "4.18.1",
9
9
  "vue": "npm:vue@2.7.16"
10
10
  },
11
11
  "devDependencies": {
12
- "@rollup/plugin-commonjs": "29.0.2",
12
+ "@rollup/plugin-commonjs": "29.0.3",
13
13
  "@rollup/plugin-node-resolve": "16.0.3",
14
14
  "@rollup/plugin-typescript": "12.3.0",
15
15
  "@types/lodash": "4.17.24",
16
- "@types/node": "24.12.0",
17
- "@vitest/coverage-istanbul": "4.1.2",
16
+ "@types/node": "24.12.4",
17
+ "@vitest/coverage-istanbul": "4.1.8",
18
18
  "@vue/test-utils": "npm:@vue/test-utils@1.3.6",
19
19
  "htmlfy": "1.0.1",
20
- "rollup": "4.60.1",
20
+ "rollup": "4.60.4",
21
21
  "rollup-plugin-dts": "6.4.1",
22
22
  "tslib": "2.8.1",
23
- "typedoc": "0.28.18",
24
- "typedoc-plugin-markdown": "4.11.0",
25
- "vitest": "4.1.2",
23
+ "typedoc": "0.28.19",
24
+ "typedoc-plugin-markdown": "4.12.0",
25
+ "vitest": "4.1.8",
26
26
  "vue-jest": "3.0.7",
27
+ "@core-ui/tsconfig": "1.0.11",
27
28
  "@core-ui/typedoc-config": "1.0.2",
28
- "@core-ui/vitest-config": "1.0.6",
29
- "@core-ui/tsconfig": "1.0.10"
29
+ "@core-ui/vitest-config": "1.0.8"
30
30
  },
31
31
  "exports": {
32
32
  "./dist/angular": {
@@ -10,13 +10,13 @@ exports[`utils > renderAttributes > Should render attributes 4`] = `"name="batma
10
10
 
11
11
  exports[`utils > renderAttributes > Should render attributes 5`] = `"name="<div class='blu'>blu</div>""`;
12
12
 
13
- exports[`utils > renderAttributes > Should render attributes 6`] = `"name="batman" user="bruce" active="true" id="1""`;
13
+ exports[`utils > renderAttributes > Should render attributes 6`] = `"name="batman" user="bruce" active="" id="1""`;
14
14
 
15
15
  exports[`utils > renderAttributes > Should render attributes 7`] = `"empty-string="""`;
16
16
 
17
17
  exports[`utils > renderAttributes > Should render attributes 8`] = `"name="0""`;
18
18
 
19
- exports[`utils > renderAttributes > Should render attributes 9`] = `"name="false""`;
19
+ exports[`utils > renderAttributes > Should render attributes 9`] = `""`;
20
20
 
21
21
  exports[`utils > renderAttributes > Should render attributes 10`] = `"name="""`;
22
22
 
@@ -44,5 +44,5 @@ exports[`utils > renderProperties > Should render properties, case id selector 1
44
44
 
45
45
  exports[`utils > renderProperties > Should render properties, case id selector 2`] = `
46
46
  "
47
- document.querySelector('div').object={};document.querySelector('div').array=[];document.querySelector('div').fn=() => {\\n };"
47
+ document.querySelector('div').object={};document.querySelector('div').array=[];document.querySelector('div').fn=() => {};"
48
48
  `;
@@ -1,24 +1,29 @@
1
1
  import { isObject, isValidString } from '../../utils';
2
2
 
3
3
  /**
4
- * Render attributes from props objects
4
+ * Render attributes from props objects.
5
+ *
6
+ * Booleans follow the HTML spec for boolean attributes: `true` emits an empty-value attribute
7
+ * (presence implies `true`), `false` omits the attribute entirely. This matches the behaviour
8
+ * of the `normalizeBooleanAttributes` Stencil helper.
5
9
  * @param args - argument to render as string. ex: `{status: 'visible'}`
6
10
  * @returns formated inline attributed. ex: 'status="visible"'
7
11
  * @example
8
12
  * ```ts
9
13
  * import { renderAttributes } from '@mgdis/core-ui-helpers/dist/playwright';
10
14
  *
11
- * const attributes = renderAttributes({ status: 'visible', color: 'red' });
12
- * console.log(attributes); // Output: 'status="visible" color="red"'
15
+ * const attributes = renderAttributes({ status: 'visible', color: 'red', disabled: true, readonly: false });
16
+ * console.log(attributes); // Output: 'status="visible" color="red" disabled=""'
13
17
  * ```
14
18
  */
15
19
  export const renderAttributes = (args: Record<string, unknown>): string =>
16
20
  (isObject<Record<string, never>>(args) &&
17
21
  Object.keys(args)
18
- .filter(key => ![null, undefined].includes(args[key]) && !['object', 'function'].includes(typeof args[key]))
22
+ .filter(key => ![null, undefined].includes(args[key]) && !['object', 'function'].includes(typeof args[key]) && args[key] !== false)
19
23
  .map(key => {
20
24
  const attribute: string = key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
21
- const value: string = ['number', 'boolean'].includes(typeof args[key]) || isValidString(args[key]) ? String(args[key]).replace(/"/g, "'") : '';
25
+ if (args[key] === true) return `${attribute}=""`;
26
+ const value: string = typeof args[key] === 'number' || isValidString(args[key]) ? String(args[key]).replace(/"/g, "'") : '';
22
27
  return `${attribute}="${value}"`;
23
28
  })
24
29
  .join(' ')) ||
@@ -0,0 +1,248 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`cemGenerator > Should generate Custom Elements Manifest v2 1`] = `
4
+ {
5
+ "modules": [
6
+ {
7
+ "declarations": [
8
+ {
9
+ "attributes": [
10
+ {
11
+ "description": "docs",
12
+ "fieldName": "prop",
13
+ "name": "prop",
14
+ "type": {
15
+ "text": "string",
16
+ },
17
+ },
18
+ {
19
+ "description": "docs",
20
+ "fieldName": "multionetype",
21
+ "name": "multionetype",
22
+ "type": {
23
+ "text": "(string | number)[]",
24
+ },
25
+ },
26
+ {
27
+ "description": "docs",
28
+ "fieldName": "number",
29
+ "name": "number",
30
+ "type": {
31
+ "text": "number",
32
+ },
33
+ },
34
+ {
35
+ "default": "false",
36
+ "description": "docs",
37
+ "fieldName": "boolean",
38
+ "name": "boolean",
39
+ "type": {
40
+ "text": "boolean",
41
+ },
42
+ },
43
+ {
44
+ "description": "docs",
45
+ "fieldName": "objecttype",
46
+ "name": "objecttype",
47
+ "type": {
48
+ "text": "{ type: string, value: "blu" | "bli" }",
49
+ },
50
+ },
51
+ {
52
+ "description": "docs",
53
+ "fieldName": "multitype",
54
+ "name": "multitype",
55
+ "type": {
56
+ "text": ""blu" | "bli"",
57
+ },
58
+ },
59
+ {
60
+ "description": "docs",
61
+ "fieldName": "multitypewithstring",
62
+ "name": "multitypewithstring",
63
+ "type": {
64
+ "text": "number | string",
65
+ },
66
+ },
67
+ {
68
+ "description": "docs",
69
+ "fieldName": "arraytypes",
70
+ "name": "arraytypes",
71
+ "type": {
72
+ "text": "number[] | string[]",
73
+ },
74
+ },
75
+ ],
76
+ "cssParts": [
77
+ {
78
+ "description": "docs",
79
+ "name": "icon",
80
+ },
81
+ ],
82
+ "cssProperties": [
83
+ {
84
+ "description": "Custom property documentation",
85
+ "name": "--custom-property",
86
+ },
87
+ ],
88
+ "customElement": true,
89
+ "description": "",
90
+ "events": [
91
+ {
92
+ "description": "docs",
93
+ "name": "event",
94
+ "type": {
95
+ "text": "CustomEvent<boolean>",
96
+ },
97
+ },
98
+ ],
99
+ "kind": "class",
100
+ "members": [
101
+ {
102
+ "attribute": "prop",
103
+ "description": "docs",
104
+ "kind": "field",
105
+ "name": "prop",
106
+ "type": {
107
+ "text": "string",
108
+ },
109
+ },
110
+ {
111
+ "description": "docs",
112
+ "kind": "field",
113
+ "name": "attr",
114
+ "type": {
115
+ "text": "string",
116
+ },
117
+ },
118
+ {
119
+ "attribute": "multionetype",
120
+ "description": "docs",
121
+ "kind": "field",
122
+ "name": "multionetype",
123
+ "type": {
124
+ "text": "(string | number)[]",
125
+ },
126
+ },
127
+ {
128
+ "attribute": "number",
129
+ "description": "docs",
130
+ "kind": "field",
131
+ "name": "number",
132
+ "type": {
133
+ "text": "number",
134
+ },
135
+ },
136
+ {
137
+ "attribute": "boolean",
138
+ "default": "false",
139
+ "description": "docs",
140
+ "kind": "field",
141
+ "name": "boolean",
142
+ "type": {
143
+ "text": "boolean",
144
+ },
145
+ },
146
+ {
147
+ "attribute": "objecttype",
148
+ "description": "docs",
149
+ "kind": "field",
150
+ "name": "objecttype",
151
+ "type": {
152
+ "text": "{ type: string, value: "blu" | "bli" }",
153
+ },
154
+ },
155
+ {
156
+ "attribute": "multitype",
157
+ "description": "docs",
158
+ "kind": "field",
159
+ "name": "multitype",
160
+ "type": {
161
+ "text": ""blu" | "bli"",
162
+ },
163
+ },
164
+ {
165
+ "attribute": "multitypewithstring",
166
+ "description": "docs",
167
+ "kind": "field",
168
+ "name": "multitypewithstring",
169
+ "type": {
170
+ "text": "number | string",
171
+ },
172
+ },
173
+ {
174
+ "attribute": "arraytypes",
175
+ "description": "docs",
176
+ "kind": "field",
177
+ "name": "arraytypes",
178
+ "type": {
179
+ "text": "number[] | string[]",
180
+ },
181
+ },
182
+ {
183
+ "description": "docs",
184
+ "kind": "method",
185
+ "name": "method",
186
+ },
187
+ ],
188
+ "name": "MyComp",
189
+ "slots": [
190
+ {
191
+ "description": "",
192
+ "name": "",
193
+ },
194
+ {
195
+ "description": "",
196
+ "name": "title",
197
+ },
198
+ ],
199
+ "tagName": "my-comp",
200
+ },
201
+ ],
202
+ "exports": [
203
+ {
204
+ "declaration": {
205
+ "module": "src/components/atoms/my-comp/my-comp.tsx",
206
+ "name": "MyComp",
207
+ },
208
+ "kind": "custom-element-definition",
209
+ "name": "my-comp",
210
+ },
211
+ ],
212
+ "kind": "javascript-module",
213
+ "path": "src/components/atoms/my-comp/my-comp.tsx",
214
+ },
215
+ {
216
+ "declarations": [
217
+ {
218
+ "attributes": [],
219
+ "cssParts": [],
220
+ "cssProperties": [],
221
+ "customElement": true,
222
+ "description": "overview",
223
+ "events": [],
224
+ "kind": "class",
225
+ "members": [],
226
+ "name": "MySecondComp",
227
+ "slots": [],
228
+ "tagName": "my-second-comp",
229
+ },
230
+ ],
231
+ "exports": [
232
+ {
233
+ "declaration": {
234
+ "module": "",
235
+ "name": "MySecondComp",
236
+ },
237
+ "kind": "custom-element-definition",
238
+ "name": "my-second-comp",
239
+ },
240
+ ],
241
+ "kind": "javascript-module",
242
+ "path": "",
243
+ },
244
+ ],
245
+ "readme": "",
246
+ "schemaVersion": "2.0.0",
247
+ }
248
+ `;
@@ -38,30 +38,6 @@ Type: \`string\`",
38
38
  {
39
39
  "description": "docs
40
40
 
41
- Type: \`string\`",
42
- "name": "attr",
43
- "references": [
44
- {
45
- "name": "Storybook",
46
- "url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
47
- },
48
- {
49
- "name": "Sources",
50
- "url": "http://sources.test/src/components/atoms/my-comp/my-comp.tsx",
51
- },
52
- ],
53
- "values": [
54
- {
55
- "name": "blu",
56
- },
57
- {
58
- "name": "bli",
59
- },
60
- ],
61
- },
62
- {
63
- "description": "docs
64
-
65
41
  Type: \`(string | number)[]\`",
66
42
  "name": "multionetype",
67
43
  "references": [
@@ -142,7 +118,14 @@ Type: \`"blu" | "bli"\`",
142
118
  "url": "http://sources.test/src/components/atoms/my-comp/my-comp.tsx",
143
119
  },
144
120
  ],
145
- "values": undefined,
121
+ "values": [
122
+ {
123
+ "name": "blu",
124
+ },
125
+ {
126
+ "name": "bli",
127
+ },
128
+ ],
146
129
  },
147
130
  {
148
131
  "description": "docs
@@ -202,7 +185,7 @@ Listeners:
202
185
  - \`keydown\`
203
186
 
204
187
  Slots:
205
- - \`\`:
188
+ - default:
206
189
  - \`title\`:
207
190
 
208
191
  ",
@@ -292,7 +275,7 @@ Type: \`boolean\`",
292
275
  "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
293
276
  "name": "boolean",
294
277
  "value": {
295
- "default": undefined,
278
+ "default": "false",
296
279
  "required": true,
297
280
  "type": "boolean",
298
281
  },
@@ -377,7 +360,7 @@ Listeners:
377
360
  - \`keydown\`
378
361
 
379
362
  Slots:
380
- - \`\`:
363
+ - default:
381
364
  - \`title\`:
382
365
 
383
366
  ",
@@ -393,18 +376,6 @@ Slots:
393
376
  {
394
377
  "description": "docs
395
378
 
396
- Type: \`string\`",
397
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
398
- "name": "prop",
399
- "value": {
400
- "default": undefined,
401
- "required": true,
402
- "type": "string",
403
- },
404
- },
405
- {
406
- "description": "docs
407
-
408
379
  Type: \`string\`",
409
380
  "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
410
381
  "name": "attr",
@@ -414,90 +385,6 @@ Type: \`string\`",
414
385
  "type": "string",
415
386
  },
416
387
  },
417
- {
418
- "description": "docs
419
-
420
- Type: \`(string | number)[]\`",
421
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
422
- "name": "multionetype",
423
- "value": {
424
- "default": undefined,
425
- "required": true,
426
- "type": "(string | number)[]",
427
- },
428
- },
429
- {
430
- "description": "docs
431
-
432
- Type: \`number\`",
433
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
434
- "name": "number",
435
- "value": {
436
- "default": undefined,
437
- "required": true,
438
- "type": "number",
439
- },
440
- },
441
- {
442
- "description": "docs
443
-
444
- Type: \`boolean\`",
445
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
446
- "name": "boolean",
447
- "value": {
448
- "default": undefined,
449
- "required": true,
450
- "type": "boolean",
451
- },
452
- },
453
- {
454
- "description": "docs
455
-
456
- Type: \`{ type: string, value: "blu" | "bli" }\`",
457
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
458
- "name": "objecttype",
459
- "value": {
460
- "default": undefined,
461
- "required": true,
462
- "type": "{ type: string, value: "blu" | "bli" }",
463
- },
464
- },
465
- {
466
- "description": "docs
467
-
468
- Type: \`"blu" | "bli"\`",
469
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
470
- "name": "multitype",
471
- "value": {
472
- "default": undefined,
473
- "required": true,
474
- "type": ""blu" | "bli"",
475
- },
476
- },
477
- {
478
- "description": "docs
479
-
480
- Type: \`number | string\`",
481
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
482
- "name": "multitypewithstring",
483
- "value": {
484
- "default": undefined,
485
- "required": true,
486
- "type": "number | string",
487
- },
488
- },
489
- {
490
- "description": "docs
491
-
492
- Type: \`number[] | string[]\`",
493
- "doc-url": "http://sb.test/?path=/docs/atoms-my-comp--docs",
494
- "name": "arraytypes",
495
- "value": {
496
- "default": undefined,
497
- "required": true,
498
- "type": "number[] | string[]",
499
- },
500
- },
501
388
  ],
502
389
  },
503
390
  "name": "my-comp",
@@ -0,0 +1,35 @@
1
+ import { describe, expect, test, vi } from 'vitest';
2
+ import { cemGenerator } from '.';
3
+ import { JsonDocs } from '@stencil/core/internal';
4
+ import jsonDocs from '../../../json-doc.test.json';
5
+
6
+ vi.mock('@stencil/core/internal/client', () => ({
7
+ renderVdom: vi.fn(),
8
+ }));
9
+
10
+ describe('cemGenerator', () => {
11
+ test('Should generate Custom Elements Manifest v2', () => {
12
+ const cem = cemGenerator(jsonDocs as JsonDocs);
13
+ expect(cem).toMatchSnapshot();
14
+ });
15
+
16
+ test('Should map attribute-backed props to both attributes and members', () => {
17
+ const cem = cemGenerator(jsonDocs as JsonDocs);
18
+ const decl = cem.modules[0].declarations[0];
19
+ const attrBackedProp = decl.attributes.find(a => a.name === 'prop');
20
+ expect(attrBackedProp).toBeDefined();
21
+ expect(attrBackedProp?.fieldName).toBe('prop');
22
+ const member = decl.members.find(m => m.kind === 'field' && m.name === 'prop');
23
+ expect(member).toBeDefined();
24
+ expect((member as { attribute?: string }).attribute).toBe('prop');
25
+ });
26
+
27
+ test('Should map JS-only props to members only (not attributes)', () => {
28
+ const cem = cemGenerator(jsonDocs as JsonDocs);
29
+ const decl = cem.modules[0].declarations[0];
30
+ expect(decl.attributes.find(a => a.name === 'attr')).toBeUndefined();
31
+ const member = decl.members.find(m => m.kind === 'field' && m.name === 'attr');
32
+ expect(member).toBeDefined();
33
+ expect((member as { attribute?: string }).attribute).toBeUndefined();
34
+ });
35
+ });