Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to @livetemplate/client will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.7.1] - 2025-12-14

### Changes

- fix: apply differential ops to existing range structures (#9) (50a3ebc)
- fix: handle objects with only numeric keys in renderValue (#8) (b1c7827)
- feat: add lvt-focus-trap and lvt-autofocus attributes (#7) (7b14402)
- feat: add reactive attributes for action lifecycle events (#6) (46e2065)


Comment on lines +8 to +17
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG entry for v0.7.1 lists changes from previous PRs (issues #6-9) that don't appear to be related to this PR. According to the PR description, this PR adds client-side updates for livepage features including event delegation updates, livetemplate client updates, and a confirm utility. The CHANGELOG should be updated to accurately reflect the changes in this specific PR.

Copilot uses AI. Check for mistakes.

## [v0.7.0] - 2025-12-10

### Changes
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.7.1
16 changes: 5 additions & 11 deletions dom/event-delegation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { debounce, throttle } from "../utils/rate-limit";
import { checkLvtConfirm } from "../utils/confirm";
import type { Logger } from "../utils/logger";

export interface EventDelegationContext {
Expand Down Expand Up @@ -142,17 +143,10 @@ export class EventDelegator {
targetElement,
});

if (
action === "delete" &&
targetElement.hasAttribute("lvt-confirm")
) {
const confirmMessage =
targetElement.getAttribute("lvt-confirm") ||
"Are you sure you want to delete this item?";
if (!confirm(confirmMessage)) {
this.logger.debug("Delete action cancelled by user");
return;
}
// Handle lvt-confirm for any action
if (!checkLvtConfirm(targetElement as HTMLElement)) {
Comment on lines +146 to +147
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change expands lvt-confirm from only working with delete actions to working with all actions. While this is a useful enhancement, it's a breaking behavioral change that should be documented in the CHANGELOG. Users who previously added lvt-confirm to non-delete actions (expecting it to be ignored) will now see confirmation dialogs. Consider noting this as a potentially breaking change in the version release notes.

Suggested change
// Handle lvt-confirm for any action
if (!checkLvtConfirm(targetElement as HTMLElement)) {
// Only apply lvt-confirm to delete-like actions to avoid breaking behavior
const isDeleteAction =
typeof action === "string" && /^delete/i.test(action);
if (isDeleteAction && !checkLvtConfirm(targetElement as HTMLElement)) {

Copilot uses AI. Check for mistakes.
this.logger.debug("Action cancelled by user:", action);
return;
}
Comment on lines +146 to 150
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactored lvt-confirm handling now applies to all actions, not just delete actions. This is a significant behavioral change that should be covered by tests. The existing tests/event-delegation.test.ts does not have any tests for lvt-confirm functionality. Tests should be added to verify that: 1) actions with lvt-confirm are properly blocked when the user cancels, 2) actions proceed when the user confirms, and 3) this works for various action types (not just delete).

Copilot uses AI. Check for mistakes.

const message: any = { action, data: {} };
Expand Down
2 changes: 2 additions & 0 deletions livetemplate-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import type {
} from "./types";
import { createLogger, Logger } from "./utils/logger";
export { loadAndApplyUpdate, compareHTML } from "./utils/testing";
export { setupReactiveAttributeListeners } from "./dom/reactive-attributes";
export { checkLvtConfirm, extractLvtData } from "./utils/confirm";

export class LiveTemplateClient {
private readonly treeRenderer: TreeRenderer;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@livetemplate/client",
"version": "0.7.0",
"version": "0.7.1",
"description": "TypeScript client for LiveTemplate tree-based updates",
"main": "dist/livetemplate-client.js",
"browser": "dist/livetemplate-client.browser.js",
Expand Down
33 changes: 33 additions & 0 deletions utils/confirm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Check if an element has lvt-confirm attribute and prompt user if needed.
* Returns true if action should proceed, false if cancelled.
*/
export function checkLvtConfirm(element: HTMLElement): boolean {
if (element.hasAttribute("lvt-confirm")) {
const confirmMessage = element.getAttribute("lvt-confirm");
if (confirmMessage && !confirm(confirmMessage)) {
return false; // User cancelled
}
}
return true; // Proceed
}
Comment on lines +5 to +13
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkLvtConfirm function lacks test coverage. Given that the repository has comprehensive test coverage for other utility functions (e.g., tests/rate-limit.test.ts for utils/rate-limit.ts), this new utility function should also have tests covering various scenarios including: elements with lvt-confirm attribute where user confirms, elements with lvt-confirm attribute where user cancels, and elements without the attribute.

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +13
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkLvtConfirm function has different behavior than the original code it replaces. The original code in dom/event-delegation.ts provided a default message "Are you sure you want to delete this item?" when lvt-confirm had an empty value. The new implementation will skip the confirmation dialog if the attribute value is empty or null (line 8 condition: if (confirmMessage && !confirm(confirmMessage))). This means elements with lvt-confirm="" will now proceed without confirmation, whereas previously they would show the default message. This could be a breaking change if any code relies on the default message behavior.

Copilot uses AI. Check for mistakes.

/**
* Extract lvt-data-* attributes from an element.
* lvt-data-id="123" becomes { id: "123" }
* lvt-data-user-name="john" becomes { "user-name": "john" }
*/
export function extractLvtData(element: HTMLElement): Record<string, string> {
const data: Record<string, string> = {};
const attributes = element.attributes;

for (let i = 0; i < attributes.length; i++) {
const attr = attributes[i];
if (attr.name.startsWith("lvt-data-")) {
const key = attr.name.substring(9); // Remove "lvt-data-" prefix
data[key] = attr.value;
}
}

return data;
}
Comment on lines +20 to +33
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extractLvtData function lacks test coverage. Given that the repository has comprehensive test coverage for other utility functions (e.g., tests/rate-limit.test.ts for utils/rate-limit.ts), this new utility function should also have tests covering various scenarios including: extracting single attributes, extracting multiple attributes, handling elements without lvt-data attributes, and handling attribute names with hyphens like lvt-data-user-name.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +33
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extractLvtData function duplicates logic that already exists in three places in dom/event-delegation.ts (lines 197-202, 365-370, and 444-449). However, there's a subtle difference: the existing code uses replace("lvt-data-", "") which would only replace the first occurrence, while this new function uses substring(9) which is more correct. Additionally, the existing code applies parseValue() to the attribute values, while this function does not. Consider consolidating this logic into a single reusable function and updating all call sites to use it, ensuring consistent behavior across the codebase.

Copilot uses AI. Check for mistakes.
Loading