@primer-io/primer-js 0.0.2 → 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.
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
{
|
|
19
19
|
"kind": "variable",
|
|
20
20
|
"name": "P",
|
|
21
|
-
"default": "class extends m{constructor(){super();this.customStyles=\"\";this.clientToken=\"\";this.options={};this.disableLoader=!1;this.hasAssignedContent=!1;this.locale=\"en-GB\";this.onSlotChange=e=>{let s=e.target.assignedNodes({flatten:!0});this.hasAssignedContent=s.length>0,this.requestUpdate()};this.sdkContextController=new
|
|
21
|
+
"default": "class extends m{constructor(){super();this.customStyles=\"\";this.clientToken=\"\";this.options={};this.disableLoader=!1;this.hasAssignedContent=!1;this.locale=\"en-GB\";this.onSlotChange=e=>{let s=e.target.assignedNodes({flatten:!0});this.hasAssignedContent=s.length>0,this.requestUpdate()};this.sdkContextController=new jt(this),this.sdkStateController=new Kt(this),this.primerEventsController=new pt(this),this.styleProcessingController=new Gt(this),new se(this)}attributeChangedCallback(e,r,s){e===\"customstyles\"?this.styleProcessingController.processCustomStyles(s):super.attributeChangedCallback(e,r,s)}willUpdate(e){e.has(\"options\")&&(this.options?.locale&&(Ne(this.options?.locale)?this.locale=Ie(this.options?.locale):E.warn(\"\\u{1F30E}\\u2757 Unsupported locale provided:\",this.options?.locale,\"- Falling back to default locale `en-GB`\")),Ae(this.locale||\"en-GB\"))}render(){let e=this.sdkStateController.state,r=e.isLoading,s=e.error,i=!r&&!s;return d` ${C(r&&!this.disableLoader,()=>d`<primer-spinner size=\"large\"></primer-spinner>`,()=>h)} ${C(s,()=>d`<p>There was an error loading the checkout</p>`)} ${C(i,()=>d` <slot name=\"main\" @slotchange=${this.onSlotChange}></slot> ${C(this.hasAssignedContent,()=>h,()=>d`<primer-main></primer-main>`)} `,()=>h)} `}addEventListener(e,r,s){super.addEventListener(e,r,s)}}"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"kind": "variable",
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
{
|
|
79
79
|
"kind": "variable",
|
|
80
80
|
"name": "rt",
|
|
81
|
-
"default": "class extends m{constructor(){super();this.paymentManagers=new Map;this._buttonId=\"button-container\";this.loadManagerTask=new S(this,{args:()=>[this.paymentMethod?.type],task:async([e])=>{if(!e)return
|
|
81
|
+
"default": "class extends m{constructor(){super();this.paymentManagers=new Map;this._buttonId=\"button-container\";this.loadManagerTask=new S(this,{args:()=>[this.paymentMethod?.type],task:async([e])=>{if(!e)return L;let r=this.paymentManagers.get(e)?.manager;if(!r)throw new Error(`No manager found for payment method type ${e}`);return r}}),new S(this,{args:()=>[this.loadManagerTask.value],task:async([e])=>{if(!e)return L;await this.updateComplete;let r=this.shadowRoot?.getElementById(this._buttonId);if(!r)return;let s=this.calculateButtonHeight(),i=e.createButton(),a=this.createRenderOptions(s);return await i.render(this.paymentMethod?.type===\"GOOGLE_PAY\"?this.shadowRoot?.getRootNode():r,a),e}})}calculateButtonHeight(){if(typeof window>\"u\"||!this.isConnected)return 0;let e=getComputedStyle(this),r=parseFloat(e.getPropertyValue(\"--primer-typography-title-large-line-height\")),s=parseFloat(e.getPropertyValue(\"--primer-space-medium\"));return r+2*s}createRenderOptions(e){let r=this.paymentMethod?.type;return r===\"GOOGLE_PAY\"?{style:{shadowRoot:!0}}:r===\"APPLE_PAY\"?{style:{buttonHeight:e}}:r===\"PAYPAL\"?{style:{buttonHeight:e}}:{style:{buttonHeight:e}}}updated(e){e.has(\"paymentMethod\")&&this.paymentMethod&&(this._buttonId=`button-container-${this.paymentMethod.type}`)}render(){return this.loadManagerTask.render({error:()=>h,complete:()=>d` <!-- The native button container is rendered first --> <div class=\"native-button-container\" id=\"${this._buttonId}\"></div> `,pending:()=>h})}}"
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
"kind": "variable",
|
|
85
|
-
"name": "
|
|
86
|
-
"default": "class extends m{constructor(){super(...arguments);this.hasAssignedContent=!1;this.selectedCardNetwork=null;this.paymentManagers=new Map;this.cardFormProvider=new
|
|
85
|
+
"name": "B",
|
|
86
|
+
"default": "class extends m{constructor(){super(...arguments);this.hasAssignedContent=!1;this.selectedCardNetwork=null;this.paymentManagers=new Map;this.cardFormProvider=new _(this,{context:pe,initialValue:null});this.eventsController=new pt(this);this.setupCardFormTask=new S(this,{task:async([e])=>{if(!e?.manager)return L;let{manager:r}=e,{cardNumberInput:s,expiryInput:i,cvvInput:a}=r.createHostedInputs();return this.cardFormProvider.setValue({cardNumberInput:s,expiryInput:i,cvvInput:a,setCardholderName:c=>r.setCardholderName(c),setCardNetwork:c=>{this.selectedCardNetwork=c},validate:()=>r.validate(),submit:c=>r.submit(c)}),!0},args:()=>[this.paymentManagers.get(\"PAYMENT_CARD\")]});this.handleSlotButtonClick=e=>{let s=e.target.closest(\"button, primer-button\");if(!s)return;this.isSubmitButton(s)&&(e.preventDefault(),this.submitCardPayment())};this.handleDirectSubmit=e=>{e.stopPropagation(),this.submitCardPayment()};this.onSlotChange=e=>{let s=e.target.assignedNodes({flatten:!0});this.hasAssignedContent=s.length>0};this.handleFormSubmit=e=>{e.preventDefault(),e.stopPropagation(),this.submitCardPayment()}}connectedCallback(){super.connectedCallback(),this.addEventListener(\"click\",this.handleSlotButtonClick),this.addEventListener(\"primer-form-submit\",this.handleDirectSubmit)}disconnectedCallback(){this.removeEventListener(\"click\",this.handleSlotButtonClick),this.removeEventListener(\"primer-form-submit\",this.handleDirectSubmit),super.disconnectedCallback()}isSubmitButton(e){let r=e.tagName.toLowerCase(),s=r===\"button\",i=r===\"primer-button\";return s&&(e.getAttribute(\"type\")===\"submit\"||e.hasAttribute(\"data-submit\"))||i&&(e.getAttribute(\"buttonType\")===\"submit\"||e.hasAttribute(\"data-submit\"))}async submitCardPayment(){let e=this.cardFormProvider.value;if(!e)return;let r=await e.validate?.();if(r?.valid){let s=await e.submit?.(this.selectedCardNetwork?{cardNetwork:this.selectedCardNetwork}:void 0);this.eventsController.dispatchFormSubmitSuccess(s)}else{let s=r?.validationErrors;this.cardFormProvider.setValue({...e,errors:s}),this.eventsController.dispatchFormSubmitErrors(s)}}render(){return this.setupCardFormTask.status===Z.ERROR||this.setupCardFormTask.status===Z.INITIAL?h:d` <form @submit=${this.handleFormSubmit}> <slot name=\"card-form-content\" @slotchange=${this.onSlotChange}></slot> ${this.setupCardFormTask.render({complete:()=>C(this.hasAssignedContent,()=>h,()=>d` <div class=\"card-form\"> <primer-input-card-number></primer-input-card-number> <div class=\"card-form-row\"> <primer-input-card-expiry></primer-input-card-expiry> <primer-input-cvv></primer-input-cvv> </div> <primer-input-card-holder-name></primer-input-card-holder-name> </div> <primer-card-form-submit></primer-card-form-submit> `)})} </form> `}}"
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
89
|
"kind": "variable",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
109
|
"kind": "variable",
|
|
110
|
-
"name": "
|
|
110
|
+
"name": "j",
|
|
111
111
|
"default": "class extends m{constructor(){super(...arguments);this._userAssignedProps=new Set;this._internalButtonText=\"\";this.variant=\"primary\";this.disabled=!1;this.handleClick=e=>{if(e.preventDefault(),this.disabled)return;let r=new CustomEvent(\"primer-form-submit\",{bubbles:!0,composed:!0,detail:{source:\"primer-card-form-submit\"}});this.dispatchEvent(r)}}get buttonText(){return this._userAssignedProps.has(\"buttonText\")?this._internalButtonText:O(\"pay\",{id:\"pay\"})}set buttonText(e){let r=this.buttonText;e!==\"\"?(this._userAssignedProps.add(\"buttonText\"),this._internalButtonText=e):(this._userAssignedProps.delete(\"buttonText\"),this._internalButtonText=\"\"),this.requestUpdate(\"buttonText\",r)}render(){return d` <primer-button buttonType=\"submit\" variant=${this.variant} ?disabled=${this.disabled} @click=${this.handleClick} data-submit > ${this.buttonText} </primer-button> `}}"
|
|
112
112
|
},
|
|
113
113
|
{
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
"kind": "js",
|
|
156
156
|
"name": "CardForm",
|
|
157
157
|
"declaration": {
|
|
158
|
-
"name": "
|
|
158
|
+
"name": "B",
|
|
159
159
|
"module": "cdn/primer-components.js"
|
|
160
160
|
}
|
|
161
161
|
},
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
"kind": "js",
|
|
212
212
|
"name": "CardFormSubmit",
|
|
213
213
|
"declaration": {
|
|
214
|
-
"name": "
|
|
214
|
+
"name": "j",
|
|
215
215
|
"module": "cdn/primer-components.js"
|
|
216
216
|
}
|
|
217
217
|
},
|
|
@@ -335,7 +335,7 @@
|
|
|
335
335
|
"declarations": [
|
|
336
336
|
{
|
|
337
337
|
"kind": "function",
|
|
338
|
-
"name": "
|
|
338
|
+
"name": "y"
|
|
339
339
|
}
|
|
340
340
|
],
|
|
341
341
|
"exports": [
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
"kind": "js",
|
|
344
344
|
"name": "loadPrimer",
|
|
345
345
|
"declaration": {
|
|
346
|
-
"name": "
|
|
346
|
+
"name": "y",
|
|
347
347
|
"module": "dist/primer-loader.js"
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -5391,7 +5391,7 @@
|
|
|
5391
5391
|
"declarations": [
|
|
5392
5392
|
{
|
|
5393
5393
|
"kind": "class",
|
|
5394
|
-
"description": "",
|
|
5394
|
+
"description": "Component for rendering native payment buttons (Apple Pay, Google Pay, PayPal)\nwith proper height calculations based on design system variables.",
|
|
5395
5395
|
"name": "NativePaymentComponent",
|
|
5396
5396
|
"members": [
|
|
5397
5397
|
{
|
|
@@ -5428,6 +5428,36 @@
|
|
|
5428
5428
|
},
|
|
5429
5429
|
"privacy": "private",
|
|
5430
5430
|
"default": "new Task(this, { args: () => [ this.paymentMethod?.type as NativePaymentMethodTypes | undefined, ], task: async ([type]) => { if (!type) { return initialState; } const manager = this.paymentManagers.get(type)?.manager; if (!manager) { throw new Error(`No manager found for payment method type ${type}`); } return manager; }, })"
|
|
5431
|
+
},
|
|
5432
|
+
{
|
|
5433
|
+
"kind": "method",
|
|
5434
|
+
"name": "calculateButtonHeight",
|
|
5435
|
+
"privacy": "private",
|
|
5436
|
+
"return": {
|
|
5437
|
+
"type": {
|
|
5438
|
+
"text": "number"
|
|
5439
|
+
}
|
|
5440
|
+
},
|
|
5441
|
+
"description": "Calculates the button height based on CSS variables\nMirrors the calculation used in the host styles"
|
|
5442
|
+
},
|
|
5443
|
+
{
|
|
5444
|
+
"kind": "method",
|
|
5445
|
+
"name": "createRenderOptions",
|
|
5446
|
+
"privacy": "private",
|
|
5447
|
+
"return": {
|
|
5448
|
+
"type": {
|
|
5449
|
+
"text": "{\n style: Record<string, unknown>;\n }"
|
|
5450
|
+
}
|
|
5451
|
+
},
|
|
5452
|
+
"parameters": [
|
|
5453
|
+
{
|
|
5454
|
+
"name": "buttonHeight",
|
|
5455
|
+
"type": {
|
|
5456
|
+
"text": "number"
|
|
5457
|
+
}
|
|
5458
|
+
}
|
|
5459
|
+
],
|
|
5460
|
+
"description": "Creates render options with appropriate styles based on payment method type"
|
|
5431
5461
|
}
|
|
5432
5462
|
],
|
|
5433
5463
|
"attributes": [
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -421,7 +421,8 @@ export type CustomElements = {
|
|
|
421
421
|
"primer-card-form": Partial<CardFormComponentProps & BaseProps & BaseEvents>;
|
|
422
422
|
|
|
423
423
|
/**
|
|
424
|
-
*
|
|
424
|
+
* Component for rendering native payment buttons (Apple Pay, Google Pay, PayPal)
|
|
425
|
+
* with proper height calculations based on design system variables.
|
|
425
426
|
* ---
|
|
426
427
|
*
|
|
427
428
|
*/
|
package/dist/primer-loader.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function loadPrimer(): Promise<void>;
|
|
2
1
|
export type CardNetwork = {
|
|
3
2
|
displayName: string;
|
|
4
3
|
network: string;
|
|
@@ -1896,6 +1895,7 @@ export interface GooglePayStyles {
|
|
|
1896
1895
|
}
|
|
1897
1896
|
export interface ApplePayStyles {
|
|
1898
1897
|
buttonType?: "plain" | "buy" | "set-up" | "donate" | "check-out" | "book" | "subscribe";
|
|
1898
|
+
buttonHeight?: number;
|
|
1899
1899
|
buttonStyle?: "white" | "white-outline" | "black";
|
|
1900
1900
|
}
|
|
1901
1901
|
export interface HeadlessButtonRenderOptions {
|
|
@@ -2637,6 +2637,15 @@ declare class NativePaymentComponent extends LitElement {
|
|
|
2637
2637
|
private _buttonId;
|
|
2638
2638
|
private loadManagerTask;
|
|
2639
2639
|
constructor();
|
|
2640
|
+
/**
|
|
2641
|
+
* Calculates the button height based on CSS variables
|
|
2642
|
+
* Mirrors the calculation used in the host styles
|
|
2643
|
+
*/
|
|
2644
|
+
private calculateButtonHeight;
|
|
2645
|
+
/**
|
|
2646
|
+
* Creates render options with appropriate styles based on payment method type
|
|
2647
|
+
*/
|
|
2648
|
+
private createRenderOptions;
|
|
2640
2649
|
protected updated(changedProperties: PropertyValues): void;
|
|
2641
2650
|
render(): symbol | TemplateResult<1> | undefined;
|
|
2642
2651
|
}
|
|
@@ -3230,5 +3239,11 @@ declare global {
|
|
|
3230
3239
|
"primer-checkout": PrimerCheckoutComponent;
|
|
3231
3240
|
}
|
|
3232
3241
|
}
|
|
3242
|
+
type PaymentsObject$1 = PaymentsObject;
|
|
3243
|
+
export declare function loadPrimer(): Promise<void>;
|
|
3244
|
+
|
|
3245
|
+
export {
|
|
3246
|
+
PaymentsObject$1 as PaymentsObject,
|
|
3247
|
+
};
|
|
3233
3248
|
|
|
3234
3249
|
export {};
|
package/dist/primer-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var n="https://sdk.primer.io/web/v2-latest/Primer.min.js",
|
|
1
|
+
var n="https://sdk.primer.io/web/v2-latest/Primer.min.js",s="https://sdk.primer.io/web/primer-js/v0-latest/primer-components.js";var i=typeof window<"u"&&typeof window.document<"u";function m(e){return document.querySelector(`script[src^="${e}"]`)}function a(e,r){let t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("async",""),t.setAttribute("crossorigin","anonymous"),r&&t.setAttribute("type","module"),t}function o(e,r=!1){if(!i)throw new Error("Cannot load script in server environment");let t=m(e)??a(e,r);return new Promise((p,c)=>{t.onload=()=>{p()},t.onerror=()=>{c()},t.parentNode||document.head.appendChild(t)})}async function d(e=n){await o(e),await window.Primer.preloadPrimer()}async function l(e=s){await o(e,!0)}async function y(){await d(),await l()}export{y as loadPrimer};
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
166
|
"name": "primer-native-payment",
|
|
167
|
-
"description": "\n---\n",
|
|
167
|
+
"description": "Component for rendering native payment buttons (Apple Pay, Google Pay, PayPal)\nwith proper height calculations based on design system variables.\n---\n",
|
|
168
168
|
"attributes": [
|
|
169
169
|
{
|
|
170
170
|
"name": "paymentMethod",
|
package/dist/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
|
|
3
3
|
"name": "@primer-io/primer-js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -444,7 +444,7 @@
|
|
|
444
444
|
},
|
|
445
445
|
{
|
|
446
446
|
"name": "primer-native-payment",
|
|
447
|
-
"description": "\n---\n",
|
|
447
|
+
"description": "Component for rendering native payment buttons (Apple Pay, Google Pay, PayPal)\nwith proper height calculations based on design system variables.\n---\n",
|
|
448
448
|
"doc-url": "",
|
|
449
449
|
"attributes": [
|
|
450
450
|
{
|