cjm-fasthtml-token-selector 0.0.1__py3-none-any.whl
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.
- cjm_fasthtml_token_selector/__init__.py +1 -0
- cjm_fasthtml_token_selector/_modidx.py +104 -0
- cjm_fasthtml_token_selector/components/__init__.py +0 -0
- cjm_fasthtml_token_selector/components/inputs.py +46 -0
- cjm_fasthtml_token_selector/components/tokens.py +217 -0
- cjm_fasthtml_token_selector/core/__init__.py +0 -0
- cjm_fasthtml_token_selector/core/config.py +57 -0
- cjm_fasthtml_token_selector/core/constants.py +50 -0
- cjm_fasthtml_token_selector/core/html_ids.py +51 -0
- cjm_fasthtml_token_selector/core/models.py +37 -0
- cjm_fasthtml_token_selector/helpers/__init__.py +0 -0
- cjm_fasthtml_token_selector/helpers/tokenizer.py +76 -0
- cjm_fasthtml_token_selector/js/__init__.py +0 -0
- cjm_fasthtml_token_selector/js/core.py +181 -0
- cjm_fasthtml_token_selector/js/display.py +146 -0
- cjm_fasthtml_token_selector/js/navigation.py +228 -0
- cjm_fasthtml_token_selector/js/repeat.py +119 -0
- cjm_fasthtml_token_selector/keyboard/__init__.py +0 -0
- cjm_fasthtml_token_selector/keyboard/actions.py +157 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/METADATA +760 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/RECORD +31 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/WHEEL +5 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/entry_points.txt +2 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/licenses/LICENSE +201 -0
- cjm_fasthtml_token_selector-0.0.1.dist-info/top_level.txt +2 -0
- demos/__init__.py +0 -0
- demos/data.py +17 -0
- demos/gap.py +93 -0
- demos/shared.py +148 -0
- demos/span.py +92 -0
- demos/word.py +88 -0
demos/word.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Word mode demo: single word selection for tagging."""
|
|
2
|
+
|
|
3
|
+
from fasthtml.common import APIRouter, Div, P, Span
|
|
4
|
+
|
|
5
|
+
from cjm_fasthtml_daisyui.utilities.semantic_colors import bg_dui, text_dui
|
|
6
|
+
from cjm_fasthtml_tailwind.utilities.spacing import p, m
|
|
7
|
+
from cjm_fasthtml_tailwind.utilities.typography import font_size, font_weight
|
|
8
|
+
from cjm_fasthtml_tailwind.utilities.borders import rounded
|
|
9
|
+
from cjm_fasthtml_tailwind.core.base import combine_classes
|
|
10
|
+
|
|
11
|
+
from cjm_fasthtml_token_selector.core.config import TokenSelectorConfig
|
|
12
|
+
from cjm_fasthtml_token_selector.core.html_ids import TokenSelectorHtmlIds
|
|
13
|
+
from cjm_fasthtml_token_selector.core.models import TokenSelectorState
|
|
14
|
+
from cjm_fasthtml_token_selector.helpers.tokenizer import tokenize, get_token_list
|
|
15
|
+
|
|
16
|
+
from demos.data import WORD_TEXT
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def setup(route_prefix="/word"):
|
|
20
|
+
"""Set up the word mode token selector demo."""
|
|
21
|
+
config = TokenSelectorConfig(prefix="word", selection_mode="word")
|
|
22
|
+
ids = TokenSelectorHtmlIds(prefix=config.prefix)
|
|
23
|
+
tokens = tokenize(WORD_TEXT)
|
|
24
|
+
state = TokenSelectorState(anchor=0, focus=0, word_count=len(tokens))
|
|
25
|
+
|
|
26
|
+
MODE_NAME = "token-select"
|
|
27
|
+
CONFIRM_BTN = "word-confirm-btn"
|
|
28
|
+
CANCEL_BTN = "word-cancel-btn"
|
|
29
|
+
RESULT_ID = "word-result"
|
|
30
|
+
|
|
31
|
+
router = APIRouter(prefix=route_prefix)
|
|
32
|
+
|
|
33
|
+
@router
|
|
34
|
+
def confirm(kw:dict):
|
|
35
|
+
"""Handle word selection confirm."""
|
|
36
|
+
anchor = int(kw.get(ids.anchor_name, 0))
|
|
37
|
+
word_list = get_token_list(WORD_TEXT)
|
|
38
|
+
selected = word_list[anchor] if 0 <= anchor < len(word_list) else "(none)"
|
|
39
|
+
|
|
40
|
+
return Div(
|
|
41
|
+
P("Selected Word:",
|
|
42
|
+
cls=combine_classes(font_weight.semibold, m.b(2))),
|
|
43
|
+
P(Span(selected,
|
|
44
|
+
cls=combine_classes(font_size.xl, font_weight.bold)),
|
|
45
|
+
cls=m.b(2)),
|
|
46
|
+
P(f"Token index: {anchor}",
|
|
47
|
+
cls=combine_classes(font_size.sm, text_dui.base_content)),
|
|
48
|
+
id=RESULT_ID,
|
|
49
|
+
hx_swap_oob="true",
|
|
50
|
+
cls=combine_classes(p(4), bg_dui.base_200, rounded.lg, m.b(4)),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
@router
|
|
54
|
+
def cancel(kw:dict):
|
|
55
|
+
"""Handle word selection cancel."""
|
|
56
|
+
return Div(
|
|
57
|
+
P("Selection cancelled. Press Enter to try again.",
|
|
58
|
+
cls=combine_classes(text_dui.base_content, font_size.sm)),
|
|
59
|
+
id=RESULT_ID,
|
|
60
|
+
hx_swap_oob="true",
|
|
61
|
+
cls=combine_classes(p(4), bg_dui.base_200, rounded.lg, m.b(4)),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return dict(
|
|
65
|
+
config=config,
|
|
66
|
+
ids=ids,
|
|
67
|
+
tokens=tokens,
|
|
68
|
+
state=state,
|
|
69
|
+
router=router,
|
|
70
|
+
mode_name=MODE_NAME,
|
|
71
|
+
confirm_btn_id=CONFIRM_BTN,
|
|
72
|
+
cancel_btn_id=CANCEL_BTN,
|
|
73
|
+
confirm_url=confirm.to(),
|
|
74
|
+
cancel_url=cancel.to(),
|
|
75
|
+
result_id=RESULT_ID,
|
|
76
|
+
title="Word Mode",
|
|
77
|
+
description=(
|
|
78
|
+
"Select individual words by highlighting them. "
|
|
79
|
+
"Good for tagging or marking specific tokens."
|
|
80
|
+
),
|
|
81
|
+
keyboard_hints=[
|
|
82
|
+
"Enter \u2014 Activate token select mode",
|
|
83
|
+
"Left/Right \u2014 Move highlight between words",
|
|
84
|
+
"Home/End \u2014 Jump to first/last word",
|
|
85
|
+
"Enter/Space \u2014 Confirm selected word",
|
|
86
|
+
"Escape \u2014 Cancel selection",
|
|
87
|
+
],
|
|
88
|
+
)
|