@sociallane/elements 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sociallane/elements",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Elementor widgets and elements with Tailwind CSS for SocialLane. WordPress plugin.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -77,7 +77,7 @@ function prepare_card_hover_reveal_view( array $settings, string $widget_id ): a
77
77
  $aspect_map = [ '16/9' => 'aspect-video', '4/3' => 'aspect-[4/3]', '3/2' => 'aspect-[3/2]', '1/1' => 'aspect-square', '3/4' => 'aspect-[3/4]' ];
78
78
  $aspect_class = $aspect_map[ $aspect_ratio ] ?? 'aspect-video';
79
79
  $columns = sociallane_validate_option( $settings['columns'] ?? '3', [ '2', '3' ], '3' );
80
- $grid_class = sociallane_grid_cols( $columns, [ '2' => 'grid-cols-1 sm:grid-cols-2', '3' => 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3' ] );
80
+ $grid_class = sociallane_grid_cols( $columns, [ '2' => 'grid-cols-1 sm:grid-cols-2', '3' => 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3' ] );
81
81
 
82
82
  $animation = sociallane_animation_view_data( $settings, [ 'headline' => true, 'stagger' => true ] );
83
83
 
@@ -23,7 +23,12 @@ function prepare_grid_components_view( array $settings, string $widget_id ): arr
23
23
  $fields = sociallane_extract_fields( $settings, [ 'headline' => [] ] );
24
24
  $headline_tag = sociallane_validate_heading_tag( $settings, 'headline_tag', 'h2' );
25
25
  $columns = sociallane_validate_option( $settings['columns'] ?? '4', [ '2', '3', '4' ], '4' );
26
- $grid_class = sociallane_grid_cols( $columns );
26
+ $grid_class = sociallane_grid_cols(
27
+ $columns,
28
+ [
29
+ '3' => 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3',
30
+ ]
31
+ );
27
32
  $placeholder_src = \Elementor\Utils::get_placeholder_image_src();
28
33
 
29
34
  $components = sociallane_process_repeater( $settings['components'] ?? [], function ( $item ) use ( $placeholder_src ) {
@@ -9,7 +9,7 @@
9
9
  * Add: copies selected widget folders into an existing plugin, updates widgets.json, runs npm install.
10
10
  */
11
11
 
12
- import { cpSync, existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs';
12
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'fs';
13
13
  import { spawnSync } from 'child_process';
14
14
  import path from 'path';
15
15
  import { fileURLToPath } from 'url';
@@ -41,7 +41,36 @@ function resolvePluginDir() {
41
41
  return path.join(cwd, 'wp-content', 'plugins', 'sociallane-elements');
42
42
  }
43
43
 
44
- function addWidgets(slugs) {
44
+ function updateWidgetsJson(pluginDir, slugsToAdd, replaceAll = false) {
45
+ const widgetsJsonPath = path.join(pluginDir, 'widgets.json');
46
+ let existing = [];
47
+
48
+ if (!replaceAll && existsSync(widgetsJsonPath)) {
49
+ try {
50
+ const raw = readFileSync(widgetsJsonPath, 'utf8');
51
+ const parsed = JSON.parse(raw);
52
+ if (Array.isArray(parsed?.widgets)) {
53
+ existing = parsed.widgets.filter((slug) => typeof slug === 'string');
54
+ }
55
+ } catch (err) {
56
+ console.warn('Could not parse widgets.json, recreating it:', err.message);
57
+ }
58
+ }
59
+
60
+ const merged = [...existing];
61
+ const existingSet = new Set(existing);
62
+ for (const slug of slugsToAdd) {
63
+ if (!existingSet.has(slug)) {
64
+ merged.push(slug);
65
+ existingSet.add(slug);
66
+ }
67
+ }
68
+
69
+ writeFileSync(widgetsJsonPath, JSON.stringify({ widgets: merged }, null, 2) + '\n');
70
+ }
71
+
72
+ function addWidgets(slugs, options = {}) {
73
+ const replaceAll = options.replaceAll === true;
45
74
  const pluginDir = resolvePluginDir();
46
75
  const widgetsDest = path.join(pluginDir, 'packages', 'widgets');
47
76
 
@@ -84,17 +113,16 @@ function addWidgets(slugs) {
84
113
  console.log('Added:', slug);
85
114
  }
86
115
 
87
- console.log('Updating widgets.json and building...');
88
- const result = spawnSync('node', [path.join(pluginDir, 'scripts', 'sync-widgets.js')], {
89
- cwd: pluginDir,
90
- stdio: 'inherit',
91
- });
92
- if (result.status !== 0) {
93
- process.exit(result.status || 1);
94
- }
116
+ updateWidgetsJson(pluginDir, slugs, replaceAll);
117
+ console.log('Updated widgets.json and installing dependencies...');
118
+
95
119
  const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
96
120
  const installResult = spawnSync(npmCmd, ['install'], {
97
121
  cwd: pluginDir,
122
+ env: {
123
+ ...process.env,
124
+ SOCIALLANE_SKIP_SYNC_WIDGETS: '1',
125
+ },
98
126
  stdio: 'inherit',
99
127
  shell: true,
100
128
  });
@@ -213,13 +241,15 @@ function main() {
213
241
  const installArgs = args.filter((a) => a !== '--minimal');
214
242
 
215
243
  if (installArgs[0] === 'add') {
216
- const slugs = installArgs.slice(1).filter(Boolean);
244
+ const addArgs = installArgs.slice(1).filter(Boolean);
245
+ const replaceAll = addArgs.includes('--only');
246
+ const slugs = addArgs.filter((arg) => arg !== '--only');
217
247
  if (slugs.length === 0) {
218
- console.error('Usage: npx @sociallane/elements add <slug> [slug...]');
219
- console.error('Example: npx @sociallane/elements add hero-split faq content-block');
248
+ console.error('Usage: npx @sociallane/elements add [--only] <slug> [slug...]');
249
+ console.error('Example: npx @sociallane/elements add --only hero-split faq-stacked content-block');
220
250
  process.exit(1);
221
251
  }
222
- addWidgets(slugs);
252
+ addWidgets(slugs, { replaceAll });
223
253
  } else {
224
254
  install(installArgs[0], minimal);
225
255
  }
@@ -54,14 +54,17 @@ function ensureLocalCliShim() {
54
54
 
55
55
  ensureLocalCliShim();
56
56
 
57
- // Run sync-widgets
58
- console.log('Running sync-widgets...');
59
- const syncResult = spawnSync('node', [path.join(__dirname, 'sync-widgets.js')], {
60
- cwd: pluginRoot,
61
- stdio: 'inherit',
62
- });
63
- if (syncResult.status !== 0) {
64
- process.exit(syncResult.status || 1);
57
+ const skipSyncWidgets = process.env.SOCIALLANE_SKIP_SYNC_WIDGETS === '1';
58
+ if (!skipSyncWidgets) {
59
+ // Run sync-widgets
60
+ console.log('Running sync-widgets...');
61
+ const syncResult = spawnSync('node', [path.join(__dirname, 'sync-widgets.js')], {
62
+ cwd: pluginRoot,
63
+ stdio: 'inherit',
64
+ });
65
+ if (syncResult.status !== 0) {
66
+ process.exit(syncResult.status || 1);
67
+ }
65
68
  }
66
69
 
67
70
  // Run build
@@ -108,7 +108,7 @@ function prepare_card_hover_reveal_view( array $settings, string $widget_id ): a
108
108
  $columns = in_array( $settings['columns'] ?? '3', [ '2', '3' ], true ) ? $settings['columns'] : '3';
109
109
  $grid_class = $columns === '2'
110
110
  ? 'grid-cols-1 sm:grid-cols-2'
111
- : 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3';
111
+ : 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3';
112
112
 
113
113
  $animation = sociallane_animation_view_data( $settings, [ 'headline' => true, 'stagger' => true ] );
114
114
 
@@ -30,7 +30,7 @@ function prepare_grid_components_view( array $settings, string $widget_id ): arr
30
30
  $columns = in_array( $settings['columns'] ?? '4', [ '2', '3', '4' ], true ) ? $settings['columns'] : '4';
31
31
  $grid_class = [
32
32
  '2' => 'grid-cols-1 sm:grid-cols-2',
33
- '3' => 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
33
+ '3' => 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3',
34
34
  '4' => 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
35
35
  ][ $columns ];
36
36