@rspress-theme-anatole/plugin-container-syntax 0.0.4 → 0.1.31

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.
Files changed (3) hide show
  1. package/container.css +101 -22
  2. package/dist/index.js +157 -2
  3. package/package.json +2 -2
package/container.css CHANGED
@@ -129,28 +129,6 @@
129
129
  color: var(--rp-container-tip-text);
130
130
  }
131
131
 
132
-
133
-
134
-
135
- .rspress-doc .rspress-directive.tabs {
136
- border-color: var(--rp-container-tip-border);
137
- background-color: var(--rp-container-tip-bg);
138
- }
139
-
140
- .rspress-doc .rspress-directive.tabs .rspress-directive-title {
141
- color: var(--rp-container-tip-text);
142
- }
143
-
144
- .rspress-doc .rspress-directive.tabs code {
145
- color: var(--rp-container-tip-text);
146
- background-color: var(--rp-container-tip-code-bg);
147
- }
148
-
149
- .rspress-doc .rspress-directive.tabs a {
150
- color: var(--rp-container-tip-text);
151
- }
152
-
153
-
154
132
  .rspress-doc .rspress-directive.info {
155
133
  border-color: var(--rp-container-info-border);
156
134
  background-color: var(--rp-container-info-bg);
@@ -225,4 +203,105 @@
225
203
 
226
204
  .rspress-doc .rspress-directive.details a {
227
205
  color: var(--rp-container-details-link);
206
+ }
207
+
208
+
209
+
210
+
211
+
212
+
213
+ .rspress-doc .rspress-directive.tabs {
214
+ border-color: var(--rp-container-tip-border);
215
+ background-color: var(--rp-container-tip-bg);
216
+ padding: 0;
217
+ overflow: hidden;
218
+ }
219
+
220
+ .rspress-doc .rspress-directive.tabs .rspress-directive-title {
221
+ color: var(--rp-container-tip-text);
222
+ display: none;
223
+ /* Hide the default title for tabs */
224
+ }
225
+
226
+ .rspress-doc .rspress-directive.tabs .rspress-directive-content {
227
+ padding: 0;
228
+ }
229
+
230
+ /* Tabs navigation styling */
231
+ .rspress-doc .tabs-nav {
232
+ display: flex;
233
+ border-bottom: 1px solid var(--rp-container-tip-border);
234
+ background-color: rgba(7, 156, 112, 0.03);
235
+ padding: 0;
236
+ margin: 0;
237
+ }
238
+
239
+ .rspress-doc .tabs-nav-item {
240
+ padding: 8px 16px;
241
+ cursor: pointer;
242
+ margin: 0;
243
+ font-size: 14px;
244
+ font-weight: 500;
245
+ color: var(--rp-container-tip-text);
246
+ border-bottom: 2px solid transparent;
247
+ transition: all 0.2s ease;
248
+ }
249
+
250
+ .rspress-doc .tabs-nav-item.active {
251
+ border-bottom: 2px solid var(--rp-container-tip-text);
252
+ background-color: rgba(7, 156, 112, 0.08);
253
+ }
254
+
255
+ /* Tab content styling */
256
+ .rspress-doc .tabs-content {
257
+ padding: 16px 24px;
258
+ }
259
+
260
+ .rspress-doc .tabs-panel {
261
+ display: none;
262
+ }
263
+
264
+ .rspress-doc .tabs-panel.active {
265
+ display: block;
266
+ }
267
+
268
+ .rspress-doc .tabs-nav-item:hover {
269
+ background-color: rgba(7, 156, 112, 0.06);
270
+ cursor: pointer;
271
+ }
272
+
273
+
274
+
275
+ /* ...existing styles... */
276
+
277
+ .rspress-directive.tabs {
278
+ margin: 1rem 0;
279
+ }
280
+
281
+ .tabs-nav {
282
+ display: flex;
283
+ border-bottom: 1px solid #ddd;
284
+ margin-bottom: 1rem;
285
+ }
286
+
287
+ .tabs-nav-item {
288
+ padding: 0.5rem 1rem;
289
+ cursor: pointer;
290
+ border: 1px solid transparent;
291
+ border-bottom: none;
292
+ margin-bottom: -1px;
293
+ }
294
+
295
+ .tabs-nav-item.active {
296
+ background-color: #fff;
297
+ border-color: #ddd;
298
+ border-bottom-color: #fff;
299
+ }
300
+
301
+ .tabs-panel {
302
+ display: none;
303
+ }
304
+
305
+ .tabs-panel.active {
306
+ display: block;
228
307
  }
package/dist/index.js CHANGED
@@ -2,7 +2,14 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress-theme-anatole/shared";
4
4
  const DIRECTIVE_TYPES = [
5
- 'tabs',
5
+ 'tip',
6
+ 'note',
7
+ 'warning',
8
+ 'caution',
9
+ 'danger',
10
+ 'info',
11
+ 'details',
12
+ 'tabs'
6
13
  ];
7
14
  const REGEX_BEGIN = /^\s*:::\s*(\w+)\s*(.*)?/;
8
15
  const REGEX_END = /\s*:::$/;
@@ -14,10 +21,125 @@ const parseTitle = (rawTitle = '', isMDX = false) => {
14
21
  const matched = rawTitle?.match(isMDX ? TITLE_REGEX_IN_MDX : TITLE_REGEX_IN_MD);
15
22
  return trimTailingQuote(matched?.[1] || rawTitle);
16
23
  };
24
+
17
25
  const createContainer = (type, title, children) => {
18
26
  const isDetails = 'details' === type;
27
+ const isTabs = 'tabs' === type;
19
28
  const rootHName = isDetails ? 'details' : 'div';
20
29
  const titleHName = isDetails ? 'summary' : 'div';
30
+
31
+ // Handle tabs differently
32
+ if (isTabs) {
33
+ // Identify tab sections by finding paragraphs starting with ==
34
+ const tabSections = [];
35
+ let currentTabContent = null;
36
+ let currentTabTitle = '';
37
+
38
+ // Process children to find tab sections
39
+ for (let i = 0; i < children.length; i++) {
40
+ const child = children[i];
41
+
42
+ if (child.type === 'paragraph' &&
43
+ child.children &&
44
+ child.children[0] &&
45
+ child.children[0].type === 'text' &&
46
+ child.children[0].value.trim().startsWith('==')) {
47
+
48
+ // If we already have a tab section, push it
49
+ if (currentTabContent) {
50
+ tabSections.push({
51
+ title: currentTabTitle,
52
+ content: currentTabContent
53
+ });
54
+ }
55
+
56
+ // Start a new tab section
57
+ currentTabTitle = child.children[0].value.trim().substring(2).trim();
58
+ currentTabContent = [];
59
+ continue;
60
+ }
61
+
62
+ // Add content to the current tab section
63
+ if (currentTabContent !== null) {
64
+ currentTabContent.push(child);
65
+ }
66
+ }
67
+
68
+ // Add the last tab section if it exists
69
+ if (currentTabContent && currentTabContent.length) {
70
+ tabSections.push({
71
+ title: currentTabTitle,
72
+ content: currentTabContent
73
+ });
74
+ }
75
+
76
+ // Create tab navigation
77
+ const tabNavItems = tabSections.map((section, index) => ({
78
+ type: 'paragraph',
79
+ data: {
80
+ hName: 'div',
81
+ hProperties: {
82
+ class: `tabs-nav-item${index === 0 ? ' active' : ''}`,
83
+ 'data-tab-index': index
84
+ }
85
+ },
86
+ children: [
87
+ {
88
+ type: 'text',
89
+ value: section.title
90
+ }
91
+ ]
92
+ }));
93
+
94
+ // Create tab content panels
95
+ const tabContentPanels = tabSections.map((section, index) => ({
96
+ type: 'paragraph',
97
+ data: {
98
+ hName: 'div',
99
+ hProperties: {
100
+ class: `tabs-panel${index === 0 ? ' active' : ''}`,
101
+ id: `tab-${index}`
102
+ }
103
+ },
104
+ children: section.content
105
+ }));
106
+
107
+ // Create the tabs container
108
+ return {
109
+ type: 'containerDirective',
110
+ data: {
111
+ hName: rootHName,
112
+ hProperties: {
113
+ class: `rspress-directive ${type}`
114
+ }
115
+ },
116
+ children: [
117
+ // Navigation tabs
118
+ {
119
+ type: 'paragraph',
120
+ data: {
121
+ hName: 'div',
122
+ hProperties: {
123
+ class: 'tabs-nav'
124
+ }
125
+ },
126
+ children: tabNavItems
127
+ },
128
+ // Tab content container
129
+ {
130
+ type: 'paragraph',
131
+ data: {
132
+ hName: 'div',
133
+ hProperties: {
134
+ class: 'tabs-content'
135
+ }
136
+ },
137
+ children: tabContentPanels
138
+ },
139
+ ]
140
+ };
141
+ }
142
+
21
143
  return {
22
144
  type: 'containerDirective',
23
145
  data: {
@@ -55,6 +177,31 @@ const createContainer = (type, title, children) => {
55
177
  ]
56
178
  };
57
179
  };
180
+
181
+ export function initializeTabs() {
182
+ document.addEventListener('DOMContentLoaded', () => {
183
+ const tabContainers = document.querySelectorAll('.rspress-directive.tabs');
184
+
185
+ tabContainers.forEach(container => {
186
+ const navItems = container.querySelectorAll('.tabs-nav-item');
187
+ const panels = container.querySelectorAll('.tabs-panel');
188
+
189
+ navItems.forEach((navItem, index) => {
190
+ navItem.addEventListener('click', () => {
191
+ // Remove active class from all nav items and panels
192
+ navItems.forEach(item => item.classList.remove('active'));
193
+ panels.forEach(panel => panel.classList.remove('active'));
194
+
195
+ // Add active class to clicked nav item and corresponding panel
196
+ navItem.classList.add('active');
197
+ panels[index].classList.add('active');
198
+ });
199
+ });
200
+ });
201
+ });
202
+ }
203
+
204
+
58
205
  function transformer(tree) {
59
206
  let i = 0;
60
207
  try {
@@ -190,9 +337,15 @@ function transformer(tree) {
190
337
  throw e;
191
338
  }
192
339
  }
340
+
193
341
  const remarkPluginContainer = () => transformer;
194
342
  const src_dirname = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizePosixPath)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url)));
195
343
  function pluginContainerSyntax() {
344
+ // Initialize tabs when the plugin loads
345
+ if (typeof window !== 'undefined') {
346
+ initializeTabs();
347
+ }
348
+
196
349
  return {
197
350
  name: '@rspress-theme-anatole/plugin-container-syntax',
198
351
  markdown: {
@@ -200,7 +353,9 @@ function pluginContainerSyntax() {
200
353
  remarkPluginContainer
201
354
  ]
202
355
  },
203
- globalStyles: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join(src_dirname, '../container.css')
356
+ globalStyles: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join(src_dirname, '../container.css'),
357
+
204
358
  };
205
359
  }
360
+
206
361
  export { pluginContainerSyntax };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/plugin-container-syntax",
3
- "version": "0.0.4",
3
+ "version": "0.1.31",
4
4
  "license": "MIT",
5
5
  "sideEffects": [
6
6
  "*.css",
@@ -17,7 +17,7 @@
17
17
  "container.css"
18
18
  ],
19
19
  "dependencies": {
20
- "@rspress-theme-anatole/shared": "0.1.19"
20
+ "@rspress-theme-anatole/shared": "0.1.30"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@microsoft/api-extractor": "^7.49.2",