nuxt-toastflow 1.0.0 → 1.0.1-beta.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
@@ -2,16 +2,21 @@
2
2
 
3
3
  # nuxt-toastflow
4
4
 
5
- Nuxt module wrapper for `vue-toastflow` so Toastflow works out of the box in Nuxt.
5
+ Nuxt module wrapper for `vue-toastflow` so Toastflow works out of the box in Nuxt
6
6
 
7
- ## Install
7
+ ## 📚 Documentation
8
+
9
+ - Docs: https://docs.toastflow.top/
10
+ - Comparisons (Vue ecosystem toasts): https://docs.toastflow.top/comparisons/overview
11
+ - Playground: https://toastflow.top/
12
+ - npm: https://www.npmjs.com/package/nuxt-toastflow
13
+
14
+ ## 🚀 Quick Start
8
15
 
9
16
  ```bash
10
17
  pnpm add nuxt-toastflow
11
18
  ```
12
19
 
13
- ## Usage
14
-
15
20
  ```ts
16
21
  // nuxt.config.ts
17
22
  export default defineNuxtConfig({
@@ -27,14 +32,6 @@ export default defineNuxtConfig({
27
32
 
28
33
  ```vue
29
34
  <!-- app.vue -->
30
- <template>
31
- <ToastContainer />
32
- <NuxtPage />
33
- </template>
34
- ```
35
-
36
- ```vue
37
-
38
35
  <script setup lang="ts">
39
36
  // Optional:
40
37
  // const toast = useToast();
@@ -44,6 +41,11 @@ export default defineNuxtConfig({
44
41
  description: "Your changes are live.",
45
42
  });
46
43
  </script>
44
+
45
+ <template>
46
+ <ToastContainer />
47
+ <NuxtPage />
48
+ </template>
47
49
  ```
48
50
 
49
51
  ## Options
@@ -0,0 +1,20 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { ToastConfig } from 'vue-toastflow';
3
+
4
+ interface NuxtToastflowOptions {
5
+ /**
6
+ * Global Toastflow config passed to createToastflow.
7
+ */
8
+ config: Partial<ToastConfig>;
9
+ /**
10
+ * Automatically include Toastflow CSS.
11
+ */
12
+ css: boolean;
13
+ /**
14
+ * Auto-register ToastContainer under this name. Set false to disable.
15
+ */
16
+ componentName: string | false;
17
+ }
18
+ declare const _default: _nuxt_schema.NuxtModule<NuxtToastflowOptions, NuxtToastflowOptions, false>;
19
+
20
+ export { type NuxtToastflowOptions, _default as default };
@@ -0,0 +1,20 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { ToastConfig } from 'vue-toastflow';
3
+
4
+ interface NuxtToastflowOptions {
5
+ /**
6
+ * Global Toastflow config passed to createToastflow.
7
+ */
8
+ config: Partial<ToastConfig>;
9
+ /**
10
+ * Automatically include Toastflow CSS.
11
+ */
12
+ css: boolean;
13
+ /**
14
+ * Auto-register ToastContainer under this name. Set false to disable.
15
+ */
16
+ componentName: string | false;
17
+ }
18
+ declare const _default: _nuxt_schema.NuxtModule<NuxtToastflowOptions, NuxtToastflowOptions, false>;
19
+
20
+ export { type NuxtToastflowOptions, _default as default };
package/dist/module.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/module.ts
21
+ var module_exports = {};
22
+ __export(module_exports, {
23
+ default: () => module_default
24
+ });
25
+ module.exports = __toCommonJS(module_exports);
26
+ var import_kit = require("@nuxt/kit");
27
+ function containsFunction(value, visited = /* @__PURE__ */ new Set()) {
28
+ if (typeof value === "function") {
29
+ return true;
30
+ }
31
+ if (!value || typeof value !== "object") {
32
+ return false;
33
+ }
34
+ if (visited.has(value)) {
35
+ return false;
36
+ }
37
+ visited.add(value);
38
+ if (Array.isArray(value)) {
39
+ return value.some(function(item) {
40
+ return containsFunction(item, visited);
41
+ });
42
+ }
43
+ const objectValues = Object.values(value);
44
+ return objectValues.some(function(item) {
45
+ return containsFunction(item, visited);
46
+ });
47
+ }
48
+ var module_default = (0, import_kit.defineNuxtModule)({
49
+ meta: {
50
+ name: "nuxt-toastflow",
51
+ configKey: "toastflow",
52
+ compatibility: {
53
+ nuxt: "^3.0.0 || ^4.0.0"
54
+ }
55
+ },
56
+ defaults: {
57
+ config: {},
58
+ css: true,
59
+ componentName: "ToastContainer"
60
+ },
61
+ setup(options, nuxt) {
62
+ if (containsFunction(options.config)) {
63
+ console.warn(
64
+ "[nuxt-toastflow] Functions in `toastflow.config` are not serializable in nuxt.config and will be omitted."
65
+ );
66
+ }
67
+ let serializedConfig = "{}";
68
+ try {
69
+ serializedConfig = JSON.stringify(options.config ?? {}, null, 2) ?? "{}";
70
+ } catch {
71
+ throw new Error(
72
+ "[nuxt-toastflow] `toastflow.config` must be JSON-serializable."
73
+ );
74
+ }
75
+ (0, import_kit.addPluginTemplate)({
76
+ filename: "toastflow.mjs",
77
+ mode: "client",
78
+ getContents: function() {
79
+ return [
80
+ 'import { createToastflow, toast } from "vue-toastflow";',
81
+ "",
82
+ "export default defineNuxtPlugin((nuxtApp) => {",
83
+ ` nuxtApp.vueApp.use(createToastflow(${serializedConfig}));`,
84
+ "",
85
+ " return {",
86
+ " provide: {",
87
+ " toast,",
88
+ " },",
89
+ " };",
90
+ "});",
91
+ ""
92
+ ].join("\n");
93
+ }
94
+ });
95
+ const toastTemplate = (0, import_kit.addTemplate)({
96
+ filename: "toastflow/toast.ts",
97
+ getContents: function() {
98
+ return [
99
+ 'import { useNuxtApp } from "#app";',
100
+ "",
101
+ 'type ToastApi = typeof import("vue-toastflow")["toast"];',
102
+ "",
103
+ "export function useToast(): ToastApi {",
104
+ " return useNuxtApp().$toast;",
105
+ "}",
106
+ "",
107
+ "export const toast: ToastApi = new Proxy({} as ToastApi, {",
108
+ " get(_target, key) {",
109
+ " const currentToast = useNuxtApp().$toast as Record<PropertyKey, unknown>;",
110
+ " const value = currentToast[key];",
111
+ ' if (typeof value === "function") {',
112
+ " return (value as (...args: unknown[]) => unknown).bind(currentToast);",
113
+ " }",
114
+ " return value;",
115
+ " },",
116
+ "});",
117
+ ""
118
+ ].join("\n");
119
+ }
120
+ });
121
+ (0, import_kit.addImports)({
122
+ name: "useToast",
123
+ from: toastTemplate.dst
124
+ });
125
+ (0, import_kit.addImports)({
126
+ name: "toast",
127
+ from: toastTemplate.dst
128
+ });
129
+ (0, import_kit.addTypeTemplate)({
130
+ filename: "types/nuxt-toastflow.d.ts",
131
+ getContents: function() {
132
+ return [
133
+ 'type ToastApi = typeof import("vue-toastflow")["toast"];',
134
+ "",
135
+ 'declare module "#app" {',
136
+ " interface NuxtApp {",
137
+ " $toast: ToastApi;",
138
+ " }",
139
+ "}",
140
+ "",
141
+ 'declare module "vue" {',
142
+ " interface ComponentCustomProperties {",
143
+ " $toast: ToastApi;",
144
+ " }",
145
+ "}",
146
+ "",
147
+ "export {};",
148
+ ""
149
+ ].join("\n");
150
+ }
151
+ });
152
+ if (options.componentName) {
153
+ (0, import_kit.addComponent)({
154
+ name: options.componentName,
155
+ export: "ToastContainer",
156
+ filePath: "vue-toastflow",
157
+ mode: "client"
158
+ });
159
+ }
160
+ if (options.css) {
161
+ const cssEntry = "vue-toastflow/styles.css";
162
+ const hasCssEntry = nuxt.options.css.some(function(entry) {
163
+ if (typeof entry === "string") {
164
+ return entry === cssEntry;
165
+ }
166
+ if (Array.isArray(entry) && typeof entry[0] === "string") {
167
+ return entry[0] === cssEntry;
168
+ }
169
+ return false;
170
+ });
171
+ if (!hasCssEntry) {
172
+ nuxt.options.css.push(cssEntry);
173
+ }
174
+ }
175
+ }
176
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "nuxt-toastflow",
3
+ "configKey": "toastflow",
4
+ "compatibility": {
5
+ "nuxt": "^3.0.0 || ^4.0.0"
6
+ },
7
+ "version": "1.0.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.2",
10
+ "unbuild": "unknown"
11
+ }
12
+ }
@@ -1,91 +1,64 @@
1
- import type { ToastConfig } from "vue-toastflow";
1
+ // src/module.ts
2
2
  import {
3
3
  addComponent,
4
4
  addImports,
5
5
  addPluginTemplate,
6
6
  addTemplate,
7
7
  addTypeTemplate,
8
- defineNuxtModule,
8
+ defineNuxtModule
9
9
  } from "@nuxt/kit";
10
-
11
- export interface NuxtToastflowOptions {
12
- /**
13
- * Global Toastflow config passed to createToastflow.
14
- */
15
- config: Partial<ToastConfig>;
16
- /**
17
- * Automatically include Toastflow CSS.
18
- */
19
- css: boolean;
20
- /**
21
- * Auto-register ToastContainer under this name. Set false to disable.
22
- */
23
- componentName: string | false;
24
- }
25
-
26
- function containsFunction(
27
- value: unknown,
28
- visited: Set<unknown> = new Set(),
29
- ): boolean {
10
+ function containsFunction(value, visited = /* @__PURE__ */ new Set()) {
30
11
  if (typeof value === "function") {
31
12
  return true;
32
13
  }
33
-
34
14
  if (!value || typeof value !== "object") {
35
15
  return false;
36
16
  }
37
-
38
17
  if (visited.has(value)) {
39
18
  return false;
40
19
  }
41
20
  visited.add(value);
42
-
43
21
  if (Array.isArray(value)) {
44
- return value.some(function (item: unknown): boolean {
22
+ return value.some(function(item) {
45
23
  return containsFunction(item, visited);
46
24
  });
47
25
  }
48
-
49
- const objectValues = Object.values(value as Record<string, unknown>);
50
-
51
- return objectValues.some(function (item: unknown): boolean {
26
+ const objectValues = Object.values(value);
27
+ return objectValues.some(function(item) {
52
28
  return containsFunction(item, visited);
53
29
  });
54
30
  }
55
-
56
- export default defineNuxtModule<NuxtToastflowOptions>({
31
+ var module_default = defineNuxtModule({
57
32
  meta: {
58
33
  name: "nuxt-toastflow",
59
34
  configKey: "toastflow",
60
35
  compatibility: {
61
- nuxt: "^3.0.0 || ^4.0.0",
62
- },
36
+ nuxt: "^3.0.0 || ^4.0.0"
37
+ }
63
38
  },
64
39
  defaults: {
65
40
  config: {},
66
41
  css: true,
67
- componentName: "ToastContainer",
42
+ componentName: "ToastContainer"
68
43
  },
69
44
  setup(options, nuxt) {
70
45
  if (containsFunction(options.config)) {
71
46
  console.warn(
72
- "[nuxt-toastflow] Functions in `toastflow.config` are not serializable in nuxt.config and will be omitted.",
47
+ "[nuxt-toastflow] Functions in `toastflow.config` are not serializable in nuxt.config and will be omitted."
73
48
  );
74
49
  }
75
-
76
50
  let serializedConfig = "{}";
77
51
  try {
78
52
  serializedConfig = JSON.stringify(options.config ?? {}, null, 2) ?? "{}";
79
53
  } catch {
80
54
  throw new Error(
81
- "[nuxt-toastflow] `toastflow.config` must be JSON-serializable.",
55
+ "[nuxt-toastflow] `toastflow.config` must be JSON-serializable."
82
56
  );
83
57
  }
84
-
85
58
  addPluginTemplate({
86
59
  filename: "toastflow.mjs",
87
60
  mode: "client",
88
- getContents: function () {
61
+ getContents: function() {
89
62
  return [
90
63
  'import { createToastflow, toast } from "vue-toastflow";',
91
64
  "",
@@ -98,14 +71,13 @@ export default defineNuxtModule<NuxtToastflowOptions>({
98
71
  " },",
99
72
  " };",
100
73
  "});",
101
- "",
74
+ ""
102
75
  ].join("\n");
103
- },
76
+ }
104
77
  });
105
-
106
78
  const toastTemplate = addTemplate({
107
79
  filename: "toastflow/toast.ts",
108
- getContents: function () {
80
+ getContents: function() {
109
81
  return [
110
82
  'import { useNuxtApp } from "#app";',
111
83
  "",
@@ -119,30 +91,27 @@ export default defineNuxtModule<NuxtToastflowOptions>({
119
91
  " get(_target, key) {",
120
92
  " const currentToast = useNuxtApp().$toast as Record<PropertyKey, unknown>;",
121
93
  " const value = currentToast[key];",
122
- " if (typeof value === \"function\") {",
94
+ ' if (typeof value === "function") {',
123
95
  " return (value as (...args: unknown[]) => unknown).bind(currentToast);",
124
96
  " }",
125
97
  " return value;",
126
98
  " },",
127
99
  "});",
128
- "",
100
+ ""
129
101
  ].join("\n");
130
- },
102
+ }
131
103
  });
132
-
133
104
  addImports({
134
105
  name: "useToast",
135
- from: toastTemplate.dst,
106
+ from: toastTemplate.dst
136
107
  });
137
-
138
108
  addImports({
139
109
  name: "toast",
140
- from: toastTemplate.dst,
110
+ from: toastTemplate.dst
141
111
  });
142
-
143
112
  addTypeTemplate({
144
113
  filename: "types/nuxt-toastflow.d.ts",
145
- getContents: function () {
114
+ getContents: function() {
146
115
  return [
147
116
  'type ToastApi = typeof import("vue-toastflow")["toast"];',
148
117
  "",
@@ -159,37 +128,35 @@ export default defineNuxtModule<NuxtToastflowOptions>({
159
128
  "}",
160
129
  "",
161
130
  "export {};",
162
- "",
131
+ ""
163
132
  ].join("\n");
164
- },
133
+ }
165
134
  });
166
-
167
135
  if (options.componentName) {
168
136
  addComponent({
169
137
  name: options.componentName,
170
138
  export: "ToastContainer",
171
139
  filePath: "vue-toastflow",
172
- mode: "client",
140
+ mode: "client"
173
141
  });
174
142
  }
175
-
176
143
  if (options.css) {
177
- const cssEntry = "vue-toastflow/src/styles.css";
178
- const hasCssEntry = nuxt.options.css.some(function (entry) {
144
+ const cssEntry = "vue-toastflow/styles.css";
145
+ const hasCssEntry = nuxt.options.css.some(function(entry) {
179
146
  if (typeof entry === "string") {
180
147
  return entry === cssEntry;
181
148
  }
182
-
183
149
  if (Array.isArray(entry) && typeof entry[0] === "string") {
184
150
  return entry[0] === cssEntry;
185
151
  }
186
-
187
152
  return false;
188
153
  });
189
-
190
154
  if (!hasCssEntry) {
191
155
  nuxt.options.css.push(cssEntry);
192
156
  }
193
157
  }
194
- },
158
+ }
195
159
  });
160
+ export {
161
+ module_default as default
162
+ };
@@ -0,0 +1,4 @@
1
+ type ToastApi = typeof import("vue-toastflow")["toast"];
2
+ export declare function useToast(): ToastApi;
3
+ export declare const toast: ToastApi;
4
+ export {};
@@ -0,0 +1,14 @@
1
+ import { useNuxtApp } from "#app";
2
+ export function useToast() {
3
+ return useNuxtApp().$toast;
4
+ }
5
+ export const toast = new Proxy({}, {
6
+ get(_target, key) {
7
+ const currentToast = useNuxtApp().$toast;
8
+ const value = currentToast[key];
9
+ if (typeof value === "function") {
10
+ return value.bind(currentToast);
11
+ }
12
+ return value;
13
+ }
14
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { createToastflow, toast } from "vue-toastflow";
2
+ export default defineNuxtPlugin((nuxtApp) => {
3
+ const runtimeConfig = useRuntimeConfig();
4
+ const toastflowConfig = runtimeConfig.public.__nuxtToastflow ?? {};
5
+ nuxtApp.vueApp.use(createToastflow(toastflowConfig));
6
+ return {
7
+ provide: {
8
+ toast
9
+ }
10
+ };
11
+ });
@@ -0,0 +1,9 @@
1
+ import type { ModulePublicRuntimeConfig } from './module.mjs'
2
+
3
+ declare module '@nuxt/schema' {
4
+ interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
5
+ }
6
+
7
+ export { default } from './module.mjs'
8
+
9
+ export { type ModuleOptions, type ModulePublicRuntimeConfig, type NuxtToastflowOptions } from './module.mjs'
package/package.json CHANGED
@@ -16,22 +16,32 @@
16
16
  "url": "https://github.com/adrianjanocko/toastflow.git",
17
17
  "directory": "packages/nuxt"
18
18
  },
19
- "version": "1.0.0",
20
- "main": "src/module.ts",
21
- "module": "src/module.ts",
22
- "types": "src/module.ts",
19
+ "version": "1.0.1-beta.0",
20
+ "main": "./dist/module.js",
21
+ "module": "./dist/module.mjs",
22
+ "types": "./dist/module.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/module.d.mts",
27
+ "default": "./dist/module.mjs"
28
+ },
29
+ "require": {
30
+ "types": "./dist/module.d.ts",
31
+ "default": "./dist/module.js"
32
+ }
33
+ }
34
+ },
23
35
  "files": [
24
- "README.md",
25
- "package.json",
26
- "tsconfig.json",
27
- "src"
36
+ "dist",
37
+ "README.md"
28
38
  ],
29
39
  "peerDependencies": {
30
40
  "nuxt": "^3.0.0 || ^4.0.0"
31
41
  },
32
42
  "dependencies": {
33
43
  "@nuxt/kit": "^3.17.5",
34
- "vue-toastflow": "^1.1.8"
44
+ "vue-toastflow": "^1.1.9-beta.0"
35
45
  },
36
46
  "devDependencies": {
37
47
  "tsup": "^8.5.1",
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["src"]
4
- }