@threadlabs/looma 0.29.5 → 0.29.6
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/editor/toolbar-tooltip.d.ts +25 -0
- package/package.json +1 -1
- package/vue/editor/index.js +56 -31
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The toolbar's one tooltip: the button it describes, its label and shortcut, and whether it shows. */
|
|
2
|
+
export interface LoomaToolbarTooltipState {
|
|
3
|
+
readonly for: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly shortcut: string;
|
|
6
|
+
readonly open: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** How long, in milliseconds, the first button waits before its tooltip shows. */
|
|
9
|
+
export declare const LOOMA_TOOLBAR_TOOLTIP_DELAY = 400;
|
|
10
|
+
/**
|
|
11
|
+
* One tooltip that follows a toolbar row: the first button waits, and moving along the row while it
|
|
12
|
+
* shows is immediate, which the native `title` attribute cannot do.
|
|
13
|
+
*
|
|
14
|
+
* @ownership The host renders the tooltip from the state and calls `show` and `hide` from its buttons.
|
|
15
|
+
* @lifecycle A pending delay runs until `hide()` or `destroy()`.
|
|
16
|
+
*/
|
|
17
|
+
export interface LoomaToolbarTooltip {
|
|
18
|
+
readonly state: LoomaToolbarTooltipState;
|
|
19
|
+
/** Describes the button with `id`; `immediate` skips the delay, as keyboard focus does. */
|
|
20
|
+
show(id: string, label: string, immediate: boolean, shortcut?: string): void;
|
|
21
|
+
hide(): void;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
}
|
|
24
|
+
/** Calls `onChange` after every state change. */
|
|
25
|
+
export declare function createToolbarTooltip(onChange: (state: LoomaToolbarTooltipState) => void): LoomaToolbarTooltip;
|
package/package.json
CHANGED
package/vue/editor/index.js
CHANGED
|
@@ -2439,6 +2439,51 @@ function formatEditorShortcut(keys, apple) {
|
|
|
2439
2439
|
].filter(Boolean).join("+");
|
|
2440
2440
|
}
|
|
2441
2441
|
var isApplePlatform = () => typeof navigator !== "undefined" && /mac|iphone|ipad|ipod/i.test(navigator.userAgentData?.platform || navigator.platform || navigator.userAgent);
|
|
2442
|
+
/** Calls `onChange` after every state change. */
|
|
2443
|
+
function createToolbarTooltip(onChange) {
|
|
2444
|
+
let state = {
|
|
2445
|
+
for: "",
|
|
2446
|
+
label: "",
|
|
2447
|
+
shortcut: "",
|
|
2448
|
+
open: false
|
|
2449
|
+
};
|
|
2450
|
+
let timer;
|
|
2451
|
+
const set = (patch) => {
|
|
2452
|
+
state = {
|
|
2453
|
+
...state,
|
|
2454
|
+
...patch
|
|
2455
|
+
};
|
|
2456
|
+
onChange(state);
|
|
2457
|
+
};
|
|
2458
|
+
const clear = () => {
|
|
2459
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
2460
|
+
timer = void 0;
|
|
2461
|
+
};
|
|
2462
|
+
return {
|
|
2463
|
+
get state() {
|
|
2464
|
+
return state;
|
|
2465
|
+
},
|
|
2466
|
+
show(id, label, immediate, shortcut = "") {
|
|
2467
|
+
clear();
|
|
2468
|
+
const open = immediate || state.open;
|
|
2469
|
+
set({
|
|
2470
|
+
for: id,
|
|
2471
|
+
label,
|
|
2472
|
+
shortcut: shortcut ? formatEditorShortcut(shortcut, isApplePlatform()) : "",
|
|
2473
|
+
open
|
|
2474
|
+
});
|
|
2475
|
+
if (!open) timer = setTimeout(() => {
|
|
2476
|
+
timer = void 0;
|
|
2477
|
+
set({ open: true });
|
|
2478
|
+
}, 400);
|
|
2479
|
+
},
|
|
2480
|
+
hide() {
|
|
2481
|
+
clear();
|
|
2482
|
+
if (state.open) set({ open: false });
|
|
2483
|
+
},
|
|
2484
|
+
destroy: clear
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2442
2487
|
//#endregion
|
|
2443
2488
|
//#region src/editor/extensions/expand.ts
|
|
2444
2489
|
/**
|
|
@@ -3573,35 +3618,15 @@ var LoomaEditor = defineComponent({
|
|
|
3573
3618
|
let chipEditing;
|
|
3574
3619
|
const chipState = shallowRef(LOOMA_CHIP_EDITING_IDLE);
|
|
3575
3620
|
const toolbarScope = `looma-editor-tool-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
3576
|
-
const
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
const
|
|
3621
|
+
const toolbarTooltip = createToolbarTooltip((state) => {
|
|
3622
|
+
tooltip.value = state;
|
|
3623
|
+
});
|
|
3624
|
+
const tooltip = shallowRef(toolbarTooltip.state);
|
|
3580
3625
|
const resizeHintFor = ref("");
|
|
3581
3626
|
let resizeHintSequence = 0;
|
|
3582
|
-
|
|
3583
|
-
const
|
|
3584
|
-
|
|
3585
|
-
tooltipTimer = 0;
|
|
3586
|
-
};
|
|
3587
|
-
const showTool = (id, label, immediate, shortcut = "") => {
|
|
3588
|
-
clearTooltipTimer();
|
|
3589
|
-
tooltipFor.value = id;
|
|
3590
|
-
tooltipLabel.value = label;
|
|
3591
|
-
tooltipShortcut.value = shortcut ? formatEditorShortcut(shortcut, isApplePlatform()) : "";
|
|
3592
|
-
if (immediate || tooltipOpen.value) {
|
|
3593
|
-
tooltipOpen.value = true;
|
|
3594
|
-
return;
|
|
3595
|
-
}
|
|
3596
|
-
tooltipTimer = window.setTimeout(() => {
|
|
3597
|
-
tooltipOpen.value = true;
|
|
3598
|
-
}, 400);
|
|
3599
|
-
};
|
|
3600
|
-
const hideTool = () => {
|
|
3601
|
-
clearTooltipTimer();
|
|
3602
|
-
tooltipOpen.value = false;
|
|
3603
|
-
};
|
|
3604
|
-
onBeforeUnmount(clearTooltipTimer);
|
|
3627
|
+
const showTool = toolbarTooltip.show;
|
|
3628
|
+
const hideTool = toolbarTooltip.hide;
|
|
3629
|
+
onBeforeUnmount(toolbarTooltip.destroy);
|
|
3605
3630
|
const tableToolbarShell = ref(null);
|
|
3606
3631
|
const tableOverlayShell = ref(null);
|
|
3607
3632
|
const tableMenuShell = ref(null);
|
|
@@ -4810,13 +4835,13 @@ var LoomaEditor = defineComponent({
|
|
|
4810
4835
|
const actions = full ? [] : renderSelectionActions(instance);
|
|
4811
4836
|
return h(EditorToolbar, { floating }, () => [...mobile.value ? [...actions, ...buttons] : [...buttons, ...actions], h(Tooltip, {
|
|
4812
4837
|
class: "looma-editor__toolbar-tip",
|
|
4813
|
-
for:
|
|
4814
|
-
open:
|
|
4838
|
+
for: tooltip.value.for,
|
|
4839
|
+
open: tooltip.value.open,
|
|
4815
4840
|
placement: floating ? "top" : "bottom",
|
|
4816
4841
|
trigger: "focus"
|
|
4817
4842
|
}, {
|
|
4818
|
-
default: () =>
|
|
4819
|
-
shortcut: () =>
|
|
4843
|
+
default: () => tooltip.value.label,
|
|
4844
|
+
shortcut: () => tooltip.value.shortcut ? h("kbd", tooltip.value.shortcut) : null
|
|
4820
4845
|
})]);
|
|
4821
4846
|
};
|
|
4822
4847
|
const focus = (position = "start") => {
|