@threadlabs/looma 0.1.17 → 0.1.18
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/README.md +2 -1
- package/dist/{chunk-OY4D3W4U.js → chunk-DTQVRGVL.js} +29 -29
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/looma.cjs.js +1 -1
- package/dist/cjs/ui-context-menu.cjs.entry.js +5 -2
- package/dist/collection/components/ui-context-menu/ui-context-menu.css +4 -0
- package/dist/collection/components/ui-context-menu/ui-context-menu.js +6 -2
- package/dist/components/ui-context-menu.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/looma.js +1 -1
- package/dist/esm/ui-context-menu.entry.js +5 -2
- package/dist/index.cjs +6 -3
- package/dist/index.js +2 -2
- package/dist/looma/looma.esm.js +1 -1
- package/dist/looma/p-063f5a89.entry.js +1 -0
- package/dist/types/components/ui-context-menu/ui-context-menu.d.ts +3 -0
- package/dist/{ui-affordance-scope.entry-X7DTKJGL.js → ui-affordance-scope.entry-2W7ZKAGK.js} +1 -1
- package/dist/{ui-avatar-group.entry-MC34FKAN.js → ui-avatar-group.entry-SE5JG2FT.js} +1 -1
- package/dist/{ui-avatar.entry-OKRQWTQV.js → ui-avatar.entry-46JDI25A.js} +1 -1
- package/dist/{ui-badge.entry-RI7JB7KV.js → ui-badge.entry-U7G3MEC5.js} +1 -1
- package/dist/{ui-button.entry-PFO5TTPN.js → ui-button.entry-DELD6KMH.js} +1 -1
- package/dist/{ui-checkbox.entry-UHFWVISP.js → ui-checkbox.entry-ZUG2P642.js} +1 -1
- package/dist/{ui-context-menu.entry-AIXB6U5D.js → ui-context-menu.entry-L4HTK3PV.js} +6 -3
- package/dist/{ui-dialog.entry-LPREQH2T.js → ui-dialog.entry-TQPYD2YI.js} +1 -1
- package/dist/{ui-disclosure.entry-7XCUIYVZ.js → ui-disclosure.entry-23TII4YU.js} +1 -1
- package/dist/{ui-floating-action-button.entry-5PNIMUAW.js → ui-floating-action-button.entry-FOQYAFJI.js} +1 -1
- package/dist/{ui-form-field.entry-77YW46SM.js → ui-form-field.entry-SCPG4STY.js} +1 -1
- package/dist/{ui-icon-button.entry-4AD6ALPQ.js → ui-icon-button.entry-U45ZVAC3.js} +1 -1
- package/dist/{ui-input.entry-E7E6QDTV.js → ui-input.entry-3AIA3G4C.js} +1 -1
- package/dist/{ui-menu-item.entry-H3HFLUB6.js → ui-menu-item.entry-3QO5TG2J.js} +1 -1
- package/dist/{ui-menu.entry-UAKZU4HG.js → ui-menu.entry-JACWGDDG.js} +1 -1
- package/dist/{ui-popover.entry-GVQKX26B.js → ui-popover.entry-2XP4H3S2.js} +1 -1
- package/dist/{ui-radio-group.entry-MNSR6UEE.js → ui-radio-group.entry-73IKFMDK.js} +1 -1
- package/dist/{ui-radio.entry-6D4WTI5E.js → ui-radio.entry-INJVXUKE.js} +1 -1
- package/dist/{ui-search-result-row.entry-J2TILUH2.js → ui-search-result-row.entry-4J732TDC.js} +1 -1
- package/dist/{ui-search-shell.entry-FSWHEZQF.js → ui-search-shell.entry-3C2WRVE2.js} +1 -1
- package/dist/{ui-select.entry-JRCYYNNW.js → ui-select.entry-3ZLDGAKX.js} +1 -1
- package/dist/{ui-switch.entry-YZWMNRP2.js → ui-switch.entry-5MJRLR2P.js} +1 -1
- package/dist/{ui-tabs.entry-F2Y344JY.js → ui-tabs.entry-F5H7OPBO.js} +1 -1
- package/dist/{ui-textarea.entry-3EZCUUAK.js → ui-textarea.entry-BNJ375JB.js} +1 -1
- package/dist/{ui-toast-region.entry-BTV4AW3I.js → ui-toast-region.entry-ZUIPJ2JH.js} +1 -1
- package/dist/{ui-tooltip.entry-U644CF5U.js → ui-tooltip.entry-DZ4RMF35.js} +1 -1
- package/dist/{ui-top-bar.entry-FGGOREQR.js → ui-top-bar.entry-VKRXIUU6.js} +1 -1
- package/dist/{ui-tree-item.entry-XVMHEONY.js → ui-tree-item.entry-NFUQ45OL.js} +1 -1
- package/dist/{ui-tree.entry-4R7DYGAM.js → ui-tree.entry-H4CWDYI6.js} +1 -1
- package/editor/{chunk-RTHHTPWK.js → chunk-3QMBK3XZ.js} +245 -41
- package/editor/{chunk-OHD4OS32.js → chunk-OXFYYLUC.js} +632 -236
- package/editor/{chunk-CX4QDKSV.js → chunk-ZOUKEZ77.js} +21 -1
- package/editor/extensions/index.d.ts +49 -1
- package/editor/extensions/index.js +15 -3
- package/editor/index.d.ts +3 -2
- package/editor/index.js +16 -4
- package/editor/ui.d.ts +9 -1
- package/editor/ui.js +2 -2
- package/editor.css +170 -0
- package/package.json +1 -1
- package/styles.css +1 -7
- package/vue/editor/index.d.ts +103 -4
- package/vue/editor/index.js +137 -63
- package/dist/looma/p-ba01f45d.entry.js +0 -1
package/vue/editor/index.js
CHANGED
|
@@ -16,73 +16,86 @@ import {
|
|
|
16
16
|
shallowRef,
|
|
17
17
|
watchEffect
|
|
18
18
|
} from "vue";
|
|
19
|
+
function createSuggestionMenuAdapter(tag, name, eventPrefix) {
|
|
20
|
+
return defineComponent({
|
|
21
|
+
name,
|
|
22
|
+
inheritAttrs: false,
|
|
23
|
+
props: {
|
|
24
|
+
open: { type: Boolean, default: false },
|
|
25
|
+
query: { type: String, default: "" },
|
|
26
|
+
items: { type: Array, default: () => [] },
|
|
27
|
+
selectedIndex: { type: Number, default: 0 },
|
|
28
|
+
anchorRect: { type: Object, default: null },
|
|
29
|
+
loading: { type: Boolean, default: false }
|
|
30
|
+
},
|
|
31
|
+
setup(props, { attrs }) {
|
|
32
|
+
const elementRef = shallowRef(null);
|
|
33
|
+
watchEffect(() => {
|
|
34
|
+
const element = elementRef.value;
|
|
35
|
+
if (!element) return;
|
|
36
|
+
if (element.open !== props.open) element.open = props.open;
|
|
37
|
+
if (element.query !== props.query) element.query = props.query;
|
|
38
|
+
if (element.items !== props.items) element.items = props.items;
|
|
39
|
+
if (element.selectedIndex !== props.selectedIndex) element.selectedIndex = props.selectedIndex;
|
|
40
|
+
if (element.anchorRect !== props.anchorRect) element.anchorRect = props.anchorRect;
|
|
41
|
+
if (element.loading !== void 0 && element.loading !== props.loading) {
|
|
42
|
+
element.loading = props.loading;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
watchEffect((onCleanup) => {
|
|
46
|
+
const element = elementRef.value;
|
|
47
|
+
if (!element) return;
|
|
48
|
+
const callbackAttrs = attrs;
|
|
49
|
+
const highlightCallback = eventPrefix === "slash" ? callbackAttrs.onSlashMenuHighlight : callbackAttrs.onMentionMenuHighlight;
|
|
50
|
+
const selectCallback = eventPrefix === "slash" ? callbackAttrs.onSlashMenuSelect : callbackAttrs.onMentionMenuSelect;
|
|
51
|
+
const eventBase = `looma-editor-${eventPrefix}-menu`;
|
|
52
|
+
const highlightHandler = typeof highlightCallback === "function" ? (event) => highlightCallback(event.detail) : void 0;
|
|
53
|
+
const selectHandler = typeof selectCallback === "function" ? (event) => selectCallback(event.detail) : void 0;
|
|
54
|
+
if (highlightHandler) element.addEventListener(`${eventBase}-highlight`, highlightHandler);
|
|
55
|
+
if (selectHandler) element.addEventListener(`${eventBase}-select`, selectHandler);
|
|
56
|
+
onCleanup(() => {
|
|
57
|
+
if (highlightHandler) element.removeEventListener(`${eventBase}-highlight`, highlightHandler);
|
|
58
|
+
if (selectHandler) element.removeEventListener(`${eventBase}-select`, selectHandler);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
const callbackAttrs = attrs;
|
|
63
|
+
const {
|
|
64
|
+
onMentionMenuHighlight,
|
|
65
|
+
onMentionMenuSelect,
|
|
66
|
+
onSlashMenuHighlight,
|
|
67
|
+
onSlashMenuSelect,
|
|
68
|
+
...forwardedAttrs
|
|
69
|
+
} = callbackAttrs;
|
|
70
|
+
void onMentionMenuHighlight;
|
|
71
|
+
void onMentionMenuSelect;
|
|
72
|
+
void onSlashMenuHighlight;
|
|
73
|
+
void onSlashMenuSelect;
|
|
74
|
+
return h(tag, {
|
|
75
|
+
...forwardedAttrs,
|
|
76
|
+
ref: (value) => {
|
|
77
|
+
elementRef.value = toHTMLElement(value);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
19
84
|
var EDITOR_EVENT_BINDINGS = [
|
|
20
85
|
["looma-editor-table-action", "onTableAction"],
|
|
21
86
|
["looma-editor-insert-table", "onInsertTable"],
|
|
22
87
|
["looma-editor-table-overlay-action", "onTableOverlayAction"]
|
|
23
88
|
];
|
|
24
|
-
var EditorSlashMenu =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setup(props, { attrs }) {
|
|
35
|
-
const elementRef = shallowRef(null);
|
|
36
|
-
watchEffect(() => {
|
|
37
|
-
const element = elementRef.value;
|
|
38
|
-
if (!element) return;
|
|
39
|
-
if (element.open !== props.open) element.open = props.open;
|
|
40
|
-
if (element.query !== props.query) element.query = props.query;
|
|
41
|
-
if (element.items !== props.items) element.items = props.items;
|
|
42
|
-
if (element.selectedIndex !== props.selectedIndex) element.selectedIndex = props.selectedIndex;
|
|
43
|
-
if (element.anchorRect !== props.anchorRect) element.anchorRect = props.anchorRect;
|
|
44
|
-
});
|
|
45
|
-
watchEffect((onCleanup) => {
|
|
46
|
-
const element = elementRef.value;
|
|
47
|
-
if (!element) return;
|
|
48
|
-
const callbackAttrs = attrs;
|
|
49
|
-
const handlers = [
|
|
50
|
-
[
|
|
51
|
-
"looma-editor-slash-menu-highlight",
|
|
52
|
-
typeof callbackAttrs.onSlashMenuHighlight === "function" ? (event) => callbackAttrs.onSlashMenuHighlight?.(
|
|
53
|
-
event.detail
|
|
54
|
-
) : void 0
|
|
55
|
-
],
|
|
56
|
-
[
|
|
57
|
-
"looma-editor-slash-menu-select",
|
|
58
|
-
typeof callbackAttrs.onSlashMenuSelect === "function" ? (event) => callbackAttrs.onSlashMenuSelect?.(
|
|
59
|
-
event.detail
|
|
60
|
-
) : void 0
|
|
61
|
-
]
|
|
62
|
-
];
|
|
63
|
-
for (const [eventName, handler] of handlers) {
|
|
64
|
-
if (handler) element.addEventListener(eventName, handler);
|
|
65
|
-
}
|
|
66
|
-
onCleanup(() => {
|
|
67
|
-
for (const [eventName, handler] of handlers) {
|
|
68
|
-
if (handler) element.removeEventListener(eventName, handler);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
return () => {
|
|
73
|
-
const callbackAttrs = attrs;
|
|
74
|
-
const { onSlashMenuHighlight, onSlashMenuSelect, ...forwardedAttrs } = callbackAttrs;
|
|
75
|
-
void onSlashMenuHighlight;
|
|
76
|
-
void onSlashMenuSelect;
|
|
77
|
-
return h("ui-editor-slash-menu", {
|
|
78
|
-
...forwardedAttrs,
|
|
79
|
-
ref: (value) => {
|
|
80
|
-
elementRef.value = toHTMLElement(value);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
});
|
|
89
|
+
var EditorSlashMenu = createSuggestionMenuAdapter(
|
|
90
|
+
"ui-editor-slash-menu",
|
|
91
|
+
"EditorSlashMenu",
|
|
92
|
+
"slash"
|
|
93
|
+
);
|
|
94
|
+
var EditorMentionMenu = createSuggestionMenuAdapter(
|
|
95
|
+
"ui-editor-mention-menu",
|
|
96
|
+
"EditorMentionMenu",
|
|
97
|
+
"mention"
|
|
98
|
+
);
|
|
86
99
|
var EditorToolbar = createAdapterComponent("ui-editor-toolbar", "EditorToolbar", EDITOR_EVENT_BINDINGS);
|
|
87
100
|
var EditorTableContextMenu = createAdapterComponent("ui-editor-table-context-menu", "EditorTableContextMenu", EDITOR_EVENT_BINDINGS);
|
|
88
101
|
var EditorTableToolbar = createAdapterComponent("ui-editor-table-toolbar", "EditorTableToolbar", EDITOR_EVENT_BINDINGS);
|
|
@@ -97,6 +110,7 @@ var EditorTableOverlay = createAdapterComponent(
|
|
|
97
110
|
var EDITOR_ADAPTER_COMPONENT_TAG_MAP = {
|
|
98
111
|
EditorToolbar: "ui-editor-toolbar",
|
|
99
112
|
EditorSlashMenu: "ui-editor-slash-menu",
|
|
113
|
+
EditorMentionMenu: "ui-editor-mention-menu",
|
|
100
114
|
EditorTableContextMenu: "ui-editor-table-context-menu",
|
|
101
115
|
EditorTableToolbar: "ui-editor-table-toolbar",
|
|
102
116
|
EditorInsertTableGrid: "ui-editor-insert-table-grid",
|
|
@@ -119,6 +133,8 @@ import {
|
|
|
119
133
|
} from "vue";
|
|
120
134
|
import {
|
|
121
135
|
createLoomaSlashCommandExtension,
|
|
136
|
+
createLoomaMentionExtension,
|
|
137
|
+
DEFAULT_MENTION_RESULT_LIMIT,
|
|
122
138
|
getActiveTableUiState,
|
|
123
139
|
getDefaultEditorExtensions,
|
|
124
140
|
handleTableAction,
|
|
@@ -312,6 +328,7 @@ function imageUploadContent(image) {
|
|
|
312
328
|
|
|
313
329
|
// src/editor/LoomaEditor.ts
|
|
314
330
|
var EMPTY_DOCUMENT = { type: "doc", content: [] };
|
|
331
|
+
var editorInstanceSequence = 0;
|
|
315
332
|
var EMPTY_CAPABILITIES = {
|
|
316
333
|
canAddRowBefore: false,
|
|
317
334
|
canAddRowAfter: false,
|
|
@@ -367,6 +384,18 @@ var LoomaEditor = defineComponent2({
|
|
|
367
384
|
type: Array,
|
|
368
385
|
default: () => []
|
|
369
386
|
},
|
|
387
|
+
mentionItems: {
|
|
388
|
+
type: Array,
|
|
389
|
+
default: () => []
|
|
390
|
+
},
|
|
391
|
+
mentionProvider: {
|
|
392
|
+
type: Function,
|
|
393
|
+
default: void 0
|
|
394
|
+
},
|
|
395
|
+
mentionLimit: {
|
|
396
|
+
type: Number,
|
|
397
|
+
default: DEFAULT_MENTION_RESULT_LIMIT
|
|
398
|
+
},
|
|
370
399
|
uploadImage: {
|
|
371
400
|
type: Function,
|
|
372
401
|
default: void 0
|
|
@@ -415,6 +444,16 @@ var LoomaEditor = defineComponent2({
|
|
|
415
444
|
rect: null,
|
|
416
445
|
select: null
|
|
417
446
|
});
|
|
447
|
+
const mention = reactive({
|
|
448
|
+
active: false,
|
|
449
|
+
items: [],
|
|
450
|
+
selectedIndex: 0,
|
|
451
|
+
query: "",
|
|
452
|
+
rect: null,
|
|
453
|
+
loading: false,
|
|
454
|
+
highlight: null,
|
|
455
|
+
select: null
|
|
456
|
+
});
|
|
418
457
|
const tableUi = reactive({
|
|
419
458
|
toolbarOpen: false,
|
|
420
459
|
overlayOpen: false,
|
|
@@ -435,6 +474,21 @@ var LoomaEditor = defineComponent2({
|
|
|
435
474
|
Object.assign(slash, state);
|
|
436
475
|
}
|
|
437
476
|
});
|
|
477
|
+
const mentionMenuId = `looma-editor-mention-menu-${++editorInstanceSequence}`;
|
|
478
|
+
const hasConsumerMention = props.extensions.some((extension) => extension.name === "mention");
|
|
479
|
+
const mentionExtension = hasConsumerMention ? null : createLoomaMentionExtension({
|
|
480
|
+
limit: props.mentionLimit,
|
|
481
|
+
menuId: mentionMenuId,
|
|
482
|
+
items: async (query, context) => {
|
|
483
|
+
if (props.mentionProvider) {
|
|
484
|
+
return await props.mentionProvider(query, context);
|
|
485
|
+
}
|
|
486
|
+
return props.mentionItems;
|
|
487
|
+
},
|
|
488
|
+
onStateChange: (state) => {
|
|
489
|
+
Object.assign(mention, state);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
438
492
|
const imageDelivery = createLoomaImageDeliveryController({
|
|
439
493
|
resolveAttributes: () => props.resolveImageAttributes
|
|
440
494
|
});
|
|
@@ -451,7 +505,10 @@ var LoomaEditor = defineComponent2({
|
|
|
451
505
|
};
|
|
452
506
|
const editor = useEditor({
|
|
453
507
|
extensions: [
|
|
454
|
-
...getDefaultEditorExtensions({
|
|
508
|
+
...getDefaultEditorExtensions({
|
|
509
|
+
placeholder: props.placeholder,
|
|
510
|
+
mention: mentionExtension ?? false
|
|
511
|
+
}),
|
|
455
512
|
imageDelivery.extension,
|
|
456
513
|
slashExtension,
|
|
457
514
|
...props.extensions
|
|
@@ -1011,6 +1068,22 @@ var LoomaEditor = defineComponent2({
|
|
|
1011
1068
|
slash.select?.(index);
|
|
1012
1069
|
}
|
|
1013
1070
|
}) : null,
|
|
1071
|
+
mention.active && (mention.loading || mention.items.length > 0) ? h2(EditorMentionMenu, {
|
|
1072
|
+
id: mentionMenuId,
|
|
1073
|
+
open: true,
|
|
1074
|
+
query: mention.query,
|
|
1075
|
+
items: mention.items,
|
|
1076
|
+
selectedIndex: mention.selectedIndex,
|
|
1077
|
+
anchorRect: mention.rect,
|
|
1078
|
+
loading: mention.loading,
|
|
1079
|
+
onMentionMenuHighlight: ({ index }) => {
|
|
1080
|
+
mention.selectedIndex = index;
|
|
1081
|
+
mention.highlight?.(index);
|
|
1082
|
+
},
|
|
1083
|
+
onMentionMenuSelect: ({ index }) => {
|
|
1084
|
+
mention.select?.(index);
|
|
1085
|
+
}
|
|
1086
|
+
}) : null,
|
|
1014
1087
|
tableUi.toolbarOpen ? h2("div", {
|
|
1015
1088
|
ref: tableToolbarShell,
|
|
1016
1089
|
class: "looma-editor__table-toolbar-shell",
|
|
@@ -1040,6 +1113,7 @@ var LoomaEditor = defineComponent2({
|
|
|
1040
1113
|
export {
|
|
1041
1114
|
EDITOR_ADAPTER_COMPONENT_TAG_MAP,
|
|
1042
1115
|
EditorInsertTableGrid,
|
|
1116
|
+
EditorMentionMenu,
|
|
1043
1117
|
EditorSlashMenu,
|
|
1044
1118
|
EditorTableContextMenu,
|
|
1045
1119
|
EditorTableOverlay,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as t,g as i,h as e,H as s}from"./p-CEeiinfk.js";import{o as n,c as a,r as o}from"./p-PM9a74r7.js";import{d as r}from"./p-JwSoedEO.js";import{a as h}from"./p-Bu0dmLBE.js";const c=class{constructor(i){t(this,i)}get host(){return i(this)}open=!1;defaultOpen=!1;for;internalOpen=!1;overlayId=`ui-context-menu-${Math.random().toString(36).slice(2,11)}`;trigger=null;contextTarget=null;pointerX=0;pointerY=0;pointPositioned=!1;surface=null;syncFromProp(){this.internalOpen=this.open}syncTarget(){this.resolveTargets(),this.attachTargetListeners()}syncOverlay(){this.syncTriggerState(),this.internalOpen?(this.pointPositioned?this.surface?.showAtPoint({x:this.pointerX,y:this.pointerY}):this.surface?.show(),n({id:this.overlayId,modal:!1,element:this.host,dismissible:!0,requestClose:(t,i)=>this.closeMenu(t,i)})):(this.surface?.hide(),a(this.overlayId))}componentDidLoad(){this.syncFromProp(),this.internalOpen=this.internalOpen||this.defaultOpen,this.resolveTargets(),this.attachTargetListeners(),this.setupSurface(),this.syncTriggerState(),this.syncOverlay()}componentDidUpdate(){this.resolveTargets(),this.attachTargetListeners(),this.pointPositioned||this.surface?.setAnchor(this.trigger),this.syncTriggerState()}disconnectedCallback(){this.detachTargetListeners(),this.surface?.destroy(),this.surface=null,a(this.overlayId)}setupSurface(){const t=this.host.shadowRoot?.querySelector(".menu");t&&(this.surface?.destroy(),this.surface=h(t,{anchor:this.trigger,placement:"bottom-start"}))}resolveTargets(){const t=this.trigger,i=this.contextTarget,e=this.host.querySelector('[slot="trigger"]'),s=this.for?document.getElementById(this.for):null;this.trigger=e,this.contextTarget=s??e??this.host.parentElement,t===this.trigger&&i===this.contextTarget||(t?.removeEventListener("click",this.onTriggerClick),t?.removeEventListener("keydown",this.onTriggerKeydown),i?.removeEventListener("contextmenu",this.onContextMenu))}attachTargetListeners(){this.detachTargetListeners(),this.trigger?.addEventListener("click",this.onTriggerClick),this.trigger?.addEventListener("keydown",this.onTriggerKeydown),this.contextTarget?.addEventListener("contextmenu",this.onContextMenu)}detachTargetListeners(){this.trigger?.removeEventListener("click",this.onTriggerClick),this.trigger?.removeEventListener("keydown",this.onTriggerKeydown),this.contextTarget?.removeEventListener("contextmenu",this.onContextMenu)}syncTriggerState(){this.trigger&&(this.trigger.setAttribute("aria-haspopup","menu"),this.trigger.setAttribute("aria-expanded",this.internalOpen?"true":"false"))}getItems(){return Array.from(this.host.querySelectorAll("ui-menu-item")).filter((t=>!this.isItemDisabled(t)))}focusFirstItem(){requestAnimationFrame((()=>this.getItems()[0]?.focus()))}openMenu(t,i,e){this.pointerX=t,this.pointerY=i,this.pointPositioned=!0,this.surface?.showAtPoint({x:t,y:i}),this.internalOpen=!0,r(this.host,"open",{open:!0,reason:"action",trigger:e}),this.focusFirstItem()}openFromTrigger(t){this.trigger&&(this.pointPositioned=!1,this.internalOpen=!0,r(this.host,"open",{open:!0,reason:"action",trigger:t}),this.focusFirstItem())}closeMenu(t,i,e=!0){this.internalOpen&&(this.internalOpen=!1,r(this.host,"close",{open:!1,reason:t,trigger:i}),e&&this.trigger?.focus())}onTriggerClick=t=>{this.internalOpen?this.closeMenu("action",0===t.detail?"keyboard":"pointer"):this.openFromTrigger(0===t.detail?"keyboard":"pointer")};onTriggerKeydown=t=>{"Enter"!==t.key&&" "!==t.key&&"ArrowDown"!==t.key||(t.preventDefault(),this.internalOpen?this.focusFirstItem():this.openFromTrigger("keyboard"))};onContextMenu=t=>{t.preventDefault(),this.openMenu(t.clientX,t.clientY,"pointer")};isItemDisabled(t){return"true"===t.getAttribute("aria-disabled")||t.hasAttribute("disabled")||"true"===t.getAttribute("disabled")||!0===t.disabled}onKeydown=t=>{if(this.internalOpen){if("Escape"===t.key)return t.preventDefault(),void o("escape","keyboard");if("Enter"===t.key||" "===t.key){const i=t.target.closest?.("ui-menu-item");if(!i||this.isItemDisabled(i))return;t.preventDefault();const e=i.getAttribute("value")??i.getAttribute("data-value")??"";r(this.host,"select",{value:e,trigger:"keyboard"}),this.closeMenu("action","keyboard")}}};onItemClick=t=>{const i=t.target.closest?.("ui-menu-item");if(!i||this.isItemDisabled(i))return;const e=i.getAttribute("value")??i.getAttribute("data-value")??"";r(this.host,"select",{value:e,trigger:"pointer"}),this.closeMenu("action","pointer")};render(){return e(s,{key:"aee76fad23434fb3cdaf885c698f62237c2a9468","data-open":this.internalOpen?"":void 0,onKeyDown:this.onKeydown,onClick:this.onItemClick},e("slot",{key:"da047f870b7a93f1acbba5fa1628b5cb66139d99",name:"trigger"}),e("div",{key:"388a473ac7fb626a20d0feda14f0d8dd16f6ab94",class:"menu","data-open":this.internalOpen?"":void 0},e("ui-menu",{key:"67ca5c05ff40d2dd1d5f17a8634636503f98c02d",open:this.internalOpen},e("slot",{key:"b7c7dfac4342afa1df67459e94de7ac7dca4a251"}))))}static get watchers(){return{open:[{syncFromProp:0}],for:[{syncTarget:0}],internalOpen:[{syncOverlay:0}]}}};c.style=":host{display:contents}.menu{position:fixed;inset:auto;margin:0;z-index:var(--ui-z-overlay, 1000);min-width:12rem;opacity:0;transform:translateY(-4px) scale(0.99);transition:opacity var(--ui-motion-fast) var(--ui-motion-ease), transform var(--ui-motion-fast) var(--ui-motion-ease), display var(--ui-motion-fast) allow-discrete, overlay var(--ui-motion-fast) allow-discrete}.menu:popover-open{opacity:1;transform:translateY(0) scale(1)}@starting-style{.menu:popover-open{opacity:0;transform:translateY(-4px) scale(0.99)}}.menu[hidden]{display:none !important}@media (prefers-reduced-motion: reduce){.menu{transition:none}}";export{c as ui_context_menu}
|