Skip to content

Commit 289741e

Browse files
authored
feat: update custom-elements-manifest to v2, add readonly (#182)
1 parent e17d872 commit 289741e

File tree

8 files changed

+36
-41
lines changed

8 files changed

+36
-41
lines changed

.changeset/fresh-candles-rush.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@api-viewer/common': patch
3+
'@api-viewer/demo': patch
4+
'@api-viewer/docs': patch
5+
'@api-viewer/tabs': patch
6+
'api-viewer-element': patch
7+
---
8+
9+
Update custom-elements-manifest to v2.0.0, add readonly support

docs/assets/custom-elements.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@
339339
"name": "focused",
340340
"type": {
341341
"text": "Element | null"
342-
}
342+
},
343+
"readonly": true
343344
},
344345
{
345346
"kind": "method",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"devDependencies": {
3939
"@changesets/cli": "^2.25.2",
40-
"@custom-elements-manifest/analyzer": "^0.6.6",
40+
"@custom-elements-manifest/analyzer": "^0.8.0",
4141
"@size-limit/preset-small-lib": "^8.1.0",
4242
"@typescript-eslint/eslint-plugin": "^5.46.0",
4343
"@typescript-eslint/parser": "^5.46.0",

packages/api-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"web-components"
2828
],
2929
"dependencies": {
30-
"custom-elements-manifest": "^1.0.0",
30+
"custom-elements-manifest": "^2.0.0",
3131
"lit": "^2.0.0",
3232
"tslib": "^2.3.1"
3333
},

packages/api-common/src/manifest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {
22
Attribute,
3-
ClassField,
3+
ClassField as ManifestClassField,
44
ClassLike,
55
ClassMember,
66
ClassMethod,
@@ -15,6 +15,15 @@ import type {
1515
Slot
1616
} from 'custom-elements-manifest/schema';
1717

18+
// FIXME: remove once new custom-elements-manifest version is released
19+
// https://github.com/webcomponents/custom-elements-manifest/pull/118
20+
type ClassField = ManifestClassField & {
21+
/**
22+
* Whether the property is read-only.
23+
*/
24+
readonly?: boolean;
25+
};
26+
1827
export type {
1928
Attribute,
2029
ClassField,

packages/api-demo/src/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class ApiDemoLayout extends LitElement {
206206
}
207207

208208
this.knobs = {};
209-
this.propKnobs = getKnobs(this.tag, this.props, this.exclude);
209+
this.propKnobs = getKnobs(this.props, this.exclude);
210210
this.customKnobs = getCustomKnobs(this.tag, this.vid);
211211
}
212212
}

packages/api-demo/src/ui/knobs.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,13 @@ const getDefault = (prop: PropertyKnob): KnobValue => {
1818
}
1919
};
2020

21-
// TODO: remove when analyzer outputs "readOnly" to JSON
22-
const isGetter = (
23-
ctor: CustomElementConstructor | undefined,
24-
prop: string
25-
): boolean => {
26-
function getDescriptor(
27-
obj: CustomElementConstructor
28-
): PropertyDescriptor | undefined {
29-
return obj === HTMLElement
30-
? undefined
31-
: Object.getOwnPropertyDescriptor(obj.prototype, prop) ||
32-
getDescriptor(Object.getPrototypeOf(obj));
33-
}
34-
35-
let result = false;
36-
if (ctor) {
37-
const descriptor = getDescriptor(ctor);
38-
result = Boolean(
39-
descriptor && descriptor.get && descriptor.set === undefined
40-
);
41-
}
42-
return result;
43-
};
44-
4521
const normalizeType = (type: string | undefined = ''): string =>
4622
type.replace(' | undefined', '').replace(' | null', '');
4723

48-
export const getKnobs = (
49-
tag: string,
50-
props: ClassField[],
51-
exclude = ''
52-
): PropertyKnob[] => {
24+
export const getKnobs = (props: ClassField[], exclude = ''): PropertyKnob[] => {
5325
// Exclude getters and specific properties
5426
let propKnobs = props.filter(
55-
({ name }) =>
56-
!exclude.includes(name) && !isGetter(customElements.get(tag), name)
27+
({ name, readonly }) => !exclude.includes(name) && !readonly
5728
) as PropertyKnob[];
5829

5930
// Set knob types and default knobs values

yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,10 +1164,10 @@
11641164
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
11651165
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg==
11661166

1167-
"@custom-elements-manifest/analyzer@^0.6.6":
1168-
version "0.6.6"
1169-
resolved "https://registry.yarnpkg.com/@custom-elements-manifest/analyzer/-/analyzer-0.6.6.tgz#52db8a3f6c575821d05694ff5a0295c0cb4bbb07"
1170-
integrity sha512-aPBZBdkrGcQPhgPPEucgw66vfOfLpS80GOGzDXE8NZuO/VmTdy3QQNAsuD4MPJmv9eRPV9W2V7ezodS5g8erng==
1167+
"@custom-elements-manifest/analyzer@^0.8.0":
1168+
version "0.8.4"
1169+
resolved "https://registry.yarnpkg.com/@custom-elements-manifest/analyzer/-/analyzer-0.8.4.tgz#34fce1158a44cb7a9d8c1c7415e8c9d03e25d95f"
1170+
integrity sha512-hibYFNoqPc/xSH9ySuotOllz3UtQnnbG912oC0RtRwHGilnOVT5zeL3Ip26swCjiuFAp8Y0uLN5DwnMpa/xXYQ==
11711171
dependencies:
11721172
"@custom-elements-manifest/find-dependencies" "^0.0.5"
11731173
"@github/catalyst" "^1.6.0"
@@ -3183,11 +3183,16 @@ csv@^5.5.0:
31833183
csv-stringify "^5.6.5"
31843184
stream-transform "^2.1.3"
31853185

3186-
[email protected], custom-elements-manifest@^1.0.0:
3186+
31873187
version "1.0.0"
31883188
resolved "https://registry.yarnpkg.com/custom-elements-manifest/-/custom-elements-manifest-1.0.0.tgz#b35c2129076a1dc9f95d720c6f7b5b71a857274b"
31893189
integrity sha512-j59k0ExGCKA8T6Mzaq+7axc+KVHwpEphEERU7VZ99260npu/p/9kd+Db+I3cGKxHkM5y6q5gnlXn00mzRQkX2A==
31903190

3191+
custom-elements-manifest@^2.0.0:
3192+
version "2.0.0"
3193+
resolved "https://registry.yarnpkg.com/custom-elements-manifest/-/custom-elements-manifest-2.0.0.tgz#6b234f7a57c68ecda291ea70882555729617de6d"
3194+
integrity sha512-1MmhBRszwnNYqn56nkMeHXn/Zlh998+6Yal3wedbXI7NzKPG02GDgjspdN1NiuDtt2yb5n94JvFwPOF7Prnocg==
3195+
31913196
date-fns@^2.29.1:
31923197
version "2.29.3"
31933198
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"

0 commit comments

Comments
 (0)