@plasmicpkgs/plasmic-tabs 0.0.3 → 0.0.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.
@@ -11,51 +11,42 @@ var React = require('react');
11
11
  var React__default = _interopDefault(React);
12
12
 
13
13
  function _extends() {
14
- _extends = Object.assign || function (target) {
14
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
15
15
  for (var i = 1; i < arguments.length; i++) {
16
16
  var source = arguments[i];
17
-
18
17
  for (var key in source) {
19
18
  if (Object.prototype.hasOwnProperty.call(source, key)) {
20
19
  target[key] = source[key];
21
20
  }
22
21
  }
23
22
  }
24
-
25
23
  return target;
26
24
  };
27
-
28
25
  return _extends.apply(this, arguments);
29
26
  }
30
27
 
31
28
  var noop = function noop() {};
32
-
33
29
  function defaultButtonChildren(label) {
34
30
  return {
35
- type: "default-component",
36
- kind: "button",
31
+ type: 'default-component',
32
+ kind: 'button',
37
33
  props: {
38
34
  children: {
39
- type: "text",
35
+ type: 'text',
40
36
  value: label
41
37
  }
42
38
  }
43
39
  };
44
40
  }
45
-
46
41
  var DebugContext = /*#__PURE__*/React.createContext(false);
47
-
48
42
  function useTabsData(_ref) {
49
43
  var initialKey = _ref.initialKey;
50
-
51
44
  var _useState = React.useState(initialKey),
52
- tabKey = _useState[0],
53
- setTabKey = _useState[1];
54
-
45
+ tabKey = _useState[0],
46
+ setTabKey = _useState[1];
55
47
  var _useState2 = React.useState(undefined),
56
- bbox = _useState2[0],
57
- setBbox = _useState2[1];
58
-
48
+ bbox = _useState2[0],
49
+ setBbox = _useState2[1];
59
50
  return {
60
51
  tabKey: tabKey,
61
52
  bbox: bbox,
@@ -63,85 +54,82 @@ function useTabsData(_ref) {
63
54
  setBbox: setBbox
64
55
  };
65
56
  }
66
-
67
57
  var _constate = /*#__PURE__*/constate(useTabsData),
68
- TabsProvider = _constate[0],
69
- useTabsContextUnsafe = _constate[1];
70
-
58
+ TabsProvider = _constate[0],
59
+ useTabsContextUnsafe = _constate[1];
71
60
  function useTabsContext() {
72
61
  var result = useTabsContextUnsafe();
73
- return "setTabKey" in result ? result : undefined;
62
+ return 'setTabKey' in result ? result : undefined;
74
63
  }
75
-
76
- var modulePath = "@plasmicpkgs/plasmic-tabs";
64
+ var modulePath = '@plasmicpkgs/plasmic-tabs';
77
65
  var TabsContainerMeta = {
78
- name: "hostless-tabs-container",
79
- displayName: "Tabs Container",
80
- importName: "TabsContainer",
66
+ name: 'hostless-tabs-container',
67
+ displayName: 'Tabs Container',
68
+ importName: 'TabsContainer',
81
69
  importPath: modulePath,
82
70
  providesData: true,
83
71
  defaultStyles: {
84
- width: "stretch",
85
- padding: "8px"
72
+ width: 'stretch',
73
+ padding: '8px'
86
74
  },
87
75
  props: {
88
76
  initialKey: {
89
- type: "string",
90
- description: "Key of the initially selected tab",
91
- defaultValue: "tab1"
77
+ type: 'string',
78
+ description: 'Key of the initially selected tab',
79
+ defaultValue: 'tab1'
92
80
  },
93
81
  previewKey: {
94
- type: "string",
95
- description: "SShow this key while editing in Plasmic Studio"
82
+ type: 'string',
83
+ description: 'SShow this key while editing in Plasmic Studio'
96
84
  },
97
85
  previewAll: {
98
- type: "boolean",
99
- description: "Reveal all tab contents while editing in Plasmic Studio"
86
+ type: 'boolean',
87
+ description: 'Reveal all tab contents while editing in Plasmic Studio'
100
88
  },
101
89
  children: {
102
- type: "slot",
90
+ type: 'slot',
103
91
  defaultValue: {
104
- type: "vbox",
92
+ type: 'vbox',
105
93
  children: [{
106
- type: "hbox",
94
+ type: 'hbox',
107
95
  children: [{
108
- type: "component",
109
- name: "hostless-tab-button",
96
+ type: 'component',
97
+ name: 'hostless-tab-button',
110
98
  props: {
111
- tabKey: "tab1",
112
- children: /*#__PURE__*/defaultButtonChildren("Tab 1")
99
+ tabKey: 'tab1',
100
+ children: /*#__PURE__*/defaultButtonChildren('Tab 1')
113
101
  }
114
102
  }, {
115
- type: "component",
116
- name: "hostless-tab-button",
103
+ type: 'component',
104
+ name: 'hostless-tab-button',
117
105
  props: {
118
- tabKey: "tab2",
119
- children: /*#__PURE__*/defaultButtonChildren("Tab 2")
106
+ tabKey: 'tab2',
107
+ children: /*#__PURE__*/defaultButtonChildren('Tab 2')
120
108
  }
121
109
  }, {
122
- type: "component",
123
- name: "hostless-tab-underline"
110
+ type: 'component',
111
+ name: 'hostless-tab-underline'
124
112
  }]
125
113
  }, {
126
- type: "vbox",
114
+ type: 'vbox',
127
115
  children: [{
128
- type: "component",
129
- name: "hostless-tab-content",
116
+ type: 'component',
117
+ name: 'hostless-tab-content',
130
118
  props: {
131
- tabKey: "tab1",
119
+ tabKey: 'tab1',
132
120
  children: [{
133
- type: "vbox",
134
- children: ["Some content for tab 1"]
121
+ type: 'vbox',
122
+ children: ['Some content for tab 1']
135
123
  }]
136
124
  }
137
125
  }, {
138
- type: "component",
139
- name: "hostless-tab-content",
126
+ type: 'component',
127
+ name: 'hostless-tab-content',
140
128
  props: {
141
- tabKey: "tab2",
129
+ tabKey: 'tab2',
142
130
  children: [{
143
- type: "vbox",
144
- children: ["Some content for tab 2"]
131
+ type: 'vbox',
132
+ children: ['Some content for tab 2']
145
133
  }]
146
134
  }
147
135
  }]
@@ -152,10 +140,10 @@ var TabsContainerMeta = {
152
140
  };
153
141
  function TabsContainer(_ref2) {
154
142
  var children = _ref2.children,
155
- initialKey = _ref2.initialKey,
156
- previewKey = _ref2.previewKey,
157
- _ref2$previewAll = _ref2.previewAll,
158
- previewAll = _ref2$previewAll === void 0 ? false : _ref2$previewAll;
143
+ initialKey = _ref2.initialKey,
144
+ previewKey = _ref2.previewKey,
145
+ _ref2$previewAll = _ref2.previewAll,
146
+ previewAll = _ref2$previewAll === void 0 ? false : _ref2$previewAll;
159
147
  var inEditor = !!host.usePlasmicCanvasContext();
160
148
  return React__default.createElement(TabsProvider, {
161
149
  initialKey: initialKey
@@ -165,103 +153,88 @@ function TabsContainer(_ref2) {
165
153
  previewKey: previewKey || initialKey
166
154
  }, children)));
167
155
  }
168
-
169
156
  function ensure(x) {
170
157
  if (!x) {
171
- throw new Error("unexpected nil");
158
+ throw new Error('unexpected nil');
172
159
  }
173
-
174
160
  return x;
175
161
  }
176
-
177
162
  function Helper(_ref3) {
178
163
  var children = _ref3.children,
179
- previewKey = _ref3.previewKey;
164
+ previewKey = _ref3.previewKey;
180
165
  var inEditor = host.usePlasmicCanvasContext();
181
-
182
166
  var _ensure = ensure(useTabsContext()),
183
- tabKey = _ensure.tabKey;
184
-
167
+ tabKey = _ensure.tabKey;
185
168
  var effectiveKey = inEditor ? previewKey || tabKey : tabKey;
186
169
  return React__default.createElement(host.DataProvider, {
187
- name: "currentTabKey",
170
+ name: 'currentTabKey',
188
171
  data: effectiveKey
189
172
  }, children);
190
173
  }
191
-
192
174
  var TabUnderlineMeta = {
193
- name: "hostless-tab-underline",
194
- displayName: "Tab Underline",
195
- importName: "TabUnderline",
175
+ name: 'hostless-tab-underline',
176
+ displayName: 'Tab Underline',
177
+ importName: 'TabUnderline',
196
178
  importPath: modulePath,
197
- props: {
198
- children: {
199
- type: "slot"
200
- }
201
- },
179
+ props: {},
202
180
  defaultStyles: {
203
- background: "#7777ff",
204
- height: "2px"
181
+ background: '#7777ff',
182
+ height: '2px'
205
183
  }
206
184
  };
207
185
  function TabUnderline(_ref4) {
208
186
  var _useTabsContext;
209
-
210
187
  var className = _ref4.className;
211
-
212
188
  var _ref5 = (_useTabsContext = useTabsContext()) != null ? _useTabsContext : {
213
- bbox: undefined
214
- },
215
- bbox = _ref5.bbox;
216
-
189
+ bbox: undefined
190
+ },
191
+ bbox = _ref5.bbox;
217
192
  return bbox ? React__default.createElement("div", {
218
193
  className: className,
219
194
  style: _extends({}, JSON.parse(JSON.stringify(bbox)), {
220
195
  top: undefined,
221
196
  bottom: 0,
222
- position: "absolute",
223
- transition: ".4s ease all"
197
+ position: 'absolute',
198
+ transition: '.4s ease all'
224
199
  })
225
200
  }) : null;
226
201
  }
227
202
  var TabButtonMeta = {
228
- name: "hostless-tab-button",
203
+ name: 'hostless-tab-button',
229
204
  isAttachment: true,
230
- displayName: "Tab Button",
231
- importName: "TabButton",
205
+ displayName: 'Tab Button',
206
+ importName: 'TabButton',
232
207
  importPath: modulePath,
233
208
  props: {
234
209
  tabKey: {
235
- type: "string",
236
- description: "The answer value selecting this choice sets"
210
+ type: 'string',
211
+ description: 'The answer value selecting this choice sets'
237
212
  },
238
213
  children: {
239
- type: "slot",
240
- defaultValue: /*#__PURE__*/defaultButtonChildren("Some tab")
214
+ type: 'slot',
215
+ defaultValue: /*#__PURE__*/defaultButtonChildren('Some tab')
241
216
  }
242
217
  },
243
218
  defaultStyles: {
244
- width: "hug"
219
+ width: 'hug'
245
220
  }
246
221
  };
247
222
  function TabButton(_ref6) {
248
223
  var className = _ref6.className,
249
- children = _ref6.children,
250
- tabKey = _ref6.tabKey;
224
+ children = _ref6.children,
225
+ tabKey = _ref6.tabKey;
251
226
  var tabsContext = useTabsContext();
252
227
  var ref = React.useRef(null);
253
-
254
228
  var _ref7 = tabsContext != null ? tabsContext : {
255
- tabKey: undefined,
256
- setTabKey: noop,
257
- bbox: undefined,
258
- setBbox: noop
259
- },
260
- activeKey = _ref7.tabKey,
261
- setTabKey = _ref7.setTabKey,
262
- bbox = _ref7.bbox,
263
- setBbox = _ref7.setBbox;
264
-
229
+ tabKey: undefined,
230
+ setTabKey: noop,
231
+ bbox: undefined,
232
+ setBbox: noop
233
+ },
234
+ activeKey = _ref7.tabKey,
235
+ setTabKey = _ref7.setTabKey,
236
+ bbox = _ref7.bbox,
237
+ setBbox = _ref7.setBbox;
265
238
  React.useEffect(function () {
266
239
  if (tabKey === activeKey) {
267
240
  setBbox({
@@ -281,23 +254,23 @@ function TabButton(_ref6) {
281
254
  }));
282
255
  }
283
256
  var TabContentMeta = {
284
- name: "hostless-tab-content",
257
+ name: 'hostless-tab-content',
285
258
  isAttachment: true,
286
- displayName: "Tab Content",
287
- importName: "TabContent",
259
+ displayName: 'Tab Content',
260
+ importName: 'TabContent',
288
261
  importPath: modulePath,
289
262
  props: {
290
263
  tabKey: {
291
- type: "string",
292
- description: "The answer value selecting this choice sets"
264
+ type: 'string',
265
+ description: 'The answer value selecting this choice sets'
293
266
  },
294
267
  children: {
295
- type: "slot",
268
+ type: 'slot',
296
269
  defaultValue: {
297
- type: "vbox",
270
+ type: 'vbox',
298
271
  children: {
299
- type: "text",
300
- value: "This is some tab content"
272
+ type: 'text',
273
+ value: 'This is some tab content'
301
274
  }
302
275
  }
303
276
  }
@@ -305,15 +278,13 @@ var TabContentMeta = {
305
278
  };
306
279
  function TabContent(_ref8) {
307
280
  var children = _ref8.children,
308
- tabKey = _ref8.tabKey;
281
+ tabKey = _ref8.tabKey;
309
282
  var tabsContext = useTabsContext();
310
283
  var previewAll = React.useContext(DebugContext);
311
-
312
284
  var _ref9 = tabsContext != null ? tabsContext : {
313
- tabKey: undefined
314
- },
315
- activeKey = _ref9.tabKey;
316
-
285
+ tabKey: undefined
286
+ },
287
+ activeKey = _ref9.tabKey;
317
288
  return React__default.createElement(React__default.Fragment, null, tabsContext === undefined || activeKey === tabKey || previewAll ? children : null);
318
289
  }
319
290
 
@@ -325,13 +296,9 @@ function registerAll(loader) {
325
296
  registerComponent(Component, defaultMeta);
326
297
  }
327
298
  };
328
-
329
299
  _registerComponent(TabsContainer, TabsContainerMeta);
330
-
331
300
  _registerComponent(TabUnderline, TabUnderlineMeta);
332
-
333
301
  _registerComponent(TabButton, TabButtonMeta);
334
-
335
302
  _registerComponent(TabContent, TabContentMeta);
336
303
  }
337
304
 
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.cjs.development.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import { DataProvider, usePlasmicCanvasContext,ComponentMeta } 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\n\nconst noop = ()=>{};\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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\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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={\"currentTabKey\"} data={effectiveKey}>\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 children: {\n type: \"slot\",\n },\n },\n defaultStyles: {\n background: \"#7777ff\",\n height: \"2px\",\n },\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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}\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,IAAMA,IAAI,GAAG,SAAPA,IAAO,KAAb;;AAEA,SAASC,qBAAT,CAA+BC,KAA/B;AACE,SAAO;AACLC,IAAAA,IAAI,EAAE,mBADD;AAELC,IAAAA,IAAI,EAAE,QAFD;AAGLC,IAAAA,KAAK,EAAE;AACLC,MAAAA,QAAQ,EAAE;AACRH,QAAAA,IAAI,EA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,WAAZ,CAAjB;AACD;AACF,GATD;;AAWAF,EAAAA,kBAAkB,CAAC/C,aAAD,EAAgBb,iBAAhB,CAAlB;;AACA4D,EAAAA,kBAAkB,CAAChC,YAAD,EAAeH,gBAAf,CAAlB;;AACAmC,EAAAA,kBAAkB,CAACpB,SAAD,EAAYF,aAAZ,CAAlB;;AACAsB,EAAAA,kBAAkB,CAACJ,UAAD,EAAaD,cAAb,CAAlB;AAED;;;;;;;;;;;;"}
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\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI,KAAW;AAErB,SAASC,qBAAqB,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;AAEzC,SAASC,WAAW;MAAGC,UAAU,QAAVA,UAAU;EAC/B,gBAA4BC,cAAQ,CAAqBD,UAAU,CAAC;IAA7DE,MAAM;IAAEC,SAAS;EACxB,iBAAwBF,cAAQ,CAC9BG,SAAS,CACV;IAFMC,IAAI;IAAEC,OAAO;EAGpB,OAAO;IACLJ,MAAM,EAANA,MAAM;IACNG,IAAI,EAAJA,IAAI;IACJF,SAAS,EAATA,SAAS;IACTG,OAAO,EAAPA;GACD;AACH;AAEA,6BAA6CC,QAAQ,CAACR,WAAW,CAAC;EAA3DS,YAAY;EAAEC,oBAAoB;AAEzC,SAASC,cAAc;EACrB,IAAMC,MAAM,GAAGF,oBAAoB,EAAE;EACrC,OAAO,WAAW,IAAIE,MAAM,GAAGA,MAAM,GAAGP,SAAS;AACnD;AACA,IAAMQ,UAAU,GAAG,2BAA2B;IAEjCC,iBAAiB,GAAqC;EACjEC,IAAI,EAAE,yBAAyB;EAC/BC,WAAW,EAAE,gBAAgB;EAC7BC,UAAU,EAAE,eAAe;EAC3BC,UAAU,EAAEL,UAAU;EACtBM,YAAY,EAAE,IAAI;EAClBC,aAAa,EAAE;IACbC,KAAK,EAAE,SAAS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2B,4DACGyB,WAAW,KAAKlD,SAAS,IAAIqD,SAAS,KAAKvD,MAAM,IAAIuB,UAAU,GAC5D9B,QAAQ,GACR,IAAI,CACP;AAEP;;SCjTgB4E,WAAW,CAACC,MAE3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkB,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,CAAC/C,aAAa,EAAEb,iBAAiB,CAAC;EACpD4D,kBAAkB,CAAChC,YAAY,EAAEH,gBAAgB,CAAC;EAClDmC,kBAAkB,CAACpB,SAAS,EAAEF,aAAa,CAAC;EAC5CsB,kBAAkB,CAACJ,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")),r=require("react"),o=e(r);function i(){return(i=Object.assign||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 p=r.createContext(!1);function c(e){var t=r.useState(e.initialKey),n=t[0],a=t[1],o=r.useState(void 0);return{tabKey:n,bbox:o[0],setTabKey:a,setBbox:o[1]}}var b=a(c),u=b[0],d=b[1];function y(){var e=d();return"setTabKey"in e?e:void 0}var h="@plasmicpkgs/plasmic-tabs",m={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",importPath:h,providesData:!0,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"},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,r=e.previewKey,i=e.previewAll,s=void 0!==i&&i,l=!!n.usePlasmicCanvasContext();return o.createElement(u,{initialKey:a},o.createElement(p.Provider,{value:l&&s},o.createElement(f,{previewKey:r||a},t)))}function f(e){var t=e.children,a=e.previewKey,r=n.usePlasmicCanvasContext(),i=function(e){if(!e)throw new Error("unexpected nil");return e}(y()).tabKey;return o.createElement(n.DataProvider,{name:"currentTabKey",data:r&&a||i},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:h,props:{children:{type:"slot"}},defaultStyles:{background:"#7777ff",height:"2px"}};function K(e){var t,n=e.className,a=(null!=(t=y())?t:{bbox:void 0}).bbox;return a?o.createElement("div",{className:n,style:i({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var T={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:h,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=y(),l=r.useRef(null),p=null!=i?i:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},c=p.tabKey,b=p.setTabKey,u=p.setBbox;return r.useEffect((function(){a===c&&u({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,u,JSON.stringify(p.bbox),a,c]),o.createElement("div",{className:t,ref:l},r.cloneElement(o.Children.toArray(n)[0],{isActive:a&&c&&c===a,onClick:function(){b(a)}}))}var C={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:h,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 w(e){var t=e.children,n=e.tabKey,a=y(),i=r.useContext(p);return o.createElement(o.Fragment,null,void 0===a||(null!=a?a:{tabKey:void 0}).tabKey===n||i?t:null)}exports.TabButton=g,exports.TabButtonMeta=T,exports.TabContent=w,exports.TabContentMeta=C,exports.TabUnderline=K,exports.TabUnderlineMeta=x,exports.TabsContainer=v,exports.TabsContainerMeta=m,exports.registerAll=function(e){var n=function(n,a){e?e.registerComponent(n,a):t(n,a)};n(v,m),n(K,x),n(g,T),n(w,C)};
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")),r=require("react"),i=e(r);function o(){return(o=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 p=r.createContext(!1);function c(e){var t=r.useState(e.initialKey),n=t[0],a=t[1],i=r.useState(void 0);return{tabKey:n,bbox:i[0],setTabKey:a,setBbox:i[1]}}var b=a(c),u=b[0],d=b[1];function y(){var e=d();return"setTabKey"in e?e:void 0}var m="@plasmicpkgs/plasmic-tabs",h={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",importPath:m,providesData:!0,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"},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,r=e.previewKey,o=e.previewAll,s=void 0!==o&&o,l=!!n.usePlasmicCanvasContext();return i.createElement(u,{initialKey:a},i.createElement(p.Provider,{value:l&&s},i.createElement(f,{previewKey:r||a},t)))}function f(e){var t=e.children,a=e.previewKey,r=n.usePlasmicCanvasContext(),o=function(e){if(!e)throw new Error("unexpected nil");return e}(y()).tabKey;return i.createElement(n.DataProvider,{name:"currentTabKey",data:r&&a||o},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:m,props:{},defaultStyles:{background:"#7777ff",height:"2px"}};function K(e){var t,n=e.className,a=(null!=(t=y())?t:{bbox:void 0}).bbox;return a?i.createElement("div",{className:n,style:o({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var T={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:m,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,o=y(),l=r.useRef(null),p=null!=o?o:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},c=p.tabKey,b=p.setTabKey,u=p.setBbox;return r.useEffect((function(){a===c&&u({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,u,JSON.stringify(p.bbox),a,c]),i.createElement("div",{className:t,ref:l},r.cloneElement(i.Children.toArray(n)[0],{isActive:a&&c&&c===a,onClick:function(){b(a)}}))}var C={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:m,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 w(e){var t=e.children,n=e.tabKey,a=y(),o=r.useContext(p);return i.createElement(i.Fragment,null,void 0===a||(null!=a?a:{tabKey:void 0}).tabKey===n||o?t:null)}exports.TabButton=g,exports.TabButtonMeta=T,exports.TabContent=w,exports.TabContentMeta=C,exports.TabUnderline=K,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(K,x),n(g,T),n(w,C)};
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 { DataProvider, usePlasmicCanvasContext,ComponentMeta } 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\n\nconst noop = ()=>{};\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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\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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={\"currentTabKey\"} data={effectiveKey}>\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 children: {\n type: \"slot\",\n },\n },\n defaultStyles: {\n background: \"#7777ff\",\n height: \"2px\",\n },\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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}\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","useState","initialKey","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"ieAcA,IAAMA,EAAO,aAEb,SAASC,EAAsBC,SACtB,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAEnC,SAASC,WACqBC,aADPC,YACdC,OAAQC,SACSH,gBACtBI,SAEK,CACLF,OAAAA,EACAG,UACAF,UAAAA,EACAG,cAIJ,MAA6CC,EAASR,GAA/CS,OAAcC,OAErB,SAASC,QACDC,EAASF,UACR,cAAeE,EAASA,OAASP,EAE1C,IAAMQ,EAAW,4BAEJC,EAAsD,CAC/DC,KAAM,0BACNC,YAAa,iBACbC,WAAY,gBACZC,WAAYL,EACZM,cAAa,EACbC,c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SAAazE,IAAAA,SAAUO,IAAAA,OAC/BmD,EAAc3C,IACde,EAAa4C,aAAWxE,UAG5BgC,qCACmBzB,IAAhBiD,UAHyBA,EAAAA,EAAe,CAAEnD,YAAQE,IAA/CF,SAGwCA,GAAUuB,EAClD9B,EACA,mOCjTkB2E,OAGpBC,EAAqB,SACzBC,EACAC,GAEIH,EACFA,EAAOI,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,IAIjCF,EAAmB7C,EAAeb,GAClC0D,EAAmB/B,EAAcH,GACjCkC,EAAmBnB,EAAWF,GAC9BqB,EAAmBH,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\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","useState","initialKey","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","_ref2$previewAll","inEditor","usePlasmicCanvasContext","React","Provider","Helper","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"qfAiBA,IAAMA,EAAO,aAEb,SAASC,EAAsBC,GAC7B,MAAO,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAEnC,SAASC,WACqBC,aADPC,YACdC,OAAQC,SACSH,gBACtBI,GAEF,MAAO,CACLF,OAAAA,EACAG,UACAF,UAAAA,EACAG,cAIJ,MAA6CC,EAASR,GAA/CS,OAAcC,OAErB,SAASC,IACP,IAAMC,EAASF,IACf,MAAO,cAAeE,EAASA,OAASP,EAE1C,IAAMQ,EAAa,4BAENC,EAAsD,CACjEC,KAAM,0BACNC,YAAa,iBACbC,WAAY,gBACZC,WAAYL,EACZM,cAAc,EACdC,cAAe,CACbC,MAAO,UACPC,QAAS,OAEX3B,MAAO,CACLO,WAAY,CACVT,KAAM,SACN8B,YAAa,oCACbC,aAAc,QAEhBC,WAAY,CACVhC,KAAM,SACN8B,YAAa,kDAEfG,WAAY,CACVjC,KAAM,UACN8B,YAAa,2DAEf3B,SAAU,CACRH,KAAM,OACN+B,aAAc,CACZ/B,KAAM,OACNG,SAAU,CACR,CACEH,KAAM,OACNG,SAAU,CACR,CACEH,KAAM,YACNsB,KAAM,sBACNpB,MAAO,CACLQ,OAAQ,OACRP,SAAUL,EAAsB,WAGpC,CACEE,KAAM,YACNsB,KAAM,sBACNpB,MAAO,CACLQ,OAAQ,OACRP,SAAUL,EAAsB,WAGpC,CACEE,KAAM,YACNsB,KAAM,4BAIZ,CACEtB,KAAM,OACNG,SAAU,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W/C,IAAAA,SAAUO,IAAAA,OACzCoD,EAAc5C,IACd6C,EAAMC,SAAuB,cACqBF,EAAAA,EAAe,CACrEpD,YAAQE,EACRD,UAAWd,EACXgB,UAAMD,EACNE,QAASjB,GAJKoE,IAARvD,OAAmBC,IAAAA,UAAiBG,IAAAA,QAc5C,OARAoD,aAAU,WACJxD,IAAWuD,GACbnD,EAAQ,CACNc,MAAOmC,EAAII,QAASC,YACpBC,KAAMN,EAAII,QAASG,eAGtB,CAACP,EAAII,QAASrD,EAASsC,KAAKE,YAbOzC,MAaUH,EAAQuD,IAEtD3B,uBAAKY,UAAWA,EAAWa,IAAKA,GAC7BQ,eAAajC,EAAMkC,SAASC,QAAQtE,GAAU,GAAoB,CACjEuE,SAAUhE,GAAUuD,GAAaA,IAAcvD,EAC/CiE,QAAS,WACPhE,EAAUD,WAYPkE,EAAiD,CAC5DtD,KAAM,uBACNsC,cAAc,EACdrC,YAAa,cACbC,WAAY,aACZC,WAAYL,EACZlB,MAAO,CACLQ,OAAQ,CACNV,KAAM,SACN8B,YAAa,+CAEf3B,SAAU,CACRH,KAAM,OACN+B,aAAc,CACZ/B,KAAM,OACNG,SAAU,CACRH,KAAM,OACNI,MAAO,yCAMDyE,SAAa1E,IAAAA,SAAUO,IAAAA,OAC/BoD,EAAc5C,IACde,EAAa6C,aAAWzE,GAE9B,OACEiC,qCACmB1B,IAAhBkD,UAHyBA,EAAAA,EAAe,CAAEpD,YAAQE,IAA/CF,SAGwCA,GAAUuB,EAClD9B,EACA,mOC9SkB4E,GAG1B,IAAMC,EAAqB,SACzBC,EACAC,GAEIH,EACFA,EAAOI,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,IAIjCF,EAAmB9C,EAAeb,GAClC2D,EAAmB/B,EAAcH,GACjCkC,EAAmBnB,EAAWF,GAC9BqB,EAAmBH,EAAYD"}
@@ -4,51 +4,42 @@ import constate from 'constate';
4
4
  import React, { useRef, useEffect, cloneElement, useContext, createContext, useState } from 'react';
5
5
 
6
6
  function _extends() {
7
- _extends = Object.assign || function (target) {
7
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
8
8
  for (var i = 1; i < arguments.length; i++) {
9
9
  var source = arguments[i];
10
-
11
10
  for (var key in source) {
12
11
  if (Object.prototype.hasOwnProperty.call(source, key)) {
13
12
  target[key] = source[key];
14
13
  }
15
14
  }
16
15
  }
17
-
18
16
  return target;
19
17
  };
20
-
21
18
  return _extends.apply(this, arguments);
22
19
  }
23
20
 
24
21
  var noop = function noop() {};
25
-
26
22
  function defaultButtonChildren(label) {
27
23
  return {
28
- type: "default-component",
29
- kind: "button",
24
+ type: 'default-component',
25
+ kind: 'button',
30
26
  props: {
31
27
  children: {
32
- type: "text",
28
+ type: 'text',
33
29
  value: label
34
30
  }
35
31
  }
36
32
  };
37
33
  }
38
-
39
34
  var DebugContext = /*#__PURE__*/createContext(false);
40
-
41
35
  function useTabsData(_ref) {
42
36
  var initialKey = _ref.initialKey;
43
-
44
37
  var _useState = useState(initialKey),
45
- tabKey = _useState[0],
46
- setTabKey = _useState[1];
47
-
38
+ tabKey = _useState[0],
39
+ setTabKey = _useState[1];
48
40
  var _useState2 = useState(undefined),
49
- bbox = _useState2[0],
50
- setBbox = _useState2[1];
51
-
41
+ bbox = _useState2[0],
42
+ setBbox = _useState2[1];
52
43
  return {
53
44
  tabKey: tabKey,
54
45
  bbox: bbox,
@@ -56,85 +47,82 @@ function useTabsData(_ref) {
56
47
  setBbox: setBbox
57
48
  };
58
49
  }
59
-
60
50
  var _constate = /*#__PURE__*/constate(useTabsData),
61
- TabsProvider = _constate[0],
62
- useTabsContextUnsafe = _constate[1];
63
-
51
+ TabsProvider = _constate[0],
52
+ useTabsContextUnsafe = _constate[1];
64
53
  function useTabsContext() {
65
54
  var result = useTabsContextUnsafe();
66
- return "setTabKey" in result ? result : undefined;
55
+ return 'setTabKey' in result ? result : undefined;
67
56
  }
68
-
69
- var modulePath = "@plasmicpkgs/plasmic-tabs";
57
+ var modulePath = '@plasmicpkgs/plasmic-tabs';
70
58
  var TabsContainerMeta = {
71
- name: "hostless-tabs-container",
72
- displayName: "Tabs Container",
73
- importName: "TabsContainer",
59
+ name: 'hostless-tabs-container',
60
+ displayName: 'Tabs Container',
61
+ importName: 'TabsContainer',
74
62
  importPath: modulePath,
75
63
  providesData: true,
76
64
  defaultStyles: {
77
- width: "stretch",
78
- padding: "8px"
65
+ width: 'stretch',
66
+ padding: '8px'
79
67
  },
80
68
  props: {
81
69
  initialKey: {
82
- type: "string",
83
- description: "Key of the initially selected tab",
84
- defaultValue: "tab1"
70
+ type: 'string',
71
+ description: 'Key of the initially selected tab',
72
+ defaultValue: 'tab1'
85
73
  },
86
74
  previewKey: {
87
- type: "string",
88
- description: "SShow this key while editing in Plasmic Studio"
75
+ type: 'string',
76
+ description: 'SShow this key while editing in Plasmic Studio'
89
77
  },
90
78
  previewAll: {
91
- type: "boolean",
92
- description: "Reveal all tab contents while editing in Plasmic Studio"
79
+ type: 'boolean',
80
+ description: 'Reveal all tab contents while editing in Plasmic Studio'
93
81
  },
94
82
  children: {
95
- type: "slot",
83
+ type: 'slot',
96
84
  defaultValue: {
97
- type: "vbox",
85
+ type: 'vbox',
98
86
  children: [{
99
- type: "hbox",
87
+ type: 'hbox',
100
88
  children: [{
101
- type: "component",
102
- name: "hostless-tab-button",
89
+ type: 'component',
90
+ name: 'hostless-tab-button',
103
91
  props: {
104
- tabKey: "tab1",
105
- children: /*#__PURE__*/defaultButtonChildren("Tab 1")
92
+ tabKey: 'tab1',
93
+ children: /*#__PURE__*/defaultButtonChildren('Tab 1')
106
94
  }
107
95
  }, {
108
- type: "component",
109
- name: "hostless-tab-button",
96
+ type: 'component',
97
+ name: 'hostless-tab-button',
110
98
  props: {
111
- tabKey: "tab2",
112
- children: /*#__PURE__*/defaultButtonChildren("Tab 2")
99
+ tabKey: 'tab2',
100
+ children: /*#__PURE__*/defaultButtonChildren('Tab 2')
113
101
  }
114
102
  }, {
115
- type: "component",
116
- name: "hostless-tab-underline"
103
+ type: 'component',
104
+ name: 'hostless-tab-underline'
117
105
  }]
118
106
  }, {
119
- type: "vbox",
107
+ type: 'vbox',
120
108
  children: [{
121
- type: "component",
122
- name: "hostless-tab-content",
109
+ type: 'component',
110
+ name: 'hostless-tab-content',
123
111
  props: {
124
- tabKey: "tab1",
112
+ tabKey: 'tab1',
125
113
  children: [{
126
- type: "vbox",
127
- children: ["Some content for tab 1"]
114
+ type: 'vbox',
115
+ children: ['Some content for tab 1']
128
116
  }]
129
117
  }
130
118
  }, {
131
- type: "component",
132
- name: "hostless-tab-content",
119
+ type: 'component',
120
+ name: 'hostless-tab-content',
133
121
  props: {
134
- tabKey: "tab2",
122
+ tabKey: 'tab2',
135
123
  children: [{
136
- type: "vbox",
137
- children: ["Some content for tab 2"]
124
+ type: 'vbox',
125
+ children: ['Some content for tab 2']
138
126
  }]
139
127
  }
140
128
  }]
@@ -145,10 +133,10 @@ var TabsContainerMeta = {
145
133
  };
146
134
  function TabsContainer(_ref2) {
147
135
  var children = _ref2.children,
148
- initialKey = _ref2.initialKey,
149
- previewKey = _ref2.previewKey,
150
- _ref2$previewAll = _ref2.previewAll,
151
- previewAll = _ref2$previewAll === void 0 ? false : _ref2$previewAll;
136
+ initialKey = _ref2.initialKey,
137
+ previewKey = _ref2.previewKey,
138
+ _ref2$previewAll = _ref2.previewAll,
139
+ previewAll = _ref2$previewAll === void 0 ? false : _ref2$previewAll;
152
140
  var inEditor = !!usePlasmicCanvasContext();
153
141
  return React.createElement(TabsProvider, {
154
142
  initialKey: initialKey
@@ -158,103 +146,88 @@ function TabsContainer(_ref2) {
158
146
  previewKey: previewKey || initialKey
159
147
  }, children)));
160
148
  }
161
-
162
149
  function ensure(x) {
163
150
  if (!x) {
164
- throw new Error("unexpected nil");
151
+ throw new Error('unexpected nil');
165
152
  }
166
-
167
153
  return x;
168
154
  }
169
-
170
155
  function Helper(_ref3) {
171
156
  var children = _ref3.children,
172
- previewKey = _ref3.previewKey;
157
+ previewKey = _ref3.previewKey;
173
158
  var inEditor = usePlasmicCanvasContext();
174
-
175
159
  var _ensure = ensure(useTabsContext()),
176
- tabKey = _ensure.tabKey;
177
-
160
+ tabKey = _ensure.tabKey;
178
161
  var effectiveKey = inEditor ? previewKey || tabKey : tabKey;
179
162
  return React.createElement(DataProvider, {
180
- name: "currentTabKey",
163
+ name: 'currentTabKey',
181
164
  data: effectiveKey
182
165
  }, children);
183
166
  }
184
-
185
167
  var TabUnderlineMeta = {
186
- name: "hostless-tab-underline",
187
- displayName: "Tab Underline",
188
- importName: "TabUnderline",
168
+ name: 'hostless-tab-underline',
169
+ displayName: 'Tab Underline',
170
+ importName: 'TabUnderline',
189
171
  importPath: modulePath,
190
- props: {
191
- children: {
192
- type: "slot"
193
- }
194
- },
172
+ props: {},
195
173
  defaultStyles: {
196
- background: "#7777ff",
197
- height: "2px"
174
+ background: '#7777ff',
175
+ height: '2px'
198
176
  }
199
177
  };
200
178
  function TabUnderline(_ref4) {
201
179
  var _useTabsContext;
202
-
203
180
  var className = _ref4.className;
204
-
205
181
  var _ref5 = (_useTabsContext = useTabsContext()) != null ? _useTabsContext : {
206
- bbox: undefined
207
- },
208
- bbox = _ref5.bbox;
209
-
182
+ bbox: undefined
183
+ },
184
+ bbox = _ref5.bbox;
210
185
  return bbox ? React.createElement("div", {
211
186
  className: className,
212
187
  style: _extends({}, JSON.parse(JSON.stringify(bbox)), {
213
188
  top: undefined,
214
189
  bottom: 0,
215
- position: "absolute",
216
- transition: ".4s ease all"
190
+ position: 'absolute',
191
+ transition: '.4s ease all'
217
192
  })
218
193
  }) : null;
219
194
  }
220
195
  var TabButtonMeta = {
221
- name: "hostless-tab-button",
196
+ name: 'hostless-tab-button',
222
197
  isAttachment: true,
223
- displayName: "Tab Button",
224
- importName: "TabButton",
198
+ displayName: 'Tab Button',
199
+ importName: 'TabButton',
225
200
  importPath: modulePath,
226
201
  props: {
227
202
  tabKey: {
228
- type: "string",
229
- description: "The answer value selecting this choice sets"
203
+ type: 'string',
204
+ description: 'The answer value selecting this choice sets'
230
205
  },
231
206
  children: {
232
- type: "slot",
233
- defaultValue: /*#__PURE__*/defaultButtonChildren("Some tab")
207
+ type: 'slot',
208
+ defaultValue: /*#__PURE__*/defaultButtonChildren('Some tab')
234
209
  }
235
210
  },
236
211
  defaultStyles: {
237
- width: "hug"
212
+ width: 'hug'
238
213
  }
239
214
  };
240
215
  function TabButton(_ref6) {
241
216
  var className = _ref6.className,
242
- children = _ref6.children,
243
- tabKey = _ref6.tabKey;
217
+ children = _ref6.children,
218
+ tabKey = _ref6.tabKey;
244
219
  var tabsContext = useTabsContext();
245
220
  var ref = useRef(null);
246
-
247
221
  var _ref7 = tabsContext != null ? tabsContext : {
248
- tabKey: undefined,
249
- setTabKey: noop,
250
- bbox: undefined,
251
- setBbox: noop
252
- },
253
- activeKey = _ref7.tabKey,
254
- setTabKey = _ref7.setTabKey,
255
- bbox = _ref7.bbox,
256
- setBbox = _ref7.setBbox;
257
-
222
+ tabKey: undefined,
223
+ setTabKey: noop,
224
+ bbox: undefined,
225
+ setBbox: noop
226
+ },
227
+ activeKey = _ref7.tabKey,
228
+ setTabKey = _ref7.setTabKey,
229
+ bbox = _ref7.bbox,
230
+ setBbox = _ref7.setBbox;
258
231
  useEffect(function () {
259
232
  if (tabKey === activeKey) {
260
233
  setBbox({
@@ -274,23 +247,23 @@ function TabButton(_ref6) {
274
247
  }));
275
248
  }
276
249
  var TabContentMeta = {
277
- name: "hostless-tab-content",
250
+ name: 'hostless-tab-content',
278
251
  isAttachment: true,
279
- displayName: "Tab Content",
280
- importName: "TabContent",
252
+ displayName: 'Tab Content',
253
+ importName: 'TabContent',
281
254
  importPath: modulePath,
282
255
  props: {
283
256
  tabKey: {
284
- type: "string",
285
- description: "The answer value selecting this choice sets"
257
+ type: 'string',
258
+ description: 'The answer value selecting this choice sets'
286
259
  },
287
260
  children: {
288
- type: "slot",
261
+ type: 'slot',
289
262
  defaultValue: {
290
- type: "vbox",
263
+ type: 'vbox',
291
264
  children: {
292
- type: "text",
293
- value: "This is some tab content"
265
+ type: 'text',
266
+ value: 'This is some tab content'
294
267
  }
295
268
  }
296
269
  }
@@ -298,15 +271,13 @@ var TabContentMeta = {
298
271
  };
299
272
  function TabContent(_ref8) {
300
273
  var children = _ref8.children,
301
- tabKey = _ref8.tabKey;
274
+ tabKey = _ref8.tabKey;
302
275
  var tabsContext = useTabsContext();
303
276
  var previewAll = useContext(DebugContext);
304
-
305
277
  var _ref9 = tabsContext != null ? tabsContext : {
306
- tabKey: undefined
307
- },
308
- activeKey = _ref9.tabKey;
309
-
278
+ tabKey: undefined
279
+ },
280
+ activeKey = _ref9.tabKey;
310
281
  return React.createElement(React.Fragment, null, tabsContext === undefined || activeKey === tabKey || previewAll ? children : null);
311
282
  }
312
283
 
@@ -318,13 +289,9 @@ function registerAll(loader) {
318
289
  registerComponent(Component, defaultMeta);
319
290
  }
320
291
  };
321
-
322
292
  _registerComponent(TabsContainer, TabsContainerMeta);
323
-
324
293
  _registerComponent(TabUnderline, TabUnderlineMeta);
325
-
326
294
  _registerComponent(TabButton, TabButtonMeta);
327
-
328
295
  _registerComponent(TabContent, TabContentMeta);
329
296
  }
330
297
 
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.esm.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import { DataProvider, usePlasmicCanvasContext,ComponentMeta } 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\n\nconst noop = ()=>{};\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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\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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={\"currentTabKey\"} data={effectiveKey}>\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 children: {\n type: \"slot\",\n },\n },\n defaultStyles: {\n background: \"#7777ff\",\n height: \"2px\",\n },\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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}\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcA,IAAMA,IAAI,GAAG,SAAPA,IAAO,KAAb;;AAEA,SAASC,qBAAT,CAA+BC,KAA/B;AACE,SAAO;AACLC,IAAAA,IAAI,EAAE,mBADD;AAELC,IAAAA,IAAI,EAAE,QAFD;AAGLC,IAAAA,KAAK,EAAE;AACLC,MAAAA,QAAQ,EAAE;AACRH,QAAAA,IAAI,EAAE,MADE;AAERI,QAAAA,KAAK,EAAEL;AAFC;AADL;AAHF,GAAP;AAUD;;AAQD,IAAMM,YAAY,gBAAGC,aAAa,CAAC,KAAD,CAAlC;;AAEA,SAASC,WAAT;MAAuBC,kBAAAA;;AACrB,kBAA4BC,QAAQ,CAAqBD,UAArB,CAApC;AAAA,MAAOE,MAAP;AAAA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AAkB,CAACJ,UAAD,EAAaD,cAAb,CAAlB;AAED;;;;"}
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\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\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\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 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 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}>\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 inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\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 { tabKey: activeKey, setTabKey, bbox, setBbox } = 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}\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};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\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","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI,KAAW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ACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAAC/C,aAAa,EAAEb,iBAAiB,CAAC;EACpD4D,kBAAkB,CAAChC,YAAY,EAAEH,gBAAgB,CAAC;EAClDmC,kBAAkB,CAACpB,SAAS,EAAEF,aAAa,CAAC;EAC5CsB,kBAAkB,CAACJ,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;"}
package/dist/tabs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ComponentMeta } from "@plasmicapp/host";
2
- import { ReactNode } from "react";
1
+ import { ComponentMeta } from '@plasmicapp/host';
2
+ import { ReactNode } from 'react';
3
3
  export interface TabsProviderProps {
4
4
  children?: ReactNode;
5
5
  initialKey?: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.3",
2
+ "version": "0.0.5",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -50,11 +50,11 @@
50
50
  ],
51
51
  "devDependencies": {
52
52
  "@size-limit/preset-small-lib": "^7.0.4",
53
- "@types/react": "^17.0.37",
54
- "@types/react-dom": "^17.0.11",
53
+ "@types/react": "^18.0.27",
54
+ "@types/react-dom": "^18.0.10",
55
55
  "husky": "^7.0.4",
56
- "react": "^17.0.2",
57
- "react-dom": "^17.0.2",
56
+ "react": "^18.2.0",
57
+ "react-dom": "^18.2.0",
58
58
  "size-limit": "^7.0.4",
59
59
  "tsdx": "^0.14.1",
60
60
  "tslib": "^2.3.1",
@@ -63,5 +63,5 @@
63
63
  "dependencies": {
64
64
  "constate": "^3.3.2"
65
65
  },
66
- "gitHead": "2d047d6d5f65d2c1f150eeff290663f58cab0e17"
66
+ "gitHead": "aa76cffecca904270776e3de48960defac03e4d5"
67
67
  }