@plexui/vue 0.10.0 → 0.11.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/es/components/ButtonGroup/ButtonGroup.js +7 -0
- package/dist/es/components/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist/es/components/ButtonGroup/index.js.map +1 -1
- package/dist/es/components/ContextMenu/shared.js +3 -2
- package/dist/es/components/ContextMenu/shared.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +135 -18
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/dialogSteps.js +85 -0
- package/dist/es/components/Dialog/dialogSteps.js.map +1 -0
- package/dist/es/components/Dialog/dialogViewport.js +74 -0
- package/dist/es/components/Dialog/dialogViewport.js.map +1 -0
- package/dist/es/components/Dialog/index.js +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +2 -1
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/IndexBar/IndexBar.js +215 -0
- package/dist/es/components/IndexBar/IndexBar.js.map +1 -0
- package/dist/es/components/IndexBar/index.js +2 -0
- package/dist/es/components/IndexBar/index.js.map +1 -0
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +149 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +10 -6
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/Page/Page.js +2 -2
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/PhoneLayout/PhoneLayout.js +50 -0
- package/dist/es/components/PhoneLayout/PhoneLayout.js.map +1 -0
- package/dist/es/components/PhoneLayout/index.js +2 -0
- package/dist/es/components/PhoneLayout/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +1 -1
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredPointerDownOutside.js +59 -4
- package/dist/es/components/Popover/deferredPointerDownOutside.js.map +1 -1
- package/dist/es/components/Select/Select.js +2 -2
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +34 -3
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/SwipeActions/SwipeActions.js +374 -0
- package/dist/es/components/SwipeActions/SwipeActions.js.map +1 -0
- package/dist/es/components/SwipeActions/index.js +2 -0
- package/dist/es/components/SwipeActions/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +3 -1
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +23 -8
- package/dist/es/components/TabBar/TabBar.js.map +1 -1
- package/dist/es/components/TabBar/index.js.map +1 -1
- package/dist/es/components/Tabs/Tabs.js +1 -0
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +3 -46
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +1 -0
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Tip/Tip.js +276 -0
- package/dist/es/components/Tip/Tip.js.map +1 -0
- package/dist/es/components/Tip/index.js +2 -0
- package/dist/es/components/Tip/index.js.map +1 -0
- package/dist/es/components/Toast/ToastRenderer.js +30 -13
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -1
- package/dist/es/components/Toast/Toaster.js +17 -6
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +113 -1
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +3 -3
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/composables/useEscCloseStack.js +8 -4
- package/dist/es/composables/useEscCloseStack.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +3 -1
- package/dist/es/lib/floatingBoundary.js.map +1 -1
- package/dist/es/lib/helpers.js +21 -0
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/phoneLayout.js +16 -0
- package/dist/es/lib/phoneLayout.js.map +1 -0
- package/dist/es/lib/toastRegion.js +6 -0
- package/dist/es/lib/toastRegion.js.map +1 -0
- package/dist/types/components/ButtonGroup/ButtonGroup.d.ts +13 -0
- package/dist/types/components/ButtonGroup/index.d.ts +1 -1
- package/dist/types/components/ContextMenu/shared.d.ts +3 -2
- package/dist/types/components/Dialog/Dialog.d.ts +93 -3
- package/dist/types/components/Dialog/dialogSteps.d.ts +10 -0
- package/dist/types/components/Dialog/dialogViewport.d.ts +1 -0
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/IndexBar/IndexBar.d.ts +112 -0
- package/dist/types/components/IndexBar/index.d.ts +1 -0
- package/dist/types/components/Menu/Menu.d.ts +14 -15
- package/dist/types/components/Page/Page.d.ts +2 -2
- package/dist/types/components/PhoneLayout/PhoneLayout.d.ts +21 -0
- package/dist/types/components/PhoneLayout/index.d.ts +1 -0
- package/dist/types/components/Popover/deferredPointerDownOutside.d.ts +1 -1
- package/dist/types/components/SwipeActions/SwipeActions.d.ts +135 -0
- package/dist/types/components/SwipeActions/index.d.ts +1 -0
- package/dist/types/components/TabBar/TabBar.d.ts +55 -6
- package/dist/types/components/TabBar/index.d.ts +1 -1
- package/dist/types/components/Tip/Tip.d.ts +146 -0
- package/dist/types/components/Tip/index.d.ts +1 -0
- package/dist/types/components/Toast/toastLifecycle.d.ts +34 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -7
- package/dist/types/composables/useEscCloseStack.d.ts +2 -2
- package/dist/types/lib/helpers.d.ts +6 -0
- package/dist/types/lib/phoneLayout.d.ts +11 -0
- package/dist/types/lib/toastRegion.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { computed, defineComponent, h, onBeforeUnmount, ref, watch } from "vue";
|
|
2
|
+
import s from "@plexui/styles/components/IndexBar/IndexBar.module.css";
|
|
3
|
+
// Vue port of packages/ui/src/components/IndexBar/IndexBar.tsx: the same strip and slider, the same dots on a
|
|
4
|
+
// short screen, presses, drags and keys. React's `onSelect` becomes the `select` event.
|
|
5
|
+
/**
|
|
6
|
+
* What the bar shows: the index of each title, or `null` for a dot. Every title shows while they fit in `capacity`
|
|
7
|
+
* lines, or while `capacity` is not known (`undefined`). Otherwise the first and the last title keep their places
|
|
8
|
+
* and titles spread evenly between them, a dot in each line between two, as UIKit's index shortens itself on a
|
|
9
|
+
* short screen; two lines hold the first and the last title, one the first, none nothing.
|
|
10
|
+
*/
|
|
11
|
+
export const indexBarSlots = (count, capacity) => {
|
|
12
|
+
const length = Math.max(0, count);
|
|
13
|
+
if (capacity === undefined || !(capacity >= 0) || length <= capacity)
|
|
14
|
+
return Array.from({ length }, (_, index) => index);
|
|
15
|
+
if (capacity < 3)
|
|
16
|
+
return [0, length - 1].slice(0, Math.floor(capacity));
|
|
17
|
+
const lines = capacity % 2 === 0 ? capacity - 1 : capacity;
|
|
18
|
+
const shown = (lines + 1) / 2;
|
|
19
|
+
const slots = [];
|
|
20
|
+
for (let i = 0; i < shown; i++) {
|
|
21
|
+
if (i > 0)
|
|
22
|
+
slots.push(null);
|
|
23
|
+
slots.push(Math.round((i * (length - 1)) / (shown - 1)));
|
|
24
|
+
}
|
|
25
|
+
return slots;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The title under a pointer. A letter is its own title; a dot stands for the titles hidden between the letters
|
|
29
|
+
* on either side, and the finger moves through them across its line.
|
|
30
|
+
*/
|
|
31
|
+
const indexAt = (rail, clientY, slots) => {
|
|
32
|
+
const rect = rail.getBoundingClientRect();
|
|
33
|
+
if (!(rect.height > 0) || slots.length < 1)
|
|
34
|
+
return undefined;
|
|
35
|
+
const offset = ((clientY - rect.top) / rect.height) * slots.length;
|
|
36
|
+
const line = Math.min(slots.length - 1, Math.max(0, Math.floor(offset)));
|
|
37
|
+
const slot = slots[line];
|
|
38
|
+
if (slot !== null && slot !== undefined)
|
|
39
|
+
return slot;
|
|
40
|
+
const before = slots[line - 1] ?? 0;
|
|
41
|
+
const after = slots[line + 1] ?? before;
|
|
42
|
+
const hidden = after - before - 1;
|
|
43
|
+
const within = Math.min(1, Math.max(0, offset - line));
|
|
44
|
+
if (hidden < 1)
|
|
45
|
+
return within < 0.5 ? before : after;
|
|
46
|
+
return before + 1 + Math.min(hidden - 1, Math.floor(within * hidden));
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* How many lines fit in the strip: its height between the bars of the Page (or the safe areas) over the rail's
|
|
50
|
+
* resolved line height, or `undefined` while the strip is not laid out (hidden from 768px up, or before layout).
|
|
51
|
+
*/
|
|
52
|
+
const capacityOf = (strip, rail) => {
|
|
53
|
+
if (!(strip.clientHeight > 0) || !rail)
|
|
54
|
+
return undefined;
|
|
55
|
+
const styles = getComputedStyle(strip);
|
|
56
|
+
const available = strip.clientHeight - parseFloat(styles.paddingTop || "0") - parseFloat(styles.paddingBottom || "0");
|
|
57
|
+
const line = parseFloat(getComputedStyle(rail).lineHeight);
|
|
58
|
+
return line > 0 ? Math.max(0, Math.floor(available / line)) : undefined;
|
|
59
|
+
};
|
|
60
|
+
const IndexBarComponent = defineComponent({
|
|
61
|
+
name: "IndexBar",
|
|
62
|
+
inheritAttrs: false,
|
|
63
|
+
props: {
|
|
64
|
+
/** The `id` of the index bar. */
|
|
65
|
+
id: String,
|
|
66
|
+
/** The titles of the sections, in order: usually letters, such as `"A"` to `"Z"` and `"#"`. */
|
|
67
|
+
items: { type: Array, required: true },
|
|
68
|
+
/** Accessible name of the index bar. @default "Section index" */
|
|
69
|
+
ariaLabel: { type: String, default: "Section index" },
|
|
70
|
+
/** The `id` of the list the index scrolls. */
|
|
71
|
+
ariaControls: String,
|
|
72
|
+
},
|
|
73
|
+
emits: {
|
|
74
|
+
/** The section to show: on a press, on each new letter while dragging, and from the keys (React `onSelect`) */
|
|
75
|
+
select: (item, index) => typeof item === "string" && typeof index === "number",
|
|
76
|
+
/** The index bar gained focus */
|
|
77
|
+
focus: (event) => event.type === "focus",
|
|
78
|
+
/** The index bar lost focus */
|
|
79
|
+
blur: (event) => event.type === "blur",
|
|
80
|
+
},
|
|
81
|
+
setup(props, { attrs, emit }) {
|
|
82
|
+
const current = ref(0);
|
|
83
|
+
const capacity = ref(undefined);
|
|
84
|
+
const pressed = ref(false);
|
|
85
|
+
const strip = ref(null);
|
|
86
|
+
const rail = ref(null);
|
|
87
|
+
let press = null;
|
|
88
|
+
let observer = null;
|
|
89
|
+
const count = computed(() => props.items.length);
|
|
90
|
+
const index = computed(() => Math.min(current.value, Math.max(0, count.value - 1)));
|
|
91
|
+
const slots = computed(() => indexBarSlots(count.value, capacity.value));
|
|
92
|
+
// The strip changes with the screen, the rail with the line height.
|
|
93
|
+
watch([strip, rail], ([element, railElement]) => {
|
|
94
|
+
observer?.disconnect();
|
|
95
|
+
observer = null;
|
|
96
|
+
if (!element || typeof ResizeObserver === "undefined")
|
|
97
|
+
return;
|
|
98
|
+
const measure = () => { capacity.value = capacityOf(element, railElement); };
|
|
99
|
+
observer = new ResizeObserver(measure);
|
|
100
|
+
observer.observe(element);
|
|
101
|
+
if (railElement)
|
|
102
|
+
observer.observe(railElement);
|
|
103
|
+
measure();
|
|
104
|
+
}, { flush: "post" });
|
|
105
|
+
onBeforeUnmount(() => observer?.disconnect());
|
|
106
|
+
const select = (next) => {
|
|
107
|
+
const item = props.items[next];
|
|
108
|
+
if (item === undefined)
|
|
109
|
+
return;
|
|
110
|
+
current.value = next;
|
|
111
|
+
emit("select", item, next);
|
|
112
|
+
};
|
|
113
|
+
const end = () => {
|
|
114
|
+
press = null;
|
|
115
|
+
pressed.value = false;
|
|
116
|
+
};
|
|
117
|
+
// A gesture ends with its rail: the letters can go away under the finger.
|
|
118
|
+
watch(count, (value) => {
|
|
119
|
+
if (value < 1 && press)
|
|
120
|
+
end();
|
|
121
|
+
});
|
|
122
|
+
const handlePointerDown = (event) => {
|
|
123
|
+
const target = event.currentTarget;
|
|
124
|
+
if (event.button !== 0 || press || !(target instanceof HTMLElement))
|
|
125
|
+
return;
|
|
126
|
+
const next = indexAt(target, event.clientY, slots.value);
|
|
127
|
+
if (next === undefined)
|
|
128
|
+
return;
|
|
129
|
+
target.setPointerCapture?.(event.pointerId);
|
|
130
|
+
press = { pointerId: event.pointerId, index: next };
|
|
131
|
+
pressed.value = true;
|
|
132
|
+
select(next);
|
|
133
|
+
};
|
|
134
|
+
const handlePointerMove = (event) => {
|
|
135
|
+
const state = press;
|
|
136
|
+
const target = event.currentTarget;
|
|
137
|
+
if (!state || state.pointerId !== event.pointerId || !(target instanceof HTMLElement))
|
|
138
|
+
return;
|
|
139
|
+
const next = indexAt(target, event.clientY, slots.value);
|
|
140
|
+
if (next === undefined || next === state.index)
|
|
141
|
+
return;
|
|
142
|
+
state.index = next;
|
|
143
|
+
select(next);
|
|
144
|
+
};
|
|
145
|
+
/** The pointer of the gesture lifted, was cancelled or lost its capture; another pointer ends nothing. */
|
|
146
|
+
const handlePointerEnd = (event) => {
|
|
147
|
+
if (press?.pointerId === event.pointerId)
|
|
148
|
+
end();
|
|
149
|
+
};
|
|
150
|
+
const handleKeyDown = (event) => {
|
|
151
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || slots.value.length < 1)
|
|
152
|
+
return;
|
|
153
|
+
const keys = {
|
|
154
|
+
ArrowDown: index.value + 1,
|
|
155
|
+
ArrowRight: index.value + 1,
|
|
156
|
+
ArrowUp: index.value - 1,
|
|
157
|
+
ArrowLeft: index.value - 1,
|
|
158
|
+
Home: 0,
|
|
159
|
+
End: count.value - 1,
|
|
160
|
+
Enter: index.value,
|
|
161
|
+
" ": index.value,
|
|
162
|
+
};
|
|
163
|
+
const target = keys[event.key];
|
|
164
|
+
if (target === undefined)
|
|
165
|
+
return;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
const next = Math.min(count.value - 1, Math.max(0, target));
|
|
168
|
+
if (next !== index.value || event.key === "Enter" || event.key === " ")
|
|
169
|
+
select(next);
|
|
170
|
+
};
|
|
171
|
+
return () => {
|
|
172
|
+
if (count.value < 1)
|
|
173
|
+
return null;
|
|
174
|
+
return h("div", { ...attrs, "ref": strip, "class": [s.IndexBar, attrs.class], "data-index-bar": "" }, [
|
|
175
|
+
h("div", {
|
|
176
|
+
"ref": rail,
|
|
177
|
+
"id": props.id,
|
|
178
|
+
"role": "slider",
|
|
179
|
+
"tabindex": 0,
|
|
180
|
+
"aria-orientation": "vertical",
|
|
181
|
+
"aria-valuemin": 1,
|
|
182
|
+
"aria-valuemax": count.value,
|
|
183
|
+
"aria-valuenow": index.value + 1,
|
|
184
|
+
"aria-valuetext": props.items[index.value],
|
|
185
|
+
"aria-label": props.ariaLabel,
|
|
186
|
+
"aria-controls": props.ariaControls,
|
|
187
|
+
// No room for a line between the bars: the bar stays measurable and leaves the focus order.
|
|
188
|
+
"hidden": slots.value.length < 1 ? true : undefined,
|
|
189
|
+
"class": s.Rail,
|
|
190
|
+
"data-pressed": pressed.value ? "" : undefined,
|
|
191
|
+
"onPointerdown": handlePointerDown,
|
|
192
|
+
"onPointermove": handlePointerMove,
|
|
193
|
+
"onPointerup": handlePointerEnd,
|
|
194
|
+
"onPointercancel": handlePointerEnd,
|
|
195
|
+
"onLostpointercapture": handlePointerEnd,
|
|
196
|
+
"onKeydown": handleKeyDown,
|
|
197
|
+
"onFocus": (event) => emit("focus", event),
|
|
198
|
+
"onBlur": (event) => emit("blur", event),
|
|
199
|
+
}, slots.value.map((slot, position) => slot === null
|
|
200
|
+
? h("span", { "key": `dot-${position}`, "class": s.Item, "aria-hidden": "true", "data-dot": "" }, "•")
|
|
201
|
+
: h("span", { "key": slot, "class": s.Item, "aria-hidden": "true", "data-index": slot }, props.items[slot]))),
|
|
202
|
+
]);
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* The section index of a phone list, as the iOS section index: a column of letters at the trailing edge of the
|
|
208
|
+
* nearest positioned container (a Page), centred between the bars of the Page. A press shows the section of the letter under the
|
|
209
|
+
* finger, and a drag moves through the sections letter by letter. On a short screen every other letter gives
|
|
210
|
+
* way to a dot. It is one slider for assistive technology: Down and Up (or Right and Left) move one section, Home
|
|
211
|
+
* and End go to the first and the last, and Enter or Space shows the current one again. A desktop list has no
|
|
212
|
+
* index, so the bar renders under 768px only.
|
|
213
|
+
*/
|
|
214
|
+
export const IndexBar = IndexBarComponent;
|
|
215
|
+
//# sourceMappingURL=IndexBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexBar.js","sourceRoot":"","sources":["../../../../src/components/IndexBar/IndexBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAiB,MAAM,KAAK,CAAA;AAC9F,OAAO,CAAC,MAAM,wDAAwD,CAAA;AAEtE,8GAA8G;AAC9G,wFAAwF;AAExF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,QAAiB,EAAwB,EAAE;IACtF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACjC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,MAAM,IAAI,QAAQ;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;IACxH,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;IACvE,MAAM,KAAK,GAAG,QAAQ,GAAG,CAAC,KAAK,CAA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,CAAC,CAAC,IAAI;oBACf,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;oBAC9C,eAAe,EAAE,iBAAiB;oBAClC,eAAe,EAAE,iBAAiB;oBAClC,aAAa,EAAE,gBAAgB;oBAC/B,iBAAiB,EAAE,gBAAgB;oBACnC,sBAAsB,EAAE,gBAAgB;oBACxC,WAAW,EAAE,aAAa;oBAC1B,SAAS,EAAE,CAAC,KAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;oBACtD,QAAQ,EAAE,CAAC,KAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;iBACrD,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI;oBAClD,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC;oBACtG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aAChH,CAAC,CAAA;QACJ,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAA","sourcesContent":["import { computed, defineComponent, h, onBeforeUnmount, ref, watch, type PropType } from \"vue\"\nimport s from \"@plexui/styles/components/IndexBar/IndexBar.module.css\"\n\n// Vue port of packages/ui/src/components/IndexBar/IndexBar.tsx: the same strip and slider, the same dots on a\n// short screen, presses, drags and keys. React's `onSelect` becomes the `select` event.\n\n/**\n * What the bar shows: the index of each title, or `null` for a dot. Every title shows while they fit in `capacity`\n * lines, or while `capacity` is not known (`undefined`). Otherwise the first and the last title keep their places\n * and titles spread evenly between them, a dot in each line between two, as UIKit's index shortens itself on a\n * short screen; two lines hold the first and the last title, one the first, none nothing.\n */\nexport const indexBarSlots = (count: number, capacity?: number): Array<number | null> => {\n const length = Math.max(0, count)\n if (capacity === undefined || !(capacity >= 0) || length <= capacity) return Array.from({ length }, (_, index) => index)\n if (capacity < 3) return [0, length - 1].slice(0, Math.floor(capacity))\n const lines = capacity % 2 === 0 ? capacity - 1 : capacity\n const shown = (lines + 1) / 2\n const slots: Array<number | null> = []\n for (let i = 0; i < shown; i++) {\n if (i > 0) slots.push(null)\n slots.push(Math.round((i * (length - 1)) / (shown - 1)))\n }\n return slots\n}\n\n/**\n * The title under a pointer. A letter is its own title; a dot stands for the titles hidden between the letters\n * on either side, and the finger moves through them across its line.\n */\nconst indexAt = (rail: HTMLElement, clientY: number, slots: Array<number | null>) => {\n const rect = rail.getBoundingClientRect()\n if (!(rect.height > 0) || slots.length < 1) return undefined\n const offset = ((clientY - rect.top) / rect.height) * slots.length\n const line = Math.min(slots.length - 1, Math.max(0, Math.floor(offset)))\n const slot = slots[line]\n if (slot !== null && slot !== undefined) return slot\n const before = slots[line - 1] ?? 0\n const after = slots[line + 1] ?? before\n const hidden = after - before - 1\n const within = Math.min(1, Math.max(0, offset - line))\n if (hidden < 1) return within < 0.5 ? before : after\n return before + 1 + Math.min(hidden - 1, Math.floor(within * hidden))\n}\n\n/**\n * How many lines fit in the strip: its height between the bars of the Page (or the safe areas) over the rail's\n * resolved line height, or `undefined` while the strip is not laid out (hidden from 768px up, or before layout).\n */\nconst capacityOf = (strip: HTMLElement, rail: HTMLElement | null) => {\n if (!(strip.clientHeight > 0) || !rail) return undefined\n const styles = getComputedStyle(strip)\n const available = strip.clientHeight - parseFloat(styles.paddingTop || \"0\") - parseFloat(styles.paddingBottom || \"0\")\n const line = parseFloat(getComputedStyle(rail).lineHeight)\n return line > 0 ? Math.max(0, Math.floor(available / line)) : undefined\n}\n\nconst IndexBarComponent = defineComponent({\n name: \"IndexBar\",\n inheritAttrs: false,\n props: {\n /** The `id` of the index bar. */\n id: String,\n /** The titles of the sections, in order: usually letters, such as `\"A\"` to `\"Z\"` and `\"#\"`. */\n items: { type: Array as PropType<string[]>, required: true },\n /** Accessible name of the index bar. @default \"Section index\" */\n ariaLabel: { type: String, default: \"Section index\" },\n /** The `id` of the list the index scrolls. */\n ariaControls: String,\n },\n emits: {\n /** The section to show: on a press, on each new letter while dragging, and from the keys (React `onSelect`) */\n select: (item: string, index: number) => typeof item === \"string\" && typeof index === \"number\",\n /** The index bar gained focus */\n focus: (event: FocusEvent) => event.type === \"focus\",\n /** The index bar lost focus */\n blur: (event: FocusEvent) => event.type === \"blur\",\n },\n setup(props, { attrs, emit }) {\n const current = ref(0)\n const capacity = ref<number | undefined>(undefined)\n const pressed = ref(false)\n const strip = ref<HTMLElement | null>(null)\n const rail = ref<HTMLElement | null>(null)\n let press: { pointerId: number; index: number } | null = null\n let observer: ResizeObserver | null = null\n const count = computed(() => props.items.length)\n const index = computed(() => Math.min(current.value, Math.max(0, count.value - 1)))\n const slots = computed(() => indexBarSlots(count.value, capacity.value))\n\n // The strip changes with the screen, the rail with the line height.\n watch([strip, rail], ([element, railElement]) => {\n observer?.disconnect()\n observer = null\n if (!element || typeof ResizeObserver === \"undefined\") return\n const measure = () => { capacity.value = capacityOf(element, railElement) }\n observer = new ResizeObserver(measure)\n observer.observe(element)\n if (railElement) observer.observe(railElement)\n measure()\n }, { flush: \"post\" })\n onBeforeUnmount(() => observer?.disconnect())\n\n const select = (next: number) => {\n const item = props.items[next]\n if (item === undefined) return\n current.value = next\n emit(\"select\", item, next)\n }\n\n const end = () => {\n press = null\n pressed.value = false\n }\n\n // A gesture ends with its rail: the letters can go away under the finger.\n watch(count, (value) => {\n if (value < 1 && press) end()\n })\n\n const handlePointerDown = (event: PointerEvent) => {\n const target = event.currentTarget\n if (event.button !== 0 || press || !(target instanceof HTMLElement)) return\n const next = indexAt(target, event.clientY, slots.value)\n if (next === undefined) return\n target.setPointerCapture?.(event.pointerId)\n press = { pointerId: event.pointerId, index: next }\n pressed.value = true\n select(next)\n }\n\n const handlePointerMove = (event: PointerEvent) => {\n const state = press\n const target = event.currentTarget\n if (!state || state.pointerId !== event.pointerId || !(target instanceof HTMLElement)) return\n const next = indexAt(target, event.clientY, slots.value)\n if (next === undefined || next === state.index) return\n state.index = next\n select(next)\n }\n\n /** The pointer of the gesture lifted, was cancelled or lost its capture; another pointer ends nothing. */\n const handlePointerEnd = (event: PointerEvent) => {\n if (press?.pointerId === event.pointerId) end()\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || slots.value.length < 1) return\n const keys: Record<string, number> = {\n ArrowDown: index.value + 1,\n ArrowRight: index.value + 1,\n ArrowUp: index.value - 1,\n ArrowLeft: index.value - 1,\n Home: 0,\n End: count.value - 1,\n Enter: index.value,\n \" \": index.value,\n }\n const target = keys[event.key]\n if (target === undefined) return\n event.preventDefault()\n const next = Math.min(count.value - 1, Math.max(0, target))\n if (next !== index.value || event.key === \"Enter\" || event.key === \" \") select(next)\n }\n\n return () => {\n if (count.value < 1) return null\n return h(\"div\", { ...attrs, \"ref\": strip, \"class\": [s.IndexBar, attrs.class], \"data-index-bar\": \"\" }, [\n h(\"div\", {\n \"ref\": rail,\n \"id\": props.id,\n \"role\": \"slider\",\n \"tabindex\": 0,\n \"aria-orientation\": \"vertical\",\n \"aria-valuemin\": 1,\n \"aria-valuemax\": count.value,\n \"aria-valuenow\": index.value + 1,\n \"aria-valuetext\": props.items[index.value],\n \"aria-label\": props.ariaLabel,\n \"aria-controls\": props.ariaControls,\n // No room for a line between the bars: the bar stays measurable and leaves the focus order.\n \"hidden\": slots.value.length < 1 ? true : undefined,\n \"class\": s.Rail,\n \"data-pressed\": pressed.value ? \"\" : undefined,\n \"onPointerdown\": handlePointerDown,\n \"onPointermove\": handlePointerMove,\n \"onPointerup\": handlePointerEnd,\n \"onPointercancel\": handlePointerEnd,\n \"onLostpointercapture\": handlePointerEnd,\n \"onKeydown\": handleKeyDown,\n \"onFocus\": (event: FocusEvent) => emit(\"focus\", event),\n \"onBlur\": (event: FocusEvent) => emit(\"blur\", event),\n }, slots.value.map((slot, position) => slot === null\n ? h(\"span\", { \"key\": `dot-${position}`, \"class\": s.Item, \"aria-hidden\": \"true\", \"data-dot\": \"\" }, \"•\")\n : h(\"span\", { \"key\": slot, \"class\": s.Item, \"aria-hidden\": \"true\", \"data-index\": slot }, props.items[slot]))),\n ])\n }\n },\n})\n\ntype IndexBarOwnProps = InstanceType<typeof IndexBarComponent>[\"$props\"]\n\n/** IndexBar props. */\nexport type IndexBarProps = IndexBarOwnProps\n\n/**\n * The section index of a phone list, as the iOS section index: a column of letters at the trailing edge of the\n * nearest positioned container (a Page), centred between the bars of the Page. A press shows the section of the letter under the\n * finger, and a drag moves through the sections letter by letter. On a short screen every other letter gives\n * way to a dot. It is one slider for assistive technology: Down and Up (or Right and Left) move one section, Home\n * and End go to the first and the last, and Enter or Space shows the current one again. A desktop list has no\n * index, so the bar renders under 768px only.\n */\nexport const IndexBar = IndexBarComponent\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/IndexBar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAsB,MAAM,eAAe,CAAA","sourcesContent":["export { IndexBar, indexBarSlots, type IndexBarProps } from \"./IndexBar.js\"\n"]}
|
|
@@ -22,6 +22,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogBody, DialogFoo
|
|
|
22
22
|
import { Field } from "../Field/index.js";
|
|
23
23
|
import { Input } from "../Input/index.js";
|
|
24
24
|
import { flattenSlot } from "../Tooltip/slot.js";
|
|
25
|
+
import { renderMarkdown } from "../Markdown/pipeline.js";
|
|
25
26
|
import s from "@plexui/styles/components/MarkdownEditor/MarkdownEditor.module.css";
|
|
26
27
|
const getMarkdown = (editor) => editor.storage.markdown?.getMarkdown?.() ?? "";
|
|
27
28
|
// A link inserted as a text node, not as `<a>` HTML: the markdown parser runs
|
|
@@ -423,7 +424,9 @@ const MarkdownEditorComponent = defineComponent({
|
|
|
423
424
|
]),
|
|
424
425
|
]),
|
|
425
426
|
h("div", { class: s.Editor, style: { minHeight: `${minHeight}px` } }, [
|
|
426
|
-
|
|
427
|
+
editor.value
|
|
428
|
+
? h(EditorContent, { editor: editor.value })
|
|
429
|
+
: editorFirstFrame(props.value ?? props.defaultValue ?? "", props.placeholder, props.disabled),
|
|
427
430
|
]),
|
|
428
431
|
h(LinkDialog, {
|
|
429
432
|
open: linkDialogOpen.value,
|
|
@@ -440,6 +443,151 @@ const MarkdownEditorComponent = defineComponent({
|
|
|
440
443
|
};
|
|
441
444
|
},
|
|
442
445
|
});
|
|
446
|
+
// The editor reads markdown with `html: false` (markdown-it): HTML is not parsed, its characters are text, and the
|
|
447
|
+
// markdown around and inside it still is
|
|
448
|
+
function remarkWithoutHtml() {
|
|
449
|
+
const data = this.data();
|
|
450
|
+
(data.micromarkExtensions ??= []).push({ disable: { null: ["htmlFlow", "htmlText"] } });
|
|
451
|
+
}
|
|
452
|
+
// The editor's schema keeps paragraphs, lists, bold, italic, links and line breaks. ProseMirror parses anything else
|
|
453
|
+
// into them: a heading is a paragraph of its text, a code block a paragraph of its lines, a quote its paragraphs,
|
|
454
|
+
// inline code its text, an image or a rule nothing, and the text of a list item sits in a paragraph. Outside a code
|
|
455
|
+
// block it collapses white space, as the page does; the editor's text keeps its spaces (white-space: break-spaces)
|
|
456
|
+
const SCHEMA_AS_PARAGRAPH = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
457
|
+
const SCHEMA_BLOCKS = new Set(["p", "ul", "ol"]);
|
|
458
|
+
const textOf = (node) => node.value ?? (node.children ?? []).map(textOf).join("");
|
|
459
|
+
const isBlank = (node) => node.type === "text" && !node.value?.trim();
|
|
460
|
+
const lineBreak = () => ({ type: "element", tagName: "br", properties: {}, children: [] });
|
|
461
|
+
// White space of a paragraph's text as ProseMirror parses it: runs collapse to one space, none at the start of the
|
|
462
|
+
// paragraph, after a line break or after another space, none at its end
|
|
463
|
+
function collapseWhiteSpace(children) {
|
|
464
|
+
let previous = null;
|
|
465
|
+
let lineStart = true;
|
|
466
|
+
const walk = (nodes) => {
|
|
467
|
+
for (const node of nodes) {
|
|
468
|
+
if (node.type === "text") {
|
|
469
|
+
let value = (node.value ?? "").replace(/[ \t\r\n\f]+/g, " ");
|
|
470
|
+
if (value.startsWith(" ") && (lineStart || previous?.value?.endsWith(" ")))
|
|
471
|
+
value = value.slice(1);
|
|
472
|
+
node.value = value;
|
|
473
|
+
if (value) {
|
|
474
|
+
previous = node;
|
|
475
|
+
lineStart = false;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else if (node.tagName === "br") {
|
|
479
|
+
lineStart = true;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
walk(node.children ?? []);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
walk(children);
|
|
487
|
+
if (previous)
|
|
488
|
+
previous.value = previous.value.replace(/ $/, "");
|
|
489
|
+
}
|
|
490
|
+
const paragraph = (children, { preserveWhiteSpace = false } = {}) => {
|
|
491
|
+
if (!preserveWhiteSpace)
|
|
492
|
+
collapseWhiteSpace(children);
|
|
493
|
+
return {
|
|
494
|
+
type: "element",
|
|
495
|
+
tagName: "p",
|
|
496
|
+
properties: {},
|
|
497
|
+
// An empty paragraph keeps its line, as ProseMirror's trailing break does
|
|
498
|
+
children: children.every((child) => child.type === "text" && !child.value) ? [lineBreak()] : children,
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
// tiptap-markdown drops the newline markdown-it writes after an element, outside a code block: a line that follows
|
|
502
|
+
// bold, a link or code joins it without a space
|
|
503
|
+
const dropNewlineAfterElements = (nodes) => nodes.map((node, index) => index && node.type === "text" && nodes[index - 1].type === "element" && node.value?.startsWith("\n")
|
|
504
|
+
? { ...node, value: node.value.slice(1) }
|
|
505
|
+
: node);
|
|
506
|
+
function toEditorSchema(nodes) {
|
|
507
|
+
return dropNewlineAfterElements(nodes).flatMap((node) => {
|
|
508
|
+
if (node.type !== "element")
|
|
509
|
+
return [node];
|
|
510
|
+
const children = node.children ?? [];
|
|
511
|
+
switch (node.tagName) {
|
|
512
|
+
case "img":
|
|
513
|
+
case "hr":
|
|
514
|
+
return [];
|
|
515
|
+
case "code":
|
|
516
|
+
return [{ type: "text", value: textOf(node) }];
|
|
517
|
+
case "pre": {
|
|
518
|
+
// ProseMirror keeps a code block's spaces and its newlines as line breaks, the last one followed by the
|
|
519
|
+
// trailing break of a paragraph that ends in a break
|
|
520
|
+
const lines = textOf(node).split("\n");
|
|
521
|
+
if (lines.every((line) => !line))
|
|
522
|
+
return [];
|
|
523
|
+
const content = [];
|
|
524
|
+
lines.forEach((line, index) => {
|
|
525
|
+
if (index)
|
|
526
|
+
content.push(lineBreak());
|
|
527
|
+
if (line)
|
|
528
|
+
content.push({ type: "text", value: line });
|
|
529
|
+
});
|
|
530
|
+
if (content[content.length - 1].tagName === "br")
|
|
531
|
+
content.push(lineBreak());
|
|
532
|
+
return [paragraph(content, { preserveWhiteSpace: true })];
|
|
533
|
+
}
|
|
534
|
+
case "blockquote":
|
|
535
|
+
return toEditorSchema(children);
|
|
536
|
+
case "p":
|
|
537
|
+
return [paragraph(toEditorSchema(children))];
|
|
538
|
+
case "li": {
|
|
539
|
+
const content = [];
|
|
540
|
+
let run = [];
|
|
541
|
+
const flush = () => {
|
|
542
|
+
if (!run.every(isBlank))
|
|
543
|
+
content.push(paragraph(run));
|
|
544
|
+
run = [];
|
|
545
|
+
};
|
|
546
|
+
for (const child of toEditorSchema(children)) {
|
|
547
|
+
if (child.type === "element" && SCHEMA_BLOCKS.has(child.tagName)) {
|
|
548
|
+
flush();
|
|
549
|
+
content.push(child);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
run.push(child);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
flush();
|
|
556
|
+
// A list item starts with a paragraph, an empty one if it has no text (an empty item, an image)
|
|
557
|
+
if (content[0]?.tagName !== "p")
|
|
558
|
+
content.unshift(paragraph([]));
|
|
559
|
+
return [{ ...node, children: content }];
|
|
560
|
+
}
|
|
561
|
+
case "ul":
|
|
562
|
+
case "ol":
|
|
563
|
+
return [{ ...node, children: toEditorSchema(children).filter((child) => !isBlank(child)) }];
|
|
564
|
+
default:
|
|
565
|
+
return SCHEMA_AS_PARAGRAPH.has(node.tagName)
|
|
566
|
+
? [paragraph(toEditorSchema(children))]
|
|
567
|
+
: [{ ...node, children: toEditorSchema(children) }];
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
function rehypeEditorSchema() {
|
|
572
|
+
return (tree) => {
|
|
573
|
+
tree.children = toEditorSchema(tree.children ?? []).filter((child) => !isBlank(child));
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* The content before the editor exists, on the server and until it mounts: the markdown as the editor will show it,
|
|
578
|
+
* in its schema and its own boxes (EditorContent's, then ProseMirror's), so the page does not move when ProseMirror
|
|
579
|
+
* takes over, as in React. An empty editor shows its placeholder while it can be edited (`showOnlyWhenEditable`).
|
|
580
|
+
*/
|
|
581
|
+
const editorFirstFrame = (markdown, placeholder, disabled) => {
|
|
582
|
+
const hint = placeholder && !disabled;
|
|
583
|
+
return h("div", null, [
|
|
584
|
+
h("div", { class: ["tiptap", s.EditorContent] }, [
|
|
585
|
+
markdown.trim()
|
|
586
|
+
? renderMarkdown({ children: markdown, remarkPlugins: [remarkWithoutHtml], rehypePlugins: [rehypeEditorSchema] })
|
|
587
|
+
: h("p", { class: hint ? "is-editor-empty" : undefined, "data-placeholder": hint ? placeholder : undefined }, [h("br")]),
|
|
588
|
+
]),
|
|
589
|
+
]);
|
|
590
|
+
};
|
|
443
591
|
/**
|
|
444
592
|
* Compact rich text editor for markdown, with a formatting toolbar (bold,
|
|
445
593
|
* italic, lists, links). Bind the markdown with `v-model:value`.
|