@classic-homes/theme-svelte 1.20.0 → 1.21.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.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * StudioCanvasItem and the inspector sheet: picking an item opens the
3
+ * inspector on phones, unless the item is edited in place.
4
+ */
5
+ import { describe, it, expect, vi, afterEach } from 'vitest';
6
+ import { mount, unmount, flushSync, createRawSnippet } from 'svelte';
7
+ const revealInspector = vi.fn();
8
+ vi.mock('../lib/components/studio/context.js', () => ({
9
+ getStudioContext: () => ({ revealInspector }),
10
+ setStudioContext: () => { },
11
+ }));
12
+ const { default: StudioCanvasItem } = await import('../lib/components/studio/StudioCanvasItem.svelte');
13
+ let instance = null;
14
+ let host;
15
+ function render(props) {
16
+ host = document.createElement('div');
17
+ document.body.appendChild(host);
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ instance = mount(StudioCanvasItem, {
20
+ target: host,
21
+ props: {
22
+ label: 'Block 1',
23
+ children: createRawSnippet(() => ({ render: () => '<p>Body</p>' })),
24
+ ...props,
25
+ },
26
+ });
27
+ flushSync();
28
+ return host;
29
+ }
30
+ afterEach(() => {
31
+ if (instance)
32
+ unmount(instance);
33
+ instance = null;
34
+ host?.remove();
35
+ revealInspector.mockClear();
36
+ });
37
+ describe('StudioCanvasItem revealOnSelect', () => {
38
+ it('reveals the inspector when picked, by default', () => {
39
+ const el = render({ onSelect: vi.fn() });
40
+ el.querySelector('p').click();
41
+ expect(revealInspector).toHaveBeenCalledTimes(1);
42
+ });
43
+ it('selects without revealing the inspector when edited in place', () => {
44
+ const onSelect = vi.fn();
45
+ const el = render({ onSelect, revealOnSelect: false });
46
+ el.querySelector('p').click();
47
+ expect(onSelect).toHaveBeenCalledTimes(1);
48
+ expect(revealInspector).not.toHaveBeenCalled();
49
+ });
50
+ });
@@ -27,6 +27,11 @@
27
27
  insertLabel?: string;
28
28
  /** Marks the item as having problems */
29
29
  invalid?: boolean;
30
+ /**
31
+ * Open the inspector sheet on phones when the item is picked (default).
32
+ * Turn off for items edited in place, where the sheet would cover them.
33
+ */
34
+ revealOnSelect?: boolean;
30
35
  class?: string;
31
36
  }
32
37
 
@@ -39,6 +44,7 @@
39
44
  onInsert,
40
45
  insertLabel,
41
46
  invalid = false,
47
+ revealOnSelect = true,
42
48
  class: className,
43
49
  }: Props = $props();
44
50
 
@@ -53,7 +59,7 @@
53
59
 
54
60
  function select(reveal: boolean) {
55
61
  if (!selected) onSelect?.();
56
- if (reveal) studio?.revealInspector();
62
+ if (reveal && revealOnSelect) studio?.revealInspector();
57
63
  }
58
64
 
59
65
  $effect(() => {
@@ -22,6 +22,11 @@ interface Props {
22
22
  insertLabel?: string;
23
23
  /** Marks the item as having problems */
24
24
  invalid?: boolean;
25
+ /**
26
+ * Open the inspector sheet on phones when the item is picked (default).
27
+ * Turn off for items edited in place, where the sheet would cover them.
28
+ */
29
+ revealOnSelect?: boolean;
25
30
  class?: string;
26
31
  }
27
32
  declare const StudioCanvasItem: import("svelte").Component<Props, {}, "">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/theme-svelte",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Svelte components for the Classic theme system",
5
5
  "type": "module",
6
6
  "svelte": "./dist/lib/index.js",