playhtml 2.0.3 → 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
@@ -123,8 +123,7 @@ IDs are recommended on all elements to uniquely identify them. If you are applyi
123
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.
124
124
 
125
125
  ### `can-move`
126
-
127
- 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
128
127
 
129
128
  Creates a movable element using 2D `translate` on the element. Dragging the element around will move it
130
129
 
@@ -134,12 +133,16 @@ Creates a movable element using 2D `translate` on the element. Dragging the elem
134
133
  - This currently doesn't work on touch screens.
135
134
 
136
135
  ### `can-toggle`
136
+ https://github.com/spencerc99/playhtml/assets/14796580/7e667c06-c32e-4369-b250-c9ca321de163
137
137
 
138
- <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_
139
139
 
140
140
  Creates an element that can be switched on and off. Clicking the element will toggle the `clicked` class on the element.
141
141
 
142
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_
143
146
 
144
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).
145
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 { }