@wcstack/broadcast 4.18.0 → 4.20.0
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/auto.min.js +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={triggerAttribute:"data-broadcast-target",tagNames:{broadcast:"wcs-broadcast"}};var t="@wcstack/broadcast",n="4.
|
|
1
|
+
const e={triggerAttribute:"data-broadcast-target",tagNames:{broadcast:"wcs-broadcast"}};var t="@wcstack/broadcast",n="4.20.0";const s="capability-missing",r="invalid-argument",a="broadcast-error";class o extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"message",event:"wcs-broadcast:message",semantics:"event"},{name:"error",event:"wcs-broadcast:error",semantics:"state"},{name:"errorInfo",event:"wcs-broadcast:error-info-changed",semantics:"state"}],commands:[{name:"open"},{name:"post"},{name:"close"}]};_target;_channel=null;_name=null;_message=null;_error=null;_errorInfo=null;_gen=0;_ready=Promise.resolve();_toldNotReady=!1;_toldUncloneable=!1;constructor(e){super(),this._target=e??this}get ready(){return this._ready}get message(){return this._message}get error(){return this._error}get errorInfo(){return this._errorInfo}observe(){return this._ready}_setMessage(e){this._message=e,this._target.dispatchEvent(new CustomEvent("wcs-broadcast:message",{detail:e,bubbles:!0}))}_setError(e){this._error!==e&&(this._error=e,this._commitErrorInfo(null===e?null:function(e){return"NotSupportedError"===e.name?{code:s,phase:"probe",recoverable:!1,message:e.message}:"DataCloneError"===e.name?{code:r,phase:"execute",recoverable:!1,message:e.message}:{code:a,phase:"execute",recoverable:!1,message:e.message}}(e)),this._target.dispatchEvent(new CustomEvent("wcs-broadcast:error",{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-broadcast:error-info-changed",{detail:e,bubbles:!0}))}open(e){if(!this._hasBroadcastChannel())return void this._setError(this._unsupportedError());if(this._channel&&this._name===e)return;this._closeChannel(),this._setError(null);const t=++this._gen,n=new BroadcastChannel(e);this._onMessage=e=>{t===this._gen&&this._setMessage(e.data)},this._onMessageError=()=>{t===this._gen&&this._setError({name:"DataError",message:"Failed to deserialize a message received on the channel."})},n.addEventListener("message",this._onMessage),n.addEventListener("messageerror",this._onMessageError),this._channel=n,this._name=e,this._toldNotReady=!1}post(e){if(this._hasBroadcastChannel()){if(!this._channel)return this._setError({name:"InvalidStateError",message:"Channel is not open. Call open(name) before post()."}),void this._warnNotReady();try{this._channel.postMessage(e)}catch(e){this._setError(this._normalizeError(e)),this._warnUncloneable(e)}}else this._setError(this._unsupportedError())}_warnUncloneable(e){this._toldUncloneable||"DataCloneError"!==e?.name||(this._toldUncloneable=!0,console.warn("[@wcstack/broadcast] [wcs/post-uncloneable] post() was refused: the message cannot be structured-cloned (DataCloneError), so it is lost. It goes to `error` too. A framework's reactive proxy is the usual cause — Vue's toRaw() unwraps one level only: pass a deep plain copy (JSON.parse(JSON.stringify(value)), or toRaw on each level). (Said once per element.)",this._target))}_warnNotReady(){this._toldNotReady||(this._toldNotReady=!0,console.warn("[@wcstack/broadcast] [wcs/command-not-ready] post() was refused: no channel is open, so the message is lost. It goes to `error` too. Give the element a `name` (or call open(name)) first. (Said once until a channel opens again.)",this._target))}close(){this._closeChannel()}dispose(){this._gen++,this._closeChannel(),this._setError(null)}_onMessage=null;_onMessageError=null;_closeChannel(){this._channel&&(this._channel.removeEventListener("message",this._onMessage),this._channel.removeEventListener("messageerror",this._onMessageError),this._channel.close(),this._channel=null,this._name=null,this._onMessage=null,this._onMessageError=null)}_hasBroadcastChannel(){return"undefined"!=typeof BroadcastChannel}_normalizeError(e){return e instanceof Error?{name:e.name,message:e.message}:{name:"Error",message:String(e)}}_unsupportedError(){return{name:"NotSupportedError",message:"BroadcastChannel is not available in this environment."}}}let i=!1;const c="data-broadcast-text";function l(t){const n=t.target;if(!(n instanceof Element))return;const s=n.closest(`[${e.triggerAttribute}]`);if(!s)return;const r=s.getAttribute(e.triggerAttribute);if(!r)return;const a=customElements.get(e.tagNames.broadcast),o=document.getElementById(r);if(!(a&&o instanceof a))return;const i=function(e){if(e.hasAttribute(c))return e.getAttribute(c)??"";const t=e.getAttribute("data-broadcast-from");if(!t)return null;let n;try{n=document.querySelector(t)}catch{return null}return n?n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement?n.value:n.textContent??"":null}(s);null!==i&&(t.preventDefault(),o.post(i))}function h(e,t){let n=Object.getPrototypeOf(e);for(;null!==n;){const e=Object.getOwnPropertyDescriptor(n,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;n=Object.getPrototypeOf(n)}return!1}const u=new WeakSet;function d(e,t,n){if(u.has(e))return;u.add(e);const s=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${s}> has the attribute ${t}="${n}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const m=new WeakMap;function g(e,t){let n=m.get(e);return void 0===n&&(n=new Map,m.set(e,n)),n.has(t)||n.set(t,e.getAttribute(t)),n.get(t)}function _(e,t,n){null===n?e.removeAttribute(t):e.setAttribute(t,n)}class p extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...o.wcBindable,inputs:[{name:"name",attribute:"name"},{name:"manual",attribute:"manual"}],commands:o.wcBindable.commands};static get observedAttributes(){return["name"]}_core;_connectedCallbackPromise=Promise.resolve();_everConnected=!1;_openPending=!1;_internals=null;constructor(){super(),this._core=new o(this),this._internals=this._initInternals(),this._wireStates({"wcs-broadcast:error":e=>({error:null!=e})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[n,s]of Object.entries(e))this.addEventListener(n,e=>{const n=this.hasAttribute("debug-states");for(const[r,a]of Object.entries(s(e.detail))){try{a?t.add(r):t.delete(r)}catch{}n&&this.toggleAttribute(`data-wcs-state-${r}`,a)}})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get name(){return this.getAttribute("name")||""}set name(e){!function(e,t,n){const s=g(e,t);_(e,t,void 0===n?s:null===n?null:String(n))}(this,"name",e)}get manual(){return this.hasAttribute("manual")}set manual(e){!function(e,t,n){const s=g(e,t);_(e,t,void 0===n?s:n?"":null)}(this,"manual",e)}get message(){return this._core.message}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}open(){this._openPending=!1,this.name&&this._core.open(this.name)}post(e){this._core.post(e)}close(){this._openPending=!1,this._core.close()}attributeChangedCallback(e,t,n){"name"===e&&this.isConnected&&!this.manual&&n&&!this._openPending&&this._core.open(n)}_scheduleOpen(){this._openPending||(this._openPending=!0,queueMicrotask(()=>{this._openPending&&(this._openPending=!1,this.isConnected&&!this.manual&&this.name&&this._core.open(this.name))}))}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,n=t?.inputs;if(void 0===n)return;const s=e.getAttribute;for(const t of n){const n=t.name,r="function"==typeof s?s.call(e,n.toLowerCase()):null;if(null!==r&&r.startsWith("[object ")&&d(e,n,r),!Object.prototype.hasOwnProperty.call(e,n))continue;if(!h(e,n))continue;const a=e,o=a[n];delete a[n],a[n]=o}}(this),this.style.display="none",i||(i=!0,document.addEventListener("click",l)),this._everConnected?this._scheduleOpen():(this._everConnected=!0,!this.manual&&this.name&&this._core.open(this.name)),this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}const b=Symbol.for("wcstack.package"),f=new WeakSet;function w(e,t){Object.defineProperty(e,b,{value:t,configurable:!0})}function v(e,t,n,s,r){if(void 0!==s&&(n===s||n.prototype instanceof s))return;const a=n[b];if(a===r||f.has(e))return;f.add(e);const o=r.slice(0,r.lastIndexOf("@"));console.warn(`[${o}] [wcs/package-twice] <${t}> is already defined by ${a??`another copy of ${o} that does not name its version`}; this copy, ${r}, does nothing. Load each package once.`)}function E(s=customElements){!function(e,t,n){for(const[s,r]of n){const n=e.get(s);void 0===n?(w(r,t),e.define(s,r)):v(e,s,n,r,t)}}(s,`${t}@${n}`,[[e.tagNames.broadcast,p]])}var y;E(y);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|
package/dist/index.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/broadcast",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.0",
|
|
4
4
|
"description": "Declarative cross-tab messaging component for Web Components. Framework-agnostic BroadcastChannel primitive via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|