Skip to content

feat: update custom-elements-manifest to v2.0.0, add readonly #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/fresh-candles-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@api-viewer/common': patch
'@api-viewer/demo': patch
'@api-viewer/docs': patch
'@api-viewer/tabs': patch
'api-viewer-element': patch
---

Update custom-elements-manifest to v2.0.0, add readonly support
3 changes: 2 additions & 1 deletion docs/assets/custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@
"name": "focused",
"type": {
"text": "Element | null"
}
},
"readonly": true
},
{
"kind": "method",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.25.2",
"@custom-elements-manifest/analyzer": "^0.6.6",
"@custom-elements-manifest/analyzer": "^0.8.0",
"@size-limit/preset-small-lib": "^8.1.0",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"web-components"
],
"dependencies": {
"custom-elements-manifest": "^1.0.0",
"custom-elements-manifest": "^2.0.0",
"lit": "^2.0.0",
"tslib": "^2.3.1"
},
Expand Down
11 changes: 10 additions & 1 deletion packages/api-common/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
Attribute,
ClassField,
ClassField as ManifestClassField,
ClassLike,
ClassMember,
ClassMethod,
Expand All @@ -15,6 +15,15 @@ import type {
Slot
} from 'custom-elements-manifest/schema';

// FIXME: remove once new custom-elements-manifest version is released
// https://github.com/webcomponents/custom-elements-manifest/pull/118
type ClassField = ManifestClassField & {
/**
* Whether the property is read-only.
*/
readonly?: boolean;
};

export type {
Attribute,
ClassField,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-demo/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class ApiDemoLayout extends LitElement {
}

this.knobs = {};
this.propKnobs = getKnobs(this.tag, this.props, this.exclude);
this.propKnobs = getKnobs(this.props, this.exclude);
this.customKnobs = getCustomKnobs(this.tag, this.vid);
}
}
Expand Down
33 changes: 2 additions & 31 deletions packages/api-demo/src/ui/knobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,13 @@ const getDefault = (prop: PropertyKnob): KnobValue => {
}
};

// TODO: remove when analyzer outputs "readOnly" to JSON
const isGetter = (
ctor: CustomElementConstructor | undefined,
prop: string
): boolean => {
function getDescriptor(
obj: CustomElementConstructor
): PropertyDescriptor | undefined {
return obj === HTMLElement
? undefined
: Object.getOwnPropertyDescriptor(obj.prototype, prop) ||
getDescriptor(Object.getPrototypeOf(obj));
}

let result = false;
if (ctor) {
const descriptor = getDescriptor(ctor);
result = Boolean(
descriptor && descriptor.get && descriptor.set === undefined
);
}
return result;
};

const normalizeType = (type: string | undefined = ''): string =>
type.replace(' | undefined', '').replace(' | null', '');

export const getKnobs = (
tag: string,
props: ClassField[],
exclude = ''
): PropertyKnob[] => {
export const getKnobs = (props: ClassField[], exclude = ''): PropertyKnob[] => {
// Exclude getters and specific properties
let propKnobs = props.filter(
({ name }) =>
!exclude.includes(name) && !isGetter(customElements.get(tag), name)
({ name, readonly }) => !exclude.includes(name) && !readonly
) as PropertyKnob[];

// Set knob types and default knobs values
Expand Down
15 changes: 10 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,10 @@
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg==

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

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

custom-elements-manifest@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/custom-elements-manifest/-/custom-elements-manifest-2.0.0.tgz#6b234f7a57c68ecda291ea70882555729617de6d"
integrity sha512-1MmhBRszwnNYqn56nkMeHXn/Zlh998+6Yal3wedbXI7NzKPG02GDgjspdN1NiuDtt2yb5n94JvFwPOF7Prnocg==

date-fns@^2.29.1:
version "2.29.3"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
Expand Down