@openreceive/vue 0.1.1 → 0.2.1

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 ADDED
@@ -0,0 +1,31 @@
1
+ # @openreceive/vue
2
+
3
+ Vue wrapper for the OpenReceive checkout custom element.
4
+
5
+ ## Mount
6
+
7
+ The component ships as a raw SFC on the `@openreceive/vue/checkout.vue` subpath
8
+ (your bundler's Vue plugin compiles it); import the checkout styles once.
9
+
10
+ ```vue
11
+ <script setup lang="ts">
12
+ import Checkout from "@openreceive/vue/checkout.vue";
13
+ import "@openreceive/vue/styles.css";
14
+ </script>
15
+
16
+ <template>
17
+ <Checkout reference="order-123" :onSettled="() => console.log('paid')" />
18
+ </template>
19
+ ```
20
+
21
+ Pass `reference` to let the element create the checkout (create mode), or pass a
22
+ `checkout` snapshot to render one your server already created. Prop names,
23
+ defaults, and the full surface are shared across the wrappers — see
24
+ `docs/internal/wrapper-parity.md` in the repository.
25
+
26
+ Event handlers (`onCopy`, `onOpenWallet`, `onState`, `onSettled`,
27
+ `onProviderCopy`, `onStartOver`, `onError`) are ordinary props, not
28
+ framework-native events: bind them as props (`:onSettled="handler"`), not with
29
+ `@settled`/`v-on`. Each receives the DOM `CustomEvent` the element dispatches.
30
+
31
+ Part of [OpenReceive](https://openreceive.org). Start with the [Node quickstart](https://github.com/openreceive/openreceive/blob/master/docs/guides/quickstart-node.md); the full API is in the [API reference](https://github.com/openreceive/openreceive/blob/master/docs/guides/api-reference.md).
package/dist/Checkout.vue CHANGED
@@ -1,40 +1,85 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted } from "vue";
2
+ import { computed, onMounted, ref } from "vue";
3
3
  import {
4
- createOpenReceiveVueCheckoutShellBinding,
5
- defineOpenReceiveElements,
6
- type CheckoutShellOptions,
7
- type CheckoutSnapshot
4
+ createWrapperCheckoutShellBinding,
5
+ defineElements,
6
+ validateCheckoutProps,
7
+ type WrapperCheckoutComponentProps,
8
8
  } from "./index.js";
9
9
 
10
- const props = withDefaults(
11
- defineProps<{
12
- snapshot: CheckoutSnapshot;
13
- options?: CheckoutShellOptions;
14
- }>(),
15
- {
16
- options: () => ({})
17
- }
18
- );
10
+ defineOptions({
11
+ name: "Checkout",
12
+ });
13
+
14
+ // The props are DERIVED from the shared wrapper surface, not restated: prop
15
+ // names, types, and per-mode applicability live once in
16
+ // @openreceive/elements/wrapper-shared (snapshot mode = `checkout`, create mode
17
+ // = `reference` + optional `prefix`), and docs/internal/wrapper-parity.md is the
18
+ // human-readable contract. `withDefaults` still spells the defaults out — a
19
+ // type carries none.
20
+ const props = withDefaults(defineProps<WrapperCheckoutComponentProps>(), {
21
+ options: () => ({}),
22
+ // Explicit undefined defaults suppress Vue's absent-Boolean-prop-to-false
23
+ // coercion: an unbound boolean prop must stay undefined so the
24
+ // `?? options.* ?? default` chains below see "not set", not "false".
25
+ paymentWizard: undefined,
26
+ themeToggle: undefined,
27
+ syncUrl: undefined,
28
+ });
19
29
 
30
+ // Storage and matchMedia only exist in the browser: resolving the theme before mount
31
+ // would make a server-rendered shell disagree with the first client render.
32
+ const mounted = ref(false);
20
33
  onMounted(() => {
21
- defineOpenReceiveElements();
34
+ mounted.value = true;
35
+ defineElements();
22
36
  });
23
37
 
24
- const shell = computed(() =>
25
- createOpenReceiveVueCheckoutShellBinding(props.snapshot, props.options)
26
- );
38
+ const shell = computed(() => {
39
+ validateCheckoutProps({
40
+ framework: "@openreceive/vue",
41
+ checkout: props.checkout,
42
+ reference: props.reference,
43
+ metadata: props.metadata,
44
+ syncUrl: props.syncUrl,
45
+ resumePathPrefix: props.resumePathPrefix,
46
+ routeReference: props.routeReference,
47
+ });
48
+ return createWrapperCheckoutShellBinding(props.checkout ?? null, {
49
+ ...props.options,
50
+ themeToggle: props.themeToggle ?? props.options.themeToggle ?? true,
51
+ deferThemeResolution: !mounted.value,
52
+ ...(props.reference === undefined ? {} : { reference: props.reference }),
53
+ ...(props.prefix === undefined ? {} : { prefix: props.prefix }),
54
+ ...(props.paymentWizard === undefined ? {} : { paymentWizard: props.paymentWizard }),
55
+ ...(props.decodeLinkUrl === undefined ? {} : { decodeLinkUrl: props.decodeLinkUrl }),
56
+ ...(props.defaultTheme === undefined ? {} : { defaultTheme: props.defaultTheme }),
57
+ ...(props.storageKey === undefined ? {} : { storageKey: props.storageKey }),
58
+ ...(props.metadata === undefined ? {} : { metadata: props.metadata }),
59
+ ...(props.syncUrl === undefined ? {} : { syncUrl: props.syncUrl }),
60
+ ...(props.resumePathPrefix === undefined ? {} : { resumePathPrefix: props.resumePathPrefix }),
61
+ ...(props.routeReference === undefined ? {} : { routeReference: props.routeReference }),
62
+ ...(props.onCopy === undefined ? {} : { onCopy: props.onCopy }),
63
+ ...(props.onOpenWallet === undefined ? {} : { onOpenWallet: props.onOpenWallet }),
64
+ ...(props.onState === undefined ? {} : { onState: props.onState }),
65
+ ...(props.onSettled === undefined ? {} : { onSettled: props.onSettled }),
66
+ ...(props.onProviderCopy === undefined ? {} : { onProviderCopy: props.onProviderCopy }),
67
+ ...(props.onStartOver === undefined ? {} : { onStartOver: props.onStartOver }),
68
+ ...(props.onError === undefined ? {} : { onError: props.onError }),
69
+ });
70
+ });
27
71
  </script>
28
72
 
29
73
  <template>
30
- <section v-bind="shell.rootAttrs">
74
+ <section v-bind="shell.rootAttributes">
31
75
  <component
76
+ v-if="shell.themeToggle"
32
77
  :is="shell.themeToggle.tagName"
33
- v-bind="shell.themeToggle.attrs"
78
+ v-bind="shell.themeToggle.attributes"
34
79
  />
35
80
  <component
36
81
  :is="shell.checkout.tagName"
37
- v-bind="shell.checkout.attrs"
82
+ v-bind="shell.checkout.attributes"
38
83
  v-on="shell.checkout.listeners"
39
84
  />
40
85
  </section>
@@ -0,0 +1,11 @@
1
+ // Hand-written module shape for the shipped SFC (the raw component is copied into dist
2
+ // by the package build, so no compiler emits this). The props themselves come from the
3
+ // shared wrapper type, so the surface exists in exactly one place.
4
+ import type { DefineComponent } from "vue";
5
+ import type { WrapperCheckoutComponentProps } from "./index.js";
6
+
7
+ export type VueCheckoutProps = WrapperCheckoutComponentProps;
8
+
9
+ declare const Checkout: DefineComponent<VueCheckoutProps>;
10
+
11
+ export default Checkout;
package/dist/index.d.ts CHANGED
@@ -1,39 +1 @@
1
- import { OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME, OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME, type CreateCheckoutShellOptions, type CheckoutElementAttributeOptions, type CheckoutElementAttributes, type CheckoutElementEventHandlers, type CheckoutElementListeners, type CheckoutController, type CheckoutControllerOptions, type CheckoutShellElements, type CheckoutShellOptions, type CheckoutSnapshot, type OpenReceiveStoredThemeModelOptions, type OpenReceiveThemeModel, type OpenReceiveThemeModelOptions, type OpenReceiveThemePreference, type OpenReceiveThemeToggleElementAttributeOptions, type OpenReceiveThemeToggleElementAttributes } from "@openreceive/browser/internal";
2
- import { defineOpenReceiveElements, type DefineOpenReceiveElementsOptions } from "@openreceive/elements";
3
- export { OPENRECEIVE_CHECKOUT_ELEMENT_EVENTS, OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME, OPENRECEIVE_THEME_STORAGE_KEY, OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME, applyCheckoutThemeAttributes, applyOpenReceiveThemeAttributes, createCheckoutController, createCheckoutElement, createCheckoutElementAttributes, createCheckoutElementListeners, createCheckoutShell, createCheckoutShellModel, createOpenReceiveStoredThemeModel, createOpenReceiveThemeModel, createOpenReceiveThemeToggleElement, createOpenReceiveThemeToggleElementAttributes, readOpenReceiveThemePreference, syncOpenReceiveStoredThemeControls, toggleOpenReceiveStoredThemeControls, toggleOpenReceiveStoredThemePreference, writeOpenReceiveThemePreference } from "@openreceive/browser/internal";
4
- export type { CreateCheckoutElementOptions, CreateCheckoutShellOptions, CreateOpenReceiveThemeToggleElementOptions, CheckoutElementAttributeOptions, CheckoutElementAttributes, CheckoutElementDocument, CheckoutElementEventHandlers, CheckoutElementListeners, CheckoutController, CheckoutControllerOptions, CheckoutShellElements, CheckoutShellCheckoutBinding, CheckoutShellModel, CheckoutShellOptions, CheckoutShellThemeToggleBinding, CheckoutElementTarget, CheckoutSnapshot, OpenReceiveReadThemePreferenceOptions, OpenReceiveStoredThemeModelOptions, OpenReceiveThemeAttributeTarget, OpenReceiveThemeControlTargets, OpenReceiveThemeLabelTarget, OpenReceiveThemeModel, OpenReceiveThemeModelOptions, OpenReceiveThemePreference, OpenReceiveThemeStorageOptions, OpenReceiveThemeToggleElementAttributeOptions, OpenReceiveThemeToggleElementAttributes } from "@openreceive/browser/internal";
5
- export { defineOpenReceiveElements } from "@openreceive/elements";
6
- export type { DefineOpenReceiveElementsOptions } from "@openreceive/elements";
7
- export interface OpenReceiveVueCheckoutBindingOptions extends CheckoutElementAttributeOptions, CheckoutElementEventHandlers {
8
- }
9
- export interface OpenReceiveVueCheckoutBinding {
10
- readonly tagName: typeof OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME;
11
- readonly attrs: CheckoutElementAttributes;
12
- readonly listeners: CheckoutElementListeners;
13
- }
14
- export interface OpenReceiveVueThemeToggleBinding {
15
- readonly tagName: typeof OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME;
16
- readonly attrs: OpenReceiveThemeToggleElementAttributes;
17
- }
18
- export interface OpenReceiveVueCheckoutShellBinding {
19
- readonly theme: OpenReceiveThemeModel;
20
- readonly rootAttrs: OpenReceiveThemeModel["attributes"];
21
- readonly checkout: OpenReceiveVueCheckoutBinding;
22
- readonly themeToggle: OpenReceiveVueThemeToggleBinding;
23
- }
24
- export interface OpenReceiveVueCheckoutComponentOptions extends CheckoutShellOptions {
25
- readonly defineElementsOptions?: DefineOpenReceiveElementsOptions;
26
- }
27
- export interface OpenReceiveVueCheckoutComponentModel extends OpenReceiveVueCheckoutShellBinding {
28
- readonly componentName: "Checkout";
29
- readonly defineElements: typeof defineOpenReceiveElements;
30
- readonly defineElementsOptions?: DefineOpenReceiveElementsOptions;
31
- }
32
- export declare function createOpenReceiveVueCheckoutBinding(snapshot: CheckoutSnapshot, options?: OpenReceiveVueCheckoutBindingOptions): OpenReceiveVueCheckoutBinding;
33
- export declare function createOpenReceiveVueThemeBinding(theme: OpenReceiveThemePreference, options?: OpenReceiveThemeModelOptions): OpenReceiveThemeModel;
34
- export declare function createOpenReceiveVueStoredThemeBinding(options?: OpenReceiveStoredThemeModelOptions): OpenReceiveThemeModel;
35
- export declare function createOpenReceiveVueThemeToggleBinding(options?: OpenReceiveThemeToggleElementAttributeOptions): OpenReceiveVueThemeToggleBinding;
36
- export declare function createOpenReceiveVueCheckoutShellBinding(snapshot: CheckoutSnapshot, options?: CheckoutShellOptions): OpenReceiveVueCheckoutShellBinding;
37
- export declare function createOpenReceiveVueCheckoutComponentModel(snapshot: CheckoutSnapshot, options?: OpenReceiveVueCheckoutComponentOptions): OpenReceiveVueCheckoutComponentModel;
38
- export declare function createOpenReceiveVueCheckoutController(options: CheckoutControllerOptions): CheckoutController;
39
- export declare function createOpenReceiveVueCheckoutShell(snapshot: CheckoutSnapshot, options?: CreateCheckoutShellOptions): CheckoutShellElements;
1
+ export * from '@openreceive/elements/wrapper-shared';
package/dist/index.js CHANGED
@@ -1,55 +1,2 @@
1
- import { OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME, OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME, createCheckoutController, createCheckoutShell, createCheckoutShellModel, createCheckoutElementAttributes, createCheckoutElementListeners, createOpenReceiveStoredThemeModel, createOpenReceiveThemeModel, createOpenReceiveThemeToggleElementAttributes } from "@openreceive/browser/internal";
2
- import { defineOpenReceiveElements } from "@openreceive/elements";
3
- export { OPENRECEIVE_CHECKOUT_ELEMENT_EVENTS, OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME, OPENRECEIVE_THEME_STORAGE_KEY, OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME, applyCheckoutThemeAttributes, applyOpenReceiveThemeAttributes, createCheckoutController, createCheckoutElement, createCheckoutElementAttributes, createCheckoutElementListeners, createCheckoutShell, createCheckoutShellModel, createOpenReceiveStoredThemeModel, createOpenReceiveThemeModel, createOpenReceiveThemeToggleElement, createOpenReceiveThemeToggleElementAttributes, readOpenReceiveThemePreference, syncOpenReceiveStoredThemeControls, toggleOpenReceiveStoredThemeControls, toggleOpenReceiveStoredThemePreference, writeOpenReceiveThemePreference } from "@openreceive/browser/internal";
4
- export { defineOpenReceiveElements } from "@openreceive/elements";
5
- export function createOpenReceiveVueCheckoutBinding(snapshot, options = {}) {
6
- return {
7
- tagName: OPENRECEIVE_CHECKOUT_ELEMENT_TAG_NAME,
8
- attrs: createCheckoutElementAttributes(snapshot, options),
9
- listeners: createCheckoutElementListeners(options)
10
- };
11
- }
12
- export function createOpenReceiveVueThemeBinding(theme, options = {}) {
13
- return createOpenReceiveThemeModel(theme, options);
14
- }
15
- export function createOpenReceiveVueStoredThemeBinding(options = {}) {
16
- return createOpenReceiveStoredThemeModel(options);
17
- }
18
- export function createOpenReceiveVueThemeToggleBinding(options = {}) {
19
- return {
20
- tagName: OPENRECEIVE_THEME_TOGGLE_ELEMENT_TAG_NAME,
21
- attrs: createOpenReceiveThemeToggleElementAttributes(options)
22
- };
23
- }
24
- export function createOpenReceiveVueCheckoutShellBinding(snapshot, options = {}) {
25
- const shell = createCheckoutShellModel(snapshot, options);
26
- return {
27
- theme: shell.theme,
28
- rootAttrs: shell.rootAttributes,
29
- checkout: {
30
- tagName: shell.checkout.tagName,
31
- attrs: shell.checkout.attributes,
32
- listeners: shell.checkout.listeners
33
- },
34
- themeToggle: {
35
- tagName: shell.themeToggle.tagName,
36
- attrs: shell.themeToggle.attributes
37
- }
38
- };
39
- }
40
- export function createOpenReceiveVueCheckoutComponentModel(snapshot, options = {}) {
41
- const { defineElementsOptions, ...shellOptions } = options;
42
- const shell = createOpenReceiveVueCheckoutShellBinding(snapshot, shellOptions);
43
- return {
44
- componentName: "Checkout",
45
- defineElements: defineOpenReceiveElements,
46
- defineElementsOptions,
47
- ...shell
48
- };
49
- }
50
- export function createOpenReceiveVueCheckoutController(options) {
51
- return createCheckoutController(options);
52
- }
53
- export function createOpenReceiveVueCheckoutShell(snapshot, options = {}) {
54
- return createCheckoutShell(snapshot, options);
55
- }
1
+ // src/index.ts
2
+ export * from "@openreceive/elements/wrapper-shared";
package/package.json CHANGED
@@ -1,28 +1,71 @@
1
1
  {
2
2
  "name": "@openreceive/vue",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
+ "description": "Vue wrapper for the OpenReceive checkout custom element.",
5
+ "keywords": [
6
+ "bitcoin",
7
+ "lightning",
8
+ "payments",
9
+ "nwc",
10
+ "bolt11",
11
+ "openreceive",
12
+ "vue",
13
+ "checkout"
14
+ ],
4
15
  "type": "module",
16
+ "sideEffects": [
17
+ "**/*.css"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
5
21
  "dependencies": {
6
- "@openreceive/browser": "0.1.1",
7
- "@openreceive/elements": "0.1.1"
22
+ "@openreceive/browser": "0.2.1",
23
+ "@openreceive/elements": "0.2.1"
8
24
  },
9
25
  "peerDependencies": {
26
+ "typescript": ">=5.0.0",
10
27
  "vue": ">=3.4.0"
11
28
  },
12
29
  "peerDependenciesMeta": {
13
- "vue": {
30
+ "typescript": {
14
31
  "optional": true
15
32
  }
16
33
  },
17
34
  "exports": {
18
- ".": "./dist/index.js",
19
- "./checkout.vue": "./dist/Checkout.vue",
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ },
39
+ "./checkout.vue": {
40
+ "types": "./dist/Checkout.vue.d.ts",
41
+ "default": "./dist/Checkout.vue"
42
+ },
20
43
  "./styles.css": "./dist/styles.css"
21
44
  },
22
- "types": "./dist/index.d.ts",
23
45
  "files": [
24
46
  "dist",
25
47
  "README.md",
26
48
  "LICENSE"
27
- ]
28
- }
49
+ ],
50
+ "scripts": {
51
+ "build": "tsup src/index.ts --format esm --dts --clean --target es2022 --out-dir dist && node ../../../tools/package/copy-static.mjs src dist styles.css Checkout.vue Checkout.vue.d.ts",
52
+ "prepack": "npm run build"
53
+ },
54
+ "license": "MIT",
55
+ "author": "OpenReceive <info@openreceive.org>",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/openreceive/openreceive.git",
59
+ "directory": "packages/js/vue"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/openreceive/openreceive/issues"
63
+ },
64
+ "homepage": "https://openreceive.org",
65
+ "publishConfig": {
66
+ "access": "public"
67
+ },
68
+ "engines": {
69
+ "node": ">=22"
70
+ }
71
+ }