playhtml 2.0.2 → 2.0.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
4
4
 
5
+ ## 2.0.4 - 2023-09-07
6
+
7
+ - added @playhtml/react library
8
+ - added `firstSetup` export from playhtml for raising error if it hasn't been initialized.
9
+ - cleaned up exports
10
+
5
11
  ## 2.0.2 - 2023-08-23
6
12
 
7
13
  - handle deprecated import version by using a timeout. This adds a significant delay to the initialization of any client using the old method and logs a warning.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # playhtml 🛝🌐
1
+ # <a href="https://playhtml.fun">playhtml</a> 🛝🌐 [![npm release](https://img.shields.io/npm/v/playhtml?color=%23ff980c)](https://www.npmjs.com/package/playhtml) [![Downloads](https://img.shields.io/npm/dm/playhtml)](https://www.npmjs.com/package/spencerc99/playhtml) [![Size](https://img.shields.io/bundlephobia/min/playhtml?color=%23c6e1ea)](https://www.npmjs.com/package/spencerc99/playhtml)
2
2
 
3
3
  _interactive, collaborative html elements with a single data attribute_
4
4
 
5
- playhtml is a library for magically creating collaborative interactive HTML elements that persist their state across sessions. For example, you can create a movable piece of HTML "furniture" by adding the `can-move` attribute:
5
+ playhtml is a fast, small (~300KB), and expressive library for magically creating collaborative interactive HTML elements that persist their state across sessions. For example, you can create a movable piece of HTML "furniture" by adding the `can-move` attribute:
6
6
 
7
7
  ```html
8
8
  <div id="couch" can-move style="font-size: 80px">🛋</div>
@@ -114,13 +114,16 @@ The only required properties are `defaultData`, `updateElement` and some kind of
114
114
 
115
115
  If you make something fun, please show me! This is designed as an open library for anyone to add on new interactions and capabilities, so we [welcome contributions](https://github.com/spencerc99/playhtml/blob/main/CONTRIBUTING.md) for new built-in capabilities.
116
116
 
117
+ ### Advanced
118
+
119
+ IDs are recommended on all elements to uniquely identify them. If you are applying the same capability to several elements, you can also use the `selector-id` attribute to specify a selector to the elements that distinguishes them. The ID will be the index of the element in that selector query.
120
+
117
121
  ## Plug-and-play Capabilities
118
122
 
119
123
  These capabilities are common ones that have been designed and created by the community. You should expect that they are relatively well-tested, and they simply build on top of the same API and constructs that `can-play` uses.
120
124
 
121
125
  ### `can-move`
122
-
123
- https://github.com/spencerc99/playhtml/assets/14796580/9c2b9bf6-142c-41e2-8c8f-93a3b121a73e
126
+ https://github.com/spencerc99/playhtml/assets/14796580/215c7631-d71f-40e6-bdda-bd8146a88006
124
127
 
125
128
  Creates a movable element using 2D `translate` on the element. Dragging the element around will move it
126
129
 
@@ -130,12 +133,16 @@ Creates a movable element using 2D `translate` on the element. Dragging the elem
130
133
  - This currently doesn't work on touch screens.
131
134
 
132
135
  ### `can-toggle`
136
+ https://github.com/spencerc99/playhtml/assets/14796580/7e667c06-c32e-4369-b250-c9ca321de163
133
137
 
134
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">today i installed some lamps on the demos-and-chill website<br><br>then <a href="https://twitter.com/_jzhao?ref_src=twsrc%5Etfw">@_jzhao</a> and i fought on whether to keep them on or not. <a href="https://t.co/sCspTwmRpS">pic.twitter.com/sCspTwmRpS</a></p>&mdash; spencer chang ☀️ (spencerchang.me @ bsky) (@spencerc99) <a href="https://twitter.com/spencerc99/status/1681048824884895744?ref_src=twsrc%5Etfw">July 17, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
138
+ _from https://twitter.com/spencerc99/status/1681048824884895744_
135
139
 
136
140
  Creates an element that can be switched on and off. Clicking the element will toggle the `clicked` class on the element.
137
141
 
138
142
  ### `can-duplicate`
143
+ https://github.com/spencerc99/playhtml/assets/14796580/6d9f1228-08cf-45a7-987a-8bebfaaefd83
144
+
145
+ _used to programmatically and dynamically create new playhtml elements that aren't included in the initial HTML_
139
146
 
140
147
  Creates an element that duplicates a target element (specified by the value of the `can-duplicate` attribute, which can be an element's ID or custom CSS selector) when clicked. Optionally can specify where the duplicate element is inserted in the DOM via the `can-duplicate-to` setting (default is as a sibling to the original element).
141
148
 
package/dist/main.d.ts CHANGED
@@ -1,30 +1,13 @@
1
1
  /// <reference lib="dom" />
2
2
 
3
+ import { ElementAwarenessEventHandlerData } from '../../common/src';
4
+ import { ElementData } from '../../common/src';
5
+ import { ElementEventHandlerData } from '../../common/src';
6
+ import { ElementSetupData } from '../../common/src';
7
+ import { ModifierKey } from '../../common/src';
8
+ import { TagType } from '@playhtml/common';
3
9
  import * as Y from 'yjs';
4
-
5
- declare interface ElementAwarenessEventHandlerData<T = any, U = any, V = any> extends ElementEventHandlerData<T, U, V> {
6
- myAwareness?: V;
7
- }
8
-
9
- declare interface ElementData<T = any, U = any, V = any> extends ElementInitializer<T> {
10
- data?: T;
11
- localData?: U;
12
- awareness?: V;
13
- element: HTMLElement;
14
- onChange: (data: T) => void;
15
- onAwarenessChange: (data: V) => void;
16
- triggerAwarenessUpdate: () => void;
17
- }
18
-
19
- declare interface ElementEventHandlerData<T = any, U = any, V = any> {
20
- data: T;
21
- localData: U;
22
- awareness: V[];
23
- element: HTMLElement;
24
- setData: (data: T) => void;
25
- setLocalData: (data: U) => void;
26
- setLocalAwareness: (data: V) => void;
27
- }
10
+ import YPartyKitProvider from 'y-partykit/provider';
28
11
 
29
12
  declare class ElementHandler<T = any, U = any, V = any> {
30
13
  defaultData: T;
@@ -67,63 +50,29 @@ declare class ElementHandler<T = any, U = any, V = any> {
67
50
  reset(): void;
68
51
  }
69
52
 
70
- declare interface ElementInitializer<T = any, U = any, V = any> {
71
- defaultData: T | ((element: HTMLElement) => T);
72
- defaultLocalData?: U | ((element: HTMLElement) => U);
73
- myDefaultAwareness?: V | ((element: HTMLElement) => V);
74
- updateElement: (data: ElementEventHandlerData<T, U, V>) => void;
75
- updateElementAwareness?: (data: ElementAwarenessEventHandlerData<T, U, V>) => void;
76
- onDrag?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
77
- onClick?: (e: MouseEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
78
- onDragStart?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
79
- additionalSetup?: (eventData: ElementSetupData<T, U, V>) => void;
80
- resetShortcut?: ModifierKey;
81
- debounceMs?: number;
82
- }
83
-
84
- declare interface ElementSetupData<T = any, U = any, V = any> {
85
- getData: () => T;
86
- getLocalData: () => U;
87
- getAwareness: () => V[];
88
- getElement: () => HTMLElement;
89
- setData: (data: T) => void;
90
- setLocalData: (data: U) => void;
91
- setLocalAwareness: (data: V) => void;
92
- }
93
-
94
53
  declare interface InitOptions {
95
54
  room?: string;
96
55
  host?: string;
97
56
  }
98
57
 
99
- export declare function initPlayHTML({ room, host, }?: InitOptions): void;
100
-
101
- declare type ModifierKey = "ctrlKey" | "altKey" | "shiftKey" | "metaKey";
58
+ declare function initPlayHTML({ room, host, }?: InitOptions): YPartyKitProvider | undefined;
102
59
 
103
60
  export declare const playhtml: PlayHTMLComponents;
104
61
 
105
62
  declare interface PlayHTMLComponents {
106
63
  init: typeof initPlayHTML;
107
64
  setupPlayElement: typeof setupPlayElement;
65
+ setupPlayElementForTag: typeof setupPlayElementForTag;
108
66
  globalData: Y.Map<any> | undefined;
109
67
  elementHandlers: Map<string, Map<string, ElementHandler>> | undefined;
68
+ firstSetup: boolean;
110
69
  }
111
70
 
112
- export declare function setupPlayElement(element: Element): void;
71
+ declare function setupPlayElement(element: Element): void;
113
72
 
114
73
  /**
115
74
  * Sets up a playhtml element to handle the given tag's capabilities.
116
75
  */
117
- export declare function setupPlayElementForTag<T extends TagType>(element: HTMLElement, tag: T): void;
118
-
119
- declare enum TagType {
120
- "CanPlay" = "can-play",
121
- "CanMove" = "can-move",
122
- "CanSpin" = "can-spin",
123
- "CanGrow" = "can-grow",
124
- "CanToggle" = "can-toggle",
125
- "CanDuplicate" = "can-duplicate",
126
- "CanPost" = "can-post"
127
- }
76
+ declare function setupPlayElementForTag<T extends TagType>(element: HTMLElement, tag: T): void;
128
77
 
129
78
  export { }