@aarongustafson/pull-to-refresh 0.0.4 → 1.0.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/README.md CHANGED
@@ -29,21 +29,31 @@ npm install @aarongustafson/pull-to-refresh
29
29
 
30
30
  ### Usage
31
31
 
32
- **Option 1: Auto-define (easiest)**
32
+ **Option 1: Manual registration**
33
33
  ```javascript
34
- import '@aarongustafson/pull-to-refresh';
34
+ import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
35
+
36
+ customElements.define('pull-to-refresh', PullToRefreshElement);
35
37
  ```
36
38
 
37
- **Option 2: Manual registration**
39
+ **Option 2: Auto-define (browser environments only)**
38
40
  ```javascript
39
- import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh/pull-to-refresh.js';
40
- customElements.define('pull-to-refresh', PullToRefreshElement);
41
+ import '@aarongustafson/pull-to-refresh/define.js';
42
+ // Registers <pull-to-refresh> when customElements is available
41
43
  ```
42
44
 
43
- **Option 3: Both (class + auto-define)**
45
+ Prefer to control when registration happens? Call the helper directly:
46
+
44
47
  ```javascript
45
- import { PullToRefreshElement } from '@aarongustafson/pull-to-refresh';
46
- // Element is registered AND class is available
48
+ import { definePullToRefresh } from '@aarongustafson/pull-to-refresh/define.js';
49
+
50
+ definePullToRefresh();
51
+ ```
52
+
53
+ You can also include the guarded script from HTML:
54
+
55
+ ```html
56
+ <script src="./node_modules/@aarongustafson/pull-to-refresh/define.js" type="module"></script>
47
57
  ```
48
58
 
49
59
  ### Basic Example
@@ -8,11 +8,225 @@
8
8
  "declarations": [
9
9
  {
10
10
  "kind": "class",
11
- "description": "Refreshes the current document or runs a specific JavaScript function when pulling down on the page",
11
+ "description": "Web component that enables pull-to-refresh functionality.",
12
12
  "name": "PullToRefreshElement",
13
- "members": [],
14
- "events": [],
15
- "attributes": [],
13
+ "members": [
14
+ {
15
+ "kind": "field",
16
+ "name": "threshold",
17
+ "type": {
18
+ "text": "number"
19
+ },
20
+ "default": "80",
21
+ "description": "Distance in pixels to trigger refresh",
22
+ "attribute": "threshold"
23
+ },
24
+ {
25
+ "kind": "field",
26
+ "name": "indicatorText",
27
+ "type": {
28
+ "text": "string"
29
+ },
30
+ "description": "Text shown when pulling down",
31
+ "attribute": "indicator-text"
32
+ },
33
+ {
34
+ "kind": "field",
35
+ "name": "releaseText",
36
+ "type": {
37
+ "text": "string"
38
+ },
39
+ "description": "Text shown when ready to release",
40
+ "attribute": "release-text"
41
+ },
42
+ {
43
+ "kind": "field",
44
+ "name": "refreshingText",
45
+ "type": {
46
+ "text": "string"
47
+ },
48
+ "description": "Text shown while refreshing",
49
+ "attribute": "refreshing-text"
50
+ },
51
+ {
52
+ "kind": "field",
53
+ "name": "disabled",
54
+ "type": {
55
+ "text": "boolean"
56
+ },
57
+ "default": "false",
58
+ "description": "Disables the pull-to-refresh functionality",
59
+ "attribute": "disabled"
60
+ },
61
+ {
62
+ "kind": "field",
63
+ "name": "disableSelection",
64
+ "type": {
65
+ "text": "boolean"
66
+ },
67
+ "default": "false",
68
+ "description": "Disables text selection during pull gesture",
69
+ "attribute": "disable-selection"
70
+ },
71
+ {
72
+ "kind": "method",
73
+ "name": "registerTranslations",
74
+ "static": true,
75
+ "parameters": [
76
+ {
77
+ "name": "translations",
78
+ "type": {
79
+ "text": "object"
80
+ },
81
+ "description": "Object containing translation strings for different languages"
82
+ }
83
+ ],
84
+ "description": "Register custom translations for the component"
85
+ },
86
+ {
87
+ "kind": "method",
88
+ "name": "triggerRefresh",
89
+ "description": "Manually trigger a refresh action"
90
+ },
91
+ {
92
+ "kind": "method",
93
+ "name": "completeRefresh",
94
+ "description": "Complete the refresh action and reset the indicator"
95
+ }
96
+ ],
97
+ "events": [
98
+ {
99
+ "name": "ptr:pull-start",
100
+ "type": {
101
+ "text": "CustomEvent"
102
+ },
103
+ "description": "Fired when pull gesture starts"
104
+ },
105
+ {
106
+ "name": "ptr:pull-move",
107
+ "type": {
108
+ "text": "CustomEvent"
109
+ },
110
+ "description": "Fired during pull gesture, contains { distance } in detail"
111
+ },
112
+ {
113
+ "name": "ptr:pull-end",
114
+ "type": {
115
+ "text": "CustomEvent"
116
+ },
117
+ "description": "Fired when pull gesture ends"
118
+ },
119
+ {
120
+ "name": "ptr:refresh",
121
+ "type": {
122
+ "text": "CustomEvent"
123
+ },
124
+ "description": "Fired when refresh is triggered"
125
+ },
126
+ {
127
+ "name": "ptr:refresh-complete",
128
+ "type": {
129
+ "text": "CustomEvent"
130
+ },
131
+ "description": "Fired when refresh completes"
132
+ }
133
+ ],
134
+ "attributes": [
135
+ {
136
+ "name": "threshold",
137
+ "type": {
138
+ "text": "number"
139
+ },
140
+ "default": "80",
141
+ "description": "Distance in pixels to trigger refresh",
142
+ "fieldName": "threshold"
143
+ },
144
+ {
145
+ "name": "indicator-text",
146
+ "type": {
147
+ "text": "string"
148
+ },
149
+ "description": "Text shown when pulling down (default: localized \"↓ Pull to refresh\")",
150
+ "fieldName": "indicatorText"
151
+ },
152
+ {
153
+ "name": "release-text",
154
+ "type": {
155
+ "text": "string"
156
+ },
157
+ "description": "Text shown when ready to release (default: localized \"↻ Release to refresh\")",
158
+ "fieldName": "releaseText"
159
+ },
160
+ {
161
+ "name": "refreshing-text",
162
+ "type": {
163
+ "text": "string"
164
+ },
165
+ "description": "Text shown while refreshing (default: localized \"⏳ Refreshing...\")",
166
+ "fieldName": "refreshingText"
167
+ },
168
+ {
169
+ "name": "lang",
170
+ "type": {
171
+ "text": "string"
172
+ },
173
+ "description": "Language code for localization (falls back to closest [lang], document lang, or 'en')"
174
+ },
175
+ {
176
+ "name": "disabled",
177
+ "type": {
178
+ "text": "boolean"
179
+ },
180
+ "description": "Disables the pull-to-refresh functionality",
181
+ "fieldName": "disabled"
182
+ },
183
+ {
184
+ "name": "disable-selection",
185
+ "type": {
186
+ "text": "boolean"
187
+ },
188
+ "description": "Disables text selection during pull gesture",
189
+ "fieldName": "disableSelection"
190
+ }
191
+ ],
192
+ "slots": [
193
+ {
194
+ "name": "",
195
+ "description": "Default slot for content"
196
+ },
197
+ {
198
+ "name": "indicator",
199
+ "description": "Optional custom indicator element"
200
+ }
201
+ ],
202
+ "cssParts": [],
203
+ "cssProperties": [
204
+ {
205
+ "name": "--ptr-indicator-height",
206
+ "description": "Height of the indicator area",
207
+ "default": "3.125rem"
208
+ },
209
+ {
210
+ "name": "--ptr-indicator-bg",
211
+ "description": "Background color of the indicator",
212
+ "default": "ButtonFace"
213
+ },
214
+ {
215
+ "name": "--ptr-indicator-color",
216
+ "description": "Text color of the indicator",
217
+ "default": "ButtonText"
218
+ },
219
+ {
220
+ "name": "--ptr-indicator-font-size",
221
+ "description": "Font size of the indicator text",
222
+ "default": "0.875rem"
223
+ },
224
+ {
225
+ "name": "--ptr-transition-duration",
226
+ "description": "Duration of indicator transitions",
227
+ "default": "0.2s"
228
+ }
229
+ ],
16
230
  "superclass": {
17
231
  "name": "HTMLElement"
18
232
  },
package/define.js CHANGED
@@ -1,3 +1,18 @@
1
1
  import { PullToRefreshElement } from './pull-to-refresh.js';
2
2
 
3
- customElements.define('pull-to-refresh', PullToRefreshElement);
3
+ export function definePullToRefresh(tagName = 'pull-to-refresh') {
4
+ const hasWindow = typeof window !== 'undefined';
5
+ const registry = hasWindow ? window.customElements : undefined;
6
+
7
+ if (!registry || typeof registry.define !== 'function') {
8
+ return false;
9
+ }
10
+
11
+ if (!registry.get(tagName)) {
12
+ registry.define(tagName, PullToRefreshElement);
13
+ }
14
+
15
+ return true;
16
+ }
17
+
18
+ definePullToRefresh();
package/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { PullToRefreshElement } from './pull-to-refresh.js';
2
- import './define.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aarongustafson/pull-to-refresh",
3
- "version": "0.0.4",
4
- "description": "Refreshes the current document or runs a specific JavaScript function when pulling down on the page",
3
+ "version": "1.0.0",
4
+ "description": "Web component that enables pull-to-refresh functionality.",
5
5
  "keywords": [
6
6
  "html",
7
7
  "custom element",
@@ -1,7 +1,7 @@
1
1
  import defaultTranslations from './translations.json' with { type: 'json' };
2
2
 
3
3
  /**
4
- * PullToRefreshElement - Refreshes the current document or runs a specific JavaScript function when pulling down on the page
4
+ * PullToRefreshElement - Web component that enables pull-to-refresh functionality
5
5
  *
6
6
  * @element pull-to-refresh
7
7
  *