bitwrench 2.0.10 → 2.0.11

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/src/bitwrench.js CHANGED
@@ -1145,6 +1145,16 @@ bw.patch = function(id, content, attr) {
1145
1145
  if (attr) {
1146
1146
  // Patch an attribute
1147
1147
  el.setAttribute(attr, String(content));
1148
+ } else if (Array.isArray(content)) {
1149
+ // Patch with array of children (strings and/or TACOs)
1150
+ el.innerHTML = '';
1151
+ content.forEach(function(item) {
1152
+ if (typeof item === 'string' || typeof item === 'number') {
1153
+ el.appendChild(document.createTextNode(String(item)));
1154
+ } else if (item && item.t) {
1155
+ el.appendChild(bw.createDOM(item));
1156
+ }
1157
+ });
1148
1158
  } else if (typeof content === 'object' && content !== null && content.t) {
1149
1159
  // Patch with a TACO — replace children
1150
1160
  el.innerHTML = '';
@@ -2341,6 +2351,7 @@ bw.getURLParam = function(key, defaultValue) {
2341
2351
  * @see bw.makeTable
2342
2352
  */
2343
2353
  bw.htmlTable = function(data, opts = {}) {
2354
+ console.warn('bw.htmlTable() is deprecated. Use bw.makeTableFromArray() for TACO output or bw.makeTable() for object-array data.');
2344
2355
  if (bw.typeOf(data) !== "array" || data.length < 1) return "";
2345
2356
 
2346
2357
  const dopts = {
@@ -2440,6 +2451,7 @@ bw._attrsToStr = function(attrs) {
2440
2451
  * @see bw.makeTabs
2441
2452
  */
2442
2453
  bw.htmlTabs = function(tabData, opts = {}) {
2454
+ console.warn('bw.htmlTabs() is deprecated. Use bw.makeTabs() instead.');
2443
2455
  if (bw.typeOf(tabData) !== "array" || tabData.length < 1) return "";
2444
2456
 
2445
2457
  const dopts = {
@@ -2486,6 +2498,7 @@ bw.htmlTabs = function(tabData, opts = {}) {
2486
2498
  * @category Legacy (v1)
2487
2499
  */
2488
2500
  bw.selectTabContent = function(tabElement) {
2501
+ console.warn('bw.selectTabContent() is deprecated. Use bw.makeTabs() instead.');
2489
2502
  if (!bw._isBrowser || !tabElement) return;
2490
2503
 
2491
2504
  const container = tabElement.closest(".bw-tab-container");
@@ -3014,12 +3027,21 @@ bw.makeTable = function(config) {
3014
3027
  const {
3015
3028
  data = [],
3016
3029
  columns,
3017
- className = "table",
3030
+ className = '',
3031
+ striped = false,
3032
+ hover = false,
3018
3033
  sortable = true,
3019
3034
  onSort,
3020
3035
  sortColumn,
3021
3036
  sortDirection = 'asc'
3022
3037
  } = config;
3038
+
3039
+ // Build class list: always include bw-table, add striped/hover, append user className
3040
+ let cls = 'bw-table';
3041
+ if (striped) cls += ' bw-table-striped';
3042
+ if (hover) cls += ' bw-table-hover';
3043
+ if (className) cls += ' ' + className;
3044
+ cls = cls.trim();
3023
3045
 
3024
3046
  // Auto-detect columns if not provided
3025
3047
  const cols = columns || (data.length > 0
@@ -3107,11 +3129,176 @@ bw.makeTable = function(config) {
3107
3129
 
3108
3130
  return {
3109
3131
  t: 'table',
3110
- a: { class: className },
3132
+ a: { class: cls },
3111
3133
  c: [thead, tbody]
3112
3134
  };
3113
3135
  };
3114
3136
 
3137
+ /**
3138
+ * Create a table from a 2D array.
3139
+ *
3140
+ * Converts a 2D array into the object-array format that `bw.makeTable()`
3141
+ * expects, then delegates. By default, the first row is used as column
3142
+ * headers. All standard `makeTable` props (striped, hover, sortable,
3143
+ * columns, onSort, etc.) are passed through.
3144
+ *
3145
+ * @param {Object} config - Configuration object
3146
+ * @param {Array<Array>} config.data - 2D array of values
3147
+ * @param {boolean} [config.headerRow=true] - Treat first row as column headers
3148
+ * @param {boolean} [config.striped=false] - Striped rows
3149
+ * @param {boolean} [config.hover=false] - Hover highlight
3150
+ * @param {boolean} [config.sortable=true] - Enable sort
3151
+ * @param {Array<Object>} [config.columns] - Override auto-generated column defs
3152
+ * @param {string} [config.className=''] - Additional CSS classes
3153
+ * @param {Function} [config.onSort] - Sort callback
3154
+ * @param {string} [config.sortColumn] - Currently sorted column key
3155
+ * @param {string} [config.sortDirection='asc'] - Sort direction
3156
+ * @returns {Object} TACO object for table
3157
+ * @category Component Builders
3158
+ * @see bw.makeTable
3159
+ * @example
3160
+ * bw.makeTableFromArray({
3161
+ * data: [
3162
+ * ['Name', 'Role', 'Status'],
3163
+ * ['Alice', 'Engineer', 'Active'],
3164
+ * ['Bob', 'Designer', 'Away']
3165
+ * ],
3166
+ * striped: true,
3167
+ * hover: true
3168
+ * });
3169
+ */
3170
+ bw.makeTableFromArray = function(config) {
3171
+ const { data = [], headerRow = true, columns, ...rest } = config;
3172
+
3173
+ if (!Array.isArray(data) || data.length === 0) {
3174
+ return bw.makeTable({ data: [], columns: columns || [], ...rest });
3175
+ }
3176
+
3177
+ // Determine headers
3178
+ let headers;
3179
+ let rows;
3180
+ if (headerRow && data.length > 0) {
3181
+ headers = data[0].map(function(h) { return String(h); });
3182
+ rows = data.slice(1);
3183
+ } else {
3184
+ // Generate col0, col1, ... headers
3185
+ const width = data[0].length;
3186
+ headers = [];
3187
+ for (let i = 0; i < width; i++) {
3188
+ headers.push('col' + i);
3189
+ }
3190
+ rows = data;
3191
+ }
3192
+
3193
+ // Convert rows to object arrays
3194
+ const objData = rows.map(function(row) {
3195
+ const obj = {};
3196
+ headers.forEach(function(key, i) {
3197
+ obj[key] = row[i] !== undefined ? row[i] : '';
3198
+ });
3199
+ return obj;
3200
+ });
3201
+
3202
+ // Auto-generate column defs if not provided
3203
+ const cols = columns || headers.map(function(key) {
3204
+ return { key: key, label: key };
3205
+ });
3206
+
3207
+ return bw.makeTable({ data: objData, columns: cols, ...rest });
3208
+ };
3209
+
3210
+ /**
3211
+ * Create a vertical bar chart from data.
3212
+ *
3213
+ * Renders a pure-CSS bar chart using flexbox and percentage heights.
3214
+ * No canvas, SVG, or external charting library required.
3215
+ *
3216
+ * @param {Object} config - Chart configuration
3217
+ * @param {Array<Object>} config.data - Array of data objects
3218
+ * @param {string} [config.labelKey='label'] - Key for bar labels
3219
+ * @param {string} [config.valueKey='value'] - Key for bar values
3220
+ * @param {string} [config.title] - Chart title
3221
+ * @param {string} [config.color='#006666'] - Bar color (hex or CSS color)
3222
+ * @param {string} [config.height='200px'] - Height of the chart area
3223
+ * @param {Function} [config.formatValue] - Value label formatter: (value) => string
3224
+ * @param {boolean} [config.showValues=true] - Show value labels above bars
3225
+ * @param {boolean} [config.showLabels=true] - Show labels below bars
3226
+ * @param {string} [config.className=''] - Additional CSS classes
3227
+ * @returns {Object} TACO object
3228
+ * @category Component Builders
3229
+ * @example
3230
+ * bw.makeBarChart({
3231
+ * data: [
3232
+ * { label: 'Jan', value: 12400 },
3233
+ * { label: 'Feb', value: 15800 },
3234
+ * { label: 'Mar', value: 9200 }
3235
+ * ],
3236
+ * title: 'Monthly Revenue',
3237
+ * color: '#0077b6',
3238
+ * formatValue: (v) => '$' + (v / 1000).toFixed(1) + 'k'
3239
+ * });
3240
+ */
3241
+ bw.makeBarChart = function(config) {
3242
+ const {
3243
+ data = [],
3244
+ labelKey = 'label',
3245
+ valueKey = 'value',
3246
+ title,
3247
+ color = '#006666',
3248
+ height = '200px',
3249
+ formatValue,
3250
+ showValues = true,
3251
+ showLabels = true,
3252
+ className = ''
3253
+ } = config;
3254
+
3255
+ if (!Array.isArray(data) || data.length === 0) {
3256
+ return { t: 'div', a: { class: ('bw-bar-chart-container ' + className).trim() }, c: '' };
3257
+ }
3258
+
3259
+ const values = data.map(function(d) { return Number(d[valueKey]) || 0; });
3260
+ const maxVal = Math.max.apply(null, values);
3261
+
3262
+ const bars = data.map(function(d, i) {
3263
+ const val = values[i];
3264
+ const pct = maxVal > 0 ? (val / maxVal * 100) : 0;
3265
+ const formatted = formatValue ? formatValue(val) : String(val);
3266
+
3267
+ const children = [];
3268
+ if (showValues) {
3269
+ children.push({ t: 'div', a: { class: 'bw-bar-value' }, c: formatted });
3270
+ }
3271
+ children.push({
3272
+ t: 'div',
3273
+ a: {
3274
+ class: 'bw-bar',
3275
+ style: 'height:' + pct + '%;background:' + color + ';'
3276
+ }
3277
+ });
3278
+ if (showLabels) {
3279
+ children.push({ t: 'div', a: { class: 'bw-bar-label' }, c: String(d[labelKey] || '') });
3280
+ }
3281
+
3282
+ return { t: 'div', a: { class: 'bw-bar-group' }, c: children };
3283
+ });
3284
+
3285
+ const chartChildren = [];
3286
+ if (title) {
3287
+ chartChildren.push({ t: 'h3', a: { class: 'bw-bar-chart-title' }, c: title });
3288
+ }
3289
+ chartChildren.push({
3290
+ t: 'div',
3291
+ a: { class: 'bw-bar-chart', style: 'height:' + height + ';' },
3292
+ c: bars
3293
+ });
3294
+
3295
+ return {
3296
+ t: 'div',
3297
+ a: { class: ('bw-bar-chart-container ' + className).trim() },
3298
+ c: chartChildren
3299
+ };
3300
+ };
3301
+
3115
3302
  /**
3116
3303
  * Create a responsive data table with title and optional wrapper
3117
3304
  *
@@ -3122,7 +3309,9 @@ bw.makeTable = function(config) {
3122
3309
  * @param {string} [config.title] - Table title heading
3123
3310
  * @param {Array<Object>} config.data - Array of row objects
3124
3311
  * @param {Array<Object>} [config.columns] - Column definitions
3125
- * @param {string} [config.className="table table-striped table-hover"] - Table CSS class
3312
+ * @param {string} [config.className=''] - Additional CSS classes for the table
3313
+ * @param {boolean} [config.striped=true] - Add striped row styling
3314
+ * @param {boolean} [config.hover=true] - Add hover row highlighting
3126
3315
  * @param {boolean} [config.responsive=true] - Wrap table in responsive overflow div
3127
3316
  * @returns {Object} TACO object for table with wrapper
3128
3317
  * @example
@@ -3137,7 +3326,9 @@ bw.makeDataTable = function(config) {
3137
3326
  title,
3138
3327
  data,
3139
3328
  columns,
3140
- className = "table table-striped table-hover",
3329
+ className = '',
3330
+ striped = true,
3331
+ hover = true,
3141
3332
  responsive = true,
3142
3333
  ...tableConfig
3143
3334
  } = config;
@@ -3146,6 +3337,8 @@ bw.makeDataTable = function(config) {
3146
3337
  data,
3147
3338
  columns,
3148
3339
  className,
3340
+ striped,
3341
+ hover,
3149
3342
  ...tableConfig
3150
3343
  });
3151
3344
 
package/src/version.js CHANGED
@@ -3,14 +3,14 @@
3
3
  * DO NOT EDIT DIRECTLY - Use npm run generate-version
4
4
  */
5
5
 
6
- export const VERSION = '2.0.10';
6
+ export const VERSION = '2.0.11';
7
7
  export const VERSION_INFO = {
8
- version: '2.0.10',
8
+ version: '2.0.11',
9
9
  name: 'bitwrench',
10
10
  description: 'A library for javascript UI functions.',
11
11
  license: 'BSD-2-Clause',
12
- homepage: 'http://deftio.com/bitwrench',
12
+ homepage: 'https://deftio.github.com/bitwrench/pages',
13
13
  repository: 'git+https://github.com/deftio/bitwrench.git',
14
14
  author: 'manu a. chatterjee <deftio@deftio.com> (https://deftio.com/)',
15
- buildDate: '2026-03-07T03:14:16.606Z'
15
+ buildDate: '2026-03-07T11:05:08.522Z'
16
16
  };