@gramlot/gramlot 0.3.20 → 0.3.26
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/components/chat/__init__.py +13 -0
- package/dist/components/chat/assets/collection.js +9 -0
- package/dist/components/chat/assets/index.js +3 -0
- package/dist/components/chat/commands.json +7 -0
- package/dist/components/chat/grammar.json +48 -0
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +26 -120912
- package/dist/components/editors/assets/index.js +2 -1
- package/dist/components/editors/assets/modules/chunk-74O4WKIV.js +1 -0
- package/dist/components/editors/assets/modules/chunk-AU4HFPIY.js +1 -0
- package/dist/components/editors/assets/modules/chunk-YSGSC7KM.js +1 -0
- package/dist/components/editors/assets/modules/code-mirror-engine-RWQTR5G5.js +92 -0
- package/dist/components/editors/assets/modules/jodit-engine-MTSA4GZ3.js +1853 -0
- package/dist/components/editors/assets/modules/markdown-document-VFC23FAY.js +1 -0
- package/dist/components/editors/assets/modules/prose-mirror-engine-GMZPJPNN.js +24 -0
- package/dist/components/grid/__init__.py +14 -0
- package/dist/components/grid/assets/collection.js +262 -0
- package/dist/components/grid/assets/index.js +3 -0
- package/dist/components/grid/commands.json +7 -0
- package/dist/components/grid/grammar.json +770 -0
- package/dist/components/grouplets/__init__.py +13 -0
- package/dist/components/grouplets/assets/collection.js +185 -0
- package/dist/components/grouplets/assets/index.js +3 -0
- package/dist/components/grouplets/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/grouplets/assets/modules/markdown-document-YWNZTOKK.js +1 -0
- package/dist/components/grouplets/commands.json +7 -0
- package/dist/components/grouplets/grammar.json +355 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +65 -24511
- package/dist/components/inputs/assets/index.js +2 -1
- package/dist/components/inputs/grammar.json +278 -6
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +68 -26732
- package/dist/components/layout/assets/index.js +2 -1
- package/dist/components/layout/grammar.json +39 -0
- package/dist/components/selection_trial/__init__.py +13 -0
- package/dist/components/selection_trial/assets/collection.js +4 -0
- package/dist/components/selection_trial/assets/index.js +3 -0
- package/dist/components/selection_trial/commands.json +7 -0
- package/dist/components/selection_trial/grammar.json +587 -0
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +27 -24612
- package/dist/components/tree/assets/index.js +2 -1
- package/dist/components/tree/grammar.json +341 -1
- package/dist/components/typst/__init__.py +2 -2
- package/dist/components/typst/assets/collection.js +12 -4
- package/dist/components/typst/assets/index.js +2 -1
- package/dist/components/typst/assets/modules/chunk-BLMUM44K.js +1 -0
- package/dist/components/typst/assets/modules/typst-client-JHC6UVYG.js +4 -0
- package/dist/components/uploads/__init__.py +13 -0
- package/dist/components/uploads/assets/collection.js +67 -0
- package/dist/components/uploads/assets/index.js +3 -0
- package/dist/components/uploads/commands.json +7 -0
- package/dist/components/uploads/grammar.json +789 -0
- package/dist/gramlot-markdown.js +16 -0
- package/dist/gramlot.js +6861 -1395
- package/dist/gramlot.min.js +1595 -46
- package/dist/runtime-notices.json +28 -0
- package/package.json +10 -3
- package/src/binding/grid-struct.js +63 -0
- package/src/binding/installation.js +5 -2
- package/src/binding/providers.js +4 -1
- package/src/binding/remote-resolver.js +1 -8
- package/src/binding/runtime.js +90 -6
- package/src/binding/validation-context.js +40 -0
- package/src/browser-camera-provider.d.ts +8 -0
- package/src/browser-camera-provider.js +104 -0
- package/src/builder/gramlot-builder.d.ts +5 -0
- package/src/builder/gramlot-builder.js +16 -0
- package/src/builder/source.js +34 -0
- package/src/chat.d.ts +12 -0
- package/src/chat.js +198 -0
- package/src/collection-artifact.js +1 -1
- package/src/components/attachment-manager.js +160 -0
- package/src/components/bases.js +19 -6
- package/src/components/border-container.js +86 -8
- package/src/components/buttons.js +11 -1
- package/src/components/chat.js +28 -0
- package/src/components/choice-editor.js +106 -38
- package/src/components/database-choices.js +133 -9
- package/src/components/editing-status-styles.js +26 -0
- package/src/components/editing-status.js +115 -0
- package/src/components/field-state.js +42 -54
- package/src/components/grid-cell-editor.js +181 -0
- package/src/components/grid-grammar.json +258 -0
- package/src/components/grid-header-interaction.js +196 -0
- package/src/components/grid-row-interaction.js +184 -0
- package/src/components/grid-row-layout.js +96 -0
- package/src/components/grid-rows.js +28 -0
- package/src/components/grid-search-box.js +142 -0
- package/src/components/grid-search-styles.js +42 -0
- package/src/components/grid-search.js +37 -0
- package/src/components/grid-structure.js +85 -0
- package/src/components/grid-styles.js +201 -0
- package/src/components/grid.js +666 -0
- package/src/components/grouplet-card.js +445 -0
- package/src/components/grouplets.js +17 -0
- package/src/components/html-preview.js +17 -4
- package/src/components/image-crop-dialog.js +272 -0
- package/src/components/image-crop.js +79 -0
- package/src/components/image-uploader.js +252 -0
- package/src/components/inputs.js +2 -1
- package/src/components/jodit-engine.js +1 -1
- package/src/components/markdown-document.js +2 -2
- package/src/components/menus.js +1 -0
- package/src/components/registry.js +4 -3
- package/src/components/screen-capture.js +43 -0
- package/src/components/selected-container.js +6 -2
- package/src/components/tray-pane.js +32 -4
- package/src/components/tree.js +416 -17
- package/src/components/typed-editor.js +23 -11
- package/src/components/upload-engine.js +156 -0
- package/src/components/uploader.js +208 -0
- package/src/components/uploads.js +7 -0
- package/src/editing-session.d.ts +25 -0
- package/src/editing-session.js +396 -0
- package/src/experiments/selection-transfer.js +78 -0
- package/src/experiments/selection-trial.js +64 -0
- package/src/experiments/window-selection.js +124 -0
- package/src/format.js +22 -7
- package/src/gramlot.d.ts +2 -0
- package/src/gramlot.js +2 -1
- package/src/handlers/device-handler.d.ts +2 -1
- package/src/handlers/rpc-handler.d.ts +3 -3
- package/src/index-page-styles.js +2 -1
- package/src/index.d.ts +16 -1
- package/src/index.js +16 -1
- package/src/inout.d.ts +2 -0
- package/src/inout.js +6 -0
- package/src/markdown-loader.d.ts +1 -0
- package/src/markdown-loader.js +4 -0
- package/src/markdown.d.ts +1 -0
- package/src/markdown.js +2 -0
- package/src/media-frame.js +9 -0
- package/src/renderer/attributes.js +7 -1
- package/src/renderer/gramlot-renderer.d.ts +2 -0
- package/src/renderer/gramlot-renderer.js +39 -3
- package/src/server/assets.d.ts +1 -1
- package/src/server/assets.js +1 -1
- package/src/server/gramlot-server.d.ts +10 -1
- package/src/server/gramlot-server.js +96 -8
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +2 -0
- package/src/server/page-base.js +17 -4
- package/src/server/page.d.ts +13 -1
- package/src/server/page.js +6 -0
- package/src/server/source-import.d.ts +2 -0
- package/src/server/source-import.js +31 -0
- package/src/server/upload.d.ts +20 -0
- package/src/server/upload.js +142 -0
- package/src/server/visual-editor.d.ts +11 -0
- package/src/server/visual-editor.js +149 -0
- package/src/source-picker.d.ts +9 -0
- package/src/source-picker.js +57 -0
- package/src/stores/bag-collection-store.js +51 -0
- package/src/stores/bag-collection-view.js +127 -0
- package/src/stores/collection-filter.js +77 -0
- package/src/tree-store.d.ts +24 -0
- package/src/tree-store.js +193 -0
- package/src/validation-run.js +50 -0
- package/src/view/button.js +8 -5
- package/src/view/controls.js +31 -32
- package/src/view/grouplet-card.js +54 -0
- package/src/view/html.js +29 -4
- package/src/view/labelbox.js +7 -3
- package/src/visual-editor-icons.js +10 -0
- package/src/visual-editor.d.ts +56 -0
- package/src/visual-editor.js +844 -0
- package/themes/gramlot-base/theme.css +127 -0
- package/themes/gramlot-compact/theme.css +8 -0
- package/themes/joanna/theme.css +8 -0
- package/themes/mimi/theme.css +8 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/** A remote Source body with Data-bound card presentation. */
|
|
2
|
+
import {defineComponent} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {labelboxContent} from '../view/labelbox.js';
|
|
5
|
+
import {positionPopup} from './popup.js';
|
|
6
|
+
|
|
7
|
+
export const GroupletCard = defineComponent({
|
|
8
|
+
name: 'groupletCard', tag: 'gramlot-grouplet-card', base: Container,
|
|
9
|
+
subTags: '*', sourceContext: true,
|
|
10
|
+
parameters: {
|
|
11
|
+
remote: {dtype: 'T', nullable: true, binding: 'read'},
|
|
12
|
+
title: {dtype: 'T', default: '', qualification: 'intl_str', binding: 'read'},
|
|
13
|
+
chromeSide: {dtype: 'T', default: 'top', enum: ['top', 'left', 'right'], binding: 'read'},
|
|
14
|
+
collapsible: {dtype: 'B', default: false, binding: 'read'},
|
|
15
|
+
collapsed: {dtype: 'B', default: false, binding: 'twoWay'},
|
|
16
|
+
checkbox: {dtype: 'B', nullable: true, default: null, binding: 'twoWay'},
|
|
17
|
+
checkboxLabel: {dtype: 'T', default: '', qualification: 'intl_str', binding: 'read'},
|
|
18
|
+
delitem: {dtype: 'B', nullable: true, default: null, binding: 'read'},
|
|
19
|
+
doc: {dtype: 'T', default: '', binding: 'read'},
|
|
20
|
+
},
|
|
21
|
+
implementation: Base => class extends Base {
|
|
22
|
+
#context;
|
|
23
|
+
#observer;
|
|
24
|
+
#menu;
|
|
25
|
+
#ownMenu;
|
|
26
|
+
#docEvents;
|
|
27
|
+
#docText;
|
|
28
|
+
#markdown;
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
const doc = this.ownerDocument;
|
|
32
|
+
const style = doc.createElement('style');
|
|
33
|
+
style.textContent = `
|
|
34
|
+
:host {
|
|
35
|
+
border: 1px solid var(--gramlot-border-control, #aaa);
|
|
36
|
+
border-radius: var(--gramlot-window-radius, 8px);
|
|
37
|
+
background: var(--gramlot-surface, Canvas);
|
|
38
|
+
}
|
|
39
|
+
.card-shell {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
min-width: 0;
|
|
43
|
+
border-radius: inherit;
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
}
|
|
46
|
+
.card-header {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
gap: .65rem;
|
|
50
|
+
padding: .6rem .85rem;
|
|
51
|
+
min-width: 0;
|
|
52
|
+
background: var(--gramlot-card-header-background, var(--gramlot-header-background, #303946));
|
|
53
|
+
color: var(--gramlot-card-header-color, var(--gramlot-header-color, #fff));
|
|
54
|
+
}
|
|
55
|
+
button {
|
|
56
|
+
font: inherit;
|
|
57
|
+
color: inherit;
|
|
58
|
+
background: transparent;
|
|
59
|
+
border: 0;
|
|
60
|
+
border-radius: var(--gramlot-radius-sm, 4px);
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
button:focus-visible,
|
|
64
|
+
input:focus-visible {
|
|
65
|
+
outline: 2px solid var(--gramlot-focus-ring, Highlight);
|
|
66
|
+
outline-offset: 2px;
|
|
67
|
+
}
|
|
68
|
+
.card-title {
|
|
69
|
+
flex: 1;
|
|
70
|
+
min-width: 0;
|
|
71
|
+
padding: 0;
|
|
72
|
+
font-size: 1rem;
|
|
73
|
+
font-weight: 600;
|
|
74
|
+
line-height: 1.5;
|
|
75
|
+
text-align: start;
|
|
76
|
+
overflow-wrap: break-word;
|
|
77
|
+
}
|
|
78
|
+
.card-title:disabled {
|
|
79
|
+
opacity: 1;
|
|
80
|
+
cursor: default;
|
|
81
|
+
}
|
|
82
|
+
.card-collapse {
|
|
83
|
+
display: grid;
|
|
84
|
+
place-items: center;
|
|
85
|
+
flex: none;
|
|
86
|
+
min-width: var(--gramlot-touch-target, 36px);
|
|
87
|
+
min-height: var(--gramlot-touch-target, 36px);
|
|
88
|
+
padding: .5rem;
|
|
89
|
+
font-size: 0;
|
|
90
|
+
}
|
|
91
|
+
.card-collapse::before {
|
|
92
|
+
content: '';
|
|
93
|
+
width: .5rem;
|
|
94
|
+
height: .5rem;
|
|
95
|
+
border-right: 2px solid currentColor;
|
|
96
|
+
border-bottom: 2px solid currentColor;
|
|
97
|
+
transform: translateY(-2px) rotate(45deg);
|
|
98
|
+
}
|
|
99
|
+
.card-collapse:hover,
|
|
100
|
+
.card-actions:hover,
|
|
101
|
+
.card-doc-button:hover,
|
|
102
|
+
.card-doc-close:hover,
|
|
103
|
+
.card-title:not(:disabled):hover {
|
|
104
|
+
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
105
|
+
}
|
|
106
|
+
.card-check {
|
|
107
|
+
flex: none;
|
|
108
|
+
width: 1.2rem;
|
|
109
|
+
height: 1.2rem;
|
|
110
|
+
margin: .4rem;
|
|
111
|
+
accent-color: var(--gramlot-action, Highlight);
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
}
|
|
114
|
+
.card-check-label {
|
|
115
|
+
display: flex;
|
|
116
|
+
align-items: center;
|
|
117
|
+
gap: .35rem;
|
|
118
|
+
min-width: 0;
|
|
119
|
+
max-width: 100%;
|
|
120
|
+
font-size: .9rem;
|
|
121
|
+
line-height: 1.4;
|
|
122
|
+
cursor: pointer;
|
|
123
|
+
}
|
|
124
|
+
.card-check-label > .card-check { margin: .25rem 0; }
|
|
125
|
+
.card-check-caption {
|
|
126
|
+
min-width: 0;
|
|
127
|
+
overflow-wrap: anywhere;
|
|
128
|
+
}
|
|
129
|
+
.card-actions {
|
|
130
|
+
flex: none;
|
|
131
|
+
min-height: var(--gramlot-touch-target, 36px);
|
|
132
|
+
padding: .35rem .5rem;
|
|
133
|
+
font-size: .9rem;
|
|
134
|
+
}
|
|
135
|
+
.card-header { flex-wrap: wrap; }
|
|
136
|
+
.card-doc-button, .card-doc-close {
|
|
137
|
+
flex: none;
|
|
138
|
+
min-height: var(--gramlot-touch-target, 36px);
|
|
139
|
+
min-width: var(--gramlot-touch-target, 36px);
|
|
140
|
+
padding: .35rem .5rem;
|
|
141
|
+
}
|
|
142
|
+
.card-doc-popup {
|
|
143
|
+
position: fixed;
|
|
144
|
+
inset: auto;
|
|
145
|
+
margin: 0;
|
|
146
|
+
padding: 0;
|
|
147
|
+
width: 34rem;
|
|
148
|
+
max-width: var(--gramlot-popup-available-width, calc(100vw - 16px));
|
|
149
|
+
max-height: var(--gramlot-popup-available-height, calc(100vh - 16px));
|
|
150
|
+
overflow: auto;
|
|
151
|
+
border: 1px solid var(--gramlot-border-control, #aaa);
|
|
152
|
+
border-radius: var(--gramlot-window-radius, 8px);
|
|
153
|
+
background: var(--gramlot-surface, Canvas);
|
|
154
|
+
color: var(--gramlot-ink, CanvasText);
|
|
155
|
+
box-shadow: 0 8px 28px #0003;
|
|
156
|
+
font-size: max(1rem, 15px);
|
|
157
|
+
line-height: 1.6;
|
|
158
|
+
overflow-wrap: anywhere;
|
|
159
|
+
}
|
|
160
|
+
.card-doc-heading {
|
|
161
|
+
display: flex;
|
|
162
|
+
align-items: center;
|
|
163
|
+
gap: 1rem;
|
|
164
|
+
padding: .6rem 1rem;
|
|
165
|
+
border-bottom: 1px solid var(--gramlot-border-control, #aaa);
|
|
166
|
+
}
|
|
167
|
+
.card-doc-heading h2 { flex: 1; font-size: 1.1em; margin: 0; }
|
|
168
|
+
.card-doc-body { padding: .25rem 1.25rem 1rem; }
|
|
169
|
+
.card-doc-body :is(h1, h2, h3) { font-size: 1.05em; line-height: 1.4; }
|
|
170
|
+
.card-doc-body :is(ul, ol) { padding-inline-start: 1.5rem; }
|
|
171
|
+
.card-doc-body li + li { margin-top: .4rem; }
|
|
172
|
+
.card-doc-body a { color: var(--gramlot-action, LinkText); }
|
|
173
|
+
.card-doc-body pre { overflow: auto; }
|
|
174
|
+
.card-doc-body img { max-width: 100%; }
|
|
175
|
+
.card-doc-body table { display: block; overflow: auto; border-collapse: collapse; }
|
|
176
|
+
.card-doc-body :is(th, td) { border: 1px solid var(--gramlot-border-control, #aaa); padding: .3rem .5rem; }
|
|
177
|
+
.control-box {
|
|
178
|
+
flex: 1;
|
|
179
|
+
min-width: 0;
|
|
180
|
+
padding: 1.25rem;
|
|
181
|
+
}
|
|
182
|
+
[hidden] { display: none !important; }
|
|
183
|
+
|
|
184
|
+
/* Side headers occupy their content height, not a solid wall. */
|
|
185
|
+
.card-shell[data-side=left],
|
|
186
|
+
.card-shell[data-side=right] {
|
|
187
|
+
flex-direction: row;
|
|
188
|
+
align-items: flex-start;
|
|
189
|
+
}
|
|
190
|
+
.card-shell[data-side=right] > .card-header { order: 1; }
|
|
191
|
+
.card-shell:not([data-side=top]) > .card-header {
|
|
192
|
+
flex: 0 0 8rem;
|
|
193
|
+
flex-direction: column;
|
|
194
|
+
align-items: flex-start;
|
|
195
|
+
max-width: 35%;
|
|
196
|
+
gap: .5rem;
|
|
197
|
+
padding: .75rem;
|
|
198
|
+
}
|
|
199
|
+
.card-shell[data-side=left] > .card-header { border-bottom-right-radius: .5rem; }
|
|
200
|
+
.card-shell[data-side=right] > .card-header { border-bottom-left-radius: .5rem; }
|
|
201
|
+
.card-shell:not([data-side=top]) > .card-header > .card-title { flex: 0; }
|
|
202
|
+
|
|
203
|
+
.card-shell[data-collapsed] { display: block; }
|
|
204
|
+
.card-shell[data-collapsed] > .card-header {
|
|
205
|
+
flex-direction: row;
|
|
206
|
+
align-items: center;
|
|
207
|
+
width: auto;
|
|
208
|
+
max-width: none;
|
|
209
|
+
border-radius: 0;
|
|
210
|
+
}
|
|
211
|
+
.card-shell[data-collapsed] > .card-header > .card-title { flex: 1; }
|
|
212
|
+
.card-shell[data-collapsed] > .card-header > .card-collapse::before {
|
|
213
|
+
transform: translateX(-2px) rotate(-45deg);
|
|
214
|
+
}
|
|
215
|
+
`;
|
|
216
|
+
this.shell = doc.createElement('div'); this.shell.className = 'card-shell';
|
|
217
|
+
this.header = doc.createElement('div'); this.header.className = 'card-header';
|
|
218
|
+
this.collapseButton = doc.createElement('button');
|
|
219
|
+
this.collapseButton.type = 'button'; this.collapseButton.className = 'card-collapse';
|
|
220
|
+
this.collapseButton.setAttribute('aria-controls', 'control');
|
|
221
|
+
this.heading = doc.createElement('button');
|
|
222
|
+
this.heading.type = 'button'; this.heading.className = 'card-title';
|
|
223
|
+
this.heading.setAttribute('aria-controls', 'control');
|
|
224
|
+
this.check = doc.createElement('input');
|
|
225
|
+
this.check.type = 'checkbox'; this.check.className = 'card-check';
|
|
226
|
+
this.checkLabel = doc.createElement('label'); this.checkLabel.className = 'card-check-label';
|
|
227
|
+
this.checkCaption = doc.createElement('span'); this.checkCaption.className = 'card-check-caption';
|
|
228
|
+
this.checkLabel.append(this.check, this.checkCaption);
|
|
229
|
+
this.actionsButton = doc.createElement('button');
|
|
230
|
+
this.actionsButton.type = 'button'; this.actionsButton.className = 'card-actions';
|
|
231
|
+
this.actionsButton.textContent = 'Actions ⋮';
|
|
232
|
+
this.actionsButton.setAttribute('aria-haspopup', 'menu');
|
|
233
|
+
this.actionsButton.setAttribute('aria-expanded', 'false');
|
|
234
|
+
this.actionsButton.hidden = true;
|
|
235
|
+
const menuSlot = doc.createElement('slot'); menuSlot.name = 'card-menu';
|
|
236
|
+
this.docButton = doc.createElement('button');
|
|
237
|
+
this.docButton.type = 'button'; this.docButton.className = 'card-doc-button';
|
|
238
|
+
this.docButton.textContent = 'ⓘ'; this.docButton.hidden = true;
|
|
239
|
+
this.docButton.setAttribute('aria-haspopup', 'dialog');
|
|
240
|
+
this.docButton.setAttribute('aria-controls', 'card-doc');
|
|
241
|
+
this.docButton.setAttribute('aria-expanded', 'false');
|
|
242
|
+
this.docPopup = doc.createElement('section');
|
|
243
|
+
this.docPopup.id = 'card-doc'; this.docPopup.className = 'card-doc-popup';
|
|
244
|
+
this.docPopup.setAttribute('popover', 'manual');
|
|
245
|
+
this.docPopup.setAttribute('role', 'dialog');
|
|
246
|
+
this.docPopup.setAttribute('aria-labelledby', 'card-doc-title');
|
|
247
|
+
const docHeading = doc.createElement('div'); docHeading.className = 'card-doc-heading';
|
|
248
|
+
this.docTitle = doc.createElement('h2'); this.docTitle.id = 'card-doc-title';
|
|
249
|
+
this.docClose = doc.createElement('button');
|
|
250
|
+
this.docClose.type = 'button'; this.docClose.className = 'card-doc-close';
|
|
251
|
+
this.docClose.textContent = 'Close'; this.docClose.setAttribute('aria-label', 'Close guide');
|
|
252
|
+
docHeading.append(this.docTitle, this.docClose);
|
|
253
|
+
this.docBody = doc.createElement('div'); this.docBody.className = 'card-doc-body';
|
|
254
|
+
this.docPopup.append(docHeading, this.docBody);
|
|
255
|
+
this.header.append(this.collapseButton, this.heading, this.docButton, this.checkLabel, this.actionsButton);
|
|
256
|
+
this.shell.append(this.header, this.controlBox);
|
|
257
|
+
this.shadowRoot.append(style, this.shell, menuSlot, this.docPopup);
|
|
258
|
+
this.docButton.addEventListener('click', event => {
|
|
259
|
+
event.stopPropagation();
|
|
260
|
+
if (this.#docEvents) this.closeDoc(); else this.openDoc();
|
|
261
|
+
});
|
|
262
|
+
this.docClose.addEventListener('click', event => { event.stopPropagation(); this.closeDoc(); });
|
|
263
|
+
this.docPopup.addEventListener('click', event => event.stopPropagation());
|
|
264
|
+
this.controlBox.setAttribute('role', 'group');
|
|
265
|
+
this.controlBox.tabIndex = -1;
|
|
266
|
+
this.collapseButton.addEventListener('click', event => {
|
|
267
|
+
event.stopPropagation();
|
|
268
|
+
if (this.isConnected && this.parameters.collapsible)
|
|
269
|
+
this.#context.writeParameter('collapsed', !this.parameters.collapsed);
|
|
270
|
+
});
|
|
271
|
+
this.heading.addEventListener('click', event => {
|
|
272
|
+
event.stopPropagation();
|
|
273
|
+
if (this.isConnected && this.parameters.collapsible && this.parameters.collapsed)
|
|
274
|
+
this.#context.writeParameter('collapsed', false);
|
|
275
|
+
});
|
|
276
|
+
this.check.addEventListener('click', event => event.stopPropagation());
|
|
277
|
+
this.checkLabel.addEventListener('click', event => event.stopPropagation());
|
|
278
|
+
this.check.addEventListener('change', event => {
|
|
279
|
+
event.stopPropagation();
|
|
280
|
+
if (this.isConnected && this.parameters.checkbox !== null) {
|
|
281
|
+
this.#context.writeParameter('checkbox', this.check.checked);
|
|
282
|
+
// A literal or read-only pointer cannot acquire local UI state.
|
|
283
|
+
this.check.checked = this.parameters.checkbox;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
this.actionsButton.addEventListener('click', event => {
|
|
287
|
+
event.stopPropagation();
|
|
288
|
+
if (this.actionsMenu?.opened) this.actionsMenu.close(); else this.openMenu();
|
|
289
|
+
});
|
|
290
|
+
this.actionsButton.addEventListener('keydown', event => {
|
|
291
|
+
if (['ArrowDown', 'ArrowUp'].includes(event.key)) {
|
|
292
|
+
event.preventDefault(); event.stopPropagation(); this.openMenu(event.key === 'ArrowUp');
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
this.#observer = new this.ownerDocument.defaultView.MutationObserver(() => this.refreshMenu());
|
|
296
|
+
}
|
|
297
|
+
setSourceContext(context) { this.#context = context; }
|
|
298
|
+
connectedCallback() {
|
|
299
|
+
this.#observer.observe(this, {childList: true});
|
|
300
|
+
this.refreshMenu();
|
|
301
|
+
}
|
|
302
|
+
disconnectedCallback() {
|
|
303
|
+
this.closeDoc(false);
|
|
304
|
+
this.#observer.disconnect();
|
|
305
|
+
this.actionsMenu?.close(false);
|
|
306
|
+
this.clearItem?.remove();
|
|
307
|
+
this.#menu = null;
|
|
308
|
+
}
|
|
309
|
+
get actionsMenu() { return this.#menu; }
|
|
310
|
+
refreshMenu() {
|
|
311
|
+
if (!this.parameters || !this.isConnected) return;
|
|
312
|
+
const menus = [...this.children].map(labelboxContent).filter(child => child.localName === 'gramlot-menu');
|
|
313
|
+
if (menus.length > 1 || menus[0]?.permanent) throw new TypeError('groupletCard accepts one direct popup menu');
|
|
314
|
+
const hasClear = this.parameters.delitem !== null;
|
|
315
|
+
if (!menus.length && hasClear && !this.#ownMenu) {
|
|
316
|
+
this.#ownMenu = this.ownerDocument.createElement('gramlot-menu');
|
|
317
|
+
this.#ownMenu.projectAttributes({});
|
|
318
|
+
this.shadowRoot.append(this.#ownMenu);
|
|
319
|
+
}
|
|
320
|
+
const menu = menus[0] ?? (hasClear ? this.#ownMenu : null);
|
|
321
|
+
if (this.#menu !== menu) {
|
|
322
|
+
this.#menu?.close(false);
|
|
323
|
+
this.clearItem?.remove();
|
|
324
|
+
this.#menu = menu;
|
|
325
|
+
}
|
|
326
|
+
if (menus[0]) menus[0].slot = 'card-menu';
|
|
327
|
+
this.actionsButton.hidden = !menu;
|
|
328
|
+
this.actionsButton.setAttribute('aria-label', `Actions for ${this.parameters.title || 'card'}`);
|
|
329
|
+
if (!menu) return;
|
|
330
|
+
if (hasClear) {
|
|
331
|
+
if (!this.clearItem) {
|
|
332
|
+
this.clearItem = this.ownerDocument.createElement('gramlot-menu-line');
|
|
333
|
+
this.clearItem.addEventListener('click', event => {
|
|
334
|
+
event.stopPropagation();
|
|
335
|
+
if (!this.isConnected || this.clearItem.disabled) return;
|
|
336
|
+
this.actionsMenu.close();
|
|
337
|
+
this.cardActions.clear().catch(error => this.#context.reportError(error, 'Clear card fields'));
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
this.clearItem.projectAttributes({caption: 'Clear', disabled: this.parameters.delitem !== true});
|
|
341
|
+
if (this.clearItem.parentElement !== menu) menu.append(this.clearItem);
|
|
342
|
+
} else this.clearItem?.remove();
|
|
343
|
+
menu.refreshItems();
|
|
344
|
+
}
|
|
345
|
+
openMenu(last = false) {
|
|
346
|
+
if (!this.isConnected) return;
|
|
347
|
+
this.closeDoc(false);
|
|
348
|
+
this.refreshMenu();
|
|
349
|
+
this.actionsMenu?.open(this.actionsButton, last);
|
|
350
|
+
}
|
|
351
|
+
refreshDoc() {
|
|
352
|
+
const content = this.parameters.doc;
|
|
353
|
+
if (typeof content !== 'string') throw new TypeError('groupletCard doc must be Markdown text');
|
|
354
|
+
const present = content.trim().length > 0;
|
|
355
|
+
if (!present && this.#docEvents) {
|
|
356
|
+
this.closeDoc(false);
|
|
357
|
+
(this.parameters.collapsible ? this.collapseButton : this.controlBox).focus({preventScroll: true});
|
|
358
|
+
}
|
|
359
|
+
this.docButton.hidden = !present;
|
|
360
|
+
this.docButton.setAttribute('aria-label', `Guide for ${this.parameters.title || 'card'}`);
|
|
361
|
+
this.docTitle.textContent = this.parameters.title || 'Card guide';
|
|
362
|
+
if (this.#docEvents && !this.#markdown && !this.docReady) {
|
|
363
|
+
this.docReady = import('./markdown-document.js').then(module => {
|
|
364
|
+
this.#markdown = module.markdownRenderer;
|
|
365
|
+
if (this.isConnected && this.#docEvents) this.refreshDoc();
|
|
366
|
+
});
|
|
367
|
+
this.docReady.catch(error => console.error(error));
|
|
368
|
+
}
|
|
369
|
+
if (this.#docEvents && this.#markdown && this.#docText !== content) {
|
|
370
|
+
// The shared Markdown renderer escapes raw HTML and rejects unsafe URL schemes.
|
|
371
|
+
this.docBody.innerHTML = this.#markdown.render(content);
|
|
372
|
+
this.#docText = content;
|
|
373
|
+
}
|
|
374
|
+
if (this.#docEvents) positionPopup(this.docPopup, this.docButton, {align: 'end'});
|
|
375
|
+
}
|
|
376
|
+
openDoc() {
|
|
377
|
+
if (!this.isConnected || !this.parameters.doc.trim()) return;
|
|
378
|
+
this.actionsMenu?.close(false);
|
|
379
|
+
this.refreshDoc();
|
|
380
|
+
if (this.#docEvents) return;
|
|
381
|
+
this.docPopup.showPopover();
|
|
382
|
+
this.#docEvents = new this.ownerDocument.defaultView.AbortController();
|
|
383
|
+
this.refreshDoc();
|
|
384
|
+
const options = {signal: this.#docEvents.signal};
|
|
385
|
+
const place = () => positionPopup(this.docPopup, this.docButton, {align: 'end'});
|
|
386
|
+
this.ownerDocument.addEventListener('keydown', event => {
|
|
387
|
+
if (event.key === 'Escape' && !event.defaultPrevented) {
|
|
388
|
+
event.preventDefault(); event.stopPropagation(); this.closeDoc();
|
|
389
|
+
}
|
|
390
|
+
}, options);
|
|
391
|
+
this.ownerDocument.addEventListener('pointerdown', event => {
|
|
392
|
+
if (!event.composedPath().includes(this.docPopup) && !event.composedPath().includes(this.docButton)) this.closeDoc(false);
|
|
393
|
+
}, options);
|
|
394
|
+
this.ownerDocument.addEventListener('focusin', event => {
|
|
395
|
+
if (!event.composedPath().includes(this.docPopup) && !event.composedPath().includes(this.docButton)) this.closeDoc(false);
|
|
396
|
+
}, options);
|
|
397
|
+
this.ownerDocument.addEventListener('scroll', place, {...options, capture: true});
|
|
398
|
+
this.ownerDocument.defaultView.addEventListener('resize', place, options);
|
|
399
|
+
this.docButton.setAttribute('aria-expanded', 'true');
|
|
400
|
+
place();
|
|
401
|
+
this.docClose.focus({preventScroll: true});
|
|
402
|
+
}
|
|
403
|
+
closeDoc(restore = true) {
|
|
404
|
+
if (!this.#docEvents) return;
|
|
405
|
+
this.#docEvents.abort(); this.#docEvents = null;
|
|
406
|
+
this.docPopup.hidePopover();
|
|
407
|
+
this.docButton.setAttribute('aria-expanded', 'false');
|
|
408
|
+
if (restore && this.isConnected) this.docButton.focus({preventScroll: true});
|
|
409
|
+
}
|
|
410
|
+
projectAttributes(attrs) {
|
|
411
|
+
const rest = super.projectAttributes(attrs);
|
|
412
|
+
const p = this.parameters;
|
|
413
|
+
if (!['top', 'left', 'right'].includes(p.chromeSide))
|
|
414
|
+
throw new TypeError('groupletCard chromeSide must be top, left or right');
|
|
415
|
+
if (typeof p.title !== 'string' || typeof p.checkboxLabel !== 'string'
|
|
416
|
+
|| typeof p.collapsible !== 'boolean' || typeof p.collapsed !== 'boolean'
|
|
417
|
+
|| (p.delitem !== null && typeof p.delitem !== 'boolean')
|
|
418
|
+
|| (p.checkbox !== null && typeof p.checkbox !== 'boolean'))
|
|
419
|
+
throw new TypeError('groupletCard requires text labels and boolean states');
|
|
420
|
+
const collapsed = p.collapsible && p.collapsed;
|
|
421
|
+
if (collapsed && !this.controlBox.hidden && this.contains(this.ownerDocument.activeElement)
|
|
422
|
+
&& this.ownerDocument.activeElement !== this) this.collapseButton.focus();
|
|
423
|
+
this.heading.textContent = p.title;
|
|
424
|
+
this.heading.disabled = !collapsed;
|
|
425
|
+
this.heading.setAttribute('aria-expanded', String(!collapsed));
|
|
426
|
+
this.controlBox.setAttribute('aria-label', p.title);
|
|
427
|
+
this.collapseButton.hidden = !p.collapsible;
|
|
428
|
+
this.collapseButton.textContent = collapsed ? '▸' : '▾';
|
|
429
|
+
this.collapseButton.title = collapsed ? 'Expand card' : 'Collapse card';
|
|
430
|
+
this.collapseButton.setAttribute('aria-label', this.collapseButton.title);
|
|
431
|
+
this.collapseButton.setAttribute('aria-expanded', String(!collapsed));
|
|
432
|
+
this.check.hidden = p.checkbox === null;
|
|
433
|
+
this.checkLabel.hidden = p.checkbox === null;
|
|
434
|
+
this.checkCaption.textContent = p.checkboxLabel;
|
|
435
|
+
this.check.checked = p.checkbox === true;
|
|
436
|
+
this.check.setAttribute('aria-label', p.checkboxLabel || (p.title ? `Select ${p.title}` : 'Select card'));
|
|
437
|
+
this.shell.dataset.side = p.chromeSide;
|
|
438
|
+
this.shell.toggleAttribute('data-collapsed', collapsed);
|
|
439
|
+
this.controlBox.hidden = collapsed;
|
|
440
|
+
this.refreshMenu();
|
|
441
|
+
this.refreshDoc();
|
|
442
|
+
return rest;
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Reusable remote Source fragments, independently activated as a collection. */
|
|
2
|
+
import {defineComponent, defineCollection} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
import {GroupletCard} from './grouplet-card.js';
|
|
5
|
+
export {GroupletCard};
|
|
6
|
+
|
|
7
|
+
export const Grouplet = defineComponent({
|
|
8
|
+
name: 'grouplet', tag: 'gramlot-grouplet', base: Container, subTags: '*',
|
|
9
|
+
parameters: {
|
|
10
|
+
remote: {dtype: 'T', nullable: true, binding: 'read'},
|
|
11
|
+
},
|
|
12
|
+
// Source owns children and Data scope. RemoteBinding owns loading and cleanup;
|
|
13
|
+
// the component must not start a second request from its DOM lifecycle.
|
|
14
|
+
implementation: Base => class extends Base {},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default defineCollection({name: 'grouplets', components: [Grouplet, GroupletCard]});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {defineComponent} from './registry.js';
|
|
2
2
|
import {projectParameters} from './parameters.js';
|
|
3
|
-
import {renderMarkdownDocument} from './markdown-document.js';
|
|
4
3
|
|
|
5
4
|
function PreviewElement(HTMLElement) {
|
|
6
5
|
return class extends HTMLElement {
|
|
@@ -15,10 +14,13 @@ function PreviewElement(HTMLElement) {
|
|
|
15
14
|
root.append(style,this.frame);
|
|
16
15
|
}
|
|
17
16
|
renderDocument(value) {return value;}
|
|
18
|
-
|
|
19
|
-
const rest=projectParameters(this,attrs);
|
|
17
|
+
render() {
|
|
20
18
|
const html=this.renderDocument(this.parameters.value);
|
|
21
19
|
if (this.frame.srcdoc !== html) this.frame.srcdoc=html;
|
|
20
|
+
}
|
|
21
|
+
projectAttributes(attrs) {
|
|
22
|
+
const rest=projectParameters(this,attrs);
|
|
23
|
+
this.render();
|
|
22
24
|
return rest;
|
|
23
25
|
}
|
|
24
26
|
};
|
|
@@ -28,6 +30,17 @@ export const HtmlPreview=defineComponent({name:'htmlPreview',tag:'gramlot-html-p
|
|
|
28
30
|
|
|
29
31
|
export const MarkdownPreview=defineComponent({name:'markdownPreview',tag:'gramlot-markdown-preview',base:PreviewElement,
|
|
30
32
|
parameters:{value:{dtype:'T',default:'',binding:'read'},allowHtml:{dtype:'B',default:false,binding:'read'}},implementation:Base=>class extends Base {
|
|
33
|
+
#renderDocument;
|
|
31
34
|
constructor(){super();this.frame.title='Markdown preview';}
|
|
32
|
-
|
|
35
|
+
connectedCallback(){this.render();}
|
|
36
|
+
render() {
|
|
37
|
+
if (this.#renderDocument) {super.render();return;}
|
|
38
|
+
if (this.ready) return;
|
|
39
|
+
this.ready=import('./markdown-document.js').then(module=>{
|
|
40
|
+
this.#renderDocument=module.renderMarkdownDocument;
|
|
41
|
+
if(this.isConnected) this.render();
|
|
42
|
+
});
|
|
43
|
+
this.ready.catch(error=>console.error(error));
|
|
44
|
+
}
|
|
45
|
+
renderDocument(value){return this.#renderDocument(value,{allowHtml:this.parameters.allowHtml,document:this.ownerDocument});}
|
|
33
46
|
}});
|