nuxt-telegram-mini-app 0.0.1 → 0.0.3
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/.github/dependabot.yml +6 -0
- package/README.md +72 -15
- package/app/assets/css/main.css +1 -1
- package/app/components/tg/Button.vue +4 -3
- package/app/components/tg/Cell.vue +1 -1
- package/app/components/tg/Content.vue +1 -0
- package/app/composables/telegram.ts +370 -36
- package/app/pages/components.vue +283 -32
- package/app/pages/index.vue +16 -21
- package/app/types/telegram-webapp.ts +157 -3
- package/app/utils/color.ts +29 -5
- package/nuxt.config.ts +1 -1
- package/package.json +17 -17
- package/tests/pages.spec.ts +9 -12
- package/tests/telegram.spec.ts +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ A comprehensive template for building Telegram Mini Apps using Nuxt 4, Vue 3, Ty
|
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
10
|
+

|
|
10
11
|
|
|
11
12
|
## ✨ Features
|
|
12
13
|
|
|
@@ -31,7 +32,9 @@ A comprehensive template for building Telegram Mini Apps using Nuxt 4, Vue 3, Ty
|
|
|
31
32
|
- **⬅️ Back Button** - Navigation back button control
|
|
32
33
|
- **👤 User Data** - Access to Telegram user information
|
|
33
34
|
- **🎨 Theme Integration** - Automatic Telegram theme colors
|
|
34
|
-
- **📐 Viewport Control** -
|
|
35
|
+
- **📐 Viewport Control** - Fullscreen, safe-area, and responsive viewport management
|
|
36
|
+
- **🏠 Home Screen Shortcuts** - Add/check Mini App shortcut support
|
|
37
|
+
- **📍 Device APIs** - Feature-detected storage, location, and motion access
|
|
35
38
|
- **🔗 Deep Linking** - External and Telegram link handling
|
|
36
39
|
- **📤 Sharing** - Built-in sharing functionality
|
|
37
40
|
|
|
@@ -159,7 +162,10 @@ import {
|
|
|
159
162
|
useBackButton,
|
|
160
163
|
useHapticFeedback,
|
|
161
164
|
useInitData,
|
|
162
|
-
useThemeParams
|
|
165
|
+
useThemeParams,
|
|
166
|
+
useViewport,
|
|
167
|
+
useHomeScreen,
|
|
168
|
+
useTelegramStorage
|
|
163
169
|
} from '~/composables/telegram'
|
|
164
170
|
|
|
165
171
|
const main = useMainButton()
|
|
@@ -167,6 +173,9 @@ const back = useBackButton()
|
|
|
167
173
|
const haptic = useHapticFeedback()
|
|
168
174
|
const init = useInitData()
|
|
169
175
|
const theme = useThemeParams()
|
|
176
|
+
const viewport = useViewport()
|
|
177
|
+
const homeScreen = useHomeScreen()
|
|
178
|
+
const storage = useTelegramStorage('device')
|
|
170
179
|
|
|
171
180
|
// Configure main button
|
|
172
181
|
onMounted(() => {
|
|
@@ -188,6 +197,17 @@ onMounted(() => {
|
|
|
188
197
|
// Access user data
|
|
189
198
|
const userName = computed(() => init.user.value?.first_name || 'Guest')
|
|
190
199
|
|
|
200
|
+
// Newer Telegram APIs are feature-detected
|
|
201
|
+
function openFullscreen() {
|
|
202
|
+
if (!viewport.fullscreen.value) {
|
|
203
|
+
viewport.requestFullscreen()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function rememberPreference() {
|
|
208
|
+
storage.setItem('preferred_mode', theme.dark.value ? 'dark' : 'light')
|
|
209
|
+
}
|
|
210
|
+
|
|
191
211
|
// Use theme colors
|
|
192
212
|
const bgColor = computed(() => theme.backgroundColor.value)
|
|
193
213
|
</script>
|
|
@@ -226,29 +246,46 @@ Nuxt Layers provide a way to extend and customize Nuxt applications by sharing c
|
|
|
226
246
|
|
|
227
247
|
### Using This Template as a Layer
|
|
228
248
|
|
|
229
|
-
To use this Telegram Mini App template as a layer in another Nuxt project:
|
|
249
|
+
To use this Telegram Mini App template as a layer in another Nuxt project, install it as an NPM package:
|
|
250
|
+
|
|
251
|
+
1. **Install the NPM package**:
|
|
252
|
+
```bash
|
|
253
|
+
npm install nuxt-telegram-mini-app
|
|
254
|
+
# or
|
|
255
|
+
yarn add nuxt-telegram-mini-app
|
|
256
|
+
# or
|
|
257
|
+
pnpm add nuxt-telegram-mini-app
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
2. **Configure your Nuxt project** to extend this layer:
|
|
261
|
+
```ts
|
|
262
|
+
// nuxt.config.ts
|
|
263
|
+
export default defineNuxtConfig({
|
|
264
|
+
extends: [
|
|
265
|
+
'nuxt-telegram-mini-app'
|
|
266
|
+
],
|
|
267
|
+
// Your custom config here
|
|
268
|
+
})
|
|
269
|
+
```
|
|
230
270
|
|
|
231
|
-
|
|
271
|
+
Alternatively, if you prefer to use a local clone or git dependency:
|
|
232
272
|
```bash
|
|
233
|
-
#
|
|
273
|
+
# Clone as a subdirectory
|
|
234
274
|
git clone https://github.com/patricktobias86/nuxt-telegram-mini-app.git layers/telegram-app
|
|
235
275
|
|
|
236
|
-
#
|
|
237
|
-
# In your project's package.json:
|
|
276
|
+
# Or add as git dependency in package.json:
|
|
238
277
|
# "dependencies": {
|
|
239
278
|
# "nuxt-telegram-mini-app": "github:patricktobias86/nuxt-telegram-mini-app"
|
|
240
279
|
# }
|
|
241
280
|
```
|
|
242
281
|
|
|
243
|
-
|
|
282
|
+
Then configure:
|
|
244
283
|
```ts
|
|
245
284
|
// nuxt.config.ts
|
|
246
285
|
export default defineNuxtConfig({
|
|
247
286
|
extends: [
|
|
248
|
-
|
|
249
|
-
'
|
|
250
|
-
// Or npm package
|
|
251
|
-
// 'nuxt-telegram-mini-app'
|
|
287
|
+
'./layers/telegram-app'
|
|
288
|
+
// or 'nuxt-telegram-mini-app' for git dependency
|
|
252
289
|
],
|
|
253
290
|
// Your custom config here
|
|
254
291
|
})
|
|
@@ -382,6 +419,7 @@ export default {
|
|
|
382
419
|
- `setParams(params)` - Configure button
|
|
383
420
|
- `onClick(callback)` - Handle clicks
|
|
384
421
|
- `visible` - Visibility state
|
|
422
|
+
- Supports shine effect, custom emoji icon, and other current BottomButton params
|
|
385
423
|
|
|
386
424
|
#### `useBackButton()`
|
|
387
425
|
- `show()` / `hide()` - Control visibility
|
|
@@ -403,6 +441,26 @@ export default {
|
|
|
403
441
|
- `buttonColor` - Theme button color
|
|
404
442
|
- And more theme colors...
|
|
405
443
|
|
|
444
|
+
#### `useViewport()`
|
|
445
|
+
- `requestFullscreen()` / `exitFullscreen()` - Toggle Telegram fullscreen when supported
|
|
446
|
+
- `insets` - Device safe-area insets
|
|
447
|
+
- `contentInsets` - Content safe-area insets
|
|
448
|
+
|
|
449
|
+
#### `useMiniApp()`
|
|
450
|
+
- `hideKeyboard()` - Hide the native keyboard when supported
|
|
451
|
+
- `lockOrientation()` / `unlockOrientation()` - Control device orientation when supported
|
|
452
|
+
- `enableVerticalSwipes()` / `disableVerticalSwipes()` - Control vertical swipe gestures
|
|
453
|
+
|
|
454
|
+
#### New Telegram APIs
|
|
455
|
+
- `useSecondaryButton()` - Control Telegram's secondary bottom button
|
|
456
|
+
- `useSettingsButton()` - Control the Mini App settings menu button
|
|
457
|
+
- `useHomeScreen()` - Add/check home screen shortcuts
|
|
458
|
+
- `useEmojiStatus()` - Request emoji status access and open the set-status dialog
|
|
459
|
+
- `useTelegramStorage(type)` - Use `cloud`, `device`, or `secure` Telegram storage
|
|
460
|
+
- `useLocationManager()` - Initialize and request native location data
|
|
461
|
+
- `useDeviceMotion()` - Access accelerometer, orientation, and gyroscope objects
|
|
462
|
+
- `shareToStory()`, `shareMessage()`, `downloadFile()`, `requestChat()` - Wrappers for newer Telegram actions
|
|
463
|
+
|
|
406
464
|
### Components
|
|
407
465
|
|
|
408
466
|
#### `<TgButton>`
|
|
@@ -588,8 +646,7 @@ export default defineNuxtConfig({
|
|
|
588
646
|
app: {
|
|
589
647
|
head: {
|
|
590
648
|
script: [{
|
|
591
|
-
src: 'https://telegram.org/js/telegram-web-app.js?
|
|
592
|
-
defer: true
|
|
649
|
+
src: 'https://telegram.org/js/telegram-web-app.js?62'
|
|
593
650
|
}]
|
|
594
651
|
}
|
|
595
652
|
}
|
|
@@ -598,7 +655,7 @@ export default defineNuxtConfig({
|
|
|
598
655
|
|
|
599
656
|
### Telegram WebApp Script
|
|
600
657
|
|
|
601
|
-
The template automatically includes the Telegram WebApp script. The
|
|
658
|
+
The template automatically includes the Telegram WebApp script. The wrapper feature-detects newer APIs because the available API version depends on the user's Telegram client.
|
|
602
659
|
|
|
603
660
|
## 🤝 Contributing
|
|
604
661
|
|
package/app/assets/css/main.css
CHANGED
|
@@ -40,7 +40,7 @@ html, body {
|
|
|
40
40
|
overscroll-behavior: contain;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
.tg-bg { background-color: var(
|
|
43
|
+
.tg-bg { background-color: var(---tg-theme-bg-color); }
|
|
44
44
|
.tg-secondary-bg { background-color: var(--tg-theme-secondary-bg-color); }
|
|
45
45
|
.tg-section-bg { background-color: var(--tg-theme-section-bg-color); }
|
|
46
46
|
.tg-link, a { color: var(--tg-theme-link-color); }
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<div class="px-3">
|
|
3
|
+
<component :is="tag" v-bind="bind" :class="classes" :disabled="disabled || loading" @click="onClick">
|
|
3
4
|
<Icon v-if="loading" name="i-heroicons-arrow-path-20-solid" class="h-5 w-5 animate-spin" />
|
|
4
5
|
<Icon v-if="icon && iconPosition === 'left' && !loading" :name="icon" class="h-5 w-5" />
|
|
5
6
|
<span>{{ title }}</span>
|
|
6
7
|
<Icon v-if="icon && iconPosition === 'right' && !loading" :name="icon" class="h-5 w-5" />
|
|
7
8
|
</component>
|
|
9
|
+
</div>
|
|
8
10
|
</template>
|
|
9
11
|
|
|
10
12
|
<script setup lang="ts">
|
|
11
13
|
import { computed } from 'vue'
|
|
12
|
-
import { shareURL } from '~/composables/telegram'
|
|
13
|
-
import { useHapticFeedback } from '~/composables/telegram'
|
|
14
|
+
import { shareURL, useHapticFeedback } from '~/composables/telegram'
|
|
14
15
|
|
|
15
16
|
const props = withDefaults(defineProps<{
|
|
16
17
|
title: string
|
|
@@ -79,7 +79,7 @@ const bgClass = computed(() => props.tone === 'secondary' ? 'bg-secondaryBg' : '
|
|
|
79
79
|
const showChevron = computed(() => props.chevron ?? isLink.value)
|
|
80
80
|
|
|
81
81
|
const rootClass = computed(() => [
|
|
82
|
-
'w-full flex items-center gap-3
|
|
82
|
+
'w-full flex items-center gap-3 p-4',
|
|
83
83
|
bgClass.value,
|
|
84
84
|
props.border ? 'border-b border-sectionSeparator last:border-b-0' : '',
|
|
85
85
|
(isLink.value || props.clickable) ? 'hover:bg-secondaryBg transition-colors' : '',
|