@octolo/js-contextmenu-builder 0.0.0-stage → 0.4.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/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ # @octolo/js-contextmenu-builder
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Visual builder for editing a JSON menu with a live preview, modeled after
4
+ `js-dynamic-form-builder`: nested tree, radius control, light / dark mode and
5
+ Small / Normal / Large sizes.
6
+ The "Add heading" button inserts a non-clickable `{ type: "heading", label }`
7
+ section title at the root or in a submenu. The "Add separator" button inserts
8
+ a `{ type: "separator" }` item. The form also supports checkboxes, radio
9
+ groups, initial states, a second line, a destructive style, links and displayed shortcuts.
10
+ The item editor also supports notification dots and text or number badges,
11
+ with per-item text and background colors and an accessible description.
12
+ Leave badge text empty for a dot. Badges are included in the exported menu JSON.
13
+ The item editor also adds multiple inline icon actions before or after a label.
14
+ Each action has a name, accessible label, icon, optional disabled state and
15
+ optional close-on-activation setting. They are exported in the menu JSON and
16
+ can be tested in the preview; connect application behavior to the core's
17
+ `contextmenu:action` event or action callbacks after export.
18
+ Open `presets/inline-actions.html` to try and edit several icon actions,
19
+ including actions in a submenu. Right-click the preview area to open the menu.
20
+ Open `presets/dropdown.html` to try an anchored dropdown with an 8px gap.
21
+ The `previewDropdown: { offset: 8 }` builder option adds the trigger to the
22
+ preview; positioning is configured through the core's `attach` options, not
23
+ the exported menu JSON.
24
+ Shortcuts are hidden by default in the preview; pass `showShortcuts: true`
25
+ to display them. The `complete.html` preset enables label wrapping and limits
26
+ menu width to 260px. It shows every item kind together, including a five-level
27
+ submenu, a submenu loaded on open, a destructive action, a link, a detail line
28
+ and a right-to-left switch. Submenus move left, up or down when they would leave
29
+ the screen. Moving toward an open submenu does not switch to the row underneath.
30
+ Each kind also has its own page, listed in `presets/index.html`. The `long.html` preset tests scrolling
31
+ in a long root menu. The `scroll.html` preset wraps recent files in a block
32
+ capped at four rows with `lines: 4`.
33
+ The `sections.html` preset demonstrates editable headings at the root and in a
34
+ submenu, together with an input, checkbox, select, button and div in the same
35
+ preview menu. The custom renderer cannot be represented in the builder's JSON.
36
+ Use `transformPreviewItems` to add runtime-only items to the preview and
37
+ `closeOnMouseLeave: false` to keep interactive controls open while using them.
38
+ In the builder, uncheck "Close when pointer leaves menu" to keep the menu open
39
+ when the mouse or pen leaves it. Outside clicks, focus changes, Escape and item
40
+ activation can still close it. The option is enabled by default.
41
+ Enable "Wrap long labels" to preview labels on multiple lines instead of
42
+ truncating them. The option also applies to submenus.
43
+ The radius field accepts a CSS `border-radius` value for menus and submenus;
44
+ leave it empty to use the size-dependent default.
45
+ The item style controls apply bold, italic, underline and CSS colors to the
46
+ whole preview, including submenus. Without either palette color, empty item color
47
+ fields use the theme defaults. Color fields also offer a color picker; item
48
+ color inputs accept other CSS colors and can be cleared to restore the default.
49
+ Set a primary hex color to use it as the menu background and generate borders,
50
+ separators, badges, hover backgrounds and contrasting text. An optional
51
+ secondary hex color influences the accents and is used as the basis for text;
52
+ otherwise the primary color is used. If only a secondary color is set, it is
53
+ used as the background and as the basis for the palette. Manually entered
54
+ menu and item colors and per-badge colors take precedence. Generated
55
+ colors appear as placeholders and remain automatic until overridden. Generated
56
+ text targets a 4.5:1 contrast ratio, borders a 3:1 ratio and hover backgrounds
57
+ a 1.5:1 ratio against their respective backgrounds.
58
+ The exported item style contains the generated colors for the current color
59
+ scheme; change the scheme in the builder to generate colors for another scheme.
60
+ Choose colors with sufficient contrast in normal and hover states, in each
61
+ color scheme. `styled.html` demonstrates bold orange text with a light orange
62
+ hover background in light mode.
63
+
64
+ ```js
65
+ import { createContextMenuBuilder } from "@octolo/js-contextmenu-builder";
66
+ import "@octolo/js-contextmenu/base.css";
67
+ import "@octolo/js-contextmenu/themes/default.css";
68
+ import "@octolo/js-contextmenu/themes/glass.css";
69
+ import "@octolo/js-contextmenu-builder/style.css";
70
+
71
+ const builder = createContextMenuBuilder(document.querySelector("#app"), [
72
+ { label: "Copy", icon: "content_copy" }
73
+ ], {
74
+ radius: "0.125rem",
75
+ wrapLabels: true,
76
+ itemStyle: {
77
+ bold: true,
78
+ color: "#8a3600",
79
+ hoverBackground: "#ffe3c2",
80
+ hoverColor: "#8a3600"
81
+ },
82
+ colorScheme: "light",
83
+ onItemStyleChange: (style) => console.log(style)
84
+ });
85
+ ```
86
+
87
+ Preset pages: `presets/index.html`.
88
+ The "Menu options JSON" section contains `itemStyle`, `wrapLabels`, `closeOnMouseLeave` and the configured `radius`
89
+ that can be passed to `createContextMenu`. Use `builder.getItemStyle()` or
90
+ listen for `contextmenubuilder:itemstylechange` to retrieve style changes.
91
+ Use `builder.getWrapLabels()`, `builder.setWrapLabels(value)`, or listen for
92
+ `contextmenubuilder:wraplabelschange` to manage label wrapping.
93
+ Use `builder.getCloseOnMouseLeave()`, `builder.setCloseOnMouseLeave(value)`, or
94
+ listen for `contextmenubuilder:closeonmouseleavechange` to manage this option.
95
+ Use `builder.getRadius()`, `builder.setRadius(value)` or listen for
96
+ `contextmenubuilder:radiuschange` to manage the radius. Omit the setter's
97
+ value to restore the default; the event's detail is then `null`.