@telepath-computer/television 1.5.9 → 1.6.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/dist/THIRD-PARTY-NOTICES.txt +701 -0
- package/dist/cli.cjs +9035 -596
- package/dist/onboarding/tv-guide/welcome.html +14 -4
- package/dist/skills/television/SKILL.md +39 -33
- package/dist/skills/television/resources.md +4 -4
- package/dist/skills/television/templates.md +77 -0
- package/dist/skills/television/theming.md +31 -17
- package/dist/templates/calendar/README.md +17 -0
- package/dist/{skills/tv-tasks → templates/calendar}/THIRD-PARTY-NOTICES.txt +22 -22
- package/dist/templates/calendar/calendar-attendees.js +131 -0
- package/dist/templates/calendar/calendar-event.js +22 -0
- package/dist/templates/calendar/calendar-motion.js +273 -0
- package/dist/templates/calendar/calendar-page.js +403 -0
- package/dist/templates/calendar/calendar-time-axis.js +32 -0
- package/dist/templates/calendar/calendar-week.js +711 -0
- package/dist/templates/calendar/data.json +3 -0
- package/dist/templates/calendar/icon.svg +1 -0
- package/dist/templates/calendar/index.html +27 -0
- package/dist/templates/calendar/manifest.json +148 -0
- package/dist/templates/calendar/styles.css +771 -0
- package/dist/templates/checklist/README.md +45 -0
- package/dist/templates/checklist/THIRD-PARTY-NOTICES.txt +29 -0
- package/dist/templates/checklist/data.json +1 -0
- package/dist/templates/checklist/icon.svg +8 -0
- package/dist/templates/checklist/icons.css +61 -0
- package/dist/templates/checklist/index.html +47 -0
- package/dist/templates/checklist/manifest.json +49 -0
- package/dist/templates/checklist/model.d.ts +30 -0
- package/dist/templates/checklist/model.js +60 -0
- package/dist/templates/checklist/page.js +425 -0
- package/dist/templates/checklist/styles.css +206 -0
- package/dist/templates/document/README.md +55 -0
- package/dist/templates/document/THIRD-PARTY-NOTICES.txt +1080 -0
- package/dist/templates/document/data.json +3 -0
- package/dist/templates/document/editor.css +1 -0
- package/dist/templates/document/editor.js +37 -0
- package/dist/templates/document/icon.svg +6 -0
- package/dist/templates/document/index.html +29 -0
- package/dist/templates/document/manifest.json +22 -0
- package/dist/templates/document/page.js +190 -0
- package/dist/templates/document/styles.css +76 -0
- package/dist/templates/map/README.md +85 -0
- package/dist/templates/map/THIRD-PARTY-NOTICES.txt +84 -0
- package/dist/templates/map/data.json +1 -0
- package/dist/templates/map/icon.svg +8 -0
- package/dist/templates/map/icons.svg +43 -0
- package/dist/templates/map/index.html +95 -0
- package/dist/templates/map/manifest.json +227 -0
- package/dist/templates/map/map-model.js +18 -0
- package/dist/templates/map/map.css +202 -0
- package/dist/templates/map/map.js +728 -0
- package/dist/templates/map/vendor/LICENSE +26 -0
- package/dist/templates/map/vendor/README.md +11 -0
- package/dist/templates/map/vendor/leaflet.css +661 -0
- package/dist/templates/map/vendor/leaflet.js +6 -0
- package/dist/templates/map/vendor/lucide/LICENSE +43 -0
- package/dist/templates/map/vendor/lucide/README.md +46 -0
- package/dist/templates/map/vendor/lucide/icons.js +832 -0
- package/dist/templates/map/vendor/lucide/svg/airport.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/bar.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/beach.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/bridge.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/bus.svg +21 -0
- package/dist/templates/map/vendor/lucide/svg/church.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/coffee.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/ferry.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/flag.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/heart.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/home.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/hospital.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/hotel.svg +24 -0
- package/dist/templates/map/vendor/lucide/svg/info.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/landmark.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/mountain.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/museum.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/music.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/park.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/parking.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/pin.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/restaurant.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/school.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/shop.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/sports.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/star.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/theatre.svg +23 -0
- package/dist/templates/map/vendor/lucide/svg/train.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/viewpoint.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/work.svg +18 -0
- package/dist/templates/sticky-note/Caveat-Medium.woff2 +0 -0
- package/dist/templates/sticky-note/README.md +47 -0
- package/dist/templates/sticky-note/THIRD-PARTY-NOTICES.txt +127 -0
- package/dist/templates/sticky-note/data.json +1 -0
- package/dist/templates/sticky-note/icon.svg +16 -0
- package/dist/templates/sticky-note/icons.css +61 -0
- package/dist/templates/sticky-note/index.html +31 -0
- package/dist/templates/sticky-note/manifest.json +27 -0
- package/dist/templates/sticky-note/model.d.ts +33 -0
- package/dist/templates/sticky-note/model.js +152 -0
- package/dist/templates/sticky-note/page.js +84 -0
- package/dist/templates/sticky-note/styles.css +140 -0
- package/dist/templates/table/README.md +107 -0
- package/dist/templates/table/data.json +4 -0
- package/dist/templates/table/icon.svg +6 -0
- package/dist/templates/table/index.html +15 -0
- package/dist/templates/table/manifest.json +70 -0
- package/dist/templates/table/model.d.ts +164 -0
- package/dist/templates/table/model.js +395 -0
- package/dist/templates/table/page.js +1045 -0
- package/dist/templates/table/selection-model.d.ts +67 -0
- package/dist/templates/table/selection-model.js +163 -0
- package/dist/templates/table/styles.css +522 -0
- package/dist/views/markdown/THIRD-PARTY-NOTICES.txt +408 -0
- package/dist/views/markdown/index.html +21 -21
- package/dist/web/assets/main-CRSNodQt.js +864 -0
- package/dist/web/assets/main-DnvQkpg4.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/skills/tv-calendar/SKILL.md +0 -100
- package/dist/skills/tv-calendar/calendar.css +0 -1
- package/dist/skills/tv-calendar/calendar.js +0 -400
- package/dist/skills/tv-table/SKILL.md +0 -95
- package/dist/skills/tv-tasks/SKILL.md +0 -269
- package/dist/skills/tv-tasks/task.css +0 -180
- package/dist/skills/tv-tasks/task.js +0 -304
- package/dist/web/assets/calendar-DToAnkzj.png +0 -0
- package/dist/web/assets/main-CPopSWec.js +0 -848
- package/dist/web/assets/main-CunC2_Nx.css +0 -1
- package/dist/web/assets/markdown-DdDrJuVK.png +0 -0
- package/dist/web/assets/table-oeG9uAN1.png +0 -0
- package/dist/web/assets/tasks-D4xqXFPl.png +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Checklist
|
|
2
|
+
|
|
3
|
+
The page and your agent share this artifact's own JSON store. Changes appear live.
|
|
4
|
+
Set `ARTIFACT_ID` to the artifact ID and `ITEM_KEY` to the key of the item to change.
|
|
5
|
+
|
|
6
|
+
The root has a `title` string and an `items` map. Each item has three fields:
|
|
7
|
+
|
|
8
|
+
- `order`: a finite number. Smaller `order` values appear first; give each item its own `order`.
|
|
9
|
+
- `text`: a string containing the item text.
|
|
10
|
+
- `done`: a boolean indicating whether the item is ticked.
|
|
11
|
+
|
|
12
|
+
Equal `order` values fall back to the store's key order: whole-number keys without leading
|
|
13
|
+
zeros first, numerically, then other keys in UTF-16 order. Adding an item can renumber
|
|
14
|
+
every item, so `order` values are not stable. Read the current items before choosing
|
|
15
|
+
an order. When the page saves item text or done state, it drops extra fields from that item
|
|
16
|
+
and keeps only `order`, `text`, and `done`.
|
|
17
|
+
|
|
18
|
+
If any part of the value breaks this shape, such as an item missing `done`, the page
|
|
19
|
+
shows an error instead of the checklist. Repair the data before editing from the page.
|
|
20
|
+
|
|
21
|
+
Change the title at `title`:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
tv resource json set --artifact "$ARTIFACT_ID" title '"Groceries"'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Add under `items` with an order. The command returns the new key:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
tv resource json push --artifact "$ARTIFACT_ID" items '{"order":0,"text":"Oat milk","done":false}'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Change one item by writing its complete three-field object at its key:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
tv resource json set --artifact "$ARTIFACT_ID" "items/$ITEM_KEY" '{"order":0,"text":"Oat milk","done":true}'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Remove one item at its key:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
tv resource json remove --artifact "$ARTIFACT_ID" "items/$ITEM_KEY"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
These scoped writes leave other items alone.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
TELEVISION THIRD-PARTY LICENSING NOTICES
|
|
2
|
+
|
|
3
|
+
This file contains the license terms and attribution notices for third-party software and materials included in Television.
|
|
4
|
+
================================================================================
|
|
5
|
+
@phosphor-icons/core@2.1.1
|
|
6
|
+
Licensed under MIT.
|
|
7
|
+
--------------------------------------------------------------------------------
|
|
8
|
+
MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2023 Phosphor Icons
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"title":"Checklist","items":{}}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
|
|
2
|
+
<rect x="1.5" y="1.5" width="17" height="17" rx="3.5" fill="#fff" stroke="#d4d4d4"/>
|
|
3
|
+
<rect x="4" y="4" width="5.5" height="5.5" rx="1.5" fill="#2563eb"/>
|
|
4
|
+
<path d="m5.3 6.85 1.25 1.2 2-2.3" fill="none" stroke="#fff" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M11.75 6.75H16" stroke="#a3a3a3" stroke-width="1.75" stroke-linecap="round"/>
|
|
6
|
+
<rect x="4.5" y="11" width="4.5" height="4.5" rx="1.25" fill="none" stroke="#a3a3a3"/>
|
|
7
|
+
<path d="M11.75 13.25H16" stroke="#525252" stroke-width="1.75" stroke-linecap="round"/>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* The icon sizes itself from the text it sits in rather than from a fixed
|
|
2
|
+
pixel size: an icon beside a label should match that label, and an icon in
|
|
3
|
+
a larger control should grow with it, without either one restating a size.
|
|
4
|
+
|
|
5
|
+
Each rule names both scopes this sheet serves — `:host` inside the
|
|
6
|
+
element's shadow root, and `tv-icon:not(:defined)` at document scope,
|
|
7
|
+
where canonical reserves the box before the definition loads so upgrade
|
|
8
|
+
adds a glyph without moving the text around it. In either scope one
|
|
9
|
+
selector of the pair matches nothing, and the box has one authority. */
|
|
10
|
+
:host,
|
|
11
|
+
tv-icon:not(:defined) {
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
flex: none;
|
|
14
|
+
width: 1em;
|
|
15
|
+
height: 1em;
|
|
16
|
+
/* Glyphs are drawn on a square canvas whose visual weight sits below the
|
|
17
|
+
cap height of the text beside them; nudging down aligns their centre with
|
|
18
|
+
the text's rather than with its baseline box. */
|
|
19
|
+
vertical-align: -0.125em;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* An icon that stands alone has no text to take its size from, so `size` names
|
|
23
|
+
one. It sets nothing but the font-size the rule above already reads, so
|
|
24
|
+
there is still one sizing rule — the attribute only changes what its `em`
|
|
25
|
+
resolves against.
|
|
26
|
+
|
|
27
|
+
Whole even pixels rather than a ratio: these are drawings, and a glyph on a
|
|
28
|
+
half-pixel grid blurs in a way a letterform does not. The names match the
|
|
29
|
+
type scale's, though the values deliberately do not — an icon standing on
|
|
30
|
+
its own is larger than the text it would otherwise have sat beside. */
|
|
31
|
+
:host([size="sm"]), tv-icon:not(:defined)[size="sm"] { font-size: 16px; }
|
|
32
|
+
:host([size="md"]), tv-icon:not(:defined)[size="md"] { font-size: 20px; }
|
|
33
|
+
:host([size="lg"]), tv-icon:not(:defined)[size="lg"] { font-size: 24px; }
|
|
34
|
+
:host([size="xl"]), tv-icon:not(:defined)[size="xl"] { font-size: 32px; }
|
|
35
|
+
|
|
36
|
+
/* Phosphor's SVGs already carry fill="currentColor", so colour follows the
|
|
37
|
+
surrounding text with nothing set here. The size does need saying: the
|
|
38
|
+
source has a viewBox and no width or height, so it would otherwise fall
|
|
39
|
+
back to the SVG default rather than filling the element. */
|
|
40
|
+
svg {
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* A spinning icon turns continuously — activity, not decoration. The turn
|
|
46
|
+
is even (linear): any easing reads as the glyph sticking once a second. */
|
|
47
|
+
:host([spinning]) > svg {
|
|
48
|
+
animation: tv-icon-spin 1s linear infinite;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@keyframes tv-icon-spin {
|
|
52
|
+
to {
|
|
53
|
+
rotate: 1turn;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-reduced-motion: reduce) {
|
|
58
|
+
:host([spinning]) > svg {
|
|
59
|
+
animation: none;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Checklist</title>
|
|
7
|
+
<link rel="stylesheet" href="/canonical/v2/styles.css?authoredForAppVersion=1.5.4">
|
|
8
|
+
<link rel="stylesheet" href="./styles.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<main class="checklist-page"></main>
|
|
12
|
+
<template id="checklist-content">
|
|
13
|
+
<h1 class="checklist-title"><span class="checklist-title-text" data-placeholder="Untitled"></span></h1>
|
|
14
|
+
<ul class="checklist-items" role="list"></ul>
|
|
15
|
+
</template>
|
|
16
|
+
<template id="checklist-row">
|
|
17
|
+
<li class="checklist-item">
|
|
18
|
+
<input type="checkbox" class="checklist-check">
|
|
19
|
+
<span class="checklist-text"></span>
|
|
20
|
+
</li>
|
|
21
|
+
</template>
|
|
22
|
+
<!-- Phosphor Icons, MIT. See THIRD-PARTY-NOTICES.txt for the upstream terms. -->
|
|
23
|
+
<template id="checklist-remove">
|
|
24
|
+
<button class="checklist-remove" variant="ghost" icon title="Remove item"><tv-icon name="close"><template shadowrootmode="open" shadowrootserializable="" shadowrootclonable=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"></path></svg></template>
|
|
25
|
+
|
|
26
|
+
</tv-icon></button>
|
|
27
|
+
</template>
|
|
28
|
+
<template id="checklist-add">
|
|
29
|
+
<label class="checklist-add">
|
|
30
|
+
<tv-icon name="add"><template shadowrootmode="open" shadowrootserializable="" shadowrootclonable=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M224,128a8,8,0,0,1-8,8H136v80a8,8,0,0,1-16,0V136H40a8,8,0,0,1,0-16h80V40a8,8,0,0,1,16,0v80h80A8,8,0,0,1,224,128Z"></path></svg></template>
|
|
31
|
+
|
|
32
|
+
</tv-icon>
|
|
33
|
+
<input class="checklist-add-input" type="text" placeholder="Add an item" aria-label="Add an item">
|
|
34
|
+
</label>
|
|
35
|
+
</template>
|
|
36
|
+
<template id="checklist-unreadable">
|
|
37
|
+
<section class="checklist-unreadable" role="alert">
|
|
38
|
+
<span class="checklist-unreadable-icon"><tv-icon name="warning" size="xl"><template shadowrootmode="open" shadowrootserializable="" shadowrootclonable=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M236.8,188.09,149.35,36.22h0a24.76,24.76,0,0,0-42.7,0L19.2,188.09a23.51,23.51,0,0,0,0,23.72A24.35,24.35,0,0,0,40.55,224h174.9a24.35,24.35,0,0,0,21.33-12.19A23.51,23.51,0,0,0,236.8,188.09ZM222.93,203.8a8.5,8.5,0,0,1-7.48,4.2H40.55a8.5,8.5,0,0,1-7.48-4.2,7.59,7.59,0,0,1,0-7.72L120.52,44.21a8.75,8.75,0,0,1,15,0l87.45,151.87A7.59,7.59,0,0,1,222.93,203.8ZM120,144V104a8,8,0,0,1,16,0v40a8,8,0,0,1-16,0Zm20,36a12,12,0,1,1-12-12A12,12,0,0,1,140,180Z"></path></svg></template>
|
|
39
|
+
|
|
40
|
+
</tv-icon></span>
|
|
41
|
+
<h1 class="checklist-unreadable-title">This checklist can't be shown</h1>
|
|
42
|
+
<p class="checklist-unreadable-text">Its saved data isn't in the form this page reads. Ask your agent to check it.</p>
|
|
43
|
+
</section>
|
|
44
|
+
</template>
|
|
45
|
+
<script type="module" src="./page.js"></script>
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Checklist",
|
|
3
|
+
"description": "A list of items to tick off and edit.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"display": {
|
|
6
|
+
"width": 640,
|
|
7
|
+
"height": 800
|
|
8
|
+
},
|
|
9
|
+
"icons": [
|
|
10
|
+
{
|
|
11
|
+
"src": "icon.svg",
|
|
12
|
+
"type": "image/svg+xml"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"dataSchema": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"required": [
|
|
18
|
+
"title",
|
|
19
|
+
"items"
|
|
20
|
+
],
|
|
21
|
+
"properties": {
|
|
22
|
+
"title": {
|
|
23
|
+
"type": "string"
|
|
24
|
+
},
|
|
25
|
+
"items": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"additionalProperties": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"required": [
|
|
30
|
+
"order",
|
|
31
|
+
"text",
|
|
32
|
+
"done"
|
|
33
|
+
],
|
|
34
|
+
"properties": {
|
|
35
|
+
"order": {
|
|
36
|
+
"type": "number"
|
|
37
|
+
},
|
|
38
|
+
"text": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
},
|
|
41
|
+
"done": {
|
|
42
|
+
"type": "boolean"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ChecklistItem {
|
|
2
|
+
order: number;
|
|
3
|
+
text: string;
|
|
4
|
+
done: boolean;
|
|
5
|
+
[field: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ChecklistItems = Record<string, ChecklistItem>;
|
|
9
|
+
|
|
10
|
+
export interface ChecklistData {
|
|
11
|
+
title: string;
|
|
12
|
+
items: ChecklistItems;
|
|
13
|
+
[field: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isItemMap(value: unknown): value is ChecklistItems;
|
|
17
|
+
export function isChecklistData(value: unknown): value is ChecklistData;
|
|
18
|
+
export function compareItemKeys(left: string, right: string): number;
|
|
19
|
+
export function orderedItems(items: ChecklistItems): Array<[string, ChecklistItem]>;
|
|
20
|
+
/** null inserts at the top; undefined or a missing predecessor appends. */
|
|
21
|
+
export function insertionOrder(items: ChecklistItems, afterKey?: string | null): number | null;
|
|
22
|
+
export function createRenumberUpdate(
|
|
23
|
+
newKey: string,
|
|
24
|
+
newItem: Pick<ChecklistItem, "text" | "done">,
|
|
25
|
+
afterKey?: string | null,
|
|
26
|
+
): (current: unknown) => ChecklistItems | undefined;
|
|
27
|
+
export function isCompletionShortcut(
|
|
28
|
+
event: Pick<KeyboardEvent, "key" | "metaKey" | "ctrlKey">,
|
|
29
|
+
platform: string,
|
|
30
|
+
): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function isObject(value) {
|
|
2
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function isItemMap(value) {
|
|
6
|
+
return isObject(value) && Object.values(value).every((item) =>
|
|
7
|
+
isObject(item) && typeof item.text === "string" && typeof item.done === "boolean"
|
|
8
|
+
&& typeof item.order === "number" && Number.isFinite(item.order));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isChecklistData(value) {
|
|
12
|
+
return isObject(value) && typeof value.title === "string" && isItemMap(value.items);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function compareItemKeys(left, right) {
|
|
16
|
+
const leftIndex = /^(?:0|[1-9][0-9]*)$/.test(left);
|
|
17
|
+
const rightIndex = /^(?:0|[1-9][0-9]*)$/.test(right);
|
|
18
|
+
if (leftIndex !== rightIndex) return leftIndex ? -1 : 1;
|
|
19
|
+
if (leftIndex && left.length !== right.length) return left.length - right.length;
|
|
20
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function orderedItems(items) {
|
|
24
|
+
return Object.entries(items).sort(([leftKey, left], [rightKey, right]) =>
|
|
25
|
+
left.order - right.order || compareItemKeys(leftKey, rightKey));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function insertionIndex(entries, afterKey) {
|
|
29
|
+
if (afterKey === null) return 0;
|
|
30
|
+
const predecessor = entries.findIndex(([key]) => key === afterKey);
|
|
31
|
+
return predecessor < 0 ? entries.length : predecessor + 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function insertionOrder(items, afterKey) {
|
|
35
|
+
const entries = orderedItems(items);
|
|
36
|
+
if (entries.length === 0) return 0;
|
|
37
|
+
const index = insertionIndex(entries, afterKey);
|
|
38
|
+
const before = entries[index - 1]?.[1].order;
|
|
39
|
+
const after = entries[index]?.[1].order;
|
|
40
|
+
const sum = before + after;
|
|
41
|
+
// Preserve subnormal midpoints; split only when adding the neighbours overflows.
|
|
42
|
+
const order = before === undefined ? after - 1
|
|
43
|
+
: after === undefined ? before + 1 : Number.isFinite(sum) ? sum / 2 : before / 2 + after / 2;
|
|
44
|
+
return Number.isFinite(order) && (before === undefined || order > before)
|
|
45
|
+
&& (after === undefined || order < after) ? order : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createRenumberUpdate(newKey, newItem, afterKey) {
|
|
49
|
+
return (current) => {
|
|
50
|
+
if (!isItemMap(current)) return undefined;
|
|
51
|
+
const entries = orderedItems(current).filter(([key]) => key !== newKey);
|
|
52
|
+
const inserted = Object.hasOwn(current, newKey) ? current[newKey] : newItem;
|
|
53
|
+
entries.splice(insertionIndex(entries, afterKey), 0, [newKey, inserted]);
|
|
54
|
+
return Object.fromEntries(entries.map(([key, item], order) => [key, { ...item, order }]));
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isCompletionShortcut(event, platform) {
|
|
59
|
+
return event.key === "Enter" && (platform.startsWith("Mac") ? event.metaKey : event.ctrlKey);
|
|
60
|
+
}
|