playhtml 2.0.9 → 2.0.10

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/README.md CHANGED
@@ -204,7 +204,6 @@ Creates a movable element using 2D `translate` on the element. Dragging the elem
204
204
  **troubleshooting**
205
205
 
206
206
  - This currently doesn't work on `inline` display elements.
207
- - This currently doesn't work on touch screens.
208
207
 
209
208
  ### `can-toggle`
210
209
 
@@ -230,12 +229,6 @@ Creates an element that can be resized using a `scale` `transform`. Clicking the
230
229
 
231
230
  Creates a rotatable element using a `rotate` `transform` on the element. Dragging the element to the left or right will rotate it counter-clockwise and clockwise respectively.
232
231
 
233
- ### `can-post`
234
-
235
- ![image](https://github.com/spencerc99/playhtml/assets/14796580/6de3fcab-2372-4080-b46f-cd768f1ed44e)
236
-
237
- Creates a communal forum from a `form` element. The form will sync any new submissions including all the `input` elements in the form, using their `name` property as the key and their value as the value. New messages will be currently prepended to the element with the `guestbookMessages` ID. TODO: make this generic and take user input
238
-
239
232
  ## Contributing
240
233
 
241
234
  See [CONTRIBUTING.md](https://github.com/spencerc99/playhtml/blob/main/CONTRIBUTING.md).
@@ -9368,10 +9368,7 @@ function di({
9368
9368
  ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
9369
9369
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
9370
9370
  ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`
9371
- ), Y = new ya(n, t, Ut), B = Ut.getMap("playhtml-global"), N = /* @__PURE__ */ new Map(), new Ta(
9372
- window.location.href,
9373
- Ut
9374
- ), Xt.globalData = B, Xt.elementHandlers = N, Y.on("sync", (i) => {
9371
+ ), Y = new ya(n, t, Ut), B = Ut.getMap("playhtml-global"), N = /* @__PURE__ */ new Map(), new Ta(t, Ut), Xt.globalData = B, Xt.elementHandlers = N, Y.on("sync", (i) => {
9375
9372
  i || console.error("Issue connecting to yjs..."), bs = !0, Pa();
9376
9373
  }), Y;
9377
9374
  }
@@ -9,4 +9,4 @@ ${e}`)}function Gn(s,e,t){const n=se(e),i=z(),r=k(n),o=s.messageHandlers[r];retu
9
9
  ࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
10
10
  ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
11
11
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
12
- ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),Q=new ha(n,t,ws),q=ws.getMap("playhtml-global"),K=new Map,new Ca(window.location.href,ws),Dt.globalData=q,Dt.elementHandlers=K,Q.on("sync",i=>{i||console.error("Issue connecting to yjs..."),ys=!0,Fa()}),Q}setTimeout(()=>{Q||(console.error("You are using a deprecated version of playhtml. Please call `playhtml.init()` explicitly rather than just importing the library. Refer to https://github.com/spencerc99/playhtml#usage for reference."),hi())},3e3);function Oa(s,e){const t=Q.awareness.getLocalState();return((t==null?void 0:t[s])??{})[e]}function _s(s){return s instanceof HTMLElement}function Ra(s,e,t,n){const i=q.get(e);return{...t,data:i.get(n)??t.defaultData,awareness:Oa(e,n)??t.myDefaultAwareness!==void 0?[t.myDefaultAwareness]:void 0,element:s,onChange:o=>{i.get(n)!==o&&i.set(n,o)},onAwarenessChange:o=>{var c;const a=((c=Q.awareness.getLocalState())==null?void 0:c[e])||{};a[n]!==o&&(a[n]=o,Q.awareness.setLocalStateField(e,a))},triggerAwarenessUpdate:()=>{ui()}}}function Ba(s){return s.defaultData!==void 0&&s.updateElement!==void 0}function Na(s,e){if(s===U.CanPlay){const t=e;return{defaultData:t.defaultData,defaultLocalData:t.defaultLocalData,myDefaultAwareness:t.myDefaultAwareness,updateElement:t.updateElement,updateElementAwareness:t.updateElementAwareness,onDrag:t.onDrag,onDragStart:t.onDragStart,onClick:t.onClick,additionalSetup:t.additionalSetup,resetShortcut:t.resetShortcut,debounceMs:t.debounceMs}}return ai[s]}function ui(){const s=new Map;function e(t,n,i,r){s.has(t)||s.set(t,new Map);const o=s.get(t);o.has(n)||o.set(n,new Map),o.get(n).set(i,r)}Q.awareness.getStates().forEach((t,n)=>{var i;for(const[r,o]of Object.entries(t)){const a=K.get(r);if(a)for(const[c,l]of a){if(!(c in o))continue;const h=o[c];e(r,c,n,h)}}for(const[r,o]of s){const a=K.get(r);if(a)for(const[c,l]of a){const h=(i=o.get(c))==null?void 0:i.values();if(!h)continue;let u=Array.from(h);l.__awareness=u}}})}function Fa(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝");for(const s of Object.values(U)){const e=Array.from(document.querySelectorAll(`[${s}]`)).filter(_s);if(e.length)for(let t=0;t<e.length;t++){const n=e[t];Et(n,s)}}Ss&&(q.observe(s=>{s.changes.keys.forEach((e,t)=>{e.action==="add"&&q.set(t,q.get(t))})}),Q.awareness.on("change",()=>ui()),Ss=!1)}const Dt={init:hi,setupPlayElement:$a,removePlayElement:qa,setupPlayElementForTag:Et,globalData:void 0,elementHandlers:void 0};window.playhtml=Dt;function Ha(s){if(K.has(s)||!ys)return;K.set(s,new Map),s!==U.CanPlay&&ai[s],q.get(s)||q.set(s,new ge);const e=q.get(s);e.observe(t=>{t.changes.keys.forEach((n,i)=>{const r=K.get(s);if(n.action==="add"){const o=ii(i);if(!_s(o)){console.log(`Element ${i} not an HTML element. Ignoring.`);return}Et(o,s)}else if(n.action==="update"){const o=r.get(i);o.__data=e.get(i)}else n.action==="delete"?r.delete(i):console.log(`Unhandled action: ${n.action}`)})})}function Va(s,e){const t=s.getAttribute(e);switch(e){case U.CanPlay:case U.CanMove:case U.CanSpin:case U.CanGrow:case U.CanToggle:case U.CanPost:return!0;case U.CanDuplicate:return t?(document.getElementById(t)||console.warn(`${U.CanDuplicate} element (${s.id}) duplicate element ("${t}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${e}`),!1}}function Et(s,e){var a;if(!Va(s,e)||!ys)return;if(!s.id){const c=s.getAttribute("selector-id");if(c){const l=li.get(c)??0;s.id=btoa(`${e}-${c}-${l}`),li.set(c,l+1)}else s.id=btoa(`${e}-${s.innerHTML}}`)}const t=ja(s);if(!t){console.error(`Element ${s} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Ha(e);const n=K.get(e),i=Na(e,s);if(!Ba(i)){console.error(`Element ${t} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const r=q.get(e),o=Ra(s,e,i,t);if(n.has(t)){n.get(t).reinitializeElementData(o);return}else n.set(t,new za(o));r.get(t)===void 0&&i.defaultData!==void 0&&r.set(t,i.defaultData),(a=o.triggerAwarenessUpdate)==null||a.call(o),s.classList.add("__playhtml-element"),s.classList.add(`__playhtml-${e}`),s.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function $a(s){if(!_s(s)){console.log(`Element ${s.id} not an HTML element. Ignoring.`);return}for(const e of Object.values(U))s.hasAttribute(e)&&Et(s,e)}function qa(s){if(!(!s||!s.id))for(const e of Object.keys(K)){const t=K.get(e);t.has(s.id)&&t.delete(s.id)}}_.playhtml=Dt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
12
+ ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),Q=new ha(n,t,ws),q=ws.getMap("playhtml-global"),K=new Map,new Ca(t,ws),Dt.globalData=q,Dt.elementHandlers=K,Q.on("sync",i=>{i||console.error("Issue connecting to yjs..."),ys=!0,Fa()}),Q}setTimeout(()=>{Q||(console.error("You are using a deprecated version of playhtml. Please call `playhtml.init()` explicitly rather than just importing the library. Refer to https://github.com/spencerc99/playhtml#usage for reference."),hi())},3e3);function Oa(s,e){const t=Q.awareness.getLocalState();return((t==null?void 0:t[s])??{})[e]}function _s(s){return s instanceof HTMLElement}function Ra(s,e,t,n){const i=q.get(e);return{...t,data:i.get(n)??t.defaultData,awareness:Oa(e,n)??t.myDefaultAwareness!==void 0?[t.myDefaultAwareness]:void 0,element:s,onChange:o=>{i.get(n)!==o&&i.set(n,o)},onAwarenessChange:o=>{var c;const a=((c=Q.awareness.getLocalState())==null?void 0:c[e])||{};a[n]!==o&&(a[n]=o,Q.awareness.setLocalStateField(e,a))},triggerAwarenessUpdate:()=>{ui()}}}function Ba(s){return s.defaultData!==void 0&&s.updateElement!==void 0}function Na(s,e){if(s===U.CanPlay){const t=e;return{defaultData:t.defaultData,defaultLocalData:t.defaultLocalData,myDefaultAwareness:t.myDefaultAwareness,updateElement:t.updateElement,updateElementAwareness:t.updateElementAwareness,onDrag:t.onDrag,onDragStart:t.onDragStart,onClick:t.onClick,additionalSetup:t.additionalSetup,resetShortcut:t.resetShortcut,debounceMs:t.debounceMs}}return ai[s]}function ui(){const s=new Map;function e(t,n,i,r){s.has(t)||s.set(t,new Map);const o=s.get(t);o.has(n)||o.set(n,new Map),o.get(n).set(i,r)}Q.awareness.getStates().forEach((t,n)=>{var i;for(const[r,o]of Object.entries(t)){const a=K.get(r);if(a)for(const[c,l]of a){if(!(c in o))continue;const h=o[c];e(r,c,n,h)}}for(const[r,o]of s){const a=K.get(r);if(a)for(const[c,l]of a){const h=(i=o.get(c))==null?void 0:i.values();if(!h)continue;let u=Array.from(h);l.__awareness=u}}})}function Fa(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝");for(const s of Object.values(U)){const e=Array.from(document.querySelectorAll(`[${s}]`)).filter(_s);if(e.length)for(let t=0;t<e.length;t++){const n=e[t];Et(n,s)}}Ss&&(q.observe(s=>{s.changes.keys.forEach((e,t)=>{e.action==="add"&&q.set(t,q.get(t))})}),Q.awareness.on("change",()=>ui()),Ss=!1)}const Dt={init:hi,setupPlayElement:$a,removePlayElement:qa,setupPlayElementForTag:Et,globalData:void 0,elementHandlers:void 0};window.playhtml=Dt;function Ha(s){if(K.has(s)||!ys)return;K.set(s,new Map),s!==U.CanPlay&&ai[s],q.get(s)||q.set(s,new ge);const e=q.get(s);e.observe(t=>{t.changes.keys.forEach((n,i)=>{const r=K.get(s);if(n.action==="add"){const o=ii(i);if(!_s(o)){console.log(`Element ${i} not an HTML element. Ignoring.`);return}Et(o,s)}else if(n.action==="update"){const o=r.get(i);o.__data=e.get(i)}else n.action==="delete"?r.delete(i):console.log(`Unhandled action: ${n.action}`)})})}function Va(s,e){const t=s.getAttribute(e);switch(e){case U.CanPlay:case U.CanMove:case U.CanSpin:case U.CanGrow:case U.CanToggle:case U.CanPost:return!0;case U.CanDuplicate:return t?(document.getElementById(t)||console.warn(`${U.CanDuplicate} element (${s.id}) duplicate element ("${t}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${e}`),!1}}function Et(s,e){var a;if(!Va(s,e)||!ys)return;if(!s.id){const c=s.getAttribute("selector-id");if(c){const l=li.get(c)??0;s.id=btoa(`${e}-${c}-${l}`),li.set(c,l+1)}else s.id=btoa(`${e}-${s.innerHTML}}`)}const t=ja(s);if(!t){console.error(`Element ${s} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Ha(e);const n=K.get(e),i=Na(e,s);if(!Ba(i)){console.error(`Element ${t} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const r=q.get(e),o=Ra(s,e,i,t);if(n.has(t)){n.get(t).reinitializeElementData(o);return}else n.set(t,new za(o));r.get(t)===void 0&&i.defaultData!==void 0&&r.set(t,i.defaultData),(a=o.triggerAwarenessUpdate)==null||a.call(o),s.classList.add("__playhtml-element"),s.classList.add(`__playhtml-${e}`),s.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function $a(s){if(!_s(s)){console.log(`Element ${s.id} not an HTML element. Ignoring.`);return}for(const e of Object.values(U))s.hasAttribute(e)&&Et(s,e)}function qa(s){if(!(!s||!s.id))for(const e of Object.keys(K)){const t=K.get(e);t.has(s.id)&&t.delete(s.id)}}_.playhtml=Dt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "playhtml",
3
3
  "title": "playhtml",
4
4
  "description": "Create interactive, collaborative html elements with a single attribute",
5
- "version": "2.0.9",
5
+ "version": "2.0.10",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "keywords": [