@pie-players/pie-tool-calculator-inline-desmos 0.3.73 → 0.3.75

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 CHANGED
@@ -4,126 +4,61 @@ Inline calculator toggle button for PIE assessment player question headers.
4
4
 
5
5
  ## Overview
6
6
 
7
- This package provides the existing `<pie-tool-calculator-inline>` compatibility
8
- element. It wraps the provider-neutral inline surface from
9
- `@pie-players/pie-tool-calculator-shared` and toggles a calculator tool instance.
7
+ `<pie-tool-calculator-inline>` is a toggle button for the calculator an item
8
+ toolbar renders. It wraps the provider-neutral inline surface from
9
+ `@pie-players/pie-tool-calculator-shared`, which the GeoGebra and Cortex inline
10
+ packages share.
10
11
 
11
12
  ## Features
12
13
 
13
- - **Web Component** - Custom element with no shadow DOM for better integration
14
- - **Imperative API** - Services passed as JavaScript properties
15
- - **Coordinator Integration** - Managed by ToolCoordinator for consistent state
14
+ - **Web Component** - Custom element with an open shadow root
15
+ - **Toolkit context** - Takes its ToolCoordinator from the toolkit runtime context and its item from the enclosing item shell
16
+ - **Shared state** - Opens the item toolbar's calculator through the toolkit's tool request path, so the button and the toolbar stay in step and policy applies to both
16
17
  - **Size Variants** - Supports sm, md, lg button sizes
17
18
  - **WCAG 2.2 Level AA** - Fully accessible with proper ARIA attributes
18
19
  - **Material Design Icon** - Calculator icon from Material Design
19
20
 
20
21
  ## Usage
21
22
 
22
- ### Basic Setup
23
-
24
- ```svelte
25
- <!-- Import the component -->
26
- <script>
27
- import '@pie-players/pie-tool-calculator-inline-desmos';
28
- import '@pie-players/pie-tool-calculator-desmos';
29
- import { ToolCoordinator } from '@pie-players/pie-assessment-toolkit';
30
-
31
- const coordinator = new ToolCoordinator();
32
- let calculatorInlineEl;
33
- let calculatorEl;
34
- let calculatorVisible = false;
35
-
36
- // Bind services imperatively (after element creation)
37
- $effect(() => {
38
- if (calculatorInlineEl) {
39
- calculatorInlineEl.coordinator = coordinator;
40
- }
41
- if (calculatorEl) {
42
- calculatorEl.coordinator = coordinator;
43
- }
44
- });
45
-
46
- // Subscribe to visibility changes
47
- $effect(() => {
48
- if (coordinator) {
49
- const unsubscribe = coordinator.subscribe(() => {
50
- calculatorVisible = coordinator.isToolVisible('calculator');
51
- });
52
- return unsubscribe;
53
- }
54
- });
55
- </script>
56
-
57
- <!-- Inline toggle button -->
58
- <pie-tool-calculator-inline
59
- bind:this={calculatorInlineEl}
60
- tool-id="calculator-inline"
61
- calculator-type="scientific"
62
- available-types="basic,scientific,graphing"
63
- size="md"
64
- ></pie-tool-calculator-inline>
65
-
66
- <!-- Calculator tool instance (hidden/shown by coordinator) -->
67
- <pie-tool-calculator
68
- bind:this={calculatorEl}
69
- visible={calculatorVisible}
70
- tool-id="calculator"
71
- ></pie-tool-calculator>
72
- ```
73
-
74
- ### In ItemToolBar
23
+ The element renders inside `<pie-item-scope>` under `<pie-assessment-toolkit>`.
24
+ The toolkit runtime context supplies the ToolCoordinator and the shell supplies
25
+ the item; section players provide both.
75
26
 
76
- The component is designed to work with `pie-item-toolbar`:
27
+ ```javascript
28
+ import '@pie-players/pie-tool-calculator-inline-desmos';
77
29
 
78
- ```svelte
79
- <pie-item-toolbar
80
- item-id="question-1"
81
- tools="tts,answerEliminator,calculator"
82
- size="md"
83
- ></pie-item-toolbar>
30
+ // itemHeader: an element inside <pie-item-scope>
31
+ const calculatorButton = document.createElement('pie-tool-calculator-inline');
32
+ calculatorButton.setAttribute('calculator-type', 'scientific');
33
+ itemHeader.append(calculatorButton);
84
34
  ```
85
35
 
86
- The toolbar will automatically:
87
- 1. Render the calculator inline button
88
- 2. Bind the coordinator imperatively
89
- 3. Manage the calculator visibility state
36
+ The calculator it opens is the item toolbar's: the toolkit's tool configuration
37
+ places `calculator` in the item toolbar and names its provider, and the item
38
+ toolbar renders that calculator. The button adds no calculator of its own and is
39
+ disabled while the toolbar does not render one, as when the item's tool policy
40
+ leaves the calculator out or its module failed to load.
90
41
 
91
42
  ### Props
92
43
 
93
44
  #### Attributes (String)
94
45
 
95
- - `tool-id` - Unique identifier for the tool (default: `'calculator-inline'`)
96
- - `calculator-type` - Default calculator type (default: `'scientific'`)
46
+ - `target-tool-id` - Scoped id of the calculator the button toggles, `<toolId>:<section|item|passage>:<scopeId>` (default: `''`). Empty resolves the enclosing item's calculator, `calculator:item:<itemId>`; set it only to toggle another toolbar's calculator
47
+ - `calculator-type` - Calculator type named in the button's label and announcements (default: `'basic'`); a type outside `available-types` falls back to `'basic'`
97
48
  - `available-types` - Comma-separated list of calculator types (default: `'basic,scientific,graphing'`)
98
49
  - `size` - Button size: `'sm' | 'md' | 'lg'` (default: `'md'`)
99
50
 
100
- #### JavaScript Properties
101
-
102
- - `coordinator` - IToolCoordinator instance (required)
103
-
104
- **Important:** The `coordinator` property must be set via JavaScript, not as an attribute:
105
-
106
- ```javascript
107
- element.coordinator = coordinatorInstance;
108
- ```
109
-
110
- ## Calculator Tool Integration
111
-
112
- This component works in tandem with `@pie-players/pie-tool-calculator-desmos`. The flow is:
113
-
114
- 1. **Button renders** - `pie-tool-calculator-inline` shows a toggle button
115
- 2. **User clicks** - Button calls `coordinator.toggleTool('calculator')`
116
- 3. **Calculator shows/hides** - `pie-tool-calculator` reacts to visibility state
117
- 4. **Button updates** - Active state reflects calculator visibility
118
-
119
- ## Tool ID Convention
120
-
121
- The inline button typically uses a different tool ID than the calculator instance:
51
+ The button is disabled until the toolkit runtime context supplies a
52
+ ToolCoordinator and the target toolbar renders the calculator. With no item
53
+ shell and no valid `target-tool-id`, it stays disabled and logs a console
54
+ warning.
122
55
 
123
- - Inline button: `calculator-inline` or `calculator-inline-{itemId}`
124
- - Calculator tool: `calculator` or `calculator-{itemId}`
56
+ ## Toggle behavior
125
57
 
126
- The component automatically strips `-inline` suffix when checking calculator visibility.
58
+ 1. The button resolves its target from the item shell context: the item toolbar for `<canonicalItemId or itemId>`, which shows the calculator as `calculator:item:<id>`.
59
+ 2. It asks the toolkit coordinator whether a tool request for `calculator` at that level and scope reaches a toolbar (`canRequestTool`), and re-asks when toolbars register or policy changes.
60
+ 3. A click on a closed calculator sends the request (`requestTool`), and the toolbar shows its calculator; a click on an open one hides it.
61
+ 4. `aria-pressed`, the active style and a status announcement follow the target's visibility, including changes made from the toolbar.
127
62
 
128
63
  ## Accessibility
129
64
 
@@ -199,8 +134,7 @@ bun run lint
199
134
 
200
135
  ## Dependencies
201
136
 
202
- - `@pie-players/pie-assessment-toolkit` - Core toolkit services
203
- - `svelte` - Framework (peer dependency)
137
+ - `@pie-players/pie-assessment-toolkit` - Toolkit contexts and scoped tool ids
204
138
 
205
139
  ## License
206
140
 
@@ -0,0 +1,8 @@
1
+ /**
2
+ * pie-tool-calculator-inline-desmos
3
+ *
4
+ * Importing this package registers `<pie-tool-calculator-inline>`. The build
5
+ * entry is the component, so this file is the type entry alone and declares
6
+ * nothing: a runtime export here would not exist in the built bundle.
7
+ */
8
+ export type {};