Skip to content

Commit 7a95a7c

Browse files
Branch was auto-updated with the latest.
2 parents b6f3f1a + c85b570 commit 7a95a7c

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

elements/pfe-readtime/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This component functions purely as inline-content and does not require any focus
1313
## Attributes
1414

1515
- `word-count`: Is the data-attribute you will leverage for readtime. Example: word-count="2500" will let the component know that there is 2500 words in that section and it will do it's calculations based on that number. If you don't want to/have a data-attribute to leverage you can use id="readtime1" and it will get the word count for you.
16-
-`wpm`: Is the attribute used to store the average words per minute readtime for each supported country. For more information on these you can read https://irisreading.com/average-reading-speed-in-various-languages and https://iovs.arvojournals.org/article.aspx?articleid=216606.
16+
- `wpm`: Is the attribute used to store the average words per minute readtime for each supported country. For more information on these you can read https://irisreading.com/average-reading-speed-in-various-languages and https://iovs.arvojournals.org/article.aspx?articleid=216606.
1717
- `template`: Rather than use the light DOM region to provide the string template, you can also pass in the value via this attribute. Note that %t will be replaced with the computed readtime.
1818
- `lang`: By default the component will look to the language specified on the html tag but it can also accept an override via this attribute on a component level.
1919
- `for`: Specify the selector of the content you want to capture the word-count from. Whatever you enter into this attribute will be found using `document.querySelector(<for attribute value>)`.

elements/pfe-readtime/pfe-readtime.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ export class PfeReadtime extends LitElement {
8787
@observed
8888
@property({ type: String, reflect: true }) for?: string;
8989

90-
@property({ type: Number, reflect: true }) readtime = 0;
91-
9290
@state() private content?: Node;
9391

9492
@state() private readString = '';
9593

94+
private _readtime = 0;
95+
96+
/**
97+
* Number of minutes readtime, estimated
98+
* @attr {number} readtime
99+
*/
100+
get readtime() {
101+
return this._readtime;
102+
}
103+
96104
connectedCallback() {
97105
super.connectedCallback();
98106
this._forChanged(undefined, this.for);
@@ -144,10 +152,12 @@ export class PfeReadtime extends LitElement {
144152
}
145153

146154
private _updateReadtime() {
147-
this.readtime =
155+
this._readtime =
148156
!this.wpm ? 0
149157
: Math.floor(this.wordCount / this.wpm) || 0;
150158

159+
this.setAttribute('readtime', this._readtime.toString());
160+
151161
this.readString =
152162
this.readtime <= 0 ? ''
153163
: this.templateString?.match(/%t/) ? this.templateString.replace('%t', `${this.readtime}`)

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/node_modules/cem-plugin-readonly/index.d.ts b/node_modules/cem-plugin-readonly/index.d.ts
2+
new file mode 100644
3+
index 0000000..7df30d1
4+
--- /dev/null
5+
+++ b/node_modules/cem-plugin-readonly/index.d.ts
6+
@@ -0,0 +1,2 @@
7+
+import type { Plugin } from '@custom-elements-manifest/analyzer';
8+
+export declare function readonlyPlugin(): Plugin;
9+
diff --git a/node_modules/cem-plugin-readonly/index.js b/node_modules/cem-plugin-readonly/index.js
10+
index 132e6ee..bf8751e 100644
11+
--- a/node_modules/cem-plugin-readonly/index.js
12+
+++ b/node_modules/cem-plugin-readonly/index.js
13+
@@ -10,7 +10,7 @@ import { isStaticMember } from '@custom-elements-manifest/analyzer/src/utils/ast
14+
function isReadonly(node, ts) {
15+
return (
16+
node.modifiers?.some?.(x => x.kind === ts.SyntaxKind.ReadonlyKeyword) ||
17+
- node.jsDoc?.tags?.some?.(tag => tag.kind === ts.SyntaxKind.JSDocReadonlyTag)
18+
+ node.jsDoc?.flatMap(i => i.tags).some(tag => tag?.kind === ts.SyntaxKind.JSDocReadonlyTag)
19+
);
20+
}
21+

tools/pfe-tools/custom-elements-manifest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Config } from '@custom-elements-manifest/analyzer';
22

33
import { moduleFileExtensionsPlugin } from 'cem-plugin-module-file-extensions';
4+
import { readonlyPlugin } from 'cem-plugin-readonly';
45
import { cssCustomPropertiesDefaultPlugin } from './custom-elements-manifest/cssCustomPropertiesDefaultPlugin.js';
56
import { dedentDescriptionsPlugin } from './custom-elements-manifest/dedent-descriptions.js';
67
import { deprecatedDescriptionInlineTagPlugin } from './custom-elements-manifest/deprecated-description-inline-tag.js';
@@ -20,6 +21,7 @@ export function pfeCustomElementsManifestConfig(options?: Config): Config {
2021
],
2122
litelement: true,
2223
plugins: [
24+
readonlyPlugin(),
2325
cssCustomPropertiesDefaultPlugin(),
2426
moduleFileExtensionsPlugin(),
2527
moduleFileExtensionsPlugin({ from: 'src/', to: '' }),

tools/pfe-tools/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@web/test-runner-playwright": "^0.8.8",
6363
"api-viewer-element": "^0.6.2",
6464
"cem-plugin-module-file-extensions": "^0.0.2",
65+
"cem-plugin-readonly": "^0.0.2",
6566
"dedent": "^0.7.0",
6667
"dotenv": "^10.0.0",
6768
"esbuild": "^0.14.0",

0 commit comments

Comments
 (0)