playhtml 1.3.1 → 2.0.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/CHANGELOG.md +34 -0
- package/README.md +13 -2
- package/dist/main.d.ts +138 -23
- package/dist/playhtml.es.js +5687 -2829
- package/dist/playhtml.umd.js +7 -7
- package/package.json +25 -3
- package/dist/candle-gif.gif +0 -0
- package/dist/candle-off.png +0 -0
- package/dist/elements.d.ts +0 -43
- package/dist/icon.png +0 -0
- package/dist/noguchi-akari-a1.png +0 -0
- package/dist/noguchi-hanging-lamp.png +0 -0
- package/dist/playhtml-candles.png +0 -0
- package/dist/playhtml-fridge.png +0 -0
- package/dist/playhtml-story.png +0 -0
- package/dist/playhtml.png +0 -0
- package/dist/server.d.ts +0 -4
- package/dist/types.d.ts +0 -70
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
|
|
4
4
|
|
|
5
|
+
## 2.0.0 - 2023-08-23
|
|
6
|
+
|
|
7
|
+
- **BREAKING CHANGE**: Changed the initializing of playhtml to be an explicit call of `playhtml.init()` from just a normal import. You can still use the old code if you pin the import to any version 1.3.1 (e.g. use `https://unpkg.com/playhtml@1.3.1` as the import source).
|
|
8
|
+
|
|
9
|
+
**OLD CODE:**
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script type="module" src="https://unpkg.com/playhtml"></script>
|
|
13
|
+
<link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**NEW CODE:**
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<script type="module">
|
|
20
|
+
import "https://unpkg.com/playhtml";
|
|
21
|
+
playhtml.init();
|
|
22
|
+
// Optionally you could call
|
|
23
|
+
// playhtml.init({
|
|
24
|
+
// room: window.location.pathname,
|
|
25
|
+
// host: "mypartykit.user.partykit.dev"
|
|
26
|
+
// })
|
|
27
|
+
</script>
|
|
28
|
+
<link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This change allows for more flexible use of the package, including specifying a partykit host and room.
|
|
32
|
+
|
|
33
|
+
- was accidentally importing all my files for the website into the package, blowing it up to 4MB. I've fixed this and compressed down the `.d.ts` types file to just what is needed, so the package is down to 360KB. It should load much faster on websites now :)
|
|
34
|
+
|
|
35
|
+
## 1.3.1 - 2023-08-09
|
|
36
|
+
|
|
37
|
+
- Removed unused code and consolidated types in `types.ts`
|
|
38
|
+
|
|
5
39
|
## 1.3.0 - 2023-08-07
|
|
6
40
|
|
|
7
41
|
- Added support for `can-duplicate` capability to duplicate elements. Make factories for playhtml elements!!
|
package/README.md
CHANGED
|
@@ -27,7 +27,15 @@ To use this library, you can import the library and the associated styles from a
|
|
|
27
27
|
id="openSign"
|
|
28
28
|
<!-- INVALID EXAMPLE <img src="https://media2.giphy.com/media/lL7A3Li0YtFHq/giphy.gif?cid=ecf05e47ah89o71gzz7ke7inrgb1ai1xcbrjnqdf7o890118&ep=v1_stickers_search&rid=giphy.gif" can-move /> -->
|
|
29
29
|
<!-- import the script -->
|
|
30
|
-
<script type="module"
|
|
30
|
+
<script type="module">
|
|
31
|
+
import "https://unpkg.com/playhtml";
|
|
32
|
+
playhtml.init();
|
|
33
|
+
// Optionally you could customize the room and host, like so:
|
|
34
|
+
// playhtml.init({
|
|
35
|
+
// room: window.location.pathname,
|
|
36
|
+
// host: "mypartykit.user.partykit.dev"
|
|
37
|
+
// })
|
|
38
|
+
</script>
|
|
31
39
|
<link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
|
|
32
40
|
</body>
|
|
33
41
|
```
|
|
@@ -90,7 +98,10 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
|
|
|
90
98
|
</script>
|
|
91
99
|
|
|
92
100
|
<!-- Import playhtml -->
|
|
93
|
-
<script type="module"
|
|
101
|
+
<script type="module">
|
|
102
|
+
import "https://unpkg.com/playhtml";
|
|
103
|
+
playhtml.init();
|
|
104
|
+
</script>
|
|
94
105
|
<link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
|
|
95
106
|
```
|
|
96
107
|
|
package/dist/main.d.ts
CHANGED
|
@@ -1,23 +1,138 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
|
|
3
|
-
import * as Y from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
|
|
3
|
+
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
|
+
}
|
|
28
|
+
|
|
29
|
+
declare class ElementHandler<T = any, U = any, V = any> {
|
|
30
|
+
defaultData: T;
|
|
31
|
+
localData: U;
|
|
32
|
+
awareness: V[];
|
|
33
|
+
selfAwareness?: V;
|
|
34
|
+
element: HTMLElement;
|
|
35
|
+
_data: T;
|
|
36
|
+
onChange: (data: T) => void;
|
|
37
|
+
onAwarenessChange: (data: V) => void;
|
|
38
|
+
debouncedOnChange: (data: T) => void;
|
|
39
|
+
resetShortcut?: ModifierKey;
|
|
40
|
+
updateElement: (data: ElementEventHandlerData<T, U, V>) => void;
|
|
41
|
+
updateElementAwareness?: (data: ElementAwarenessEventHandlerData<T, U, V>) => void;
|
|
42
|
+
triggerAwarenessUpdate?: () => void;
|
|
43
|
+
constructor({ element, onChange, onAwarenessChange, defaultData, defaultLocalData, myDefaultAwareness, data, awareness: awarenessData, updateElement, updateElementAwareness, onClick, onDrag, onDragStart, additionalSetup, resetShortcut, debounceMs, triggerAwarenessUpdate, }: ElementData<T>);
|
|
44
|
+
get data(): T;
|
|
45
|
+
setLocalData(localData: U): void;
|
|
46
|
+
/**
|
|
47
|
+
* // PRIVATE USE ONLY \\
|
|
48
|
+
*
|
|
49
|
+
* Updates the internal state with the given data and handles all the downstream effects. Should only be used by the sync code to ensure one-way
|
|
50
|
+
* reactivity.
|
|
51
|
+
* (e.g. calling `updateElement` and `onChange`)
|
|
52
|
+
*/
|
|
53
|
+
set __data(data: T);
|
|
54
|
+
set __awareness(data: V[]);
|
|
55
|
+
getEventHandlerData(): ElementEventHandlerData<T, U, V>;
|
|
56
|
+
getAwarenessEventHandlerData(): ElementAwarenessEventHandlerData<T, U, V>;
|
|
57
|
+
getSetupData(): ElementSetupData<T, U>;
|
|
58
|
+
/**
|
|
59
|
+
* Public-use setter for data that makes the change to all clients.
|
|
60
|
+
*/
|
|
61
|
+
setData(data: T): void;
|
|
62
|
+
setLocalAwareness(data: V): void;
|
|
63
|
+
setDataDebounced(data: T): void;
|
|
64
|
+
/**
|
|
65
|
+
* Resets the element to its default state.
|
|
66
|
+
*/
|
|
67
|
+
reset(): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
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
|
+
declare interface InitOptions {
|
|
95
|
+
room?: string;
|
|
96
|
+
host?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export declare function initPlayHTML({ room, host, }?: InitOptions): void;
|
|
100
|
+
|
|
101
|
+
declare type ModifierKey = "ctrlKey" | "altKey" | "shiftKey" | "metaKey";
|
|
102
|
+
|
|
103
|
+
export declare const playhtml: PlayHTMLComponents;
|
|
104
|
+
|
|
105
|
+
declare interface PlayHTMLComponents {
|
|
106
|
+
init: typeof initPlayHTML;
|
|
107
|
+
setupElements: typeof setupElements;
|
|
108
|
+
setupPlayElement: typeof setupPlayElement;
|
|
109
|
+
globalData: Y.Map<any> | undefined;
|
|
110
|
+
elementHandlers: Map<string, Map<string, ElementHandler>> | undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Sets up any playhtml elements that are currently on the page.
|
|
115
|
+
*
|
|
116
|
+
* Should be called only once. If you'd like to set up new elements, use `setupPlayElement`, which is exposed
|
|
117
|
+
* on the `playhtml` object on `window`.
|
|
118
|
+
*/
|
|
119
|
+
export declare function setupElements(): void;
|
|
120
|
+
|
|
121
|
+
export declare function setupPlayElement(element: Element): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sets up a playhtml element to handle the given tag's capabilities.
|
|
125
|
+
*/
|
|
126
|
+
export declare function setupPlayElementForTag<T extends TagType>(element: HTMLElement, tag: T): void;
|
|
127
|
+
|
|
128
|
+
declare enum TagType {
|
|
129
|
+
"CanPlay" = "can-play",
|
|
130
|
+
"CanMove" = "can-move",
|
|
131
|
+
"CanSpin" = "can-spin",
|
|
132
|
+
"CanGrow" = "can-grow",
|
|
133
|
+
"CanToggle" = "can-toggle",
|
|
134
|
+
"CanDuplicate" = "can-duplicate",
|
|
135
|
+
"CanPost" = "can-post"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { }
|