playhtml 1.2.0 → 1.3.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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
4
4
 
5
+ ## 1.3.0 - 2023-08-07
6
+
7
+ - Added support for `can-duplicate` capability to duplicate elements. Make factories for playhtml elements!!
8
+
5
9
  ## 1.2.0 - 2023-08-03
6
10
 
7
11
  - Added support for yjs's `awareness` protocol to handle synced data that shouldn't be persisted.
package/README.md CHANGED
@@ -8,8 +8,6 @@ playhtml is a library for magically creating collaborative interactive HTML elem
8
8
  <div id="couch" can-move style="font-size: 80px">🛋</div>
9
9
  ```
10
10
 
11
- This is designed as an open library for anyone to add on new interactions and capabilities. To get started, see the [New Capabilities](#new-capabilities).
12
-
13
11
  https://github.com/spencerc99/playhtml/assets/14796580/00e84e15-2c1c-4b4b-8e15-2af22f39db7a
14
12
 
15
13
  If you enjoy this, please consider [sponsoring the project or sending a small donation](https://github.com/sponsors/spencerc99). This helps ensure that the library is maintained and improved over time and funds the hosting costs for the syncing and persistence services.
@@ -44,9 +42,11 @@ If you have dynamic elements that are hydrated after the initial load, you can c
44
42
 
45
43
  To create your own custom element, refer to the [can-play](#can-play) section.
46
44
 
45
+ If you're trying this out and having trouble, please message me ([email](mailto:spencerc99@gmail.com), [twitter](https://twitter.com/spencerc99)) and I'm happy to help out!
46
+
47
47
  ## Examples
48
48
 
49
- Check out the [full gallery of community examples](https://gallery.playhtml.fun/) for more inspiration on what you can do! And [submit your own](https://coda.io/form/playhtml-example_dnUR7xNE7wz) once you've made one.
49
+ Check out the [full gallery of community examples](https://coda.io/@spencer/playhtml) for more inspiration on what you can do! And [submit your own](https://coda.io/form/playhtml-example_dnUR7xNE7wz) once you've made one.
50
50
 
51
51
  ## Capabilities
52
52
 
@@ -103,6 +103,8 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
103
103
 
104
104
  The only required properties are `defaultData`, `updateElement` and some kind of setup to trigger those functions (in this case, `onClick`, but you can add custom event listeners and logic using the `additionalSetup` property). See more examples based on the definitions for the included capabilities in `elements.ts`.
105
105
 
106
+ 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 I'd love to host your custom elements here as well.
107
+
106
108
  ## Plug-and-play Capabilities
107
109
 
108
110
  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.
@@ -113,26 +115,30 @@ We welcome any contributions if you have custom `can-play` elements that you wou
113
115
 
114
116
  https://github.com/spencerc99/playhtml/assets/14796580/9c2b9bf6-142c-41e2-8c8f-93a3b121a73e
115
117
 
116
- Creates a movable object using 2D `translate` on the element. Dragging the element around will move it
118
+ Creates a movable element using 2D `translate` on the element. Dragging the element around will move it
117
119
 
118
120
  **troubleshooting**
119
121
 
120
122
  - This currently doesn't work on `inline` display elements.
121
123
  - This currently doesn't work on touch screens.
122
124
 
123
- ### `can-spin`
124
-
125
- Creates a rotatable object using a `rotate` `transform` on the element. Dragging the element to the left or right will rotate it counter-clockwise and clockwise respectively.
126
-
127
125
  ### `can-toggle`
128
126
 
129
127
  <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>
130
128
 
131
- Creates an object that can be switched on and off. Clicking the element will toggle the `clicked` class on the element.
129
+ Creates an element that can be switched on and off. Clicking the element will toggle the `clicked` class on the element.
130
+
131
+ ### `can-duplicate`
132
+
133
+ 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).
132
134
 
133
135
  ### `can-grow`
134
136
 
135
- Creates an object that can be resized using a `scale` `transform`. Clicking the object will grow it, clicking with <kbd>ALT</kbd> will shrink it. Currently, the max size is 2x the original size and the min size is 1/2 the original size.
137
+ Creates an element that can be resized using a `scale` `transform`. Clicking the element will grow it, clicking with <kbd>ALT</kbd> will shrink it. Currently, the max size is 2x the original size and the min size is 1/2 the original size.
138
+
139
+ ### `can-spin`
140
+
141
+ 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.
136
142
 
137
143
  ### `can-post`
138
144
 
package/dist/main.d.ts CHANGED
@@ -1,11 +1,23 @@
1
1
  /// <reference lib="dom" />
2
+ import { TagType } from "./types";
2
3
  import * as Y from "yjs";
3
4
  import { ElementHandler } from "./elements";
4
- export declare const globalData: Y.Map<Y.Map<any>>;
5
5
  export declare function getElementFromId(id: string): HTMLElement | null;
6
- export declare const elementHandlers: Map<string, Map<string, ElementHandler<any, any, any>>>;
7
6
  /**
8
7
  * Sets up any playhtml elements that are currently on the page.
9
- * Can be repeatedly called to set up new elements without affecting existing ones.
8
+ *
9
+ * Should be called only once. If you'd like to set up new elements, use `setupPlayElement`, which is exposed
10
+ * on the `playhtml` object on `window`.
10
11
  */
11
12
  export declare function setupElements(): void;
13
+ export declare const playhtml: {
14
+ setupElements: typeof setupElements;
15
+ globalData: Y.Map<Y.Map<any>>;
16
+ elementHandlers: Map<string, Map<string, ElementHandler<any, any, any>>>;
17
+ setupPlayElement: typeof setupPlayElement;
18
+ };
19
+ /**
20
+ * Sets up a playhtml element to handle the given tag's capabilities.
21
+ */
22
+ export declare function setupPlayElementForTag<T extends TagType>(element: HTMLElement, tag: T): void;
23
+ export declare function setupPlayElement(element: Element): void;
Binary file
Binary file