@plasmicpkgs/plasmic-tabs 0.0.31 → 0.0.33

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.
@@ -73,6 +73,7 @@ var TabsContainerMeta = {
73
73
  name: 'hostless-tabs-container',
74
74
  displayName: 'Tabs Container',
75
75
  importName: 'TabsContainer',
76
+ styleSections: false,
76
77
  importPath: modulePath,
77
78
  providesData: true,
78
79
  description: 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',
@@ -88,7 +89,7 @@ var TabsContainerMeta = {
88
89
  },
89
90
  previewKey: {
90
91
  type: 'string',
91
- description: 'SShow this key while editing in Plasmic Studio'
92
+ description: 'Show this key while editing in Plasmic Studio'
92
93
  },
93
94
  previewAll: {
94
95
  type: 'boolean',
@@ -327,7 +328,7 @@ function TabContent(_ref8) {
327
328
  }, children);
328
329
  switch (mountMode) {
329
330
  case 'mountOneAtATime':
330
- return React__default.createElement(React__default.Fragment, null, show ? children : null);
331
+ return React__default.createElement(React__default.Fragment, null, show ? divContent : null);
331
332
  case 'mountAllEagerly':
332
333
  return divContent;
333
334
  case 'mountLazily':
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.cjs.development.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","initialKey","previewKey","_ref$mountMode","mountMode","_useState","useState","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","inEditor","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","React","Provider","Helper","ensure","x","Error","_ref3","_ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_ref5","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAIA;;AACR,CACD;AAED,SAASC,qBAAqBA,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,mBAAa,CAAC,KAAK,CAAC;AAIzC,SAASC,WAAWA,CAAAC,IAAA;MAClBC,UAAU,GAAAD,IAAA,CAAVC,UAAU;IACVC,UAAU,GAAAF,IAAA,CAAVE,UAAU;IAAAC,cAAA,GAAAH,IAAA,CACVI,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,iBAAiB,GAAAA,cAAA;EAM7B,IAAAE,SAAA,GAA4BC,cAAQ,CAAqBL,UAAU,CAAC;IAA7DM,MAAM,GAAAF,SAAA;IAAEG,SAAS,GAAAH,SAAA;EACxB,IAAAI,UAAA,GAAwBH,cAAQ,CAC9BI,SAAS,CACV;IAFMC,IAAI,GAAAF,UAAA;IAAEG,OAAO,GAAAH,UAAA;EAGpB,IAAMI,QAAQ,GAAGC,4BAAuB,EAAE;EAC1C,OAAO;IACLP,MAAM,EAAEM,QAAQ,GAAGX,UAAU,IAAIK,MAAM,GAAGA,MAAM;IAChDI,IAAI,EAAJA,IAAI;IACJH,SAAS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B,SAAS,EAAEF,aAAa,CAAC;EAC5CgC,kBAAkB,CAACZ,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plasmic-tabs.cjs.development.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n styleSections: false,\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'Show this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? divContent : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","initialKey","previewKey","_ref$mountMode","mountMode","_useState","useState","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","inEditor","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","styleSections","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","React","Provider","Helper","ensure","x","Error","_ref3","_ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_ref5","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAIA;;AACR,CACD;AAED,SAASC,qBAAqBA,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,m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KAAK,iBAAiB;MACpB,OAAOqC,4DAAGmD,IAAI,GAAGI,UAAU,GAAG,IAAI,CAAI;IACxC,KAAK,iBAAiB;MACpB,OAAOA,UAAU;IACnB,KAAK,aAAa;MAChB,OAAOvD,4DAAGqD,WAAW,IAAIE,UAAU,CAAI;;EAE3C,MAAM,IAAIlD,KAAK,4BAA0B1C,SAAW,CAAC;AACvD;;SChXgB8F,WAAWA,CAACC,MAE3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAAC9D,aAAa,EAAEhB,iBAAiB,CAAC;EACpD8E,kBAAkB,CAAC9C,YAAY,EAAEH,gBAAgB,CAAC;EAClDiD,kBAAkB,CAAC9B,SAAS,EAAEF,aAAa,CAAC;EAC5CgC,kBAAkB,CAACZ,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),n=require("@plasmicapp/host"),a=e(require("constate")),o=require("react"),r=e(o);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var s=function(){};function l(e){return{type:"default-component",kind:"button",props:{children:{type:"text",value:e}}}}var u=o.createContext(!1);function c(e){var t=e.previewKey,a=e.mountMode,r=void 0===a?"mountOneAtATime":a,i=o.useState(e.initialKey),s=i[0],l=i[1],u=o.useState(void 0),c=u[0],p=u[1];return{tabKey:n.usePlasmicCanvasContext()&&t||s,bbox:c,setTabKey:l,setBbox:p,mountMode:r}}var p=a(c),d=p[0],b=p[1];function m(){var e=b();return"setTabKey"in e?e:void 0}var y="@plasmicpkgs/plasmic-tabs",h={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",importPath:y,providesData:!0,description:"Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)",defaultStyles:{width:"stretch",padding:"8px"},props:{initialKey:{type:"string",description:"Key of the initially selected tab",defaultValue:"tab1"},previewKey:{type:"string",description:"SShow this key while editing in Plasmic Studio"},previewAll:{type:"boolean",description:"Reveal all tab contents while editing in Plasmic Studio"},mountMode:{advanced:!0,description:"How to render/mount tab content.",type:"choice",options:[{label:"Mount one at a time, unmount on hide",value:"mountOneAtATime"},{label:"Mount all up-front, do not unmount",value:"mountAllEagerly"},{label:"Mount on-demand/lazily, do not unmount",value:"mountLazily"}],defaultValueHint:"mountOneAtATime"},children:{type:"slot",defaultValue:{type:"vbox",children:[{type:"hbox",children:[{type:"component",name:"hostless-tab-button",props:{tabKey:"tab1",children:l("Tab 1")}},{type:"component",name:"hostless-tab-button",props:{tabKey:"tab2",children:l("Tab 2")}},{type:"component",name:"hostless-tab-underline"}]},{type:"vbox",children:[{type:"component",name:"hostless-tab-content",props:{tabKey:"tab1",children:[{type:"vbox",children:["Some content for tab 1"]}]}},{type:"component",name:"hostless-tab-content",props:{tabKey:"tab2",children:[{type:"vbox",children:["Some content for tab 2"]}]}}]}]}}}};function v(e){var t=e.children,a=e.initialKey,o=e.previewKey,i=e.previewAll,s=void 0!==i&&i,l=!!n.usePlasmicCanvasContext();return r.createElement(d,{initialKey:a,previewKey:o},r.createElement(u.Provider,{value:l&&s},r.createElement(f,{previewKey:o||a},t)))}function f(e){var t=e.children,a=function(e){if(!e)throw new Error("unexpected nil");return e}(m());return r.createElement(n.DataProvider,{name:"currentTabKey",data:a.tabKey},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:y,props:{},defaultStyles:{background:"#7777ff",height:"2px"}};function T(e){var t,n=e.className,a=(null!=(t=m())?t:{bbox:void 0}).bbox;return a?r.createElement("div",{className:n,style:i({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var K={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:l("Some tab")}},defaultStyles:{width:"hug"}};function g(e){var t=e.className,n=e.children,a=e.tabKey,i=m(),l=o.useRef(null),u=null!=i?i:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},c=u.tabKey,p=u.setTabKey,d=u.setBbox;return o.useEffect((function(){a===c&&d({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,d,JSON.stringify(u.bbox),a,c]),r.createElement("div",{className:t,ref:l},o.cloneElement(r.Children.toArray(n)[0],{isActive:a&&c&&c===a,onClick:function(){p(a)}}))}var w={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:{type:"vbox",children:{type:"text",value:"This is some tab content"}}}}};function A(e){var t=e.children,n=e.className,a=e.tabKey,i=m(),s=o.useContext(u),l=null!=i?i:{tabKey:void 0,mountMode:"mountOneAtATime"},c=l.mountMode,p=void 0===i||l.tabKey===a||s,d=o.useState(!1),b=d[0],y=d[1];o.useEffect((function(){p&&y(!0)}),[p]);var h=r.createElement("div",{className:n,style:p?{}:{display:"none"}},t);switch(c){case"mountOneAtATime":return r.createElement(r.Fragment,null,p?t:null);case"mountAllEagerly":return h;case"mountLazily":return r.createElement(r.Fragment,null,b&&h)}throw new Error("Unexpected mount mode "+c)}exports.TabButton=g,exports.TabButtonMeta=K,exports.TabContent=A,exports.TabContentMeta=w,exports.TabUnderline=T,exports.TabUnderlineMeta=x,exports.TabsContainer=v,exports.TabsContainerMeta=h,exports.registerAll=function(e){var n=function(n,a){e?e.registerComponent(n,a):t(n,a)};n(v,h),n(T,x),n(g,K),n(A,w)};
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),n=require("@plasmicapp/host"),a=e(require("constate")),o=require("react"),r=e(o);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var s=function(){};function l(e){return{type:"default-component",kind:"button",props:{children:{type:"text",value:e}}}}var c=o.createContext(!1);function u(e){var t=e.previewKey,a=e.mountMode,r=void 0===a?"mountOneAtATime":a,i=o.useState(e.initialKey),s=i[0],l=i[1],c=o.useState(void 0),u=c[0],p=c[1];return{tabKey:n.usePlasmicCanvasContext()&&t||s,bbox:u,setTabKey:l,setBbox:p,mountMode:r}}var p=a(u),d=p[0],b=p[1];function m(){var e=b();return"setTabKey"in e?e:void 0}var y="@plasmicpkgs/plasmic-tabs",h={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",styleSections:!1,importPath:y,providesData:!0,description:"Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)",defaultStyles:{width:"stretch",padding:"8px"},props:{initialKey:{type:"string",description:"Key of the initially selected tab",defaultValue:"tab1"},previewKey:{type:"string",description:"Show this key while editing in Plasmic Studio"},previewAll:{type:"boolean",description:"Reveal all tab contents while editing in Plasmic Studio"},mountMode:{advanced:!0,description:"How to render/mount tab content.",type:"choice",options:[{label:"Mount one at a time, unmount on hide",value:"mountOneAtATime"},{label:"Mount all up-front, do not unmount",value:"mountAllEagerly"},{label:"Mount on-demand/lazily, do not unmount",value:"mountLazily"}],defaultValueHint:"mountOneAtATime"},children:{type:"slot",defaultValue:{type:"vbox",children:[{type:"hbox",children:[{type:"component",name:"hostless-tab-button",props:{tabKey:"tab1",children:l("Tab 1")}},{type:"component",name:"hostless-tab-button",props:{tabKey:"tab2",children:l("Tab 2")}},{type:"component",name:"hostless-tab-underline"}]},{type:"vbox",children:[{type:"component",name:"hostless-tab-content",props:{tabKey:"tab1",children:[{type:"vbox",children:["Some content for tab 1"]}]}},{type:"component",name:"hostless-tab-content",props:{tabKey:"tab2",children:[{type:"vbox",children:["Some content for tab 2"]}]}}]}]}}}};function v(e){var t=e.children,a=e.initialKey,o=e.previewKey,i=e.previewAll,s=void 0!==i&&i,l=!!n.usePlasmicCanvasContext();return r.createElement(d,{initialKey:a,previewKey:o},r.createElement(c.Provider,{value:l&&s},r.createElement(f,{previewKey:o||a},t)))}function f(e){var t=e.children,a=function(e){if(!e)throw new Error("unexpected nil");return e}(m());return r.createElement(n.DataProvider,{name:"currentTabKey",data:a.tabKey},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:y,props:{},defaultStyles:{background:"#7777ff",height:"2px"}};function T(e){var t,n=e.className,a=(null!=(t=m())?t:{bbox:void 0}).bbox;return a?r.createElement("div",{className:n,style:i({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var K={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:l("Some tab")}},defaultStyles:{width:"hug"}};function g(e){var t=e.className,n=e.children,a=e.tabKey,i=m(),l=o.useRef(null),c=null!=i?i:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},u=c.tabKey,p=c.setTabKey,d=c.setBbox;return o.useEffect((function(){a===u&&d({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,d,JSON.stringify(c.bbox),a,u]),r.createElement("div",{className:t,ref:l},o.cloneElement(r.Children.toArray(n)[0],{isActive:a&&u&&u===a,onClick:function(){p(a)}}))}var w={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:{type:"vbox",children:{type:"text",value:"This is some tab content"}}}}};function A(e){var t=e.children,n=e.className,a=e.tabKey,i=m(),s=o.useContext(c),l=null!=i?i:{tabKey:void 0,mountMode:"mountOneAtATime"},u=l.mountMode,p=void 0===i||l.tabKey===a||s,d=o.useState(!1),b=d[0],y=d[1];o.useEffect((function(){p&&y(!0)}),[p]);var h=r.createElement("div",{className:n,style:p?{}:{display:"none"}},t);switch(u){case"mountOneAtATime":return r.createElement(r.Fragment,null,p?h:null);case"mountAllEagerly":return h;case"mountLazily":return r.createElement(r.Fragment,null,b&&h)}throw new Error("Unexpected mount mode "+u)}exports.TabButton=g,exports.TabButtonMeta=K,exports.TabContent=A,exports.TabContentMeta=w,exports.TabUnderline=T,exports.TabUnderlineMeta=x,exports.TabsContainer=v,exports.TabsContainerMeta=h,exports.registerAll=function(e){var n=function(n,a){e?e.registerComponent(n,a):t(n,a)};n(v,h),n(T,x),n(g,K),n(A,w)};
2
2
  //# sourceMappingURL=plasmic-tabs.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.cjs.production.min.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","previewKey","_ref$mountMode","mountMode","_useState","useState","initialKey","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","inEditor","React","Provider","Helper","_ref3","_ensure","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"qfAiBA,IAAMA,EAAO,aAIb,SAASC,EAAsBC,GAC7B,MAAO,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAInC,SAASC,EAAWC,OAElBC,EAAUD,EAAVC,WAAUC,EAAAF,EACVG,UAAAA,WAASD,EAAG,kBAAiBA,EAM7BE,EAA4BC,WARlBL,EAAVM,YAQOC,EAAMH,KAAEI,EAASJ,KACxBK,EAAwBJ,gBACtBK,GADKC,EAAIF,KAAEG,EAAOH,KAIpB,MAAO,CACLF,OAFeM,6BAEIZ,GAAuBM,EAC1CI,KAAAA,EACAH,UAAAA,EACAI,QAAAA,EACAT,UAAAA,GAIJ,IAAAW,EAA6CC,EAAShB,GAA/CiB,EAAYF,KAAEG,EAAoBH,KAEzC,SAASI,IACP,IAAMC,EAASF,IACf,MAAO,cAAeE,EAASA,OAAST,EAE1C,IAAMU,EAAa,4BAENC,EAAsD,CACjEC,KAAM,0BACNC,YAAa,iBACbC,WAAY,gBACZC,WAAYL,EACZM,cAAc,EACdC,YACE,+GACFC,cAAe,CACbC,MAAO,UACPC,QAAS,OAEXpC,MAAO,CACLY,WAAY,CACVd,KAAM,SACNmC,YAAa,oCACbI,aAAc,QAEhB9B,WAAY,CACVT,KAAM,SACNmC,YAAa,kDAEfK,WAAY,CACVxC,KAAM,UACNmC,YAAa,2DAEfxB,UAAW,CACT8B,UA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,cACbC,WAAY,aACZC,WAAYL,EACZ1B,MAAO,CACLa,OAAQ,CACNf,KAAM,SACNmC,YAAa,+CAEfhC,SAAU,CACRH,KAAM,OACNuC,aAAc,CACZvC,KAAM,OACNG,SAAU,CACRH,KAAM,OACNI,MAAO,yCAOD0F,EAAUC,OACxB5F,EAAQ4F,EAAR5F,SACA4D,EAASgC,EAAThC,UACAhD,EAAMgF,EAANhF,OAEM+D,EAAcpD,IACdc,EAAawD,aAAW3F,GAC9B4F,QAAyCnB,EAAAA,EAAe,CACtD/D,YAAQG,EACRP,UAAW,mBAFcA,EAASsF,EAATtF,UAIrBuF,OAAuBhF,IAAhB4D,GAJYmB,EAAjBlF,SAIgDA,GAAUyB,EAClE2D,EAAsCtF,YAAS,GAAxCuF,EAAWD,KAAEE,EAAcF,KAClChB,aAAU,WACJe,GACFG,GAAe,KAEhB,CAACH,IACJ,IAAMI,EACJtD,uBAAKe,UAAWA,EAAWE,MAAOiC,EAAO,GAAK,CAAEK,QAAS,SACtDpG,GAGL,OAAQQ,GACN,IAAK,kBACH,OAAOqC,gCAAGkD,EAAO/F,EAAW,MAC9B,IAAK,kBACH,OAAOmG,EACT,IAAK,cACH,OAAOtD,gCAAGoD,GAAeE,GAE7B,MAAM,IAAIhD,+BAA+B3C,gOC9Wf6F,GAG1B,IAAMC,EAAqB,SACzBC,EACAC,GAEIH,EACFA,EAAOI,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,IAIjCF,EAAmB7D,EAAef,GAClC4E,EAAmB5C,EAAcH,GACjC+C,EAAmB7B,EAAWF,GAC9B+B,EAAmBX,EAAYD"}
1
+ {"version":3,"file":"plasmic-tabs.cjs.production.min.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n styleSections: false,\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'Show this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? divContent : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","previewKey","_ref$mountMode","mountMode","_useState","useState","initialKey","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","styleSections","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","inEditor","React","Provider","Helper","_ref3","_ensure","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"qfAiBA,IAAMA,EAAO,aAIb,SAASC,EAAsBC,GAC7B,MAAO,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAInC,SAASC,EAAWC,OAElBC,EAAUD,EAAVC,WAAUC,EAAAF,EACVG,UAAAA,WAASD,EAAG,kBAAiBA,EAM7BE,EAA4BC,WARlBL,EAAVM,YAQOC,EAAMH,KAAEI,EAASJ,KACxBK,EAAwBJ,gBACtBK,GADKC,EAAIF,KAAEG,EAAOH,KAIpB,MAAO,CACLF,OAFeM,6BAEIZ,GAAuBM,EAC1CI,KAAAA,EACAH,UAAAA,EACAI,QAAAA,EACAT,UAAAA,GAIJ,IAAAW,EAA6CC,EAAShB,GAA/CiB,EAAYF,KAAEG,EAAoBH,KAEzC,SAASI,IACP,IAAMC,EAASF,IACf,MAAO,cAAeE,EAASA,OAAST,EAE1C,IAAMU,EAAa,4BAENC,EAAsD,CACjEC,KAAM,0BACNC,YAAa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mB7B,EAAWF,GAC9B+B,EAAmBX,EAAYD"}
@@ -66,6 +66,7 @@ var TabsContainerMeta = {
66
66
  name: 'hostless-tabs-container',
67
67
  displayName: 'Tabs Container',
68
68
  importName: 'TabsContainer',
69
+ styleSections: false,
69
70
  importPath: modulePath,
70
71
  providesData: true,
71
72
  description: 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',
@@ -81,7 +82,7 @@ var TabsContainerMeta = {
81
82
  },
82
83
  previewKey: {
83
84
  type: 'string',
84
- description: 'SShow this key while editing in Plasmic Studio'
85
+ description: 'Show this key while editing in Plasmic Studio'
85
86
  },
86
87
  previewAll: {
87
88
  type: 'boolean',
@@ -320,7 +321,7 @@ function TabContent(_ref8) {
320
321
  }, children);
321
322
  switch (mountMode) {
322
323
  case 'mountOneAtATime':
323
- return React.createElement(React.Fragment, null, show ? children : null);
324
+ return React.createElement(React.Fragment, null, show ? divContent : null);
324
325
  case 'mountAllEagerly':
325
326
  return divContent;
326
327
  case 'mountLazily':
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.esm.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","initialKey","previewKey","_ref$mountMode","mountMode","_useState","useState","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","inEditor","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","React","Provider","Helper","ensure","x","Error","_ref3","_ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_ref5","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAIA;;AACR,CACD;AAED,SAASC,qBAAqBA,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,aAAa,CAAC,KAAK,CAAC;AAIzC,SAASC,WAAWA,CAAAC,IAAA;MAClBC,UAAU,GAAAD,IAAA,CAAVC,UAAU;IACVC,UAAU,GAAAF,IAAA,CAAVE,UAAU;IAAAC,cAAA,GAAAH,IAAA,CACVI,SAAS;IAATA,SAAS,GAAAD,cAAA,cAAG,iBAAiB,GAAAA,cAAA;EAM7B,IAAAE,SAAA,GAA4BC,QAAQ,CAAqBL,UAAU,CAAC;IAA7DM,MAAM,GAAAF,SAAA;IAAEG,SAAS,GAAAH,SAAA;EACxB,IAAAI,UAAA,GAAwBH,QAAQ,CAC9BI,SAAS,CACV;IAFMC,IAAI,GAAAF,UAAA;IAAEG,OAAO,GAAAH,UAAA;EAGpB,IAAMI,QAAQ,GAAGC,uBAAuB,EAAE;EAC1C,OAAO;IACLP,MAAM,EAAEM,QAAQ,GAAGX,UAAU,IAAIK,MAAM,GAAGA,MAAM;IAChDI,IAAI,EAAJA,IAAI;IACJH,SAAS,EAATA,SAAS;IACTI,OAAO,EAAPA,OAAO;IACPR,SAAS,EAATA;GACD;AACH;AAEA,IAAAW,SAAA,gBAA6CC,QAAQ,CA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plasmic-tabs.esm.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n previewKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n previewKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n const inEditor = usePlasmicCanvasContext();\n return {\n tabKey: inEditor ? previewKey || tabKey : tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n styleSections: false,\n importPath: modulePath,\n providesData: true,\n description:\n 'Create bespoke/advanced tab-like UIs. [See example project](https://docs.plasmic.app/learn/tabs-components/)',\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'Show this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey} previewKey={previewKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const { tabKey } = ensure(useTabsContext());\n return (\n <DataProvider name={'currentTabKey'} data={tabKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? divContent : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref","initialKey","previewKey","_ref$mountMode","mountMode","_useState","useState","tabKey","setTabKey","_useState2","undefined","bbox","setBbox","inEditor","usePlasmicCanvasContext","_constate","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","styleSections","importPath","providesData","description","defaultStyles","width","padding","defaultValue","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2","_ref2$previewAll","React","Provider","Helper","ensure","x","Error","_ref3","_ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","_ref4","className","_ref5","_useTabsContext","style","_extends","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","_ref6","tabsContext","ref","useRef","_ref7","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","_ref8","useContext","_ref9","show","_useState3","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAIA;;AACR,CACD;AAED,SAASC,qBAAqBA,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,aAAa,CAAC,KAAK,CAAC;AAIzC,SAASC,WAAWA,CAAAC,IAAA;MAClBC,UAAU,GAAAD,IAAA,CAAVC,UAAU;IACVC,UAAU,GAAAF,IAAA,CAAVE,U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AChB,OAAOvD,0CAAGqD,WAAW,IAAIE,UAAU,CAAI;;EAE3C,MAAM,IAAIlD,KAAK,4BAA0B1C,SAAW,CAAC;AACvD;;SChXgB8F,WAAWA,CAACC,MAE3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAAC9D,aAAa,EAAEhB,iBAAiB,CAAC;EACpD8E,kBAAkB,CAAC9C,YAAY,EAAEH,gBAAgB,CAAC;EAClDiD,kBAAkB,CAAC9B,SAAS,EAAEF,aAAa,CAAC;EAC5CgC,kBAAkB,CAACZ,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.31",
2
+ "version": "0.0.33",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -60,8 +60,8 @@
60
60
  "tslib": "^2.3.1"
61
61
  },
62
62
  "dependencies": {
63
- "@plasmicapp/host": "1.0.191",
63
+ "@plasmicapp/host": "1.0.192",
64
64
  "constate": "^3.3.2"
65
65
  },
66
- "gitHead": "df264a9098a27ee0323639e37204ec0dc58ba9f2"
66
+ "gitHead": "0597c84c0fa0df12523bfdbc1ba21ce81d34d63c"
67
67
  }