@octolo/js-contextmenu-builder 0.0.0-stage → 0.2.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,90 @@
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 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
+ Shortcuts are hidden by default in the preview; pass `showShortcuts: true`
21
+ to display them. The `complete.html` preset enables label wrapping and limits
22
+ menu width to 260px. It shows every item kind together, including a five-level
23
+ submenu that moves left, up or down when it would leave the screen.
24
+ Each kind also has its own page, listed in `presets/index.html`. The `long.html` preset tests scrolling
25
+ in a long root menu.
26
+ The `sections.html` preset demonstrates editable headings at the root and in a
27
+ submenu, together with an input, checkbox, select, button and div in the same
28
+ preview menu. The custom renderer cannot be represented in the builder's JSON.
29
+ Use `transformPreviewItems` to add runtime-only items to the preview and
30
+ `closeOnMouseLeave: false` to keep interactive controls open while using them.
31
+ In the builder, uncheck "Close when pointer leaves menu" to keep the menu open
32
+ when the mouse or pen leaves it. Outside clicks, focus changes, Escape and item
33
+ activation can still close it. The option is enabled by default.
34
+ Enable "Wrap long labels" to preview labels on multiple lines instead of
35
+ truncating them. The option also applies to submenus.
36
+ The radius field accepts a CSS `border-radius` value for menus and submenus;
37
+ leave it empty to use the size-dependent default.
38
+ The item style controls apply bold, italic, underline and CSS colors to the
39
+ whole preview, including submenus. Without either palette color, empty item color
40
+ fields use the theme defaults. Color fields also offer a color picker; item
41
+ color inputs accept other CSS colors and can be cleared to restore the default.
42
+ Set a primary hex color to use it as the menu background and generate borders,
43
+ separators, badges, hover backgrounds and contrasting text. An optional
44
+ secondary hex color influences the accents and is used as the basis for text;
45
+ otherwise the primary color is used. If only a secondary color is set, it is
46
+ used as the background and as the basis for the palette. Manually entered
47
+ menu and item colors and per-badge colors take precedence. Generated
48
+ colors appear as placeholders and remain automatic until overridden. Generated
49
+ text targets a 4.5:1 contrast ratio, borders a 3:1 ratio and hover backgrounds
50
+ a 1.5:1 ratio against their respective backgrounds.
51
+ The exported item style contains the generated colors for the current color
52
+ scheme; change the scheme in the builder to generate colors for another scheme.
53
+ Choose colors with sufficient contrast in normal and hover states, in each
54
+ color scheme. `styled.html` demonstrates bold orange text with a light orange
55
+ hover background in light mode.
56
+
57
+ ```js
58
+ import { createContextMenuBuilder } from "@octolo/js-contextmenu-builder";
59
+ import "@octolo/js-contextmenu/base.css";
60
+ import "@octolo/js-contextmenu/themes/default.css";
61
+ import "@octolo/js-contextmenu/themes/glass.css";
62
+ import "@octolo/js-contextmenu-builder/style.css";
63
+
64
+ const builder = createContextMenuBuilder(document.querySelector("#app"), [
65
+ { label: "Copy", icon: "content_copy" }
66
+ ], {
67
+ radius: "0.125rem",
68
+ wrapLabels: true,
69
+ itemStyle: {
70
+ bold: true,
71
+ color: "#8a3600",
72
+ hoverBackground: "#ffe3c2",
73
+ hoverColor: "#8a3600"
74
+ },
75
+ colorScheme: "light",
76
+ onItemStyleChange: (style) => console.log(style)
77
+ });
78
+ ```
79
+
80
+ Preset pages: `presets/index.html`.
81
+ The "Menu options JSON" section contains `itemStyle`, `wrapLabels`, `closeOnMouseLeave` and the configured `radius`
82
+ that can be passed to `createContextMenu`. Use `builder.getItemStyle()` or
83
+ listen for `contextmenubuilder:itemstylechange` to retrieve style changes.
84
+ Use `builder.getWrapLabels()`, `builder.setWrapLabels(value)`, or listen for
85
+ `contextmenubuilder:wraplabelschange` to manage label wrapping.
86
+ Use `builder.getCloseOnMouseLeave()`, `builder.setCloseOnMouseLeave(value)`, or
87
+ listen for `contextmenubuilder:closeonmouseleavechange` to manage this option.
88
+ Use `builder.getRadius()`, `builder.setRadius(value)` or listen for
89
+ `contextmenubuilder:radiuschange` to manage the radius. Omit the setter's
90
+ value to restore the default; the event's detail is then `null`.