@mgdis/core-ui-helpers 1.2.1 → 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.
- package/dist/angular/index.cjs +1 -1
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.js +1 -1
- package/dist/angular/index.js.map +1 -1
- package/dist/angular/index.umd.js +1 -1
- package/dist/angular/index.umd.js.map +1 -1
- package/dist/locale/index.cjs +3 -1
- package/dist/locale/index.cjs.map +1 -1
- package/dist/locale/index.js +3 -1
- package/dist/locale/index.js.map +1 -1
- package/dist/locale/index.umd.js +3 -1
- package/dist/locale/index.umd.js.map +1 -1
- package/dist/playwright/index.cjs +12 -5
- package/dist/playwright/index.cjs.map +1 -1
- package/dist/playwright/index.js +12 -5
- package/dist/playwright/index.js.map +1 -1
- package/dist/playwright/index.umd.js +12 -5
- package/dist/playwright/index.umd.js.map +1 -1
- package/dist/stencil/index.cjs +33 -33
- package/dist/stencil/index.cjs.map +1 -1
- package/dist/stencil/index.js +33 -33
- package/dist/stencil/index.js.map +1 -1
- package/dist/stencil/index.umd.js +33 -33
- package/dist/stencil/index.umd.js.map +1 -1
- package/dist/storybook/index.cjs +9 -7
- package/dist/storybook/index.cjs.map +1 -1
- package/dist/storybook/index.js +9 -7
- package/dist/storybook/index.js.map +1 -1
- package/dist/storybook/index.umd.js +9 -7
- package/dist/storybook/index.umd.js.map +1 -1
- package/dist/tests/index.cjs +24 -9
- package/dist/tests/index.cjs.map +1 -1
- package/dist/tests/index.d.ts +2 -2
- package/dist/tests/index.js +24 -9
- package/dist/tests/index.js.map +1 -1
- package/dist/tests/index.umd.js +24 -9
- package/dist/tests/index.umd.js.map +1 -1
- package/dist/utils/index.cjs +14 -6
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +14 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.umd.js +14 -6
- package/dist/utils/index.umd.js.map +1 -1
- package/dist/vue/index.cjs +2 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +2 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.umd.js +2 -1
- package/dist/vue/index.umd.js.map +1 -1
- package/package.json +11 -8
- package/.turbo/turbo-build.log +0 -49
- package/CHANGELOG.md +0 -95
- package/json-doc.test.json +0 -264
- package/rollup.config.mjs +0 -61
- package/src/angular/index.spec.ts +0 -8
- package/src/angular/index.ts +0 -1
- package/src/angular/mg-angular-logger/index.ts +0 -1
- package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +0 -3
- package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +0 -40
- package/src/angular/mg-angular-logger/mg-angular-logger.ts +0 -23
- package/src/locale/index.spec.ts +0 -15
- package/src/locale/index.ts +0 -1
- package/src/locale/locale.spec.ts +0 -266
- package/src/locale/locale.ts +0 -193
- package/src/playwright/config/index.ts +0 -43
- package/src/playwright/index.spec.ts +0 -16
- package/src/playwright/index.ts +0 -4
- package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +0 -48
- package/src/playwright/utils/index.ts +0 -1
- package/src/playwright/utils/utils.spec.ts +0 -43
- package/src/playwright/utils/utils.ts +0 -69
- package/src/stencil/ide/__snapshots__/cem.spec.ts.snap +0 -248
- package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +0 -414
- package/src/stencil/ide/cem.spec.ts +0 -35
- package/src/stencil/ide/cem.ts +0 -96
- package/src/stencil/ide/ide.spec.ts +0 -29
- package/src/stencil/ide/ide.ts +0 -221
- package/src/stencil/ide/index.ts +0 -2
- package/src/stencil/index.spec.ts +0 -16
- package/src/stencil/index.ts +0 -2
- package/src/stencil/normalize-boolean-attributes/index.ts +0 -1
- package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.spec.ts +0 -63
- package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.ts +0 -40
- package/src/storybook/index.spec.ts +0 -19
- package/src/storybook/index.ts +0 -1
- package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +0 -329
- package/src/storybook/stencil/index.ts +0 -1
- package/src/storybook/stencil/stencil-shim.d.ts +0 -1
- package/src/storybook/stencil/stencil.conf.ts +0 -4
- package/src/storybook/stencil/stencil.spec.ts +0 -146
- package/src/storybook/stencil/stencil.ts +0 -366
- package/src/tests/index.spec.ts +0 -14
- package/src/tests/index.ts +0 -1
- package/src/tests/unit/__snapshots__/unit.spec.ts.snap +0 -52
- package/src/tests/unit/index.ts +0 -1
- package/src/tests/unit/unit.conf.ts +0 -9
- package/src/tests/unit/unit.spec.ts +0 -164
- package/src/tests/unit/unit.ts +0 -306
- package/src/utils/attributes/class-list/class-list.spec.ts +0 -36
- package/src/utils/attributes/class-list/class-list.ts +0 -51
- package/src/utils/attributes/class-list/index.ts +0 -1
- package/src/utils/attributes/id/id.spec.ts +0 -51
- package/src/utils/attributes/id/id.ts +0 -46
- package/src/utils/attributes/id/index.ts +0 -1
- package/src/utils/attributes/index.ts +0 -3
- package/src/utils/attributes/to-kebab-case/index.ts +0 -1
- package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +0 -29
- package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +0 -23
- package/src/utils/components/__snapshots__/components.spec.ts.snap +0 -313
- package/src/utils/components/components.conf.ts +0 -11
- package/src/utils/components/components.spec.ts +0 -192
- package/src/utils/components/components.ts +0 -138
- package/src/utils/components/index.ts +0 -2
- package/src/utils/date/date.spec.ts +0 -12
- package/src/utils/date/date.ts +0 -20
- package/src/utils/date/index.ts +0 -1
- package/src/utils/elements/elements.spec.ts +0 -17
- package/src/utils/elements/elements.ts +0 -16
- package/src/utils/elements/index.ts +0 -1
- package/src/utils/index.spec.ts +0 -84
- package/src/utils/index.ts +0 -8
- package/src/utils/number/index.ts +0 -1
- package/src/utils/number/number.spec.ts +0 -14
- package/src/utils/number/number.ts +0 -6
- package/src/utils/object/index.ts +0 -2
- package/src/utils/object/object.conf.ts +0 -4
- package/src/utils/object/object.spec.ts +0 -110
- package/src/utils/object/object.ts +0 -26
- package/src/utils/string/index.ts +0 -1
- package/src/utils/string/string.spec.ts +0 -47
- package/src/utils/string/string.ts +0 -38
- package/src/utils/windows/index.ts +0 -1
- package/src/utils/windows/windows.spec.ts +0 -65
- package/src/utils/windows/windows.ts +0 -50
- package/src/vue/index.spec.ts +0 -8
- package/src/vue/index.ts +0 -1
- package/src/vue/mg-model/index.ts +0 -1
- package/src/vue/mg-model/mg-model.conf.ts +0 -6
- package/src/vue/mg-model/mg-model.spec.ts +0 -50
- package/src/vue/mg-model/mg-model.ts +0 -50
- package/tsconfig.json +0 -17
- package/typedoc.json +0 -14
- package/vitest.config.mts +0 -13
package/src/stencil/ide/ide.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { JsonDocs, JsonDocsComponent, JsonDocsProp } from '@stencil/core/internal';
|
|
2
|
-
import { getStorybookUrl } from '../../storybook';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Retrieve Component source URL from file path
|
|
6
|
-
* @param sourcesBaseUrl - Source base URL
|
|
7
|
-
* @param filePath - Component file path
|
|
8
|
-
* @returns Component source URL
|
|
9
|
-
*/
|
|
10
|
-
const getSourcesUrl = (sourcesBaseUrl: string, filePath: string | undefined): string | undefined => {
|
|
11
|
-
if (!filePath) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
return `${sourcesBaseUrl}${filePath}`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get Component element description.
|
|
19
|
-
*
|
|
20
|
-
* Neither WebStorm nor VS Code render the structured `attributes` /
|
|
21
|
-
* `js.properties` arrays in the tag-level quick-doc — they only show this
|
|
22
|
-
* markdown description. So the attribute and property listings have to live
|
|
23
|
-
* here, even though they're redundant with the structured arrays used by the
|
|
24
|
-
* inline autocomplete.
|
|
25
|
-
* @param component - Component
|
|
26
|
-
* @returns Component element description
|
|
27
|
-
*/
|
|
28
|
-
const getElementDescription = (component: JsonDocsComponent): string => {
|
|
29
|
-
let description = component.overview ? `${component.overview}\n\n` : '';
|
|
30
|
-
const attributes = component.props.filter(({ attr }) => attr !== undefined);
|
|
31
|
-
if (attributes.length) {
|
|
32
|
-
description += `Attributes:\n`;
|
|
33
|
-
description += attributes.map(({ attr, docs }) => `- \`${attr}\`: ${docs}\n`).join('');
|
|
34
|
-
description += '\n';
|
|
35
|
-
}
|
|
36
|
-
const properties = component.props.filter(({ attr }) => attr === undefined);
|
|
37
|
-
if (properties.length) {
|
|
38
|
-
description += `Properties:\n`;
|
|
39
|
-
description += properties.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
|
|
40
|
-
description += '\n';
|
|
41
|
-
}
|
|
42
|
-
if (component.methods.length) {
|
|
43
|
-
description += `Methods:\n`;
|
|
44
|
-
description += component.methods.map(({ name, docs }) => `- \`${name}\`: ${docs}\n`).join('');
|
|
45
|
-
description += '\n';
|
|
46
|
-
}
|
|
47
|
-
if (component.events.length) {
|
|
48
|
-
description += `Events:\n`;
|
|
49
|
-
description += component.events.map(({ event, docs }) => `- \`${event}\`: ${docs}\n`).join('');
|
|
50
|
-
description += '\n';
|
|
51
|
-
}
|
|
52
|
-
if (component.listeners.length) {
|
|
53
|
-
description += `Listeners:\n`;
|
|
54
|
-
description += component.listeners.map(({ event }) => `- \`${event}\`\n`).join('');
|
|
55
|
-
description += '\n';
|
|
56
|
-
}
|
|
57
|
-
if (component.slots.length) {
|
|
58
|
-
description += `Slots:\n`;
|
|
59
|
-
description += component.slots
|
|
60
|
-
.map(({ name, docs }) => {
|
|
61
|
-
const label = name ? `\`${name}\`` : 'default';
|
|
62
|
-
return `- ${label}: ${docs}\n`;
|
|
63
|
-
})
|
|
64
|
-
.join('');
|
|
65
|
-
description += '\n';
|
|
66
|
-
}
|
|
67
|
-
return description;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Get Props Description
|
|
72
|
-
* @param prop - Component Property
|
|
73
|
-
* @returns Props Description
|
|
74
|
-
*/
|
|
75
|
-
const getAttributeDescription = (prop: JsonDocsProp): string => {
|
|
76
|
-
return `${prop.docs}\n\nType: \`${prop.type}\``;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Generate Web Types metadata for IntelliJ's IDE
|
|
81
|
-
* @param name - Library name
|
|
82
|
-
* @param version - Library version
|
|
83
|
-
* @param jsonDocs - Stencil JSON doc
|
|
84
|
-
* @param storybookBaseUrl - Storybook Base Url
|
|
85
|
-
* @returns Web Types metadata
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const webTypesJson = webTypesGenerator('@mgdis/mg-components', '1.0.0', jsonDocs, 'https://storybook.example.com');
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export const webTypesGenerator = (name: string, version: string, jsonDocs: JsonDocs, storybookBaseUrl: string) => ({
|
|
92
|
-
'$schema': 'https://json.schemastore.org/web-types',
|
|
93
|
-
name,
|
|
94
|
-
version,
|
|
95
|
-
'description-markup': 'markdown',
|
|
96
|
-
'contributions': {
|
|
97
|
-
html: {
|
|
98
|
-
elements: jsonDocs.components.map(component => {
|
|
99
|
-
const docUrl = getStorybookUrl(storybookBaseUrl, component.filePath);
|
|
100
|
-
return {
|
|
101
|
-
'name': component.tag,
|
|
102
|
-
'description': getElementDescription(component),
|
|
103
|
-
'doc-url': docUrl,
|
|
104
|
-
'attributes': component.props
|
|
105
|
-
.filter(prop => prop.attr)
|
|
106
|
-
.map(prop => ({
|
|
107
|
-
'name': prop.attr,
|
|
108
|
-
'description': getAttributeDescription(prop),
|
|
109
|
-
'doc-url': docUrl,
|
|
110
|
-
'value': {
|
|
111
|
-
type: prop.type,
|
|
112
|
-
default: prop.default,
|
|
113
|
-
required: prop.required,
|
|
114
|
-
},
|
|
115
|
-
})),
|
|
116
|
-
'js': {
|
|
117
|
-
properties: component.props
|
|
118
|
-
.filter(prop => prop.attr === undefined)
|
|
119
|
-
.map(prop => ({
|
|
120
|
-
'name': prop.name,
|
|
121
|
-
'description': getAttributeDescription(prop),
|
|
122
|
-
'doc-url': docUrl,
|
|
123
|
-
'value': {
|
|
124
|
-
type: prop.type,
|
|
125
|
-
default: prop.default,
|
|
126
|
-
required: prop.required,
|
|
127
|
-
},
|
|
128
|
-
})),
|
|
129
|
-
events: component.events.map(event => ({
|
|
130
|
-
name: event.event,
|
|
131
|
-
description: event.docs,
|
|
132
|
-
})),
|
|
133
|
-
},
|
|
134
|
-
'css': {
|
|
135
|
-
properties: component.styles.map(style => ({
|
|
136
|
-
name: style.name,
|
|
137
|
-
description: style.docs,
|
|
138
|
-
})),
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
}),
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Create Storybook Reference
|
|
148
|
-
* @param storybookBaseUrl - Storybook Base Url
|
|
149
|
-
* @param filePath - Component file path
|
|
150
|
-
* @returns Storybook Reference
|
|
151
|
-
*/
|
|
152
|
-
const getReferences = (storybookBaseUrl: string, sourceBaseUrl: string, filePath: string | undefined) => {
|
|
153
|
-
return [
|
|
154
|
-
{ name: 'Storybook', url: getStorybookUrl(storybookBaseUrl, filePath) },
|
|
155
|
-
{ name: 'Sources', url: getSourcesUrl(sourceBaseUrl, filePath) },
|
|
156
|
-
];
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get Property possible values
|
|
161
|
-
* @param prop - Component Property
|
|
162
|
-
* @returns Property possible values
|
|
163
|
-
*/
|
|
164
|
-
const getValues = (prop: JsonDocsProp): unknown[] | undefined => {
|
|
165
|
-
// Only values Array where all objects have a value seems to be usefull
|
|
166
|
-
if (prop.values.some(({ value }) => value === undefined)) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
return prop.values.map(({ value }) => ({ name: value }));
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Generate custom HTML datasets for VS Code
|
|
174
|
-
* @param jsonDocs - Stencil JSON doc
|
|
175
|
-
* @param storybookBaseUrl - Storybook Base Url
|
|
176
|
-
* @returns custom HTML datasets
|
|
177
|
-
* @example
|
|
178
|
-
* ```ts
|
|
179
|
-
* const customDataJson = vsCodeGenerator(jsonDocs, 'https://storybook.example.com', 'https://sources.example.com');
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
export const vsCodeGenerator = (jsonDocs: JsonDocs, storybookBaseUrl: string, sourceBaseUrl: string) => ({
|
|
183
|
-
version: 1.1,
|
|
184
|
-
tags: jsonDocs.components.map(component => {
|
|
185
|
-
const references = getReferences(storybookBaseUrl, sourceBaseUrl, component.filePath);
|
|
186
|
-
return {
|
|
187
|
-
name: component.tag,
|
|
188
|
-
description: getElementDescription(component),
|
|
189
|
-
attributes: component.props
|
|
190
|
-
.filter(prop => prop.attr !== undefined)
|
|
191
|
-
.map(prop => ({
|
|
192
|
-
name: prop.attr,
|
|
193
|
-
description: getAttributeDescription(prop),
|
|
194
|
-
values: getValues(prop),
|
|
195
|
-
references,
|
|
196
|
-
})),
|
|
197
|
-
references,
|
|
198
|
-
};
|
|
199
|
-
}),
|
|
200
|
-
globalAttributes: [],
|
|
201
|
-
valueSets: [],
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Generate custom CSS datasets for VS Code
|
|
206
|
-
* @param jsonDocs - Stencil JSON doc
|
|
207
|
-
* @returns custom CSS datasets
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const customDataJson = vsCodeCssGenerator(jsonDocs);
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
export const vsCodeCssGenerator = (jsonDocs: JsonDocs) => ({
|
|
214
|
-
version: 1.1,
|
|
215
|
-
properties: jsonDocs.components.flatMap(component =>
|
|
216
|
-
component.styles.map(style => ({
|
|
217
|
-
name: style.name,
|
|
218
|
-
description: style.docs,
|
|
219
|
-
})),
|
|
220
|
-
),
|
|
221
|
-
});
|
package/src/stencil/ide/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
-
import { webTypesGenerator, vsCodeGenerator, vsCodeCssGenerator } from '.';
|
|
3
|
-
|
|
4
|
-
vi.mock('@stencil/core/internal/client', () => ({
|
|
5
|
-
renderVdom: vi.fn(),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe('stencil', () => {
|
|
9
|
-
describe('ide', () => {
|
|
10
|
-
test('import', () => {
|
|
11
|
-
expect(webTypesGenerator).toBeDefined();
|
|
12
|
-
expect(vsCodeGenerator).toBeDefined();
|
|
13
|
-
expect(vsCodeCssGenerator).toBeDefined();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/stencil/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './normalize-boolean-attributes';
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { normalizeBooleanAttributes } from '.';
|
|
3
|
-
|
|
4
|
-
const makeTarget = (html: string, props: Record<string, unknown>): { element: HTMLElement } => {
|
|
5
|
-
const element = document.createElement('div');
|
|
6
|
-
// Parse attributes from a fake tag so we can pass arbitrary attribute names/values
|
|
7
|
-
const tmp = document.createElement('div');
|
|
8
|
-
tmp.innerHTML = `<my-elem ${html}></my-elem>`;
|
|
9
|
-
const source = tmp.firstElementChild as HTMLElement;
|
|
10
|
-
for (const attr of Array.from(source.attributes)) {
|
|
11
|
-
element.setAttribute(attr.name, attr.value);
|
|
12
|
-
}
|
|
13
|
-
return { element, ...props };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe('normalizeBooleanAttributes', () => {
|
|
17
|
-
test('rewrites boolean-typed attributes to empty string regardless of original value', () => {
|
|
18
|
-
const target = makeTarget('readonly="false" disabled="true" required="" multiple', {
|
|
19
|
-
readonly: false,
|
|
20
|
-
disabled: true,
|
|
21
|
-
required: false,
|
|
22
|
-
multiple: false,
|
|
23
|
-
});
|
|
24
|
-
normalizeBooleanAttributes(target);
|
|
25
|
-
expect(target.element.getAttribute('readonly')).toBe('');
|
|
26
|
-
expect(target.element.getAttribute('disabled')).toBe('');
|
|
27
|
-
expect(target.element.getAttribute('required')).toBe('');
|
|
28
|
-
expect(target.element.getAttribute('multiple')).toBe('');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('skips attributes that do not map to a boolean prop', () => {
|
|
32
|
-
const target = makeTarget('class="foo" id="bar" data-x="1"', {});
|
|
33
|
-
normalizeBooleanAttributes(target);
|
|
34
|
-
expect(target.element.getAttribute('class')).toBe('foo');
|
|
35
|
-
expect(target.element.getAttribute('id')).toBe('bar');
|
|
36
|
-
expect(target.element.getAttribute('data-x')).toBe('1');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('skips attributes whose prop is not boolean-typed', () => {
|
|
40
|
-
const target = makeTarget('label="hello" count="3"', { label: 'hello', count: 3 });
|
|
41
|
-
normalizeBooleanAttributes(target);
|
|
42
|
-
expect(target.element.getAttribute('label')).toBe('hello');
|
|
43
|
-
expect(target.element.getAttribute('count')).toBe('3');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('converts kebab-case attribute name to camelCase prop name', () => {
|
|
47
|
-
const target = makeTarget('is-legend="false" label-on-top="false"', { isLegend: false, labelOnTop: false });
|
|
48
|
-
normalizeBooleanAttributes(target);
|
|
49
|
-
expect(target.element.getAttribute('is-legend')).toBe('');
|
|
50
|
-
expect(target.element.getAttribute('label-on-top')).toBe('');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('leaves attributes alone when there is no matching prop', () => {
|
|
54
|
-
const target = makeTarget('flag="false"', {});
|
|
55
|
-
normalizeBooleanAttributes(target);
|
|
56
|
-
expect(target.element.getAttribute('flag')).toBe('false');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('handles an element with no attributes', () => {
|
|
60
|
-
const target = makeTarget('', { readonly: false });
|
|
61
|
-
expect(() => normalizeBooleanAttributes(target)).not.toThrow();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per the HTML spec, a boolean attribute is `true` whenever it is present on the
|
|
3
|
-
* element, regardless of its value (including `="false"`). Stencil's default Prop
|
|
4
|
-
* parser converts the string `"false"` to the boolean `false`, which breaks this
|
|
5
|
-
* contract for consumers writing markup. Call this helper from `componentWillLoad`
|
|
6
|
-
* to re-normalize every present attribute that maps to a boolean-typed Prop.
|
|
7
|
-
*
|
|
8
|
-
* Iterates the host element's attributes and, for each one whose camelCase name
|
|
9
|
-
* matches a `typeof === 'boolean'` Prop on the instance, rewrites the attribute
|
|
10
|
-
* to `''` — Stencil's parser then turns that into `true` via the standard
|
|
11
|
-
* attribute → prop pipeline (no need for `mutable: true` on the Prop, since the
|
|
12
|
-
* write goes through Stencil's internal setter, not through user code).
|
|
13
|
-
*
|
|
14
|
-
* Non-boolean Props and non-Prop attributes (`class`, `id`, ...) are skipped
|
|
15
|
-
* naturally by the type check.
|
|
16
|
-
*
|
|
17
|
-
* @param target - the component instance (must expose `element` via `@Element()`)
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* @Component({ tag: 'my-input' })
|
|
22
|
-
* export class MyInput {
|
|
23
|
-
* @Element() element: HTMLMyInputElement;
|
|
24
|
-
* @Prop() readonly = false;
|
|
25
|
-
* @Prop() disabled = false;
|
|
26
|
-
*
|
|
27
|
-
* componentWillLoad() {
|
|
28
|
-
* normalizeBooleanAttributes(this);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export const normalizeBooleanAttributes = (target: { element: HTMLElement }): void => {
|
|
34
|
-
for (const attr of Array.from(target.element.attributes)) {
|
|
35
|
-
const propName = attr.name.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase());
|
|
36
|
-
if (typeof (target as Record<string, unknown>)[propName] === 'boolean') {
|
|
37
|
-
target.element.setAttribute(attr.name, '');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
-
import { filterArgs, getStorybookUrl, getStoryHTML, stencilWrapper, StorybookPreview } from '.';
|
|
3
|
-
|
|
4
|
-
vi.mock('@stencil/core/internal/client', () => ({
|
|
5
|
-
renderVdom: vi.fn(),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe('storybook', () => {
|
|
9
|
-
describe('stencil', () => {
|
|
10
|
-
test('import', () => {
|
|
11
|
-
expect(filterArgs).toBeDefined();
|
|
12
|
-
expect(stencilWrapper).toBeDefined();
|
|
13
|
-
expect(getStoryHTML).toBeDefined();
|
|
14
|
-
expect(getStorybookUrl).toBeDefined();
|
|
15
|
-
expect(stencilWrapper).toBeDefined();
|
|
16
|
-
expect(StorybookPreview).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
});
|
package/src/storybook/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './stencil';
|