@tripod311/splash 0.0.5 → 0.0.6
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 +43 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -168,7 +168,49 @@ this.slots["mySlot"].setContent([child]);
|
|
|
168
168
|
|
|
169
169
|
---
|
|
170
170
|
|
|
171
|
-
### 3.
|
|
171
|
+
### 3. Drops
|
|
172
|
+
|
|
173
|
+
Drops are lightweight HTML snippets stored in the `TemplateCache`.
|
|
174
|
+
They are not components: no state, no lifecycle, no reactivity.
|
|
175
|
+
Instead, they allow you to register small reusable pieces of HTML with the same directives (`data-ref`, `data-text`, `data-html`, `data-class`, `data-style`, `data-prop-*`).
|
|
176
|
+
|
|
177
|
+
A drop can be **instantiated** at any moment, filled with values, and mounted into the DOM as a regular element.
|
|
178
|
+
|
|
179
|
+
**Example template registration:**
|
|
180
|
+
```ts
|
|
181
|
+
TemplateCache.registerDrop("chatMessage", `
|
|
182
|
+
<div class="msg">
|
|
183
|
+
<span data-ref="author" data-text="author"></span>
|
|
184
|
+
<p data-ref="text" data-html="text"></p>
|
|
185
|
+
</div>
|
|
186
|
+
`);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Creating a drop**
|
|
190
|
+
```ts
|
|
191
|
+
const drop = TemplateCache.createDrop("chatMessage", {
|
|
192
|
+
author: "Alice",
|
|
193
|
+
text: "<b>Hello!</b>"
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Access refs
|
|
197
|
+
console.log(drop.refs.author.innerText); // "Alice"
|
|
198
|
+
|
|
199
|
+
// Insert into DOM
|
|
200
|
+
document.body.appendChild(drop.node);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Drop interface**
|
|
204
|
+
```ts
|
|
205
|
+
export interface Drop {
|
|
206
|
+
node: Node; // the root DOM node
|
|
207
|
+
refs: Record<string, HTMLElement>; // all elements with data-ref
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### 4. Mounting & Unmounting
|
|
172
214
|
|
|
173
215
|
To place a component on the page you can use the `mount` method:
|
|
174
216
|
|