bitwrench 2.0.7 → 2.0.9
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/dist/bitwrench-code-edit.cjs.js +1 -1
- package/dist/bitwrench-code-edit.es5.js +1 -1
- package/dist/bitwrench-code-edit.es5.min.js +3 -3
- package/dist/bitwrench-code-edit.esm.js +1 -1
- package/dist/bitwrench-code-edit.esm.min.js +2 -2
- package/dist/bitwrench-code-edit.umd.js +1 -1
- package/dist/bitwrench-code-edit.umd.min.js +3 -3
- package/dist/bitwrench.cjs.js +202 -22
- package/dist/bitwrench.cjs.min.js +6 -6
- package/dist/bitwrench.es5.js +227 -47
- package/dist/bitwrench.es5.min.js +4 -4
- package/dist/bitwrench.esm.js +202 -22
- package/dist/bitwrench.esm.min.js +6 -6
- package/dist/bitwrench.umd.js +202 -22
- package/dist/bitwrench.umd.min.js +6 -6
- package/package.json +9 -2
- package/src/bitwrench.js +199 -19
- package/src/version.js +3 -3
package/dist/bitwrench.es5.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! bitwrench v2.0.
|
|
1
|
+
/*! bitwrench v2.0.9 | BSD-2-Clause | http://deftio.com/bitwrench */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -203,14 +203,14 @@
|
|
|
203
203
|
*/
|
|
204
204
|
|
|
205
205
|
var VERSION_INFO = {
|
|
206
|
-
version: '2.0.
|
|
206
|
+
version: '2.0.9',
|
|
207
207
|
name: 'bitwrench',
|
|
208
208
|
description: 'A library for javascript UI functions.',
|
|
209
209
|
license: 'BSD-2-Clause',
|
|
210
210
|
homepage: 'http://deftio.com/bitwrench',
|
|
211
211
|
repository: 'git+https://github.com/deftio/bitwrench.git',
|
|
212
212
|
author: 'manu a. chatterjee <deftio@deftio.com> (https://deftio.com/)',
|
|
213
|
-
buildDate: '2026-03-
|
|
213
|
+
buildDate: '2026-03-07T02:56:20.305Z'
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
/**
|
|
@@ -3683,8 +3683,8 @@
|
|
|
3683
3683
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3684
3684
|
var children = props.children,
|
|
3685
3685
|
onsubmit = props.onsubmit,
|
|
3686
|
-
_props$
|
|
3687
|
-
className = _props$
|
|
3686
|
+
_props$className0 = props.className,
|
|
3687
|
+
className = _props$className0 === void 0 ? '' : _props$className0;
|
|
3688
3688
|
return {
|
|
3689
3689
|
t: 'form',
|
|
3690
3690
|
a: {
|
|
@@ -3784,8 +3784,8 @@
|
|
|
3784
3784
|
readonly = _props$readonly === void 0 ? false : _props$readonly,
|
|
3785
3785
|
_props$required = props.required,
|
|
3786
3786
|
required = _props$required === void 0 ? false : _props$required,
|
|
3787
|
-
_props$
|
|
3788
|
-
className = _props$
|
|
3787
|
+
_props$className1 = props.className,
|
|
3788
|
+
className = _props$className1 === void 0 ? '' : _props$className1,
|
|
3789
3789
|
style = props.style,
|
|
3790
3790
|
eventHandlers = _objectWithoutProperties(props, _excluded$1);
|
|
3791
3791
|
return {
|
|
@@ -3841,8 +3841,8 @@
|
|
|
3841
3841
|
readonly = _props$readonly2 === void 0 ? false : _props$readonly2,
|
|
3842
3842
|
_props$required2 = props.required,
|
|
3843
3843
|
required = _props$required2 === void 0 ? false : _props$required2,
|
|
3844
|
-
_props$
|
|
3845
|
-
className = _props$
|
|
3844
|
+
_props$className10 = props.className,
|
|
3845
|
+
className = _props$className10 === void 0 ? '' : _props$className10,
|
|
3846
3846
|
eventHandlers = _objectWithoutProperties(props, _excluded2);
|
|
3847
3847
|
return {
|
|
3848
3848
|
t: 'textarea',
|
|
@@ -3896,8 +3896,8 @@
|
|
|
3896
3896
|
disabled = _props$disabled4 === void 0 ? false : _props$disabled4,
|
|
3897
3897
|
_props$required3 = props.required,
|
|
3898
3898
|
required = _props$required3 === void 0 ? false : _props$required3,
|
|
3899
|
-
_props$
|
|
3900
|
-
className = _props$
|
|
3899
|
+
_props$className11 = props.className,
|
|
3900
|
+
className = _props$className11 === void 0 ? '' : _props$className11,
|
|
3901
3901
|
eventHandlers = _objectWithoutProperties(props, _excluded3);
|
|
3902
3902
|
return {
|
|
3903
3903
|
t: 'select',
|
|
@@ -4004,8 +4004,8 @@
|
|
|
4004
4004
|
direction = _props$direction === void 0 ? 'vertical' : _props$direction,
|
|
4005
4005
|
_props$gap = props.gap,
|
|
4006
4006
|
gap = _props$gap === void 0 ? 3 : _props$gap,
|
|
4007
|
-
_props$
|
|
4008
|
-
className = _props$
|
|
4007
|
+
_props$className12 = props.className,
|
|
4008
|
+
className = _props$className12 === void 0 ? '' : _props$className12;
|
|
4009
4009
|
return {
|
|
4010
4010
|
t: 'div',
|
|
4011
4011
|
a: {
|
|
@@ -4096,8 +4096,8 @@
|
|
|
4096
4096
|
overlay = _props$overlay === void 0 ? false : _props$overlay,
|
|
4097
4097
|
backgroundImage = props.backgroundImage,
|
|
4098
4098
|
actions = props.actions,
|
|
4099
|
-
_props$
|
|
4100
|
-
className = _props$
|
|
4099
|
+
_props$className13 = props.className,
|
|
4100
|
+
className = _props$className13 === void 0 ? '' : _props$className13;
|
|
4101
4101
|
var sizeClasses = {
|
|
4102
4102
|
sm: 'bw-py-3',
|
|
4103
4103
|
md: 'bw-py-4',
|
|
@@ -4186,8 +4186,8 @@
|
|
|
4186
4186
|
centered = _props$centered2 === void 0 ? true : _props$centered2,
|
|
4187
4187
|
_props$iconSize = props.iconSize,
|
|
4188
4188
|
iconSize = _props$iconSize === void 0 ? '3rem' : _props$iconSize,
|
|
4189
|
-
_props$
|
|
4190
|
-
className = _props$
|
|
4189
|
+
_props$className14 = props.className,
|
|
4190
|
+
className = _props$className14 === void 0 ? '' : _props$className14;
|
|
4191
4191
|
var colClass = "bw-col-md-".concat(12 / columns);
|
|
4192
4192
|
return {
|
|
4193
4193
|
t: 'div',
|
|
@@ -4267,8 +4267,8 @@
|
|
|
4267
4267
|
variant = _props$variant7 === void 0 ? 'light' : _props$variant7,
|
|
4268
4268
|
_props$centered3 = props.centered,
|
|
4269
4269
|
centered = _props$centered3 === void 0 ? true : _props$centered3,
|
|
4270
|
-
_props$
|
|
4271
|
-
className = _props$
|
|
4270
|
+
_props$className15 = props.className,
|
|
4271
|
+
className = _props$className15 === void 0 ? '' : _props$className15;
|
|
4272
4272
|
return {
|
|
4273
4273
|
t: 'section',
|
|
4274
4274
|
a: {
|
|
@@ -4337,8 +4337,8 @@
|
|
|
4337
4337
|
variant = _props$variant8 === void 0 ? 'default' : _props$variant8,
|
|
4338
4338
|
_props$spacing = props.spacing,
|
|
4339
4339
|
spacing = _props$spacing === void 0 ? 'md' : _props$spacing,
|
|
4340
|
-
_props$
|
|
4341
|
-
className = _props$
|
|
4340
|
+
_props$className16 = props.className,
|
|
4341
|
+
className = _props$className16 === void 0 ? '' : _props$className16;
|
|
4342
4342
|
var spacingClasses = {
|
|
4343
4343
|
sm: 'bw-py-3',
|
|
4344
4344
|
md: 'bw-py-4',
|
|
@@ -4921,6 +4921,26 @@
|
|
|
4921
4921
|
_subIdCounter: 0,
|
|
4922
4922
|
// monotonic ID for subscriptions
|
|
4923
4923
|
|
|
4924
|
+
// ── Node reference cache ──────────────────────────────────────────────
|
|
4925
|
+
// Fast O(1) lookup for elements by bw_id, id attribute, or bw_uuid.
|
|
4926
|
+
//
|
|
4927
|
+
// Populated by bw.createDOM() when elements have:
|
|
4928
|
+
// - data-bw-id attribute (user-declared addressable elements)
|
|
4929
|
+
// - id attribute (standard HTML id)
|
|
4930
|
+
// - bw_uuid (internal, for lifecycle-managed elements)
|
|
4931
|
+
//
|
|
4932
|
+
// Cleaned up by bw.cleanup() when elements are destroyed via bitwrench APIs.
|
|
4933
|
+
// On cache miss, falls back to querySelector/getElementById — never fails,
|
|
4934
|
+
// just slower. Stale entries (refs to detached nodes) are removed on miss
|
|
4935
|
+
// via parentNode === null check (IE11-safe, unlike el.isConnected).
|
|
4936
|
+
//
|
|
4937
|
+
// Elements created via bw.createDOM() also get el._bw_refs — a local map of
|
|
4938
|
+
// child bw_id → DOM node ref for fast parent→child access in o.render.
|
|
4939
|
+
// This is the bitwrench equivalent of React's compiled template "holes".
|
|
4940
|
+
//
|
|
4941
|
+
// Contract: if you remove elements outside of bitwrench APIs (raw el.remove()),
|
|
4942
|
+
// map entries may linger until the next lookup attempt cleans them.
|
|
4943
|
+
_nodeMap: {},
|
|
4924
4944
|
// Monkey patch for testing (same as v1)
|
|
4925
4945
|
__monkey_patch_is_nodejs__: {
|
|
4926
4946
|
_value: 'ignore',
|
|
@@ -5145,6 +5165,107 @@
|
|
|
5145
5165
|
return "".concat(tag).concat(timestamp, "_").concat(counter, "_").concat(random);
|
|
5146
5166
|
};
|
|
5147
5167
|
|
|
5168
|
+
/**
|
|
5169
|
+
* Look up a DOM element by ID string, using the node cache for O(1) access.
|
|
5170
|
+
*
|
|
5171
|
+
* Resolution order:
|
|
5172
|
+
* 1. Check `bw._nodeMap[id]` — if found and still attached (parentNode !== null), return it
|
|
5173
|
+
* 2. If cached ref is detached (parentNode === null), remove stale entry
|
|
5174
|
+
* 3. Fall back to `document.getElementById(id)` then `document.querySelector(...)`
|
|
5175
|
+
* 4. If fallback finds the element, cache it for next time
|
|
5176
|
+
* 5. If not found anywhere, return null
|
|
5177
|
+
*
|
|
5178
|
+
* Accepts a DOM element directly (pass-through) or a string identifier.
|
|
5179
|
+
* String identifiers are tried as: direct map key, getElementById,
|
|
5180
|
+
* querySelector (for CSS selectors starting with . or #), and
|
|
5181
|
+
* data-bw-id attribute selector.
|
|
5182
|
+
*
|
|
5183
|
+
* @param {string|Element} id - Element ID, CSS selector, data-bw-id value, or DOM element
|
|
5184
|
+
* @returns {Element|null} The DOM element, or null if not found
|
|
5185
|
+
* @category Internal
|
|
5186
|
+
*/
|
|
5187
|
+
bw._el = function (id) {
|
|
5188
|
+
// Pass-through for DOM elements
|
|
5189
|
+
if (typeof id !== 'string') return id || null;
|
|
5190
|
+
if (!id) return null;
|
|
5191
|
+
if (!bw._isBrowser) return null;
|
|
5192
|
+
|
|
5193
|
+
// 1. Check cache
|
|
5194
|
+
var cached = bw._nodeMap[id];
|
|
5195
|
+
if (cached) {
|
|
5196
|
+
// Verify not detached (parentNode check is IE11-safe)
|
|
5197
|
+
if (cached.parentNode !== null) {
|
|
5198
|
+
return cached;
|
|
5199
|
+
}
|
|
5200
|
+
// Stale — remove and fall through
|
|
5201
|
+
delete bw._nodeMap[id];
|
|
5202
|
+
}
|
|
5203
|
+
|
|
5204
|
+
// 2. DOM fallback: try getElementById first (fastest native lookup)
|
|
5205
|
+
var el = document.getElementById(id);
|
|
5206
|
+
|
|
5207
|
+
// 3. Try querySelector for CSS selectors (starts with # or .)
|
|
5208
|
+
if (!el && (id.charAt(0) === '#' || id.charAt(0) === '.')) {
|
|
5209
|
+
el = document.querySelector(id);
|
|
5210
|
+
}
|
|
5211
|
+
|
|
5212
|
+
// 4. Try data-bw-id attribute (for bw.uuid-generated IDs)
|
|
5213
|
+
if (!el) {
|
|
5214
|
+
el = document.querySelector('[data-bw-id="' + id + '"]');
|
|
5215
|
+
}
|
|
5216
|
+
|
|
5217
|
+
// 5. Cache the result for next time
|
|
5218
|
+
if (el) {
|
|
5219
|
+
bw._nodeMap[id] = el;
|
|
5220
|
+
}
|
|
5221
|
+
return el;
|
|
5222
|
+
};
|
|
5223
|
+
|
|
5224
|
+
/**
|
|
5225
|
+
* Register a DOM element in the node cache under one or more keys.
|
|
5226
|
+
*
|
|
5227
|
+
* Called internally by `bw.createDOM()`. Registers elements that have
|
|
5228
|
+
* id attributes, data-bw-id attributes, or both.
|
|
5229
|
+
*
|
|
5230
|
+
* @param {Element} el - DOM element to register
|
|
5231
|
+
* @param {string} [bwId] - data-bw-id value to register under
|
|
5232
|
+
* @category Internal
|
|
5233
|
+
*/
|
|
5234
|
+
bw._registerNode = function (el, bwId) {
|
|
5235
|
+
if (!el) return;
|
|
5236
|
+
// Register under data-bw-id
|
|
5237
|
+
if (bwId) {
|
|
5238
|
+
bw._nodeMap[bwId] = el;
|
|
5239
|
+
}
|
|
5240
|
+
// Register under id attribute
|
|
5241
|
+
var htmlId = el.getAttribute ? el.getAttribute('id') : null;
|
|
5242
|
+
if (htmlId) {
|
|
5243
|
+
bw._nodeMap[htmlId] = el;
|
|
5244
|
+
}
|
|
5245
|
+
};
|
|
5246
|
+
|
|
5247
|
+
/**
|
|
5248
|
+
* Remove a DOM element from the node cache.
|
|
5249
|
+
*
|
|
5250
|
+
* Called internally by `bw.cleanup()` when elements are destroyed
|
|
5251
|
+
* through bitwrench APIs.
|
|
5252
|
+
*
|
|
5253
|
+
* @param {Element} el - DOM element to deregister
|
|
5254
|
+
* @param {string} [bwId] - data-bw-id value to remove
|
|
5255
|
+
* @category Internal
|
|
5256
|
+
*/
|
|
5257
|
+
bw._deregisterNode = function (el, bwId) {
|
|
5258
|
+
// Remove data-bw-id entry
|
|
5259
|
+
if (bwId) {
|
|
5260
|
+
delete bw._nodeMap[bwId];
|
|
5261
|
+
}
|
|
5262
|
+
// Remove id attribute entry
|
|
5263
|
+
var htmlId = el && el.getAttribute ? el.getAttribute('id') : null;
|
|
5264
|
+
if (htmlId) {
|
|
5265
|
+
delete bw._nodeMap[htmlId];
|
|
5266
|
+
}
|
|
5267
|
+
};
|
|
5268
|
+
|
|
5148
5269
|
/**
|
|
5149
5270
|
* Escape HTML special characters to prevent XSS.
|
|
5150
5271
|
*
|
|
@@ -5381,26 +5502,66 @@
|
|
|
5381
5502
|
}
|
|
5382
5503
|
}
|
|
5383
5504
|
|
|
5384
|
-
// Add children
|
|
5505
|
+
// Add children, building _bw_refs for fast parent→child access.
|
|
5506
|
+
// Children with data-bw-id or id attributes get local refs on the parent,
|
|
5507
|
+
// so o.render functions can access them without any DOM lookup.
|
|
5385
5508
|
if (content != null) {
|
|
5386
5509
|
if (Array.isArray(content)) {
|
|
5387
5510
|
content.forEach(function (child) {
|
|
5388
5511
|
if (child != null) {
|
|
5389
|
-
|
|
5512
|
+
var childEl = bw.createDOM(child, options);
|
|
5513
|
+
el.appendChild(childEl);
|
|
5514
|
+
// Build local refs for addressable children
|
|
5515
|
+
var childBwId = child && child.a ? child.a['data-bw-id'] || child.a.id : null;
|
|
5516
|
+
if (childBwId) {
|
|
5517
|
+
if (!el._bw_refs) el._bw_refs = {};
|
|
5518
|
+
el._bw_refs[childBwId] = childEl;
|
|
5519
|
+
}
|
|
5520
|
+
// Bubble up grandchild refs (flatten one level)
|
|
5521
|
+
if (childEl._bw_refs) {
|
|
5522
|
+
if (!el._bw_refs) el._bw_refs = {};
|
|
5523
|
+
for (var rk in childEl._bw_refs) {
|
|
5524
|
+
if (Object.prototype.hasOwnProperty.call(childEl._bw_refs, rk)) {
|
|
5525
|
+
el._bw_refs[rk] = childEl._bw_refs[rk];
|
|
5526
|
+
}
|
|
5527
|
+
}
|
|
5528
|
+
}
|
|
5390
5529
|
}
|
|
5391
5530
|
});
|
|
5392
5531
|
} else if (_typeof(content) === 'object' && content.t) {
|
|
5393
|
-
|
|
5532
|
+
var childEl = bw.createDOM(content, options);
|
|
5533
|
+
el.appendChild(childEl);
|
|
5534
|
+
var childBwId = content.a ? content.a['data-bw-id'] || content.a.id : null;
|
|
5535
|
+
if (childBwId) {
|
|
5536
|
+
if (!el._bw_refs) el._bw_refs = {};
|
|
5537
|
+
el._bw_refs[childBwId] = childEl;
|
|
5538
|
+
}
|
|
5539
|
+
if (childEl._bw_refs) {
|
|
5540
|
+
if (!el._bw_refs) el._bw_refs = {};
|
|
5541
|
+
for (var rk in childEl._bw_refs) {
|
|
5542
|
+
if (Object.prototype.hasOwnProperty.call(childEl._bw_refs, rk)) {
|
|
5543
|
+
el._bw_refs[rk] = childEl._bw_refs[rk];
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5394
5547
|
} else {
|
|
5395
5548
|
el.textContent = String(content);
|
|
5396
5549
|
}
|
|
5397
5550
|
}
|
|
5398
5551
|
|
|
5552
|
+
// Register element in node cache if it has an id attribute
|
|
5553
|
+
if (attrs.id) {
|
|
5554
|
+
bw._registerNode(el, null);
|
|
5555
|
+
}
|
|
5556
|
+
|
|
5399
5557
|
// Handle lifecycle hooks and state
|
|
5400
5558
|
if (opts.mounted || opts.unmount || opts.render || opts.state) {
|
|
5401
5559
|
var id = attrs['data-bw-id'] || bw.uuid();
|
|
5402
5560
|
el.setAttribute('data-bw-id', id);
|
|
5403
5561
|
|
|
5562
|
+
// Register in node cache under data-bw-id
|
|
5563
|
+
bw._registerNode(el, id);
|
|
5564
|
+
|
|
5404
5565
|
// Store state
|
|
5405
5566
|
if (opts.state) {
|
|
5406
5567
|
el._bw_state = opts.state;
|
|
@@ -5442,6 +5603,9 @@
|
|
|
5442
5603
|
opts.unmount(el, el._bw_state || {});
|
|
5443
5604
|
});
|
|
5444
5605
|
}
|
|
5606
|
+
} else if (attrs['data-bw-id']) {
|
|
5607
|
+
// Element has explicit data-bw-id but no lifecycle hooks — still register it
|
|
5608
|
+
bw._registerNode(el, attrs['data-bw-id']);
|
|
5445
5609
|
}
|
|
5446
5610
|
return el;
|
|
5447
5611
|
};
|
|
@@ -5476,8 +5640,8 @@
|
|
|
5476
5640
|
throw new Error('bw.DOM requires a DOM environment (document/window). Use bw.html() instead.');
|
|
5477
5641
|
}
|
|
5478
5642
|
|
|
5479
|
-
// Get target element
|
|
5480
|
-
var targetEl =
|
|
5643
|
+
// Get target element (use cache-backed lookup)
|
|
5644
|
+
var targetEl = bw._el(target);
|
|
5481
5645
|
if (!targetEl) {
|
|
5482
5646
|
console.error('bw.DOM: Target element not found:', target);
|
|
5483
5647
|
return null;
|
|
@@ -5498,7 +5662,11 @@
|
|
|
5498
5662
|
// Restore the target's own state/render/subs after cleanup
|
|
5499
5663
|
if (savedState !== undefined) targetEl._bw_state = savedState;
|
|
5500
5664
|
if (savedRender) targetEl._bw_render = savedRender;
|
|
5501
|
-
if (savedBwId)
|
|
5665
|
+
if (savedBwId) {
|
|
5666
|
+
targetEl.setAttribute('data-bw-id', savedBwId);
|
|
5667
|
+
// Re-register mount point in node cache (cleanup deregistered it)
|
|
5668
|
+
bw._registerNode(targetEl, savedBwId);
|
|
5669
|
+
}
|
|
5502
5670
|
if (savedSubs) targetEl._bw_subs = savedSubs;
|
|
5503
5671
|
|
|
5504
5672
|
// Clear and mount new content
|
|
@@ -5749,6 +5917,9 @@
|
|
|
5749
5917
|
bw._unmountCallbacks["delete"](id);
|
|
5750
5918
|
}
|
|
5751
5919
|
|
|
5920
|
+
// Deregister from node cache
|
|
5921
|
+
bw._deregisterNode(el, id);
|
|
5922
|
+
|
|
5752
5923
|
// Clean up pub/sub subscriptions tied to this element
|
|
5753
5924
|
if (el._bw_subs) {
|
|
5754
5925
|
el._bw_subs.forEach(function (unsub) {
|
|
@@ -5757,9 +5928,10 @@
|
|
|
5757
5928
|
delete el._bw_subs;
|
|
5758
5929
|
}
|
|
5759
5930
|
|
|
5760
|
-
// Clean up state and
|
|
5931
|
+
// Clean up state, render, and local refs
|
|
5761
5932
|
delete el._bw_state;
|
|
5762
5933
|
delete el._bw_render;
|
|
5934
|
+
delete el._bw_refs;
|
|
5763
5935
|
});
|
|
5764
5936
|
|
|
5765
5937
|
// Check element itself
|
|
@@ -5770,6 +5942,10 @@
|
|
|
5770
5942
|
callback();
|
|
5771
5943
|
bw._unmountCallbacks["delete"](id);
|
|
5772
5944
|
}
|
|
5945
|
+
|
|
5946
|
+
// Deregister from node cache
|
|
5947
|
+
bw._deregisterNode(element, id);
|
|
5948
|
+
|
|
5773
5949
|
// Clean up pub/sub subscriptions tied to element itself
|
|
5774
5950
|
if (element._bw_subs) {
|
|
5775
5951
|
element._bw_subs.forEach(function (unsub) {
|
|
@@ -5779,6 +5955,7 @@
|
|
|
5779
5955
|
}
|
|
5780
5956
|
delete element._bw_state;
|
|
5781
5957
|
delete element._bw_render;
|
|
5958
|
+
delete element._bw_refs;
|
|
5782
5959
|
}
|
|
5783
5960
|
};
|
|
5784
5961
|
|
|
@@ -5793,7 +5970,7 @@
|
|
|
5793
5970
|
* Calls `el._bw_render(el, state)` and emits `bw:statechange` so other
|
|
5794
5971
|
* components can react without tight coupling.
|
|
5795
5972
|
*
|
|
5796
|
-
* @param {string|Element} target - CSS selector or DOM element
|
|
5973
|
+
* @param {string|Element} target - Element ID, data-bw-id, CSS selector, or DOM element
|
|
5797
5974
|
* @returns {Element|null} The element, or null if not found / no render function
|
|
5798
5975
|
* @category State Management
|
|
5799
5976
|
* @see bw.patch
|
|
@@ -5803,7 +5980,7 @@
|
|
|
5803
5980
|
* bw.update(el); // re-renders, emits bw:statechange
|
|
5804
5981
|
*/
|
|
5805
5982
|
bw.update = function (target) {
|
|
5806
|
-
var el =
|
|
5983
|
+
var el = bw._el(target);
|
|
5807
5984
|
if (el && el._bw_render) {
|
|
5808
5985
|
el._bw_render(el, el._bw_state || {});
|
|
5809
5986
|
bw.emit(el, 'statechange', el._bw_state);
|
|
@@ -5818,7 +5995,8 @@
|
|
|
5818
5995
|
* Use `bw.patch()` for lightweight value updates (scores, labels, counters)
|
|
5819
5996
|
* and `bw.update()` for full structural re-renders.
|
|
5820
5997
|
*
|
|
5821
|
-
* @param {string|Element} id - Element ID
|
|
5998
|
+
* @param {string|Element} id - Element ID, data-bw-id, CSS selector, or DOM element.
|
|
5999
|
+
* Uses node cache for O(1) lookup; falls back to DOM query on cache miss.
|
|
5822
6000
|
* @param {string|Object} content - New text content, or TACO object to replace children
|
|
5823
6001
|
* @param {string} [attr] - If provided, sets this attribute instead of content
|
|
5824
6002
|
* @returns {Element|null} The patched element, or null if not found
|
|
@@ -5831,7 +6009,7 @@
|
|
|
5831
6009
|
* bw.patch('info', { t: 'em', c: 'new' }); // replace children with TACO
|
|
5832
6010
|
*/
|
|
5833
6011
|
bw.patch = function (id, content, attr) {
|
|
5834
|
-
var el =
|
|
6012
|
+
var el = bw._el(id);
|
|
5835
6013
|
if (!el) return null;
|
|
5836
6014
|
if (attr) {
|
|
5837
6015
|
// Patch an attribute
|
|
@@ -5881,7 +6059,8 @@
|
|
|
5881
6059
|
* bubble by default so ancestor elements can listen. Use with `bw.on()` for
|
|
5882
6060
|
* DOM-scoped communication between components.
|
|
5883
6061
|
*
|
|
5884
|
-
* @param {string|Element} target - CSS selector or DOM element
|
|
6062
|
+
* @param {string|Element} target - Element ID, data-bw-id, CSS selector, or DOM element.
|
|
6063
|
+
* Uses node cache for O(1) lookup; falls back to DOM query on cache miss.
|
|
5885
6064
|
* @param {string} eventName - Event name (will be prefixed with 'bw:')
|
|
5886
6065
|
* @param {*} [detail] - Data to pass with the event
|
|
5887
6066
|
* @category Events (DOM)
|
|
@@ -5891,7 +6070,7 @@
|
|
|
5891
6070
|
* // Dispatches CustomEvent 'bw:statechange' on the element
|
|
5892
6071
|
*/
|
|
5893
6072
|
bw.emit = function (target, eventName, detail) {
|
|
5894
|
-
var el =
|
|
6073
|
+
var el = bw._el(target);
|
|
5895
6074
|
if (el) {
|
|
5896
6075
|
el.dispatchEvent(new CustomEvent('bw:' + eventName, {
|
|
5897
6076
|
bubbles: true,
|
|
@@ -5907,7 +6086,8 @@
|
|
|
5907
6086
|
* is the first argument so you don't need to destructure `e.detail`.
|
|
5908
6087
|
* Events bubble, so you can listen on an ancestor element.
|
|
5909
6088
|
*
|
|
5910
|
-
* @param {string|Element} target - CSS selector or DOM element
|
|
6089
|
+
* @param {string|Element} target - Element ID, data-bw-id, CSS selector, or DOM element.
|
|
6090
|
+
* Uses node cache for O(1) lookup; falls back to DOM query on cache miss.
|
|
5911
6091
|
* @param {string} eventName - Event name (will be prefixed with 'bw:')
|
|
5912
6092
|
* @param {Function} handler - Called with (detail, event)
|
|
5913
6093
|
* @returns {Element|null} The element (for chaining), or null if not found
|
|
@@ -5919,7 +6099,7 @@
|
|
|
5919
6099
|
* });
|
|
5920
6100
|
*/
|
|
5921
6101
|
bw.on = function (target, eventName, handler) {
|
|
5922
|
-
var el =
|
|
6102
|
+
var el = bw._el(target);
|
|
5923
6103
|
if (el) {
|
|
5924
6104
|
el.addEventListener('bw:' + eventName, function (e) {
|
|
5925
6105
|
handler(e.detail, e);
|
|
@@ -6094,9 +6274,9 @@
|
|
|
6094
6274
|
value = _ref8[1];
|
|
6095
6275
|
return value != null;
|
|
6096
6276
|
}).map(function (_ref9) {
|
|
6097
|
-
var
|
|
6098
|
-
prop =
|
|
6099
|
-
value =
|
|
6277
|
+
var _ref0 = _slicedToArray(_ref9, 2),
|
|
6278
|
+
prop = _ref0[0],
|
|
6279
|
+
value = _ref0[1];
|
|
6100
6280
|
// Convert camelCase to kebab-case
|
|
6101
6281
|
var kebabProp = prop.replace(/[A-Z]/g, function (m) {
|
|
6102
6282
|
return '-' + m.toLowerCase();
|
|
@@ -8378,10 +8558,10 @@
|
|
|
8378
8558
|
};
|
|
8379
8559
|
|
|
8380
8560
|
// Register all make functions
|
|
8381
|
-
Object.entries(components).forEach(function (
|
|
8382
|
-
var
|
|
8383
|
-
name =
|
|
8384
|
-
fn =
|
|
8561
|
+
Object.entries(components).forEach(function (_ref1) {
|
|
8562
|
+
var _ref10 = _slicedToArray(_ref1, 2),
|
|
8563
|
+
name = _ref10[0],
|
|
8564
|
+
fn = _ref10[1];
|
|
8385
8565
|
if (name.startsWith('make')) {
|
|
8386
8566
|
bw[name] = fn;
|
|
8387
8567
|
}
|
|
@@ -8391,10 +8571,10 @@
|
|
|
8391
8571
|
bw._componentHandles = componentHandles || {};
|
|
8392
8572
|
|
|
8393
8573
|
// Create functions that return handles
|
|
8394
|
-
Object.entries(components).forEach(function (
|
|
8395
|
-
var
|
|
8396
|
-
name =
|
|
8397
|
-
fn =
|
|
8574
|
+
Object.entries(components).forEach(function (_ref11) {
|
|
8575
|
+
var _ref12 = _slicedToArray(_ref11, 2),
|
|
8576
|
+
name = _ref12[0],
|
|
8577
|
+
fn = _ref12[1];
|
|
8398
8578
|
if (name.startsWith('make')) {
|
|
8399
8579
|
var componentType = name.substring(4).toLowerCase(); // Remove 'make' prefix
|
|
8400
8580
|
var createName = 'create' + name.substring(4); // createCard, createTable, etc.
|