@shopkit/builder 0.1.4 → 0.1.5
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/dist/hooks/index.js +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +2 -1
package/dist/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';const
|
|
2
|
+
'use strict';const _0x1c596f=_0x49fb;function _0x5003(){const _0x240df2=['y3vYCMvUDejYzwfRCg9PBNq','z2v0qNjLywTWB2LUDenVBMzPzW','C3vIC2nYAwjL','DxnLqNjLywTWB2LUDhm','AM9PBG','mtK4otqYowTssK50DG','mZqZnZm0meztBerfsa','wMDkEgS','zgvSzxrL','CMvHy3q','ywrKrxzLBNrmAxn0zw5LCG','zM9YrwfJAa','ywrK','ndmYmtG4ne5Zufrgsq','DwTyq0S','Bwf0y2HLCW','q1HXENi','BwLU','EKrIyMq','ChGP','y3vZDg9T','BwvKAwfrDwvYEuXPC3rLBMvYCW','BgLZDgvUzxjZ','mta2ndu3mw5PsuTAsW','s2zWCva','igfUzca','C2v0','zw50CMLLCW','Ahnsr0q','kg1HEc13Awr0AdOG','ngvctvj3CG','y2XLyxi','DgfIBgv0','z2v0q3vYCMvUDejYzwfRCg9PBNq','Bwf0y2HnzwrPyq','zgv0zwn0q3vYCMvUDejYzwfRCg9PBNq','BM90Awz5tgLZDgvUzxjZ','Bwf4','rgzQB3C','zgvZA3rVCa','yNjLywTWB2LUDhm','DxnLu3rHDgu','A2v5CW','zhLyANm','nJaZmZi4Dw5puw5T','zgvZDhjVEq','C2v0DxbnzwrPyvf1zxj5tgLZDgvUzxjZ','Bw9IAwXL','y2HHBMDL','ugHZueC','Bw5guw0','D2LKzq','mJG0nti0mg9KwM5hqG','z2v0twvKAwfrDwvYEq','ChvZAa','ntK3odq1CvzSBuHZ','Aw5UzxjxAwr0Aa','yM91BMriyw5KBgvY','uvDNs2W'];_0x5003=function(){return _0x240df2;};return _0x5003();}function _0x49fb(_0x1e0ab8,_0xa33f32){_0x1e0ab8=_0x1e0ab8-0x98;const _0x5003cb=_0x5003();let _0x49fb53=_0x5003cb[_0x1e0ab8];if(_0x49fb['bXfiph']===undefined){var _0x220e81=function(_0x4bef2a){const _0x3d9e8f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x598831='',_0x546c04='';for(let _0x599283=0x0,_0x35a03a,_0x2c7984,_0x1c3aa8=0x0;_0x2c7984=_0x4bef2a['charAt'](_0x1c3aa8++);~_0x2c7984&&(_0x35a03a=_0x599283%0x4?_0x35a03a*0x40+_0x2c7984:_0x2c7984,_0x599283++%0x4)?_0x598831+=String['fromCharCode'](0xff&_0x35a03a>>(-0x2*_0x599283&0x6)):0x0){_0x2c7984=_0x3d9e8f['indexOf'](_0x2c7984);}for(let _0x34a017=0x0,_0x315152=_0x598831['length'];_0x34a017<_0x315152;_0x34a017++){_0x546c04+='%'+('00'+_0x598831['charCodeAt'](_0x34a017)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x546c04);};_0x49fb['plLpxD']=_0x220e81,_0x49fb['GphjwJ']={},_0x49fb['bXfiph']=!![];}const _0x2d2202=_0x5003cb[0x0],_0x117112=_0x1e0ab8+_0x2d2202,_0x4dd57f=_0x49fb['GphjwJ'][_0x117112];return!_0x4dd57f?(_0x49fb53=_0x49fb['plLpxD'](_0x49fb53),_0x49fb['GphjwJ'][_0x117112]=_0x49fb53):_0x49fb53=_0x4dd57f,_0x49fb53;}(function(_0x36b028,_0x491cee){const _0x5b8ca8=_0x49fb,_0x58d0d6=_0x36b028();while(!![]){try{const _0xdb2e95=-parseInt(_0x5b8ca8(0xc6))/0x1+parseInt(_0x5b8ca8(0xa0))/0x2+parseInt(_0x5b8ca8(0xb4))/0x3+-parseInt(_0x5b8ca8(0xcd))/0x4*(-parseInt(_0x5b8ca8(0xab))/0x5)+parseInt(_0x5b8ca8(0xb5))/0x6+parseInt(_0x5b8ca8(0xbc))/0x7+-parseInt(_0x5b8ca8(0xa8))/0x8;if(_0xdb2e95===_0x491cee)break;else _0x58d0d6['push'](_0x58d0d6['shift']());}catch(_0x28ea74){_0x58d0d6['push'](_0x58d0d6['shift']());}}}(_0x5003,0xd09b4));var react=require(_0x1c596f(0xb8)),a={'mobile':{'max':0x2ff},'tablet':{'min':0x300,'max':0x3ff},'desktop':{'min':0x400,'max':0x780},'wide':{'min':0x781}},o=class{constructor(_0x3f3622=a){const _0x4dd75d=_0x1c596f;this[_0x4dd75d(0xc4)]=new Map(),this['currentBreakpoint']=_0x4dd75d(0x9b),this['listeners']=new Set(),this['boundHandler']=null,(this[_0x4dd75d(0x9c)]=_0x3f3622,typeof window<'u'&&(this[_0x4dd75d(0xa2)](),this['detectCurrentBreakpoint']()));}[_0x1c596f(0xd0)](){const _0xbe9ef3=_0x1c596f;return this[_0xbe9ef3(0xaf)];}['getBreakpoints'](){return this['breakpoints'];}[_0x1c596f(0xa9)](_0x17e181){const _0x5db536=_0x1c596f,_0x21b51b={'KfpqP':function(_0x2a347b,_0x3b0f61){return _0x2a347b!==_0x3b0f61;},'ukXCK':_0x5db536(0xc8)};let _0x1c314b=this[_0x5db536(0xb0)](_0x17e181);if(!_0x1c314b)return'';let _0x197b5c=[];return _0x21b51b[_0x5db536(0xc7)](_0x1c314b[_0x5db536(0xc0)],void 0x0)&&_0x197b5c[_0x5db536(0xaa)]('(min-width:\x20'+_0x1c314b[_0x5db536(0xc0)]+_0x5db536(0xc2)),_0x21b51b[_0x5db536(0xc7)](_0x1c314b[_0x5db536(0x99)],void 0x0)&&_0x197b5c[_0x5db536(0xaa)](_0x5db536(0xcc)+_0x1c314b[_0x5db536(0x99)]+'px)'),_0x197b5c[_0x5db536(0xb3)](_0x21b51b[_0x5db536(0xbd)]);}[_0x1c596f(0xb0)](_0x345c95){const _0x3d1179=_0x1c596f;return _0x345c95 in this[_0x3d1179(0x9c)]?this[_0x3d1179(0x9c)][_0x345c95]:this[_0x3d1179(0x9c)]['custom']&&_0x345c95 in this[_0x3d1179(0x9c)][_0x3d1179(0xc3)]?this[_0x3d1179(0x9c)][_0x3d1179(0xc3)][_0x345c95]:null;}[_0x1c596f(0xa2)](){const _0x484225=_0x1c596f,_0x572aef={'mnFQm':function(_0x3d6914,_0x28c615){return _0x3d6914===_0x28c615;},'ZgJxk':'change'};this[_0x484225(0xad)]=()=>this[_0x484225(0xd2)](),Object[_0x484225(0x9e)](this['breakpoints'])[_0x484225(0xba)](_0x261bc3=>{const _0x80cf55=_0x484225;if(_0x572aef[_0x80cf55(0xa6)](_0x261bc3,'custom'))return;let _0x170bc6=this[_0x80cf55(0xa9)](_0x261bc3);if(_0x170bc6){let _0x56b3ee=window[_0x80cf55(0xd1)](_0x170bc6);this['mediaQueryListeners'][_0x80cf55(0xc9)](_0x261bc3,_0x56b3ee),_0x56b3ee[_0x80cf55(0xb9)](_0x572aef[_0x80cf55(0xb6)],this[_0x80cf55(0xad)]);}}),this[_0x484225(0x9c)][_0x484225(0xc3)]&&Object[_0x484225(0x9e)](this[_0x484225(0x9c)][_0x484225(0xc3)])[_0x484225(0xba)](_0x2ae464=>{const _0x4ee383=_0x484225;let _0x4e2812=this[_0x4ee383(0xa9)](_0x2ae464);if(_0x4e2812){let _0x4052ec=window[_0x4ee383(0xd1)](_0x4e2812);this['mediaQueryListeners'][_0x4ee383(0xc9)](_0x2ae464,_0x4052ec),_0x4052ec[_0x4ee383(0xb9)](_0x572aef[_0x4ee383(0xb6)],this[_0x4ee383(0xad)]);}});}[_0x1c596f(0xd2)](){const _0x460fa6=_0x1c596f,_0x13dffe={'CXqzr':function(_0x22688b,_0x2f684a){return _0x22688b>=_0x2f684a;},'Dfjow':function(_0x1c69f7,_0x5313b5){return _0x1c69f7<=_0x5313b5;},'zDbbd':_0x460fa6(0xcf),'PhsPG':_0x460fa6(0x9b),'QWgKl':function(_0x54bdfd,_0x51ad67){return _0x54bdfd>=_0x51ad67;},'XnuGP':_0x460fa6(0xa7),'dyXjs':function(_0x32afa8,_0x5c3566){return _0x32afa8===_0x5c3566;}};let _0x1b7755=window[_0x460fa6(0xac)],_0x5e12e1='desktop';if(_0x1b7755<=this['breakpoints'][_0x460fa6(0xa3)]['max']?_0x5e12e1=_0x460fa6(0xa3):_0x13dffe['CXqzr'](_0x1b7755,this[_0x460fa6(0x9c)][_0x460fa6(0xcf)][_0x460fa6(0xc0)])&&_0x13dffe[_0x460fa6(0x9a)](_0x1b7755,this[_0x460fa6(0x9c)][_0x460fa6(0xcf)][_0x460fa6(0x99)])?_0x5e12e1=_0x13dffe[_0x460fa6(0xc1)]:_0x13dffe[_0x460fa6(0xbf)](_0x1b7755,this[_0x460fa6(0x9c)][_0x460fa6(0x9b)][_0x460fa6(0xc0)])&&_0x1b7755<=this[_0x460fa6(0x9c)][_0x460fa6(0x9b)][_0x460fa6(0x99)]?_0x5e12e1=_0x13dffe[_0x460fa6(0xa5)]:_0x13dffe[_0x460fa6(0xae)](_0x1b7755,this[_0x460fa6(0x9c)][_0x460fa6(0xa7)][_0x460fa6(0xc0)])&&(_0x5e12e1=_0x13dffe['XnuGP']),this[_0x460fa6(0x9c)][_0x460fa6(0xc3)]){for(let [_0x38fa61,_0xb1785f]of Object[_0x460fa6(0xca)](this[_0x460fa6(0x9c)][_0x460fa6(0xc3)]))if((_0x13dffe[_0x460fa6(0x9f)](_0xb1785f[_0x460fa6(0xc0)],void 0x0)||_0x1b7755>=_0xb1785f[_0x460fa6(0xc0)])&&(_0xb1785f[_0x460fa6(0x99)]===void 0x0||_0x1b7755<=_0xb1785f[_0x460fa6(0x99)])){_0x5e12e1=_0x38fa61;break;}}_0x5e12e1!==this['currentBreakpoint']&&(this[_0x460fa6(0xaf)]=_0x5e12e1,this[_0x460fa6(0x98)]());}[_0x1c596f(0xb1)](_0x2ec1d0){const _0x37a4e3=_0x1c596f;return this[_0x37a4e3(0xc5)][_0x37a4e3(0xbb)](_0x2ec1d0),()=>this[_0x37a4e3(0xc5)][_0x37a4e3(0xb7)](_0x2ec1d0);}[_0x1c596f(0x98)](){const _0x1b0fd5=_0x1c596f;this[_0x1b0fd5(0xc5)]['forEach'](_0xc468d4=>_0xc468d4(this[_0x1b0fd5(0xaf)]));}[_0x1c596f(0xbe)](_0x2e3ab5){const _0x410ec7=_0x1c596f;let _0x557803=this[_0x410ec7(0xc4)]['get'](_0x2e3ab5);return _0x557803?_0x557803['matches']:![];}[_0x1c596f(0xa1)](){const _0xab17a3=_0x1c596f;this['boundHandler']&&(this[_0xab17a3(0xc4)][_0xab17a3(0xba)](_0x12541b=>{const _0x136174=_0xab17a3;_0x12541b['removeEventListener'](_0x136174(0xa4),this[_0x136174(0xad)]);}),this[_0xab17a3(0xad)]=null),this[_0xab17a3(0xc4)][_0xab17a3(0xce)](),this[_0xab17a3(0xc5)]['clear']();}},s=null;function p(_0x5a2789){return s||(s=new o(_0x5a2789)),s;}function b(_0x204d33){const _0x507731=_0x1c596f,_0x3186d9={'bQEvw':_0x507731(0x9b),'hsRGD':function(_0x2c7f8e,_0x13841e){return _0x2c7f8e===_0x13841e;},'pheAW':_0x507731(0xa7)};let [_0x577b10,_0x9833bc]=react[_0x507731(0x9d)](_0x3186d9['bQEvw']),_0x11798d=p(_0x204d33);return react['useEffect'](()=>(_0x9833bc(_0x11798d[_0x507731(0xd0)]()),_0x11798d['subscribe'](_0xb46db2=>{_0x9833bc(_0xb46db2);})),[_0x204d33]),{'currentBreakpoint':_0x577b10,'isMobile':_0x577b10===_0x507731(0xa3),'isTablet':_0x3186d9[_0x507731(0xcb)](_0x577b10,_0x507731(0xcf)),'isDesktop':_0x3186d9['hsRGD'](_0x577b10,_0x3186d9['bQEvw']),'isWide':_0x577b10===_0x3186d9['pheAW'],'matches':_0x460207=>_0x11798d['matches'](_0x460207)};}exports[_0x1c596f(0xb2)]=b;
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
const _0x35e2c0=_0x384a;(function(_0x21316d,_0xb1c7d7){const _0x4d4789=_0x384a,_0x67da43=_0x21316d();while(!![]){try{const _0x5da577=-parseInt(_0x4d4789(0xe7))/0x1*(-parseInt(_0x4d4789(0xd5))/0x2)+-parseInt(_0x4d4789(0xdc))/0x3*(parseInt(_0x4d4789(0xdd))/0x4)+parseInt(_0x4d4789(0xb7))/0x5+-parseInt(_0x4d4789(0xe5))/0x6*(-parseInt(_0x4d4789(0xbd))/0x7)+parseInt(_0x4d4789(0xc5))/0x8*(-parseInt(_0x4d4789(0xc7))/0x9)+-parseInt(_0x4d4789(0xd1))/0xa*(parseInt(_0x4d4789(0xaf))/0xb)+-parseInt(_0x4d4789(0xe0))/0xc*(-parseInt(_0x4d4789(0xb0))/0xd);if(_0x5da577===_0xb1c7d7)break;else _0x67da43['push'](_0x67da43['shift']());}catch(_0x4e5280){_0x67da43['push'](_0x67da43['shift']());}}}(_0x57d3,0xba882));import{useState,useEffect}from'react';function _0x57d3(){const _0x197e4b=['uejAvvG','z2v0q3vYCMvUDejYzwfRCg9PBNq','mJC1nJyYnxbkz0HvBa','z2v0qNjLywTWB2LUDhm','zgvZDhjVEq','z2v0','Aw5UzxjxAwr0Aa','BKzzBw8','mtu0qMfzDNbm','yLrTsge','zgvSzxrL','reTLuwy','Bw9IAwXL','y3vZDg9T','ywrK','zgv0zwn0q3vYCMvUDejYzwfRCg9PBNq','mtzgrvbosu4','yNjLywTWB2LUDhm','nJqWotK3mwPiv2LOuW','sgHeu2O','BwHMtwq','y2XLyxi','kg1PBI13Awr0AdOG','B3jIy0e','DgfIBgv0','zgvZA3rVCa','ChGP','BM90Awz5tgLZDgvUzxjZ','mti0nZG2mfzZtxPZsa','C3vIC2nYAwjL','y3vYCMvUDejYzwfRCg9PBNq','C2v0','mZGXmJznv2LrEM4','z2v0qNjLywTWB2LUDenVBMzPzW','yNbyAue','BwvKAwfrDwvYEuXPC3rLBMvYCW','BgLZDgvUzxjZ','Bwf4','zM9YrwfJAa','m1f3zuz0wG','nJa1odKXmKjdsw9JyW','uLb1Cu0','z2v0twvKAwfrDwvYEq','mZeWmtG4AgDys1Pn','ChvZAa','AM9PBG','BwLU','y2HHBMDL','mteZnZG0r05Auu5m','wMnhuxO','ndrcB21YBvO','igfUzca','D2LKzq','A2v5CW','C2v0DxbnzwrPyvf1zxj5tgLZDgvUzxjZ','kg1HEc13Awr0AdOG','wK9gv1G','CvvUCKm','mJjIBufjthi','mta3ovvcwgzfAa','CuveB1e','Bwf0y2HnzwrPyq','yM91BMriyw5KBgvY','ywrKrxzLBNrmAxn0zw5LCG'];_0x57d3=function(){return _0x197e4b;};return _0x57d3();}function _0x384a(_0x4684db,_0x12678d){_0x4684db=_0x4684db-0xaf;const _0x57d310=_0x57d3();let _0x384a05=_0x57d310[_0x4684db];if(_0x384a['NyhAVU']===undefined){var _0x3c5a58=function(_0x428dc9){const _0x5ad685='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x44dee2='',_0x429f45='';for(let _0x10e486=0x0,_0x56f3ea,_0x378ce5,_0x33992b=0x0;_0x378ce5=_0x428dc9['charAt'](_0x33992b++);~_0x378ce5&&(_0x56f3ea=_0x10e486%0x4?_0x56f3ea*0x40+_0x378ce5:_0x378ce5,_0x10e486++%0x4)?_0x44dee2+=String['fromCharCode'](0xff&_0x56f3ea>>(-0x2*_0x10e486&0x6)):0x0){_0x378ce5=_0x5ad685['indexOf'](_0x378ce5);}for(let _0x4b5348=0x0,_0x2be14c=_0x44dee2['length'];_0x4b5348<_0x2be14c;_0x4b5348++){_0x429f45+='%'+('00'+_0x44dee2['charCodeAt'](_0x4b5348)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x429f45);};_0x384a['gwzYJf']=_0x3c5a58,_0x384a['CqDbOC']={},_0x384a['NyhAVU']=!![];}const _0x2adf46=_0x57d310[0x0],_0x152e83=_0x4684db+_0x2adf46,_0x29d88d=_0x384a['CqDbOC'][_0x152e83];return!_0x29d88d?(_0x384a05=_0x384a['gwzYJf'](_0x384a05),_0x384a['CqDbOC'][_0x152e83]=_0x384a05):_0x384a05=_0x29d88d,_0x384a05;}var a={'mobile':{'max':0x2ff},'tablet':{'min':0x300,'max':0x3ff},'desktop':{'min':0x400,'max':0x780},'wide':{'min':0x781}},o=class{constructor(_0x53f6aa=a){const _0x3a2a16=_0x384a,_0x204e27={'orbcA':_0x3a2a16(0xce),'bpXiA':function(_0x486419,_0xcee48f){return _0x486419<_0xcee48f;}};this[_0x3a2a16(0xd8)]=new Map(),this[_0x3a2a16(0xd3)]=_0x204e27[_0x3a2a16(0xcc)],this[_0x3a2a16(0xd9)]=new Set(),this[_0x3a2a16(0xb3)]=null,(this['breakpoints']=_0x53f6aa,_0x204e27[_0x3a2a16(0xd7)](typeof window,'u')&&(this[_0x3a2a16(0xeb)](),this[_0x3a2a16(0xc4)]()));}['getCurrentBreakpoint'](){const _0x171a94=_0x384a;return this[_0x171a94(0xd3)];}[_0x35e2c0(0xb8)](){const _0x3ce893=_0x35e2c0;return this[_0x3ce893(0xc6)];}[_0x35e2c0(0xdf)](_0xca6901){const _0x463a55=_0x35e2c0,_0x15c901={'bTmHa':function(_0x315738,_0x4e2ab7){return _0x315738!==_0x4e2ab7;},'ZcGQz':_0x463a55(0xe8)};let _0x38749e=this[_0x463a55(0xd6)](_0xca6901);if(!_0x38749e)return'';let _0x420c2d=[];return _0x15c901[_0x463a55(0xbe)](_0x38749e[_0x463a55(0xe3)],void 0x0)&&_0x420c2d[_0x463a55(0xe1)](_0x463a55(0xcb)+_0x38749e[_0x463a55(0xe3)]+_0x463a55(0xcf)),_0x38749e[_0x463a55(0xda)]!==void 0x0&&_0x420c2d[_0x463a55(0xe1)](_0x463a55(0xec)+_0x38749e[_0x463a55(0xda)]+'px)'),_0x420c2d[_0x463a55(0xe2)](_0x15c901[_0x463a55(0xe6)]);}['getBreakpointConfig'](_0x1b7d43){const _0x215c65=_0x35e2c0;return _0x1b7d43 in this['breakpoints']?this[_0x215c65(0xc6)][_0x1b7d43]:this['breakpoints'][_0x215c65(0xc2)]&&_0x1b7d43 in this[_0x215c65(0xc6)][_0x215c65(0xc2)]?this[_0x215c65(0xc6)][_0x215c65(0xc2)][_0x1b7d43]:null;}['setupMediaQueryListeners'](){const _0x250654=_0x35e2c0,_0x3310e3={'hlWyg':_0x250654(0xe4)};this[_0x250654(0xb3)]=()=>this['detectCurrentBreakpoint'](),Object['keys'](this[_0x250654(0xc6)])['forEach'](_0x1c1b4f=>{const _0x4d38a7=_0x250654;if(_0x1c1b4f===_0x4d38a7(0xc2))return;let _0x514062=this[_0x4d38a7(0xdf)](_0x1c1b4f);if(_0x514062){let _0x1a133=window[_0x4d38a7(0xb2)](_0x514062);this[_0x4d38a7(0xd8)]['set'](_0x1c1b4f,_0x1a133),_0x1a133[_0x4d38a7(0xb4)](_0x4d38a7(0xe4),this[_0x4d38a7(0xb3)]);}}),this['breakpoints']['custom']&&Object[_0x250654(0xea)](this[_0x250654(0xc6)][_0x250654(0xc2)])[_0x250654(0xdb)](_0x5a832e=>{const _0x477884=_0x250654;let _0x3d4d5e=this[_0x477884(0xdf)](_0x5a832e);if(_0x3d4d5e){let _0x412dab=window[_0x477884(0xb2)](_0x3d4d5e);this[_0x477884(0xd8)][_0x477884(0xd4)](_0x5a832e,_0x412dab),_0x412dab[_0x477884(0xb4)](_0x3310e3['hlWyg'],this[_0x477884(0xb3)]);}});}[_0x35e2c0(0xc4)](){const _0x300e5c=_0x35e2c0,_0x38d34a={'DKeQf':_0x300e5c(0xce),'ZOFWX':_0x300e5c(0xc1),'qEDoQ':function(_0x4725d3,_0x4fe5f5){return _0x4725d3>=_0x4fe5f5;},'HhDSj':function(_0x1c240b,_0x2612fd){return _0x1c240b<=_0x2612fd;},'KlMLo':_0x300e5c(0xcd),'wmZaN':_0x300e5c(0xe9),'RPuqM':function(_0x3ef5ef,_0x546eb8){return _0x3ef5ef===_0x546eb8;},'EJygj':function(_0x2a7893,_0x44d757){return _0x2a7893!==_0x44d757;}};let _0x413db1=window[_0x300e5c(0xbb)],_0x1601f7=_0x38d34a[_0x300e5c(0xc0)];if(_0x413db1<=this[_0x300e5c(0xc6)][_0x300e5c(0xc1)][_0x300e5c(0xda)]?_0x1601f7=_0x38d34a[_0x300e5c(0xed)]:_0x38d34a[_0x300e5c(0xb1)](_0x413db1,this[_0x300e5c(0xc6)][_0x300e5c(0xcd)][_0x300e5c(0xe3)])&&_0x38d34a[_0x300e5c(0xc8)](_0x413db1,this[_0x300e5c(0xc6)]['tablet'][_0x300e5c(0xda)])?_0x1601f7=_0x38d34a['KlMLo']:_0x38d34a['qEDoQ'](_0x413db1,this[_0x300e5c(0xc6)]['desktop']['min'])&&_0x413db1<=this[_0x300e5c(0xc6)]['desktop'][_0x300e5c(0xda)]?_0x1601f7=_0x300e5c(0xce):_0x413db1>=this[_0x300e5c(0xc6)]['wide']['min']&&(_0x1601f7=_0x38d34a['wmZaN']),this['breakpoints'][_0x300e5c(0xc2)]){for(let [_0x157d1e,_0x2e4dea]of Object['entries'](this[_0x300e5c(0xc6)][_0x300e5c(0xc2)]))if((_0x2e4dea[_0x300e5c(0xe3)]===void 0x0||_0x413db1>=_0x2e4dea[_0x300e5c(0xe3)])&&(_0x38d34a[_0x300e5c(0xde)](_0x2e4dea['max'],void 0x0)||_0x38d34a[_0x300e5c(0xc8)](_0x413db1,_0x2e4dea[_0x300e5c(0xda)]))){_0x1601f7=_0x157d1e;break;}}_0x38d34a['EJygj'](_0x1601f7,this[_0x300e5c(0xd3)])&&(this[_0x300e5c(0xd3)]=_0x1601f7,this[_0x300e5c(0xd0)]());}[_0x35e2c0(0xd2)](_0x4472a5){const _0x2f407e=_0x35e2c0;return this['listeners'][_0x2f407e(0xc3)](_0x4472a5),()=>this[_0x2f407e(0xd9)][_0x2f407e(0xbf)](_0x4472a5);}[_0x35e2c0(0xd0)](){const _0x130cae=_0x35e2c0;this[_0x130cae(0xd9)][_0x130cae(0xdb)](_0x238e85=>_0x238e85(this[_0x130cae(0xd3)]));}['matches'](_0x538d0e){const _0x267a99=_0x35e2c0;let _0x2be7cf=this[_0x267a99(0xd8)][_0x267a99(0xba)](_0x538d0e);return _0x2be7cf?_0x2be7cf['matches']:![];}[_0x35e2c0(0xb9)](){const _0x47811c=_0x35e2c0;this[_0x47811c(0xb3)]&&(this[_0x47811c(0xd8)][_0x47811c(0xdb)](_0x351194=>{const _0x44814d=_0x47811c;_0x351194['removeEventListener'](_0x44814d(0xe4),this['boundHandler']);}),this[_0x47811c(0xb3)]=null),this['mediaQueryListeners'][_0x47811c(0xca)](),this['listeners'][_0x47811c(0xca)]();}},s=null;function p(_0x31fea1){return s||(s=new o(_0x31fea1)),s;}function b(_0x154c49){const _0x5b27b1=_0x35e2c0,_0x10fd48={'YDVpP':function(_0x5c8dd9,_0x1385cc){return _0x5c8dd9(_0x1385cc);},'PBZUX':function(_0x430118,_0x1c841b){return _0x430118(_0x1c841b);},'nFYmo':_0x5b27b1(0xce),'mhfMd':function(_0xd22f5a,_0x7326f7){return _0xd22f5a(_0x7326f7);},'qUnrC':_0x5b27b1(0xc1),'XxCZo':function(_0x24550c,_0x43a94b){return _0x24550c===_0x43a94b;}};let [_0x1ef90c,_0x481fe8]=_0x10fd48[_0x5b27b1(0xb5)](useState,_0x10fd48[_0x5b27b1(0xbc)]),_0x2231ea=_0x10fd48[_0x5b27b1(0xc9)](p,_0x154c49);return useEffect(()=>(_0x481fe8(_0x2231ea[_0x5b27b1(0xb6)]()),_0x2231ea[_0x5b27b1(0xd2)](_0x54d5ac=>{_0x10fd48['YDVpP'](_0x481fe8,_0x54d5ac);})),[_0x154c49]),{'currentBreakpoint':_0x1ef90c,'isMobile':_0x1ef90c===_0x10fd48[_0x5b27b1(0xee)],'isTablet':_0x1ef90c===_0x5b27b1(0xcd),'isDesktop':_0x1ef90c===_0x10fd48[_0x5b27b1(0xbc)],'isWide':_0x10fd48['XxCZo'](_0x1ef90c,'wide'),'matches':_0x57423a=>_0x2231ea['matches'](_0x57423a)};}export{b as useBreakpoints};
|
package/dist/index.d.mts
CHANGED
|
@@ -776,6 +776,55 @@ interface RenderPageParams {
|
|
|
776
776
|
*/
|
|
777
777
|
pageConfig?: PageConfig;
|
|
778
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Parameters for rendering layout chrome (header + footer).
|
|
781
|
+
*/
|
|
782
|
+
interface RenderChromeParams {
|
|
783
|
+
/**
|
|
784
|
+
* Merchant identifier (theme folder name in this pipeline) - REQUIRED.
|
|
785
|
+
*/
|
|
786
|
+
merchantName: string;
|
|
787
|
+
/**
|
|
788
|
+
* Locale for this render.
|
|
789
|
+
*/
|
|
790
|
+
locale?: Locale;
|
|
791
|
+
/**
|
|
792
|
+
* Translation messages for i18n.
|
|
793
|
+
*/
|
|
794
|
+
messages?: Record<string, any>;
|
|
795
|
+
/**
|
|
796
|
+
* Pre-loaded header config. When provided, it is used directly (skips
|
|
797
|
+
* resolution). REQUIRED in the visual editor, whose template loader is a
|
|
798
|
+
* stub that throws. Omit in production to resolve by template name.
|
|
799
|
+
*/
|
|
800
|
+
headerConfig?: PageConfig;
|
|
801
|
+
/**
|
|
802
|
+
* Pre-loaded footer config. Same rules as headerConfig.
|
|
803
|
+
*/
|
|
804
|
+
footerConfig?: PageConfig;
|
|
805
|
+
/**
|
|
806
|
+
* Template name for the header chrome. Default: "header".
|
|
807
|
+
*/
|
|
808
|
+
headerTemplateName?: string;
|
|
809
|
+
/**
|
|
810
|
+
* Template name for the footer chrome. Default: "footer".
|
|
811
|
+
*/
|
|
812
|
+
footerTemplateName?: string;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Rendered layout chrome. Either field is null if its template is absent or
|
|
816
|
+
* errored - a missing footer must never crash the page (graceful degradation).
|
|
817
|
+
*/
|
|
818
|
+
interface ChromeResult {
|
|
819
|
+
header: React.ReactNode | null;
|
|
820
|
+
footer: React.ReactNode | null;
|
|
821
|
+
/**
|
|
822
|
+
* Distinct nav-menu handles referenced by the chrome widgets' `menuHandle`
|
|
823
|
+
* setting (derive-from-JSON). The layout passes these to `getNavMenus` so a
|
|
824
|
+
* handle the editor assigns is fetched automatically — no per-app handle list.
|
|
825
|
+
*/
|
|
826
|
+
menuHandles: string[];
|
|
827
|
+
}
|
|
779
828
|
|
|
780
829
|
/**
|
|
781
830
|
* Page Builder Factory Function
|
|
@@ -836,6 +885,11 @@ interface PageBuilder {
|
|
|
836
885
|
* Render a page to React nodes
|
|
837
886
|
*/
|
|
838
887
|
renderPage(params: RenderPageParams): Promise<React.ReactNode>;
|
|
888
|
+
/**
|
|
889
|
+
* Render layout chrome (header + footer) so callers can place page content
|
|
890
|
+
* between them. Used by both production layout and the visual editor.
|
|
891
|
+
*/
|
|
892
|
+
renderChrome(params: RenderChromeParams): Promise<ChromeResult>;
|
|
839
893
|
/**
|
|
840
894
|
* Clear internal caches
|
|
841
895
|
*/
|
|
@@ -1201,4 +1255,4 @@ declare function createSectionRendererFromComponent(Component: React.ComponentTy
|
|
|
1201
1255
|
children: React.ReactNode[];
|
|
1202
1256
|
}>): SectionRenderer;
|
|
1203
1257
|
|
|
1204
|
-
export { ASPECT_RATIO_OPTIONS, type AspectRatioOption, type Breakpoint, type BreakpointConfig, CARD_STYLE_OPTIONS, type CardStyleOption, DATA_SOURCE_TYPES, DEFAULT_BREAKPOINTS, DEFAULT_LOCALE, type DataSourceConfig, type DataSourceType, DefaultSectionWrapper, type FileSystemPresetOptions, type ITemplateLoader, type IThemeLoader, type IWidgetRegistry, type Locale, type PageBuilder, type PageBuilderOptions, type PageConfig, PageConfigHelpers, type RenderPageParams, type ResponsiveSpacing, type RouteContext, SECTION_ALIGNMENT_OPTIONS, SECTION_LAYOUT_OPTIONS, SECTION_TYPES, type SectionAlignmentOption, type SectionConfig, type SectionLayoutOption, type SectionRegistry, type SectionRenderContext, type SectionRenderer, type SectionSchema, type SectionSettings, type SectionType, type Spacing, TEXT_ALIGNMENT_OPTIONS, type Template, type TemplateVariantRegistry, type TextAlignmentOption, type Theme, type ThemeConfig, type ThemeRole, type ValidationResult, type VariantRegistryResult, type WidgetConfig, type WidgetEntry, type WidgetProps, WidgetRegistry, type WidgetResponsiveConfig, type WidgetSchema, type WidgetSchemaRegistry, createDefaultSectionRenderer, createFileSystemPageBuilder, createPageBuilder, createSectionRendererFromComponent, getPageBuilder, resetPageBuilder };
|
|
1258
|
+
export { ASPECT_RATIO_OPTIONS, type AspectRatioOption, type Breakpoint, type BreakpointConfig, CARD_STYLE_OPTIONS, type CardStyleOption, type ChromeResult, DATA_SOURCE_TYPES, DEFAULT_BREAKPOINTS, DEFAULT_LOCALE, type DataSourceConfig, type DataSourceType, DefaultSectionWrapper, type FileSystemPresetOptions, type ITemplateLoader, type IThemeLoader, type IWidgetRegistry, type Locale, type PageBuilder, type PageBuilderOptions, type PageConfig, PageConfigHelpers, type RenderChromeParams, type RenderPageParams, type ResponsiveSpacing, type RouteContext, SECTION_ALIGNMENT_OPTIONS, SECTION_LAYOUT_OPTIONS, SECTION_TYPES, type SectionAlignmentOption, type SectionConfig, type SectionLayoutOption, type SectionRegistry, type SectionRenderContext, type SectionRenderer, type SectionSchema, type SectionSettings, type SectionType, type Spacing, TEXT_ALIGNMENT_OPTIONS, type Template, type TemplateVariantRegistry, type TextAlignmentOption, type Theme, type ThemeConfig, type ThemeRole, type ValidationResult, type VariantRegistryResult, type WidgetConfig, type WidgetEntry, type WidgetProps, WidgetRegistry, type WidgetResponsiveConfig, type WidgetSchema, type WidgetSchemaRegistry, createDefaultSectionRenderer, createFileSystemPageBuilder, createPageBuilder, createSectionRendererFromComponent, getPageBuilder, resetPageBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -776,6 +776,55 @@ interface RenderPageParams {
|
|
|
776
776
|
*/
|
|
777
777
|
pageConfig?: PageConfig;
|
|
778
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* Parameters for rendering layout chrome (header + footer).
|
|
781
|
+
*/
|
|
782
|
+
interface RenderChromeParams {
|
|
783
|
+
/**
|
|
784
|
+
* Merchant identifier (theme folder name in this pipeline) - REQUIRED.
|
|
785
|
+
*/
|
|
786
|
+
merchantName: string;
|
|
787
|
+
/**
|
|
788
|
+
* Locale for this render.
|
|
789
|
+
*/
|
|
790
|
+
locale?: Locale;
|
|
791
|
+
/**
|
|
792
|
+
* Translation messages for i18n.
|
|
793
|
+
*/
|
|
794
|
+
messages?: Record<string, any>;
|
|
795
|
+
/**
|
|
796
|
+
* Pre-loaded header config. When provided, it is used directly (skips
|
|
797
|
+
* resolution). REQUIRED in the visual editor, whose template loader is a
|
|
798
|
+
* stub that throws. Omit in production to resolve by template name.
|
|
799
|
+
*/
|
|
800
|
+
headerConfig?: PageConfig;
|
|
801
|
+
/**
|
|
802
|
+
* Pre-loaded footer config. Same rules as headerConfig.
|
|
803
|
+
*/
|
|
804
|
+
footerConfig?: PageConfig;
|
|
805
|
+
/**
|
|
806
|
+
* Template name for the header chrome. Default: "header".
|
|
807
|
+
*/
|
|
808
|
+
headerTemplateName?: string;
|
|
809
|
+
/**
|
|
810
|
+
* Template name for the footer chrome. Default: "footer".
|
|
811
|
+
*/
|
|
812
|
+
footerTemplateName?: string;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Rendered layout chrome. Either field is null if its template is absent or
|
|
816
|
+
* errored - a missing footer must never crash the page (graceful degradation).
|
|
817
|
+
*/
|
|
818
|
+
interface ChromeResult {
|
|
819
|
+
header: React.ReactNode | null;
|
|
820
|
+
footer: React.ReactNode | null;
|
|
821
|
+
/**
|
|
822
|
+
* Distinct nav-menu handles referenced by the chrome widgets' `menuHandle`
|
|
823
|
+
* setting (derive-from-JSON). The layout passes these to `getNavMenus` so a
|
|
824
|
+
* handle the editor assigns is fetched automatically — no per-app handle list.
|
|
825
|
+
*/
|
|
826
|
+
menuHandles: string[];
|
|
827
|
+
}
|
|
779
828
|
|
|
780
829
|
/**
|
|
781
830
|
* Page Builder Factory Function
|
|
@@ -836,6 +885,11 @@ interface PageBuilder {
|
|
|
836
885
|
* Render a page to React nodes
|
|
837
886
|
*/
|
|
838
887
|
renderPage(params: RenderPageParams): Promise<React.ReactNode>;
|
|
888
|
+
/**
|
|
889
|
+
* Render layout chrome (header + footer) so callers can place page content
|
|
890
|
+
* between them. Used by both production layout and the visual editor.
|
|
891
|
+
*/
|
|
892
|
+
renderChrome(params: RenderChromeParams): Promise<ChromeResult>;
|
|
839
893
|
/**
|
|
840
894
|
* Clear internal caches
|
|
841
895
|
*/
|
|
@@ -1201,4 +1255,4 @@ declare function createSectionRendererFromComponent(Component: React.ComponentTy
|
|
|
1201
1255
|
children: React.ReactNode[];
|
|
1202
1256
|
}>): SectionRenderer;
|
|
1203
1257
|
|
|
1204
|
-
export { ASPECT_RATIO_OPTIONS, type AspectRatioOption, type Breakpoint, type BreakpointConfig, CARD_STYLE_OPTIONS, type CardStyleOption, DATA_SOURCE_TYPES, DEFAULT_BREAKPOINTS, DEFAULT_LOCALE, type DataSourceConfig, type DataSourceType, DefaultSectionWrapper, type FileSystemPresetOptions, type ITemplateLoader, type IThemeLoader, type IWidgetRegistry, type Locale, type PageBuilder, type PageBuilderOptions, type PageConfig, PageConfigHelpers, type RenderPageParams, type ResponsiveSpacing, type RouteContext, SECTION_ALIGNMENT_OPTIONS, SECTION_LAYOUT_OPTIONS, SECTION_TYPES, type SectionAlignmentOption, type SectionConfig, type SectionLayoutOption, type SectionRegistry, type SectionRenderContext, type SectionRenderer, type SectionSchema, type SectionSettings, type SectionType, type Spacing, TEXT_ALIGNMENT_OPTIONS, type Template, type TemplateVariantRegistry, type TextAlignmentOption, type Theme, type ThemeConfig, type ThemeRole, type ValidationResult, type VariantRegistryResult, type WidgetConfig, type WidgetEntry, type WidgetProps, WidgetRegistry, type WidgetResponsiveConfig, type WidgetSchema, type WidgetSchemaRegistry, createDefaultSectionRenderer, createFileSystemPageBuilder, createPageBuilder, createSectionRendererFromComponent, getPageBuilder, resetPageBuilder };
|
|
1258
|
+
export { ASPECT_RATIO_OPTIONS, type AspectRatioOption, type Breakpoint, type BreakpointConfig, CARD_STYLE_OPTIONS, type CardStyleOption, type ChromeResult, DATA_SOURCE_TYPES, DEFAULT_BREAKPOINTS, DEFAULT_LOCALE, type DataSourceConfig, type DataSourceType, DefaultSectionWrapper, type FileSystemPresetOptions, type ITemplateLoader, type IThemeLoader, type IWidgetRegistry, type Locale, type PageBuilder, type PageBuilderOptions, type PageConfig, PageConfigHelpers, type RenderChromeParams, type RenderPageParams, type ResponsiveSpacing, type RouteContext, SECTION_ALIGNMENT_OPTIONS, SECTION_LAYOUT_OPTIONS, SECTION_TYPES, type SectionAlignmentOption, type SectionConfig, type SectionLayoutOption, type SectionRegistry, type SectionRenderContext, type SectionRenderer, type SectionSchema, type SectionSettings, type SectionType, type Spacing, TEXT_ALIGNMENT_OPTIONS, type Template, type TemplateVariantRegistry, type TextAlignmentOption, type Theme, type ThemeConfig, type ThemeRole, type ValidationResult, type VariantRegistryResult, type WidgetConfig, type WidgetEntry, type WidgetProps, WidgetRegistry, type WidgetResponsiveConfig, type WidgetSchema, type WidgetSchemaRegistry, createDefaultSectionRenderer, createFileSystemPageBuilder, createPageBuilder, createSectionRendererFromComponent, getPageBuilder, resetPageBuilder };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var D=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var D__default=/*#__PURE__*/_interopDefault(D);var v="en";var y=class{constructor(e="en",t={}){this.locale=e,this.messages=t;}getLocale(){return this.locale}getMessages(){return this.messages}translate(e,t){if(typeof e!="string")return String(e);if(!e.startsWith("t:"))return e;let r=e.slice(2),n=this.getNestedValue(this.messages,r);return n==null?r:typeof n!="string"?n:t?this.interpolate(n,t):n}translateRaw(e){if(typeof e!="string"||!e.startsWith("t:"))return e;let t=e.slice(2),r=this.getNestedValue(this.messages,t);return r!==void 0?r:e}translateObject(e,t){if(e==null)return e;if(typeof e=="string"){if(e.startsWith("t:")){let r=this.translateRaw(e);return typeof r!="string"?r:t?this.interpolate(r,t):r}return e}if(Array.isArray(e))return e.map(r=>this.translateObject(r,t));if(typeof e=="object"){let r={};for(let[n,i]of Object.entries(e))r[n]=this.translateObject(i,t);return r}return e}getNestedValue(e,t){if(!t||!e)return;let r=t.split("."),n=e;for(let i of r){if(n==null)return;n=n[i];}return n}interpolate(e,t){return e.replace(/\{(\w+)\}/g,(r,n)=>{let i=t[n];return i!==void 0?String(i):r})}};var g={PRODUCT:"PRODUCT",PRODUCTS:"PRODUCTS",PRODUCTS_BY_HANDLES:"PRODUCTS_BY_HANDLES",COLLECTION:"COLLECTION",COLLECTIONS:"COLLECTIONS",COLLECTION_BY_HANDLES:"COLLECTION_BY_HANDLES",COLLECTION_FILTERS:"COLLECTION_FILTERS",STATIC:"STATIC",FETCH_REQUEST:"FETCH_REQUEST",GRAPHQL_REQUEST:"GRAPHQL_REQUEST"};var R=class{constructor(e){this.commerceClient=e;}async fetchPageData(e){let{merchantName:t,pageConfig:r,routeContext:n}=e,i={merchantName:t},a=this.collectRequirements(r,n),s=await this.fetchAllData(a);return {...i,...s}}collectRequirements(e,t){let r=[];if(e.dataSources)for(let[n,i]of Object.entries(e.dataSources))r.push({type:i.type,params:{...i.params,...t.params},required:i.required||false,sourceId:n,options:i.options});return r}async fetchAllData(e){let t={};return await Promise.all(e.map(async r=>{try{let n=await this.fetchSingleRequirement(r);t[r.sourceId]=n;}catch(n){if(console.error(`Error fetching data for ${r.sourceId}:`,n),r.required)throw n;t[r.sourceId]=null;}})),t}async fetchSingleRequirement(e){let{type:t,params:r,options:n}=e;switch(t){case g.STATIC:return r;case g.PRODUCT:return this.commerceClient.getProduct(r,n);case g.PRODUCTS:return this.commerceClient.getProducts(r,n);case g.PRODUCTS_BY_HANDLES:return this.commerceClient.getProductsByHandles(r,n);case g.COLLECTION:return this.commerceClient.getCollection(r,n);case g.COLLECTIONS:return this.commerceClient.getCollections(r,n);case g.COLLECTION_BY_HANDLES:return this.commerceClient.getCollectionsByHandles(r,n);case g.COLLECTION_FILTERS:return this.commerceClient.getCollectionFilters(r,n);case g.FETCH_REQUEST:return this.commerceClient.fetchRequest(r);case g.GRAPHQL_REQUEST:return this.commerceClient.graphqlRequest(r);default:return console.warn(`Unknown data source type: ${t}`),null}}};var S=class{constructor(e){this.widgetRegistry=e;}createWidgets({pageConfig:e,pageData:t,routeContext:r,translationService:n}){let i={};for(let a of e.sections){if(!a.widgets?.length){console.warn(`Section ${a.id} has no widgets.`);continue}for(let s of a.widgets){let c=this.createSingleWidget(s,e,t,r,n);c&&(i[s.id]=c);}}return i}createSingleWidget(e,t,r,n,i){try{let a=this.widgetRegistry.get(e.type);if(!a)return console.error(`Widget type not found: ${e.type}`),console.error("Available widgets:",this.widgetRegistry.getRegisteredTypes()),null;let s=this.prepareWidgetData(e,t,r);if(s===null)return null;let c={key:e.id,id:e.id,data:s,settings:e.settings,routeContext:n};return i&&(c.locale=i.getLocale()),D__default.default.createElement(a,c)}catch(a){return console.error(`Error creating widget: ${e.id}`,a),null}}prepareWidgetData(e,t,r){if(!e.dataSourceKey)return {};let n=e.dataSourceKey,i=r[n];return (t.dataSources?.[n]?.required||false)&&!i?(console.error(`Required data not available for widget: ${e.id} (dataSourceKey: ${n})`),null):i||{}}};var C=class{constructor(e){this.renderSectionWrapper=e;}renderLayout({pageConfig:e,widgets:t,styles:r,routeContext:n,isEditing:i=false,onSelectSection:a,onSelectWidget:s}){return jsxRuntime.jsx("div",{className:"page-container",children:e.sections.map(c=>this.renderSection(c,t,r,i,a,s))})}renderSection(e,t,r,n=false,i,a){let s=e.widgets.map(d=>{let u=t[d.id];if(!u)return null;let f=D__default.default.cloneElement(u,{key:d.id,...d.responsive&&{responsive:d.responsive}});return n?jsxRuntime.jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsxRuntime.jsx("div",{className:"absolute inset-0 pointer-events-auto rounded cursor-pointer","data-widget-id":d.id,style:{zIndex:1e4,border:"2px solid transparent",transition:"border-color 0.2s",borderRadius:"0.375rem"},onClick:p=>{p.preventDefault(),p.stopPropagation(),a&&a(e.id,d.id);},onMouseEnter:p=>{p.currentTarget.style.borderColor="#EF4444";},onMouseLeave:p=>{p.currentTarget.style.borderColor="transparent";}}),f]},d.id):f}).filter(Boolean),c=this.renderSectionWrapper(e,s,r);return n?jsxRuntime.jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsxRuntime.jsx("div",{className:"absolute inset-0 pointer-events-auto rounded-md cursor-pointer","data-section-id":e.id}),c]},e.id):c}};var h=class{constructor(e){this.themeLoader=e;}async processStyles({merchantName:e,pageConfig:t}){try{return {...(await this.themeLoader.loadTheme(e)).config,...t.theme}}catch(r){throw console.error(`Error processing styles for merchant ${e}:`,r),new Error(`Failed to process styles for merchant ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}};var T=new Map,P=class{constructor(e){this.templateLoader=e;}async resolveTemplate({merchantName:e,routeContext:t,variant:r}){if(!e)throw new Error("Merchant name is required");let{templateName:n,apiData:i}=t||{};if(!n)throw new Error("Template name is required in the route context");let a=r||(i?await this.determineVariant(e,n,i):"default"),s=`${e}-${n}-${a}`;if(T.has(s))return T.get(s);let c;try{c=await this.loadMerchantTemplate(e,n,a),this.validateTemplate(c)&&T.set(s,c);}catch(d){throw console.error(`Error loading merchant template for ${e}/${n}:`,d),new Error(`Unable to load template for ${e}/${n}. Make sure the template exists.`)}if(!this.validateTemplate(c))throw new Error(`Invalid template configuration for ${e}/${n}`);return c}async loadMerchantTemplate(e,t,r="default"){try{let n=await this.templateLoader.loadTemplate(e,t,r);if(!n)throw new Error(`Template not returned for ${e}/${t}/${r}`);return n}catch(n){if(r!=="default")return console.warn(`Template variant "${r}" not found for ${e}/${t}, falling back to default`),this.loadMerchantTemplate(e,t,"default");throw console.error(`Error loading template ${e}/${t}/${r}:`,n),n}}validateTemplate(e){if(!e.id||!e.sections)return console.error("Template validation failed: Missing required fields (id, or sections)"),false;if(!Array.isArray(e.sections)||e.sections.length===0)return console.error("Template validation failed: Sections must be a non-empty array"),false;for(let t of e.sections){if(!t.id||!t.widgets||!Array.isArray(t.widgets))return console.error("Template validation failed: Each section must have id and widgets array"),console.error("Section structure:",{id:t.id,hasWidgets:!!t.widgets,isArray:Array.isArray(t.widgets)}),false;if(!t.name||!t.type)return console.error("Template validation failed: Each section must have name and type"),console.error("Section:",{id:t.id,name:t.name,type:t.type}),false;if(!t.settings)return console.error("Template validation failed: Each section must have settings"),console.error("Section:",{id:t.id,hasSettings:!!t.settings}),false;for(let r of t.widgets){if(!r.id||!r.type||!r.name)return console.error("Template validation failed: Each widget must have id, type, and name"),console.error("Widget:",{id:r.id,type:r.type,name:r.name}),false;if(!r.settings)return console.error("Template validation failed: Each widget must have settings"),console.error("Widget:",{id:r.id,hasSettings:!!r.settings}),false}}return true}clearCache(){T.clear();}async determineVariant(e,t,r){try{if(!this.templateLoader.loadVariantRegistry)return "default";let n=await this.templateLoader.loadVariantRegistry(e);if(!n||!n.variantRegistry)return "default";let i=n.variantRegistry[t];if(!i)return "default";let{apiField:a,variantMap:s,defaultVariant:c}=i,d=this.getNestedValue(r,a);return d&&s&&s[d]?s[d]:c||"default"}catch(n){return console.warn(`Failed to load variant registry for template type ${t}:`,n),"default"}}getNestedValue(e,t){return t.split(".").reduce((r,n)=>r&&r[n]!==void 0?r[n]:void 0,e)}};function B(o,e="desktop"){let n=o.settings.responsive?.[e]||{padding:o.settings.padding||{top:0,right:0,bottom:0,left:0},margin:o.settings.margin},i=n.padding?`${n.padding.top}px ${n.padding.right}px ${n.padding.bottom}px ${n.padding.left}px`:"0",a=n.margin?`${n.margin.top}px ${n.margin.right}px ${n.margin.bottom}px ${n.margin.left}px`:void 0;return {padding:i,margin:a}}function l(o,e,t){let{styles:r,breakpoint:n="desktop"}=t,{layout:i}=o.settings,a=B(o,n),s={width:"100%",padding:a.padding,...a.margin&&{margin:a.margin},...i==="page"&&{maxWidth:r?.spacing?.container||"1280px",marginLeft:"auto",marginRight:"auto"}};return D__default.default.createElement("section",{key:o.id,"data-section-id":o.id,"data-section-type":o.type,"data-breakpoint":n,style:s},e)}function F(){return l}var I=class{constructor(e){let{commerceClient:t,themeLoader:r,templateLoader:n,widgetRegistry:i,sectionRenderer:a,defaultLocale:s="en"}=e;this.templateResolver=new P(n),this.dataFetcher=new R(t),this.widgetFactory=new S(i),this.styleProcessor=new h(r),this.sectionRenderer=a||l,this.defaultLocale=s;}createLayoutRenderer(e){let t=this.sectionRenderer,r=(n,i,a)=>t(n,i,{styles:a,routeContext:e,breakpoint:"desktop"});return new C(r)}async renderPage({merchantName:e,pageConfig:t,routeContext:r,locale:n,messages:i}){let a=n||this.defaultLocale,s=new y(a,i||{}),c=t||await this.templateResolver.resolveTemplate({merchantName:e,routeContext:r}),d=this.translatePageConfig(c,s),u=await this.dataFetcher.fetchPageData({merchantName:e,pageConfig:d,routeContext:r}),f=await this.styleProcessor.processStyles({merchantName:e,pageConfig:d}),p=this.widgetFactory.createWidgets({pageConfig:d,pageData:u,routeContext:r,translationService:s});return this.createLayoutRenderer(r).renderLayout({pageConfig:d,widgets:p,styles:f,routeContext:r})}clearCache(){this.templateResolver.clearCache();}validateConfig(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((i,a)=>{i.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),i.type||t.push(`Widget "${i.id}" must have a type`);});}),{valid:t.length===0,errors:t}}translatePageConfig(e,t){return {...e,sections:e.sections.map(r=>({...r,widgets:r.widgets.map(n=>({...n,settings:t.translateObject(n.settings||{})}))}))}}};function x(o){if(!o.commerceClient)throw new Error("commerceClient is required");if(!o.themeLoader)throw new Error("themeLoader is required");if(!o.templateLoader)throw new Error("templateLoader is required");if(!o.widgetRegistry)throw new Error("widgetRegistry is required");let e=new I({commerceClient:o.commerceClient,themeLoader:o.themeLoader,templateLoader:o.templateLoader,widgetRegistry:o.widgetRegistry,sectionRenderer:o.sectionRenderer,defaultLocale:o.defaultLocale});return {renderPage:t=>e.renderPage(t),clearCache:()=>e.clearCache(),validateConfig:t=>e.validateConfig(t)}}var m=class{constructor(){this.widgets=new Map;}register(e,t){if(!e){console.warn("WidgetRegistry: Cannot register widget with empty type");return}this.widgets.set(e,t);}registerAll(e){for(let{type:t,component:r}of e)this.register(t,r);}get(e){return this.widgets.get(e)}has(e){return this.widgets.has(e)}getRegisteredTypes(){return Array.from(this.widgets.keys())}clear(){this.widgets.clear();}get size(){return this.widgets.size}};var O=class{static getUsedDataSources(e){let t=new Set;for(let r of e.sections)for(let n of r.widgets)n.dataSourceKey&&t.add(n.dataSourceKey);return Array.from(t)}static findWidget(e,t){for(let r of e.sections){let n=r.widgets.find(i=>i.id===t);if(n)return n}return null}static findSection(e,t){return e.sections.find(r=>r.id===t)||null}static generateId(e){return `${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}static validate(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((i,a)=>{i.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),i.type||t.push(`Widget "${i.id}" must have a type`);});}),{valid:t.length===0,errors:t}}};var $={HEADER_SECTION:"HEADER_SECTION",GRID_SECTION:"GRID_SECTION",HERO_SECTION:"HERO_SECTION",CONTENT_SECTION:"CONTENT_SECTION",FOOTER_SECTION:"FOOTER_SECTION"},k={PAGE:"page",FULL:"full"},M={LEFT:"left",CENTER:"center",RIGHT:"right"},U={SQUARE:"1:1",STANDARD:"4:3",CLASSIC:"3:2",WIDE:"16:9"},H={LEFT:"left",CENTER:"center",RIGHT:"right"},Y={STANDARD:"standard",COMPACT:"compact",MINIMAL:"minimal"};var V={mobile:{max:767},tablet:{min:768,max:1023},desktop:{min:1024,max:1920},wide:{min:1921}};var E=null;function Q(o){let e=[];if((!o.widgets||!Array.isArray(o.widgets))&&e.push("widgets (array of { type, component })"),o.commerceClient||e.push("commerceClient (ICommerceClient)"),o.themeLoader||e.push("themeLoader (IThemeLoader)"),o.templateLoader||e.push("templateLoader (ITemplateLoader)"),e.length>0)throw new Error(`[PageBuilder] Missing required options:
|
|
1
|
+
'use strict';var b=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);var x="en";var R=class{constructor(e="en",t={}){this.locale=e,this.messages=t;}getLocale(){return this.locale}getMessages(){return this.messages}translate(e,t){if(typeof e!="string")return String(e);if(!e.startsWith("t:"))return e;let r=e.slice(2),n=this.getNestedValue(this.messages,r);return n==null?r:typeof n!="string"?n:t?this.interpolate(n,t):n}translateRaw(e){if(typeof e!="string"||!e.startsWith("t:"))return e;let t=e.slice(2),r=this.getNestedValue(this.messages,t);return r!==void 0?r:e}translateObject(e,t){if(e==null)return e;if(typeof e=="string"){if(e.startsWith("t:")){let r=this.translateRaw(e);return typeof r!="string"?r:t?this.interpolate(r,t):r}return e}if(Array.isArray(e))return e.map(r=>this.translateObject(r,t));if(typeof e=="object"){let r={};for(let[n,o]of Object.entries(e))r[n]=this.translateObject(o,t);return r}return e}getNestedValue(e,t){if(!t||!e)return;let r=t.split("."),n=e;for(let o of r){if(n==null)return;n=n[o];}return n}interpolate(e,t){return e.replace(/\{(\w+)\}/g,(r,n)=>{let o=t[n];return o!==void 0?String(o):r})}};var g={PRODUCT:"PRODUCT",PRODUCTS:"PRODUCTS",PRODUCTS_BY_HANDLES:"PRODUCTS_BY_HANDLES",COLLECTION:"COLLECTION",COLLECTIONS:"COLLECTIONS",COLLECTION_BY_HANDLES:"COLLECTION_BY_HANDLES",COLLECTION_FILTERS:"COLLECTION_FILTERS",STATIC:"STATIC",FETCH_REQUEST:"FETCH_REQUEST",GRAPHQL_REQUEST:"GRAPHQL_REQUEST"};var C=class{constructor(e){this.commerceClient=e;}async fetchPageData(e){let{merchantName:t,pageConfig:r,routeContext:n}=e,o={merchantName:t},a=this.collectRequirements(r,n),s=await this.fetchAllData(a);return {...o,...s}}collectRequirements(e,t){let r=[];if(e.dataSources)for(let[n,o]of Object.entries(e.dataSources))r.push({type:o.type,params:{...o.params,...t.params},required:o.required||false,sourceId:n,options:o.options});return r}async fetchAllData(e){let t={};return await Promise.all(e.map(async r=>{try{let n=await this.fetchSingleRequirement(r);t[r.sourceId]=n;}catch(n){if(console.error(`Error fetching data for ${r.sourceId}:`,n),r.required)throw n;t[r.sourceId]=null;}})),t}async fetchSingleRequirement(e){let{type:t,params:r,options:n}=e;switch(t){case g.STATIC:return r;case g.PRODUCT:return this.commerceClient.getProduct(r,n);case g.PRODUCTS:return this.commerceClient.getProducts(r,n);case g.PRODUCTS_BY_HANDLES:return this.commerceClient.getProductsByHandles(r,n);case g.COLLECTION:return this.commerceClient.getCollection(r,n);case g.COLLECTIONS:return this.commerceClient.getCollections(r,n);case g.COLLECTION_BY_HANDLES:return this.commerceClient.getCollectionsByHandles(r,n);case g.COLLECTION_FILTERS:return this.commerceClient.getCollectionFilters(r,n);case g.FETCH_REQUEST:return this.commerceClient.fetchRequest(r);case g.GRAPHQL_REQUEST:return this.commerceClient.graphqlRequest(r);default:return console.warn(`Unknown data source type: ${t}`),null}}};var h=class{constructor(e){this.widgetRegistry=e;}createWidgets({pageConfig:e,pageData:t,routeContext:r,translationService:n}){let o={};for(let a of e.sections){if(!a.widgets?.length){console.warn(`Section ${a.id} has no widgets.`);continue}for(let s of a.widgets){let c=this.createSingleWidget(s,e,t,r,n);c&&(o[s.id]=c);}}return o}createSingleWidget(e,t,r,n,o){try{let a=this.widgetRegistry.get(e.type);if(!a)return console.error(`Widget type not found: ${e.type}`),console.error("Available widgets:",this.widgetRegistry.getRegisteredTypes()),null;let s=this.prepareWidgetData(e,t,r);if(s===null)return null;let c={key:e.id,id:e.id,data:s,settings:e.settings,routeContext:n};return o&&(c.locale=o.getLocale()),b__default.default.createElement(a,c)}catch(a){return console.error(`Error creating widget: ${e.id}`,a),null}}prepareWidgetData(e,t,r){if(!e.dataSourceKey)return {};let n=e.dataSourceKey,o=r[n];return (t.dataSources?.[n]?.required||false)&&!o?(console.error(`Required data not available for widget: ${e.id} (dataSourceKey: ${n})`),null):o||{}}};var T=class{constructor(e){this.renderSectionWrapper=e;}renderLayout({pageConfig:e,widgets:t,styles:r,routeContext:n,isEditing:o=false,onSelectSection:a,onSelectWidget:s}){return jsxRuntime.jsx("div",{className:"page-container",children:e.sections.map(c=>jsxRuntime.jsx(b__default.default.Fragment,{children:this.renderSection(c,t,r,o,a,s)},c.id))})}renderSection(e,t,r,n=false,o,a){let s=e.widgets.map(d=>{let p=t[d.id];if(!p)return null;let m=b__default.default.cloneElement(p,{key:d.id,...d.responsive&&{responsive:d.responsive}});return n?jsxRuntime.jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsxRuntime.jsx("div",{className:"absolute inset-0 pointer-events-auto rounded cursor-pointer","data-widget-id":d.id,style:{zIndex:1e4,border:"2px solid transparent",transition:"border-color 0.2s",borderRadius:"0.375rem"},onClick:l=>{l.preventDefault(),l.stopPropagation(),a&&a(e.id,d.id);},onMouseEnter:l=>{l.currentTarget.style.borderColor="#EF4444";},onMouseLeave:l=>{l.currentTarget.style.borderColor="transparent";}}),m]},d.id):m}).filter(Boolean),c=this.renderSectionWrapper(e,s,r);return n?jsxRuntime.jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsxRuntime.jsx("div",{className:"absolute inset-0 pointer-events-auto rounded-md cursor-pointer","data-section-id":e.id}),c]},e.id):c}};var P=class{constructor(e){this.themeLoader=e;}async processStyles({merchantName:e,pageConfig:t}){try{return {...(await this.themeLoader.loadTheme(e)).config,...t.theme}}catch(r){throw console.error(`Error processing styles for merchant ${e}:`,r),new Error(`Failed to process styles for merchant ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}};var I=new Map,v=class{constructor(e){this.templateLoader=e;}async resolveTemplate({merchantName:e,routeContext:t,variant:r}){if(!e)throw new Error("Merchant name is required");let{templateName:n,apiData:o}=t||{};if(!n)throw new Error("Template name is required in the route context");let a=r||(o?await this.determineVariant(e,n,o):"default"),s=`${e}-${n}-${a}`;if(I.has(s))return I.get(s);let c;try{c=await this.loadMerchantTemplate(e,n,a),this.validateTemplate(c)&&I.set(s,c);}catch(d){throw console.error(`Error loading merchant template for ${e}/${n}:`,d),new Error(`Unable to load template for ${e}/${n}. Make sure the template exists.`)}if(!this.validateTemplate(c))throw new Error(`Invalid template configuration for ${e}/${n}`);return c}async loadMerchantTemplate(e,t,r="default"){try{let n=await this.templateLoader.loadTemplate(e,t,r);if(!n)throw new Error(`Template not returned for ${e}/${t}/${r}`);return n}catch(n){if(r!=="default")return console.warn(`Template variant "${r}" not found for ${e}/${t}, falling back to default`),this.loadMerchantTemplate(e,t,"default");throw console.error(`Error loading template ${e}/${t}/${r}:`,n),n}}validateTemplate(e){if(!e.id||!e.sections)return console.error("Template validation failed: Missing required fields (id, or sections)"),false;if(!Array.isArray(e.sections)||e.sections.length===0)return console.error("Template validation failed: Sections must be a non-empty array"),false;for(let t of e.sections){if(!t.id||!t.widgets||!Array.isArray(t.widgets))return console.error("Template validation failed: Each section must have id and widgets array"),console.error("Section structure:",{id:t.id,hasWidgets:!!t.widgets,isArray:Array.isArray(t.widgets)}),false;if(!t.name||!t.type)return console.error("Template validation failed: Each section must have name and type"),console.error("Section:",{id:t.id,name:t.name,type:t.type}),false;if(!t.settings)return console.error("Template validation failed: Each section must have settings"),console.error("Section:",{id:t.id,hasSettings:!!t.settings}),false;for(let r of t.widgets){if(!r.id||!r.type||!r.name)return console.error("Template validation failed: Each widget must have id, type, and name"),console.error("Widget:",{id:r.id,type:r.type,name:r.name}),false;if(!r.settings)return console.error("Template validation failed: Each widget must have settings"),console.error("Widget:",{id:r.id,hasSettings:!!r.settings}),false}}return true}clearCache(){I.clear();}async determineVariant(e,t,r){try{if(!this.templateLoader.loadVariantRegistry)return "default";let n=await this.templateLoader.loadVariantRegistry(e);if(!n||!n.variantRegistry)return "default";let o=n.variantRegistry[t];if(!o)return "default";let{apiField:a,variantMap:s,defaultVariant:c}=o,d=this.getNestedValue(r,a);return d&&s&&s[d]?s[d]:c||"default"}catch(n){return console.warn(`Failed to load variant registry for template type ${t}:`,n),"default"}}getNestedValue(e,t){return t.split(".").reduce((r,n)=>r&&r[n]!==void 0?r[n]:void 0,e)}};function k(i,e="desktop"){let n=i.settings.responsive?.[e]||{padding:i.settings.padding||{top:0,right:0,bottom:0,left:0},margin:i.settings.margin},o=n.padding?`${n.padding.top}px ${n.padding.right}px ${n.padding.bottom}px ${n.padding.left}px`:"0",a=n.margin?`${n.margin.top}px ${n.margin.right}px ${n.margin.bottom}px ${n.margin.left}px`:void 0;return {padding:o,margin:a}}function f(i,e,t){let{styles:r,breakpoint:n="desktop"}=t,{layout:o}=i.settings,a=k(i,n),s={width:"100%",padding:a.padding,...a.margin&&{margin:a.margin},...o==="page"&&{maxWidth:r?.spacing?.container||"1280px",marginLeft:"auto",marginRight:"auto"}};return b__default.default.createElement("section",{key:i.id,"data-section-id":i.id,"data-section-type":i.type,"data-breakpoint":n,style:s},e)}function M(){return f}function U(i,e){if(i)for(let t of i.sections??[])for(let r of t.widgets??[]){let n=r.settings?.menuHandle;typeof n=="string"&&n.length>0&&e.add(n);}}var E=class{constructor(e){let{commerceClient:t,themeLoader:r,templateLoader:n,widgetRegistry:o,sectionRenderer:a,defaultLocale:s="en"}=e;this.templateResolver=new v(n),this.dataFetcher=new C(t),this.widgetFactory=new h(o),this.styleProcessor=new P(r),this.sectionRenderer=a||f,this.defaultLocale=s;}createLayoutRenderer(e){let t=this.sectionRenderer,r=(n,o,a)=>t(n,o,{styles:a,routeContext:e,breakpoint:"desktop"});return new T(r)}async renderPage({merchantName:e,pageConfig:t,routeContext:r,locale:n,messages:o}){let a=n||this.defaultLocale,s=new R(a,o||{}),c=t||await this.templateResolver.resolveTemplate({merchantName:e,routeContext:r}),d=this.translatePageConfig(c,s),p=await this.dataFetcher.fetchPageData({merchantName:e,pageConfig:d,routeContext:r}),m=await this.styleProcessor.processStyles({merchantName:e,pageConfig:d}),l=this.widgetFactory.createWidgets({pageConfig:d,pageData:p,routeContext:r,translationService:s});return this.createLayoutRenderer(r).renderLayout({pageConfig:d,widgets:l,styles:m,routeContext:r})}async renderChrome({merchantName:e,locale:t,messages:r,headerConfig:n,footerConfig:o,headerTemplateName:a="header",footerTemplateName:s="footer"}){let c=new Set,d=async(l,A)=>{try{let u={templateName:l,path:"/",params:{},query:{},fetchAPITemplate:!0},_=A??await this.templateResolver.resolveTemplate({merchantName:e,routeContext:u});return U(_,c),await this.renderPage({merchantName:e,pageConfig:_,routeContext:u,locale:t,messages:r})}catch(u){return console.error(JSON.stringify({level:"error",service:"builder",message:"renderChrome slot failed",slot:l,merchantName:e,error:u instanceof Error?u.message:String(u)})),null}},[p,m]=await Promise.all([d(a,n),d(s,o)]);return {header:p,footer:m,menuHandles:[...c]}}clearCache(){this.templateResolver.clearCache();}validateConfig(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((o,a)=>{o.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),o.type||t.push(`Widget "${o.id}" must have a type`);});}),{valid:t.length===0,errors:t}}translatePageConfig(e,t){return {...e,sections:e.sections.map(r=>({...r,widgets:r.widgets.map(n=>({...n,settings:t.translateObject(n.settings||{})}))}))}}};function O(i){if(!i.commerceClient)throw new Error("commerceClient is required");if(!i.themeLoader)throw new Error("themeLoader is required");if(!i.templateLoader)throw new Error("templateLoader is required");if(!i.widgetRegistry)throw new Error("widgetRegistry is required");let e=new E({commerceClient:i.commerceClient,themeLoader:i.themeLoader,templateLoader:i.templateLoader,widgetRegistry:i.widgetRegistry,sectionRenderer:i.sectionRenderer,defaultLocale:i.defaultLocale});return {renderPage:t=>e.renderPage(t),renderChrome:t=>e.renderChrome(t),clearCache:()=>e.clearCache(),validateConfig:t=>e.validateConfig(t)}}var y=class{constructor(){this.widgets=new Map;}register(e,t){if(!e){console.warn("WidgetRegistry: Cannot register widget with empty type");return}this.widgets.set(e,t);}registerAll(e){for(let{type:t,component:r}of e)this.register(t,r);}get(e){return this.widgets.get(e)}has(e){return this.widgets.has(e)}getRegisteredTypes(){return Array.from(this.widgets.keys())}clear(){this.widgets.clear();}get size(){return this.widgets.size}};var w=class{static getUsedDataSources(e){let t=new Set;for(let r of e.sections)for(let n of r.widgets)n.dataSourceKey&&t.add(n.dataSourceKey);return Array.from(t)}static findWidget(e,t){for(let r of e.sections){let n=r.widgets.find(o=>o.id===t);if(n)return n}return null}static findSection(e,t){return e.sections.find(r=>r.id===t)||null}static generateId(e){return `${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}static validate(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((o,a)=>{o.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),o.type||t.push(`Widget "${o.id}" must have a type`);});}),{valid:t.length===0,errors:t}}};var H={HEADER_SECTION:"HEADER_SECTION",GRID_SECTION:"GRID_SECTION",HERO_SECTION:"HERO_SECTION",CONTENT_SECTION:"CONTENT_SECTION",FOOTER_SECTION:"FOOTER_SECTION"},Y={PAGE:"page",FULL:"full"},V={LEFT:"left",CENTER:"center",RIGHT:"right"},G={SQUARE:"1:1",STANDARD:"4:3",CLASSIC:"3:2",WIDE:"16:9"},Q={LEFT:"left",CENTER:"center",RIGHT:"right"},K={STANDARD:"standard",COMPACT:"compact",MINIMAL:"minimal"};var j={mobile:{max:767},tablet:{min:768,max:1023},desktop:{min:1024,max:1920},wide:{min:1921}};var L=null;function z(i){let e=[];if((!i.widgets||!Array.isArray(i.widgets))&&e.push("widgets (array of { type, component })"),i.commerceClient||e.push("commerceClient (ICommerceClient)"),i.themeLoader||e.push("themeLoader (IThemeLoader)"),i.templateLoader||e.push("templateLoader (ITemplateLoader)"),e.length>0)throw new Error(`[PageBuilder] Missing required options:
|
|
2
2
|
`+e.map(t=>` - ${t}`).join(`
|
|
3
3
|
`)+`
|
|
4
4
|
|
|
@@ -11,5 +11,5 @@ Example usage:
|
|
|
11
11
|
commerceClient: getCommerceClient(),
|
|
12
12
|
themeLoader: { loadTheme: async (merchant) => ... },
|
|
13
13
|
templateLoader: { loadTemplate: async (...) => ... },
|
|
14
|
-
});`)}function
|
|
15
|
-
Provide widgets, commerceClient, themeLoader, and templateLoader.`);
|
|
14
|
+
});`)}function N(i){z(i);let e=new y;e.registerAll(i.widgets);let t=i.sectionRenderer||f;return O({commerceClient:i.commerceClient,themeLoader:i.themeLoader,templateLoader:i.templateLoader,widgetRegistry:e,sectionRenderer:t,defaultLocale:i.defaultLocale||"en"})}function W(i){if(!L){if(!i)throw new Error(`[PageBuilder] getPageBuilder() requires options on first call.
|
|
15
|
+
Provide widgets, commerceClient, themeLoader, and templateLoader.`);L=N(i);}return L}function q(){L=null;}function F(i){return (e,t,r)=>b__default.default.createElement(i,{section:e,styles:r.styles,children:t})}exports.ASPECT_RATIO_OPTIONS=G;exports.CARD_STYLE_OPTIONS=K;exports.DATA_SOURCE_TYPES=g;exports.DEFAULT_BREAKPOINTS=j;exports.DEFAULT_LOCALE=x;exports.DefaultSectionWrapper=f;exports.PageConfigHelpers=w;exports.SECTION_ALIGNMENT_OPTIONS=V;exports.SECTION_LAYOUT_OPTIONS=Y;exports.SECTION_TYPES=H;exports.TEXT_ALIGNMENT_OPTIONS=Q;exports.WidgetRegistry=y;exports.createDefaultSectionRenderer=M;exports.createFileSystemPageBuilder=N;exports.createPageBuilder=O;exports.createSectionRendererFromComponent=F;exports.getPageBuilder=W;exports.resetPageBuilder=q;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import D from'react';import {jsx,jsxs}from'react/jsx-runtime';var v="en";var y=class{constructor(e="en",t={}){this.locale=e,this.messages=t;}getLocale(){return this.locale}getMessages(){return this.messages}translate(e,t){if(typeof e!="string")return String(e);if(!e.startsWith("t:"))return e;let r=e.slice(2),n=this.getNestedValue(this.messages,r);return n==null?r:typeof n!="string"?n:t?this.interpolate(n,t):n}translateRaw(e){if(typeof e!="string"||!e.startsWith("t:"))return e;let t=e.slice(2),r=this.getNestedValue(this.messages,t);return r!==void 0?r:e}translateObject(e,t){if(e==null)return e;if(typeof e=="string"){if(e.startsWith("t:")){let r=this.translateRaw(e);return typeof r!="string"?r:t?this.interpolate(r,t):r}return e}if(Array.isArray(e))return e.map(r=>this.translateObject(r,t));if(typeof e=="object"){let r={};for(let[n,i]of Object.entries(e))r[n]=this.translateObject(i,t);return r}return e}getNestedValue(e,t){if(!t||!e)return;let r=t.split("."),n=e;for(let i of r){if(n==null)return;n=n[i];}return n}interpolate(e,t){return e.replace(/\{(\w+)\}/g,(r,n)=>{let i=t[n];return i!==void 0?String(i):r})}};var g={PRODUCT:"PRODUCT",PRODUCTS:"PRODUCTS",PRODUCTS_BY_HANDLES:"PRODUCTS_BY_HANDLES",COLLECTION:"COLLECTION",COLLECTIONS:"COLLECTIONS",COLLECTION_BY_HANDLES:"COLLECTION_BY_HANDLES",COLLECTION_FILTERS:"COLLECTION_FILTERS",STATIC:"STATIC",FETCH_REQUEST:"FETCH_REQUEST",GRAPHQL_REQUEST:"GRAPHQL_REQUEST"};var R=class{constructor(e){this.commerceClient=e;}async fetchPageData(e){let{merchantName:t,pageConfig:r,routeContext:n}=e,i={merchantName:t},a=this.collectRequirements(r,n),s=await this.fetchAllData(a);return {...i,...s}}collectRequirements(e,t){let r=[];if(e.dataSources)for(let[n,i]of Object.entries(e.dataSources))r.push({type:i.type,params:{...i.params,...t.params},required:i.required||false,sourceId:n,options:i.options});return r}async fetchAllData(e){let t={};return await Promise.all(e.map(async r=>{try{let n=await this.fetchSingleRequirement(r);t[r.sourceId]=n;}catch(n){if(console.error(`Error fetching data for ${r.sourceId}:`,n),r.required)throw n;t[r.sourceId]=null;}})),t}async fetchSingleRequirement(e){let{type:t,params:r,options:n}=e;switch(t){case g.STATIC:return r;case g.PRODUCT:return this.commerceClient.getProduct(r,n);case g.PRODUCTS:return this.commerceClient.getProducts(r,n);case g.PRODUCTS_BY_HANDLES:return this.commerceClient.getProductsByHandles(r,n);case g.COLLECTION:return this.commerceClient.getCollection(r,n);case g.COLLECTIONS:return this.commerceClient.getCollections(r,n);case g.COLLECTION_BY_HANDLES:return this.commerceClient.getCollectionsByHandles(r,n);case g.COLLECTION_FILTERS:return this.commerceClient.getCollectionFilters(r,n);case g.FETCH_REQUEST:return this.commerceClient.fetchRequest(r);case g.GRAPHQL_REQUEST:return this.commerceClient.graphqlRequest(r);default:return console.warn(`Unknown data source type: ${t}`),null}}};var S=class{constructor(e){this.widgetRegistry=e;}createWidgets({pageConfig:e,pageData:t,routeContext:r,translationService:n}){let i={};for(let a of e.sections){if(!a.widgets?.length){console.warn(`Section ${a.id} has no widgets.`);continue}for(let s of a.widgets){let c=this.createSingleWidget(s,e,t,r,n);c&&(i[s.id]=c);}}return i}createSingleWidget(e,t,r,n,i){try{let a=this.widgetRegistry.get(e.type);if(!a)return console.error(`Widget type not found: ${e.type}`),console.error("Available widgets:",this.widgetRegistry.getRegisteredTypes()),null;let s=this.prepareWidgetData(e,t,r);if(s===null)return null;let c={key:e.id,id:e.id,data:s,settings:e.settings,routeContext:n};return i&&(c.locale=i.getLocale()),D.createElement(a,c)}catch(a){return console.error(`Error creating widget: ${e.id}`,a),null}}prepareWidgetData(e,t,r){if(!e.dataSourceKey)return {};let n=e.dataSourceKey,i=r[n];return (t.dataSources?.[n]?.required||false)&&!i?(console.error(`Required data not available for widget: ${e.id} (dataSourceKey: ${n})`),null):i||{}}};var C=class{constructor(e){this.renderSectionWrapper=e;}renderLayout({pageConfig:e,widgets:t,styles:r,routeContext:n,isEditing:i=false,onSelectSection:a,onSelectWidget:s}){return jsx("div",{className:"page-container",children:e.sections.map(c=>this.renderSection(c,t,r,i,a,s))})}renderSection(e,t,r,n=false,i,a){let s=e.widgets.map(d=>{let u=t[d.id];if(!u)return null;let f=D.cloneElement(u,{key:d.id,...d.responsive&&{responsive:d.responsive}});return n?jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsx("div",{className:"absolute inset-0 pointer-events-auto rounded cursor-pointer","data-widget-id":d.id,style:{zIndex:1e4,border:"2px solid transparent",transition:"border-color 0.2s",borderRadius:"0.375rem"},onClick:p=>{p.preventDefault(),p.stopPropagation(),a&&a(e.id,d.id);},onMouseEnter:p=>{p.currentTarget.style.borderColor="#EF4444";},onMouseLeave:p=>{p.currentTarget.style.borderColor="transparent";}}),f]},d.id):f}).filter(Boolean),c=this.renderSectionWrapper(e,s,r);return n?jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsx("div",{className:"absolute inset-0 pointer-events-auto rounded-md cursor-pointer","data-section-id":e.id}),c]},e.id):c}};var h=class{constructor(e){this.themeLoader=e;}async processStyles({merchantName:e,pageConfig:t}){try{return {...(await this.themeLoader.loadTheme(e)).config,...t.theme}}catch(r){throw console.error(`Error processing styles for merchant ${e}:`,r),new Error(`Failed to process styles for merchant ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}};var T=new Map,P=class{constructor(e){this.templateLoader=e;}async resolveTemplate({merchantName:e,routeContext:t,variant:r}){if(!e)throw new Error("Merchant name is required");let{templateName:n,apiData:i}=t||{};if(!n)throw new Error("Template name is required in the route context");let a=r||(i?await this.determineVariant(e,n,i):"default"),s=`${e}-${n}-${a}`;if(T.has(s))return T.get(s);let c;try{c=await this.loadMerchantTemplate(e,n,a),this.validateTemplate(c)&&T.set(s,c);}catch(d){throw console.error(`Error loading merchant template for ${e}/${n}:`,d),new Error(`Unable to load template for ${e}/${n}. Make sure the template exists.`)}if(!this.validateTemplate(c))throw new Error(`Invalid template configuration for ${e}/${n}`);return c}async loadMerchantTemplate(e,t,r="default"){try{let n=await this.templateLoader.loadTemplate(e,t,r);if(!n)throw new Error(`Template not returned for ${e}/${t}/${r}`);return n}catch(n){if(r!=="default")return console.warn(`Template variant "${r}" not found for ${e}/${t}, falling back to default`),this.loadMerchantTemplate(e,t,"default");throw console.error(`Error loading template ${e}/${t}/${r}:`,n),n}}validateTemplate(e){if(!e.id||!e.sections)return console.error("Template validation failed: Missing required fields (id, or sections)"),false;if(!Array.isArray(e.sections)||e.sections.length===0)return console.error("Template validation failed: Sections must be a non-empty array"),false;for(let t of e.sections){if(!t.id||!t.widgets||!Array.isArray(t.widgets))return console.error("Template validation failed: Each section must have id and widgets array"),console.error("Section structure:",{id:t.id,hasWidgets:!!t.widgets,isArray:Array.isArray(t.widgets)}),false;if(!t.name||!t.type)return console.error("Template validation failed: Each section must have name and type"),console.error("Section:",{id:t.id,name:t.name,type:t.type}),false;if(!t.settings)return console.error("Template validation failed: Each section must have settings"),console.error("Section:",{id:t.id,hasSettings:!!t.settings}),false;for(let r of t.widgets){if(!r.id||!r.type||!r.name)return console.error("Template validation failed: Each widget must have id, type, and name"),console.error("Widget:",{id:r.id,type:r.type,name:r.name}),false;if(!r.settings)return console.error("Template validation failed: Each widget must have settings"),console.error("Widget:",{id:r.id,hasSettings:!!r.settings}),false}}return true}clearCache(){T.clear();}async determineVariant(e,t,r){try{if(!this.templateLoader.loadVariantRegistry)return "default";let n=await this.templateLoader.loadVariantRegistry(e);if(!n||!n.variantRegistry)return "default";let i=n.variantRegistry[t];if(!i)return "default";let{apiField:a,variantMap:s,defaultVariant:c}=i,d=this.getNestedValue(r,a);return d&&s&&s[d]?s[d]:c||"default"}catch(n){return console.warn(`Failed to load variant registry for template type ${t}:`,n),"default"}}getNestedValue(e,t){return t.split(".").reduce((r,n)=>r&&r[n]!==void 0?r[n]:void 0,e)}};function B(o,e="desktop"){let n=o.settings.responsive?.[e]||{padding:o.settings.padding||{top:0,right:0,bottom:0,left:0},margin:o.settings.margin},i=n.padding?`${n.padding.top}px ${n.padding.right}px ${n.padding.bottom}px ${n.padding.left}px`:"0",a=n.margin?`${n.margin.top}px ${n.margin.right}px ${n.margin.bottom}px ${n.margin.left}px`:void 0;return {padding:i,margin:a}}function l(o,e,t){let{styles:r,breakpoint:n="desktop"}=t,{layout:i}=o.settings,a=B(o,n),s={width:"100%",padding:a.padding,...a.margin&&{margin:a.margin},...i==="page"&&{maxWidth:r?.spacing?.container||"1280px",marginLeft:"auto",marginRight:"auto"}};return D.createElement("section",{key:o.id,"data-section-id":o.id,"data-section-type":o.type,"data-breakpoint":n,style:s},e)}function F(){return l}var I=class{constructor(e){let{commerceClient:t,themeLoader:r,templateLoader:n,widgetRegistry:i,sectionRenderer:a,defaultLocale:s="en"}=e;this.templateResolver=new P(n),this.dataFetcher=new R(t),this.widgetFactory=new S(i),this.styleProcessor=new h(r),this.sectionRenderer=a||l,this.defaultLocale=s;}createLayoutRenderer(e){let t=this.sectionRenderer,r=(n,i,a)=>t(n,i,{styles:a,routeContext:e,breakpoint:"desktop"});return new C(r)}async renderPage({merchantName:e,pageConfig:t,routeContext:r,locale:n,messages:i}){let a=n||this.defaultLocale,s=new y(a,i||{}),c=t||await this.templateResolver.resolveTemplate({merchantName:e,routeContext:r}),d=this.translatePageConfig(c,s),u=await this.dataFetcher.fetchPageData({merchantName:e,pageConfig:d,routeContext:r}),f=await this.styleProcessor.processStyles({merchantName:e,pageConfig:d}),p=this.widgetFactory.createWidgets({pageConfig:d,pageData:u,routeContext:r,translationService:s});return this.createLayoutRenderer(r).renderLayout({pageConfig:d,widgets:p,styles:f,routeContext:r})}clearCache(){this.templateResolver.clearCache();}validateConfig(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((i,a)=>{i.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),i.type||t.push(`Widget "${i.id}" must have a type`);});}),{valid:t.length===0,errors:t}}translatePageConfig(e,t){return {...e,sections:e.sections.map(r=>({...r,widgets:r.widgets.map(n=>({...n,settings:t.translateObject(n.settings||{})}))}))}}};function x(o){if(!o.commerceClient)throw new Error("commerceClient is required");if(!o.themeLoader)throw new Error("themeLoader is required");if(!o.templateLoader)throw new Error("templateLoader is required");if(!o.widgetRegistry)throw new Error("widgetRegistry is required");let e=new I({commerceClient:o.commerceClient,themeLoader:o.themeLoader,templateLoader:o.templateLoader,widgetRegistry:o.widgetRegistry,sectionRenderer:o.sectionRenderer,defaultLocale:o.defaultLocale});return {renderPage:t=>e.renderPage(t),clearCache:()=>e.clearCache(),validateConfig:t=>e.validateConfig(t)}}var m=class{constructor(){this.widgets=new Map;}register(e,t){if(!e){console.warn("WidgetRegistry: Cannot register widget with empty type");return}this.widgets.set(e,t);}registerAll(e){for(let{type:t,component:r}of e)this.register(t,r);}get(e){return this.widgets.get(e)}has(e){return this.widgets.has(e)}getRegisteredTypes(){return Array.from(this.widgets.keys())}clear(){this.widgets.clear();}get size(){return this.widgets.size}};var O=class{static getUsedDataSources(e){let t=new Set;for(let r of e.sections)for(let n of r.widgets)n.dataSourceKey&&t.add(n.dataSourceKey);return Array.from(t)}static findWidget(e,t){for(let r of e.sections){let n=r.widgets.find(i=>i.id===t);if(n)return n}return null}static findSection(e,t){return e.sections.find(r=>r.id===t)||null}static generateId(e){return `${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}static validate(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((i,a)=>{i.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),i.type||t.push(`Widget "${i.id}" must have a type`);});}),{valid:t.length===0,errors:t}}};var $={HEADER_SECTION:"HEADER_SECTION",GRID_SECTION:"GRID_SECTION",HERO_SECTION:"HERO_SECTION",CONTENT_SECTION:"CONTENT_SECTION",FOOTER_SECTION:"FOOTER_SECTION"},k={PAGE:"page",FULL:"full"},M={LEFT:"left",CENTER:"center",RIGHT:"right"},U={SQUARE:"1:1",STANDARD:"4:3",CLASSIC:"3:2",WIDE:"16:9"},H={LEFT:"left",CENTER:"center",RIGHT:"right"},Y={STANDARD:"standard",COMPACT:"compact",MINIMAL:"minimal"};var V={mobile:{max:767},tablet:{min:768,max:1023},desktop:{min:1024,max:1920},wide:{min:1921}};var E=null;function Q(o){let e=[];if((!o.widgets||!Array.isArray(o.widgets))&&e.push("widgets (array of { type, component })"),o.commerceClient||e.push("commerceClient (ICommerceClient)"),o.themeLoader||e.push("themeLoader (IThemeLoader)"),o.templateLoader||e.push("templateLoader (ITemplateLoader)"),e.length>0)throw new Error(`[PageBuilder] Missing required options:
|
|
1
|
+
import b from'react';import {jsx,jsxs}from'react/jsx-runtime';var x="en";var R=class{constructor(e="en",t={}){this.locale=e,this.messages=t;}getLocale(){return this.locale}getMessages(){return this.messages}translate(e,t){if(typeof e!="string")return String(e);if(!e.startsWith("t:"))return e;let r=e.slice(2),n=this.getNestedValue(this.messages,r);return n==null?r:typeof n!="string"?n:t?this.interpolate(n,t):n}translateRaw(e){if(typeof e!="string"||!e.startsWith("t:"))return e;let t=e.slice(2),r=this.getNestedValue(this.messages,t);return r!==void 0?r:e}translateObject(e,t){if(e==null)return e;if(typeof e=="string"){if(e.startsWith("t:")){let r=this.translateRaw(e);return typeof r!="string"?r:t?this.interpolate(r,t):r}return e}if(Array.isArray(e))return e.map(r=>this.translateObject(r,t));if(typeof e=="object"){let r={};for(let[n,o]of Object.entries(e))r[n]=this.translateObject(o,t);return r}return e}getNestedValue(e,t){if(!t||!e)return;let r=t.split("."),n=e;for(let o of r){if(n==null)return;n=n[o];}return n}interpolate(e,t){return e.replace(/\{(\w+)\}/g,(r,n)=>{let o=t[n];return o!==void 0?String(o):r})}};var g={PRODUCT:"PRODUCT",PRODUCTS:"PRODUCTS",PRODUCTS_BY_HANDLES:"PRODUCTS_BY_HANDLES",COLLECTION:"COLLECTION",COLLECTIONS:"COLLECTIONS",COLLECTION_BY_HANDLES:"COLLECTION_BY_HANDLES",COLLECTION_FILTERS:"COLLECTION_FILTERS",STATIC:"STATIC",FETCH_REQUEST:"FETCH_REQUEST",GRAPHQL_REQUEST:"GRAPHQL_REQUEST"};var C=class{constructor(e){this.commerceClient=e;}async fetchPageData(e){let{merchantName:t,pageConfig:r,routeContext:n}=e,o={merchantName:t},a=this.collectRequirements(r,n),s=await this.fetchAllData(a);return {...o,...s}}collectRequirements(e,t){let r=[];if(e.dataSources)for(let[n,o]of Object.entries(e.dataSources))r.push({type:o.type,params:{...o.params,...t.params},required:o.required||false,sourceId:n,options:o.options});return r}async fetchAllData(e){let t={};return await Promise.all(e.map(async r=>{try{let n=await this.fetchSingleRequirement(r);t[r.sourceId]=n;}catch(n){if(console.error(`Error fetching data for ${r.sourceId}:`,n),r.required)throw n;t[r.sourceId]=null;}})),t}async fetchSingleRequirement(e){let{type:t,params:r,options:n}=e;switch(t){case g.STATIC:return r;case g.PRODUCT:return this.commerceClient.getProduct(r,n);case g.PRODUCTS:return this.commerceClient.getProducts(r,n);case g.PRODUCTS_BY_HANDLES:return this.commerceClient.getProductsByHandles(r,n);case g.COLLECTION:return this.commerceClient.getCollection(r,n);case g.COLLECTIONS:return this.commerceClient.getCollections(r,n);case g.COLLECTION_BY_HANDLES:return this.commerceClient.getCollectionsByHandles(r,n);case g.COLLECTION_FILTERS:return this.commerceClient.getCollectionFilters(r,n);case g.FETCH_REQUEST:return this.commerceClient.fetchRequest(r);case g.GRAPHQL_REQUEST:return this.commerceClient.graphqlRequest(r);default:return console.warn(`Unknown data source type: ${t}`),null}}};var h=class{constructor(e){this.widgetRegistry=e;}createWidgets({pageConfig:e,pageData:t,routeContext:r,translationService:n}){let o={};for(let a of e.sections){if(!a.widgets?.length){console.warn(`Section ${a.id} has no widgets.`);continue}for(let s of a.widgets){let c=this.createSingleWidget(s,e,t,r,n);c&&(o[s.id]=c);}}return o}createSingleWidget(e,t,r,n,o){try{let a=this.widgetRegistry.get(e.type);if(!a)return console.error(`Widget type not found: ${e.type}`),console.error("Available widgets:",this.widgetRegistry.getRegisteredTypes()),null;let s=this.prepareWidgetData(e,t,r);if(s===null)return null;let c={key:e.id,id:e.id,data:s,settings:e.settings,routeContext:n};return o&&(c.locale=o.getLocale()),b.createElement(a,c)}catch(a){return console.error(`Error creating widget: ${e.id}`,a),null}}prepareWidgetData(e,t,r){if(!e.dataSourceKey)return {};let n=e.dataSourceKey,o=r[n];return (t.dataSources?.[n]?.required||false)&&!o?(console.error(`Required data not available for widget: ${e.id} (dataSourceKey: ${n})`),null):o||{}}};var T=class{constructor(e){this.renderSectionWrapper=e;}renderLayout({pageConfig:e,widgets:t,styles:r,routeContext:n,isEditing:o=false,onSelectSection:a,onSelectWidget:s}){return jsx("div",{className:"page-container",children:e.sections.map(c=>jsx(b.Fragment,{children:this.renderSection(c,t,r,o,a,s)},c.id))})}renderSection(e,t,r,n=false,o,a){let s=e.widgets.map(d=>{let p=t[d.id];if(!p)return null;let m=b.cloneElement(p,{key:d.id,...d.responsive&&{responsive:d.responsive}});return n?jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsx("div",{className:"absolute inset-0 pointer-events-auto rounded cursor-pointer","data-widget-id":d.id,style:{zIndex:1e4,border:"2px solid transparent",transition:"border-color 0.2s",borderRadius:"0.375rem"},onClick:l=>{l.preventDefault(),l.stopPropagation(),a&&a(e.id,d.id);},onMouseEnter:l=>{l.currentTarget.style.borderColor="#EF4444";},onMouseLeave:l=>{l.currentTarget.style.borderColor="transparent";}}),m]},d.id):m}).filter(Boolean),c=this.renderSectionWrapper(e,s,r);return n?jsxs("div",{className:"relative",style:{overflow:"visible"},children:[jsx("div",{className:"absolute inset-0 pointer-events-auto rounded-md cursor-pointer","data-section-id":e.id}),c]},e.id):c}};var P=class{constructor(e){this.themeLoader=e;}async processStyles({merchantName:e,pageConfig:t}){try{return {...(await this.themeLoader.loadTheme(e)).config,...t.theme}}catch(r){throw console.error(`Error processing styles for merchant ${e}:`,r),new Error(`Failed to process styles for merchant ${e}: ${r instanceof Error?r.message:"Unknown error"}`)}}};var I=new Map,v=class{constructor(e){this.templateLoader=e;}async resolveTemplate({merchantName:e,routeContext:t,variant:r}){if(!e)throw new Error("Merchant name is required");let{templateName:n,apiData:o}=t||{};if(!n)throw new Error("Template name is required in the route context");let a=r||(o?await this.determineVariant(e,n,o):"default"),s=`${e}-${n}-${a}`;if(I.has(s))return I.get(s);let c;try{c=await this.loadMerchantTemplate(e,n,a),this.validateTemplate(c)&&I.set(s,c);}catch(d){throw console.error(`Error loading merchant template for ${e}/${n}:`,d),new Error(`Unable to load template for ${e}/${n}. Make sure the template exists.`)}if(!this.validateTemplate(c))throw new Error(`Invalid template configuration for ${e}/${n}`);return c}async loadMerchantTemplate(e,t,r="default"){try{let n=await this.templateLoader.loadTemplate(e,t,r);if(!n)throw new Error(`Template not returned for ${e}/${t}/${r}`);return n}catch(n){if(r!=="default")return console.warn(`Template variant "${r}" not found for ${e}/${t}, falling back to default`),this.loadMerchantTemplate(e,t,"default");throw console.error(`Error loading template ${e}/${t}/${r}:`,n),n}}validateTemplate(e){if(!e.id||!e.sections)return console.error("Template validation failed: Missing required fields (id, or sections)"),false;if(!Array.isArray(e.sections)||e.sections.length===0)return console.error("Template validation failed: Sections must be a non-empty array"),false;for(let t of e.sections){if(!t.id||!t.widgets||!Array.isArray(t.widgets))return console.error("Template validation failed: Each section must have id and widgets array"),console.error("Section structure:",{id:t.id,hasWidgets:!!t.widgets,isArray:Array.isArray(t.widgets)}),false;if(!t.name||!t.type)return console.error("Template validation failed: Each section must have name and type"),console.error("Section:",{id:t.id,name:t.name,type:t.type}),false;if(!t.settings)return console.error("Template validation failed: Each section must have settings"),console.error("Section:",{id:t.id,hasSettings:!!t.settings}),false;for(let r of t.widgets){if(!r.id||!r.type||!r.name)return console.error("Template validation failed: Each widget must have id, type, and name"),console.error("Widget:",{id:r.id,type:r.type,name:r.name}),false;if(!r.settings)return console.error("Template validation failed: Each widget must have settings"),console.error("Widget:",{id:r.id,hasSettings:!!r.settings}),false}}return true}clearCache(){I.clear();}async determineVariant(e,t,r){try{if(!this.templateLoader.loadVariantRegistry)return "default";let n=await this.templateLoader.loadVariantRegistry(e);if(!n||!n.variantRegistry)return "default";let o=n.variantRegistry[t];if(!o)return "default";let{apiField:a,variantMap:s,defaultVariant:c}=o,d=this.getNestedValue(r,a);return d&&s&&s[d]?s[d]:c||"default"}catch(n){return console.warn(`Failed to load variant registry for template type ${t}:`,n),"default"}}getNestedValue(e,t){return t.split(".").reduce((r,n)=>r&&r[n]!==void 0?r[n]:void 0,e)}};function k(i,e="desktop"){let n=i.settings.responsive?.[e]||{padding:i.settings.padding||{top:0,right:0,bottom:0,left:0},margin:i.settings.margin},o=n.padding?`${n.padding.top}px ${n.padding.right}px ${n.padding.bottom}px ${n.padding.left}px`:"0",a=n.margin?`${n.margin.top}px ${n.margin.right}px ${n.margin.bottom}px ${n.margin.left}px`:void 0;return {padding:o,margin:a}}function f(i,e,t){let{styles:r,breakpoint:n="desktop"}=t,{layout:o}=i.settings,a=k(i,n),s={width:"100%",padding:a.padding,...a.margin&&{margin:a.margin},...o==="page"&&{maxWidth:r?.spacing?.container||"1280px",marginLeft:"auto",marginRight:"auto"}};return b.createElement("section",{key:i.id,"data-section-id":i.id,"data-section-type":i.type,"data-breakpoint":n,style:s},e)}function M(){return f}function U(i,e){if(i)for(let t of i.sections??[])for(let r of t.widgets??[]){let n=r.settings?.menuHandle;typeof n=="string"&&n.length>0&&e.add(n);}}var E=class{constructor(e){let{commerceClient:t,themeLoader:r,templateLoader:n,widgetRegistry:o,sectionRenderer:a,defaultLocale:s="en"}=e;this.templateResolver=new v(n),this.dataFetcher=new C(t),this.widgetFactory=new h(o),this.styleProcessor=new P(r),this.sectionRenderer=a||f,this.defaultLocale=s;}createLayoutRenderer(e){let t=this.sectionRenderer,r=(n,o,a)=>t(n,o,{styles:a,routeContext:e,breakpoint:"desktop"});return new T(r)}async renderPage({merchantName:e,pageConfig:t,routeContext:r,locale:n,messages:o}){let a=n||this.defaultLocale,s=new R(a,o||{}),c=t||await this.templateResolver.resolveTemplate({merchantName:e,routeContext:r}),d=this.translatePageConfig(c,s),p=await this.dataFetcher.fetchPageData({merchantName:e,pageConfig:d,routeContext:r}),m=await this.styleProcessor.processStyles({merchantName:e,pageConfig:d}),l=this.widgetFactory.createWidgets({pageConfig:d,pageData:p,routeContext:r,translationService:s});return this.createLayoutRenderer(r).renderLayout({pageConfig:d,widgets:l,styles:m,routeContext:r})}async renderChrome({merchantName:e,locale:t,messages:r,headerConfig:n,footerConfig:o,headerTemplateName:a="header",footerTemplateName:s="footer"}){let c=new Set,d=async(l,A)=>{try{let u={templateName:l,path:"/",params:{},query:{},fetchAPITemplate:!0},_=A??await this.templateResolver.resolveTemplate({merchantName:e,routeContext:u});return U(_,c),await this.renderPage({merchantName:e,pageConfig:_,routeContext:u,locale:t,messages:r})}catch(u){return console.error(JSON.stringify({level:"error",service:"builder",message:"renderChrome slot failed",slot:l,merchantName:e,error:u instanceof Error?u.message:String(u)})),null}},[p,m]=await Promise.all([d(a,n),d(s,o)]);return {header:p,footer:m,menuHandles:[...c]}}clearCache(){this.templateResolver.clearCache();}validateConfig(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((o,a)=>{o.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),o.type||t.push(`Widget "${o.id}" must have a type`);});}),{valid:t.length===0,errors:t}}translatePageConfig(e,t){return {...e,sections:e.sections.map(r=>({...r,widgets:r.widgets.map(n=>({...n,settings:t.translateObject(n.settings||{})}))}))}}};function O(i){if(!i.commerceClient)throw new Error("commerceClient is required");if(!i.themeLoader)throw new Error("themeLoader is required");if(!i.templateLoader)throw new Error("templateLoader is required");if(!i.widgetRegistry)throw new Error("widgetRegistry is required");let e=new E({commerceClient:i.commerceClient,themeLoader:i.themeLoader,templateLoader:i.templateLoader,widgetRegistry:i.widgetRegistry,sectionRenderer:i.sectionRenderer,defaultLocale:i.defaultLocale});return {renderPage:t=>e.renderPage(t),renderChrome:t=>e.renderChrome(t),clearCache:()=>e.clearCache(),validateConfig:t=>e.validateConfig(t)}}var y=class{constructor(){this.widgets=new Map;}register(e,t){if(!e){console.warn("WidgetRegistry: Cannot register widget with empty type");return}this.widgets.set(e,t);}registerAll(e){for(let{type:t,component:r}of e)this.register(t,r);}get(e){return this.widgets.get(e)}has(e){return this.widgets.has(e)}getRegisteredTypes(){return Array.from(this.widgets.keys())}clear(){this.widgets.clear();}get size(){return this.widgets.size}};var w=class{static getUsedDataSources(e){let t=new Set;for(let r of e.sections)for(let n of r.widgets)n.dataSourceKey&&t.add(n.dataSourceKey);return Array.from(t)}static findWidget(e,t){for(let r of e.sections){let n=r.widgets.find(o=>o.id===t);if(n)return n}return null}static findSection(e,t){return e.sections.find(r=>r.id===t)||null}static generateId(e){return `${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}static validate(e){let t=[];return e.id||t.push("Page config must have an id"),(!e.sections||!Array.isArray(e.sections))&&t.push("Page config must have a sections array"),(!e.dataSources||typeof e.dataSources!="object")&&t.push("Page config must have a dataSources object"),e.sections?.forEach((r,n)=>{r.id||t.push(`Section at index ${n} must have an id`),(!r.widgets||!Array.isArray(r.widgets))&&t.push(`Section "${r.id}" must have a widgets array`),r.widgets?.forEach((o,a)=>{o.id||t.push(`Widget at section "${r.id}" index ${a} must have an id`),o.type||t.push(`Widget "${o.id}" must have a type`);});}),{valid:t.length===0,errors:t}}};var H={HEADER_SECTION:"HEADER_SECTION",GRID_SECTION:"GRID_SECTION",HERO_SECTION:"HERO_SECTION",CONTENT_SECTION:"CONTENT_SECTION",FOOTER_SECTION:"FOOTER_SECTION"},Y={PAGE:"page",FULL:"full"},V={LEFT:"left",CENTER:"center",RIGHT:"right"},G={SQUARE:"1:1",STANDARD:"4:3",CLASSIC:"3:2",WIDE:"16:9"},Q={LEFT:"left",CENTER:"center",RIGHT:"right"},K={STANDARD:"standard",COMPACT:"compact",MINIMAL:"minimal"};var j={mobile:{max:767},tablet:{min:768,max:1023},desktop:{min:1024,max:1920},wide:{min:1921}};var L=null;function z(i){let e=[];if((!i.widgets||!Array.isArray(i.widgets))&&e.push("widgets (array of { type, component })"),i.commerceClient||e.push("commerceClient (ICommerceClient)"),i.themeLoader||e.push("themeLoader (IThemeLoader)"),i.templateLoader||e.push("templateLoader (ITemplateLoader)"),e.length>0)throw new Error(`[PageBuilder] Missing required options:
|
|
2
2
|
`+e.map(t=>` - ${t}`).join(`
|
|
3
3
|
`)+`
|
|
4
4
|
|
|
@@ -11,5 +11,5 @@ Example usage:
|
|
|
11
11
|
commerceClient: getCommerceClient(),
|
|
12
12
|
themeLoader: { loadTheme: async (merchant) => ... },
|
|
13
13
|
templateLoader: { loadTemplate: async (...) => ... },
|
|
14
|
-
});`)}function
|
|
15
|
-
Provide widgets, commerceClient, themeLoader, and templateLoader.`);
|
|
14
|
+
});`)}function N(i){z(i);let e=new y;e.registerAll(i.widgets);let t=i.sectionRenderer||f;return O({commerceClient:i.commerceClient,themeLoader:i.themeLoader,templateLoader:i.templateLoader,widgetRegistry:e,sectionRenderer:t,defaultLocale:i.defaultLocale||"en"})}function W(i){if(!L){if(!i)throw new Error(`[PageBuilder] getPageBuilder() requires options on first call.
|
|
15
|
+
Provide widgets, commerceClient, themeLoader, and templateLoader.`);L=N(i);}return L}function q(){L=null;}function F(i){return (e,t,r)=>b.createElement(i,{section:e,styles:r.styles,children:t})}export{G as ASPECT_RATIO_OPTIONS,K as CARD_STYLE_OPTIONS,g as DATA_SOURCE_TYPES,j as DEFAULT_BREAKPOINTS,x as DEFAULT_LOCALE,f as DefaultSectionWrapper,w as PageConfigHelpers,V as SECTION_ALIGNMENT_OPTIONS,Y as SECTION_LAYOUT_OPTIONS,H as SECTION_TYPES,Q as TEXT_ALIGNMENT_OPTIONS,y as WidgetRegistry,M as createDefaultSectionRenderer,N as createFileSystemPageBuilder,O as createPageBuilder,F as createSectionRendererFromComponent,W as getPageBuilder,q as resetPageBuilder};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopkit/builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Page builder for creating dynamic storefronts with configurable widgets and layouts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"javascript-obfuscator": "^5.3.0",
|
|
46
46
|
"tsup": "^8.0.0",
|
|
47
47
|
"typescript": "^5.3.0",
|
|
48
|
+
"vitest": "^1.0.0",
|
|
48
49
|
"@shopkit/test-utils": "workspace:*"
|
|
49
50
|
},
|
|
50
51
|
"keywords": [
|