@pairbo/ui-kit 0.2.3 → 0.2.4

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/pairbo.es.js CHANGED
@@ -20814,9 +20814,207 @@ PboGiftOptions$1 = __decorateClass([
20814
20814
  t$3("pbo-gift-options")
20815
20815
  ], PboGiftOptions$1);
20816
20816
  const PboGiftOptions2 = PboGiftOptions$1;
20817
+ class PboBridge {
20818
+ /* ------------------------------- constructor ------------------------------ */
20819
+ constructor({
20820
+ getCards,
20821
+ getCategories,
20822
+ drawer,
20823
+ pageManager,
20824
+ giftOptions,
20825
+ selectionGroupBy = "category",
20826
+ submitTypeForm,
20827
+ submitHandwrittenForm,
20828
+ getProcessedImg
20829
+ }) {
20830
+ this._isLoading = {
20831
+ isLoading: false,
20832
+ isError: false
20833
+ };
20834
+ this._cards = [];
20835
+ this._categories = [];
20836
+ this.setDrawer(drawer || null);
20837
+ this.setPageManager(pageManager || null);
20838
+ this.setGiftOptions(giftOptions || null);
20839
+ const drawerEl = this.getDrawer();
20840
+ const pageManagerEl = this.getPageManager();
20841
+ const giftOptionsEl = this.getGiftOptions();
20842
+ if (!pageManagerEl) {
20843
+ throw new Error("Page manager element is required");
20844
+ }
20845
+ if (drawerEl) {
20846
+ console.log(drawerEl);
20847
+ document.addEventListener("pbo-open-drawer", (e3) => {
20848
+ console.log("pbo-open-drawer event triggered", e3);
20849
+ drawerEl == null ? void 0 : drawerEl.show();
20850
+ });
20851
+ }
20852
+ drawerEl == null ? void 0 : drawerEl.addEventListener("pbo-after-drawer-closed", () => {
20853
+ giftOptionsEl == null ? void 0 : giftOptionsEl.setPremiumEnabled(false);
20854
+ });
20855
+ pageManagerEl.onClose = () => {
20856
+ drawerEl == null ? void 0 : drawerEl.hide();
20857
+ };
20858
+ if (selectionGroupBy === "category") {
20859
+ if (!getCategories) {
20860
+ throw new Error("getCategories function is required when selectionGroupBy is 'category'");
20861
+ }
20862
+ this.setIsLoading(true);
20863
+ getCategories().then((categories) => {
20864
+ this.setCategories(categories);
20865
+ }).catch((error) => {
20866
+ console.error("Failed to fetch categories:", error);
20867
+ this.setIsError(true);
20868
+ }).finally(() => {
20869
+ this.setIsLoading(false);
20870
+ });
20871
+ }
20872
+ if (selectionGroupBy === "none") {
20873
+ if (!getCards) {
20874
+ throw new Error("getCards function is required when selectionGroupBy is 'none'");
20875
+ }
20876
+ this.setIsLoading(true);
20877
+ getCards().then((cards) => {
20878
+ this.setCards(cards);
20879
+ }).catch((error) => {
20880
+ console.error("Failed to fetch cards:", error);
20881
+ this.setIsError(true);
20882
+ }).finally(() => {
20883
+ this.setIsLoading(false);
20884
+ });
20885
+ }
20886
+ if (submitTypeForm) {
20887
+ pageManagerEl.submitTypeForm = submitTypeForm;
20888
+ }
20889
+ if (submitHandwrittenForm) {
20890
+ pageManagerEl.submitHandwrittenForm = submitHandwrittenForm;
20891
+ }
20892
+ if (getProcessedImg) {
20893
+ pageManagerEl.getProcessedImg = getProcessedImg;
20894
+ }
20895
+ }
20896
+ /* ----------------------- Elements getter and setter ----------------------- */
20897
+ setDrawer(drawer) {
20898
+ if (this._drawer === null || this._drawer) {
20899
+ throw new Error("Drawer can only be set during initialization");
20900
+ }
20901
+ if (drawer === null) {
20902
+ this._drawer = null;
20903
+ return;
20904
+ }
20905
+ switch (typeof drawer) {
20906
+ case "string":
20907
+ const temp = document.querySelector(drawer);
20908
+ if (!temp) {
20909
+ throw new Error(`Drawer element with selector ${drawer} not found`);
20910
+ }
20911
+ this._drawer = temp;
20912
+ break;
20913
+ case "object":
20914
+ if (drawer instanceof PboModal) {
20915
+ this._drawer = drawer;
20916
+ break;
20917
+ }
20918
+ throw new Error("Drawer must be a string or an instance of PboDrawer");
20919
+ default:
20920
+ throw new Error("Drawer must be a string or an instance of PboDrawer");
20921
+ }
20922
+ }
20923
+ getDrawer() {
20924
+ return this._drawer;
20925
+ }
20926
+ setGiftOptions(giftOptions) {
20927
+ if (this._giftOptions === null || this._giftOptions) {
20928
+ throw new Error("Gift options can only be set during initialization");
20929
+ }
20930
+ if (giftOptions === null) {
20931
+ this._giftOptions = null;
20932
+ return;
20933
+ }
20934
+ switch (typeof giftOptions) {
20935
+ case "string":
20936
+ const temp = document.querySelector(giftOptions);
20937
+ if (!temp) {
20938
+ throw new Error(`Gift options element with selector "${giftOptions}" not found`);
20939
+ }
20940
+ this._giftOptions = temp;
20941
+ return;
20942
+ case "object":
20943
+ if (giftOptions instanceof PboModal) {
20944
+ this._giftOptions = giftOptions;
20945
+ return;
20946
+ }
20947
+ throw new Error("Gift options must be a string or an instance of PboDrawer");
20948
+ default:
20949
+ throw new Error("Gift options must be a string or an instance of PboDrawer");
20950
+ }
20951
+ }
20952
+ getGiftOptions() {
20953
+ return this._giftOptions;
20954
+ }
20955
+ setPageManager(pageManager) {
20956
+ if (this._pageManager === null || this._pageManager) {
20957
+ throw new Error("Page manager can only be set during initialization");
20958
+ }
20959
+ if (pageManager === null) {
20960
+ this._pageManager = null;
20961
+ return;
20962
+ }
20963
+ switch (typeof pageManager) {
20964
+ case "string":
20965
+ const temp = document.querySelector(pageManager);
20966
+ if (!temp) {
20967
+ throw new Error(`Page manager element with selector "${pageManager}" not found`);
20968
+ }
20969
+ this._pageManager = temp;
20970
+ return;
20971
+ case "object":
20972
+ if (pageManager instanceof PboPageManager$1) {
20973
+ this._pageManager = pageManager;
20974
+ return;
20975
+ }
20976
+ throw new Error("Page manager must be a string or an instance of PboDrawer");
20977
+ default:
20978
+ throw new Error("Page manager must be a string or an instance of PboDrawer");
20979
+ }
20980
+ }
20981
+ getPageManager() {
20982
+ return this._pageManager;
20983
+ }
20984
+ /* ------------------ Cards & Categories getter and setter ------------------ */
20985
+ getCategories() {
20986
+ return this._categories;
20987
+ }
20988
+ setCategories(categories) {
20989
+ this._categories = categories;
20990
+ if (this._pageManager) {
20991
+ this._pageManager.categories = categories;
20992
+ } else {
20993
+ console.warn("Page manager is not set, categories will not be updated");
20994
+ }
20995
+ }
20996
+ getCards() {
20997
+ return this._cards;
20998
+ }
20999
+ setCards(cards) {
21000
+ this._cards = cards;
21001
+ if (this._pageManager) ;
21002
+ else {
21003
+ console.warn("Page manager is not set, cards will not be updated");
21004
+ }
21005
+ }
21006
+ /* -------------------- Loading states getter and setter -------------------- */
21007
+ setIsLoading(isLoading) {
21008
+ this._isLoading.isLoading = isLoading;
21009
+ }
21010
+ setIsError(isError) {
21011
+ this._isLoading.isError = isError;
21012
+ }
21013
+ }
20817
21014
  export {
20818
21015
  FabricExample,
20819
21016
  PairboMessageSelector as MessageSelector,
21017
+ PboBridge,
20820
21018
  PboButton2 as PboButton,
20821
21019
  PboButtonGroup2 as PboButtonGroup,
20822
21020
  PboCardSelection2 as PboCardSelection,