@casualoffice/sheets 0.16.0 → 0.17.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/chrome.cjs +82 -63
- package/dist/chrome.cjs.map +1 -1
- package/dist/chrome.d.cts +33 -0
- package/dist/chrome.d.ts +33 -0
- package/dist/chrome.js +82 -63
- package/dist/chrome.js.map +1 -1
- package/dist/embed/embed-runtime.js +107 -107
- package/package.json +1 -1
- package/src/chrome/MenuBar.feature-gate.unit.test.ts +152 -0
- package/src/chrome/MenuBar.tsx +36 -141
- package/src/chrome/menu-model.ts +191 -0
package/dist/chrome.d.cts
CHANGED
|
@@ -75,6 +75,38 @@ interface AutoSumPickerProps {
|
|
|
75
75
|
}
|
|
76
76
|
declare function AutoSumPicker({ api }: AutoSumPickerProps): react.JSX.Element;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Copyright 2026 Casual Office
|
|
80
|
+
*
|
|
81
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
82
|
+
* you may not use this file except in compliance with the License.
|
|
83
|
+
* You may obtain a copy of the License at
|
|
84
|
+
*
|
|
85
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
86
|
+
*
|
|
87
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
88
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
89
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
90
|
+
* See the License for the specific language governing permissions and
|
|
91
|
+
* limitations under the License.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* MenuBar data model + pure gating engine.
|
|
95
|
+
*
|
|
96
|
+
* Split out of `MenuBar.tsx` so the feature-gating contract is unit-testable
|
|
97
|
+
* under `node --test`: `MenuBar.tsx` statically imports `@univerjs/core` values
|
|
98
|
+
* (which the vendored typeless-package ESM can't expose as named exports to
|
|
99
|
+
* node), so it can't be imported in a DOM-less test. This module has only
|
|
100
|
+
* type-only imports (all erased at build), so `computeVisibleMenus` — the code
|
|
101
|
+
* that decides which menus/items a host actually sees — can be exercised
|
|
102
|
+
* directly.
|
|
103
|
+
*
|
|
104
|
+
* Feature gates: pass `features` to hide a control or whole menu group when its
|
|
105
|
+
* feature is disabled. Defaults to all-enabled. A control whose feature is
|
|
106
|
+
* `false` does not render. An entire top-level menu whose own `feature` is
|
|
107
|
+
* `false`, or that ends up with no runnable items, is dropped.
|
|
108
|
+
*/
|
|
109
|
+
|
|
78
110
|
/**
|
|
79
111
|
* Dialog kinds the host can choose to render via `onDialogRequest`. These are
|
|
80
112
|
* the actions the SDK chrome can't fulfil on its own (no built-in modal). The
|
|
@@ -82,6 +114,7 @@ declare function AutoSumPicker({ api }: AutoSumPickerProps): react.JSX.Element;
|
|
|
82
114
|
* carries the pre-resolved A1 selection so the host doesn't have to re-read it.
|
|
83
115
|
*/
|
|
84
116
|
type MenuDialogKind = DialogKind;
|
|
117
|
+
|
|
85
118
|
interface MenuBarProps {
|
|
86
119
|
/** Live API, or `null` until the editor is ready. */
|
|
87
120
|
api: CasualSheetsAPI | null;
|
package/dist/chrome.d.ts
CHANGED
|
@@ -75,6 +75,38 @@ interface AutoSumPickerProps {
|
|
|
75
75
|
}
|
|
76
76
|
declare function AutoSumPicker({ api }: AutoSumPickerProps): react.JSX.Element;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Copyright 2026 Casual Office
|
|
80
|
+
*
|
|
81
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
82
|
+
* you may not use this file except in compliance with the License.
|
|
83
|
+
* You may obtain a copy of the License at
|
|
84
|
+
*
|
|
85
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
86
|
+
*
|
|
87
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
88
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
89
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
90
|
+
* See the License for the specific language governing permissions and
|
|
91
|
+
* limitations under the License.
|
|
92
|
+
*/
|
|
93
|
+
/**
|
|
94
|
+
* MenuBar data model + pure gating engine.
|
|
95
|
+
*
|
|
96
|
+
* Split out of `MenuBar.tsx` so the feature-gating contract is unit-testable
|
|
97
|
+
* under `node --test`: `MenuBar.tsx` statically imports `@univerjs/core` values
|
|
98
|
+
* (which the vendored typeless-package ESM can't expose as named exports to
|
|
99
|
+
* node), so it can't be imported in a DOM-less test. This module has only
|
|
100
|
+
* type-only imports (all erased at build), so `computeVisibleMenus` — the code
|
|
101
|
+
* that decides which menus/items a host actually sees — can be exercised
|
|
102
|
+
* directly.
|
|
103
|
+
*
|
|
104
|
+
* Feature gates: pass `features` to hide a control or whole menu group when its
|
|
105
|
+
* feature is disabled. Defaults to all-enabled. A control whose feature is
|
|
106
|
+
* `false` does not render. An entire top-level menu whose own `feature` is
|
|
107
|
+
* `false`, or that ends up with no runnable items, is dropped.
|
|
108
|
+
*/
|
|
109
|
+
|
|
78
110
|
/**
|
|
79
111
|
* Dialog kinds the host can choose to render via `onDialogRequest`. These are
|
|
80
112
|
* the actions the SDK chrome can't fulfil on its own (no built-in modal). The
|
|
@@ -82,6 +114,7 @@ declare function AutoSumPicker({ api }: AutoSumPickerProps): react.JSX.Element;
|
|
|
82
114
|
* carries the pre-resolved A1 selection so the host doesn't have to re-read it.
|
|
83
115
|
*/
|
|
84
116
|
type MenuDialogKind = DialogKind;
|
|
117
|
+
|
|
85
118
|
interface MenuBarProps {
|
|
86
119
|
/** Live API, or `null` until the editor is ready. */
|
|
87
120
|
api: CasualSheetsAPI | null;
|
package/dist/chrome.js
CHANGED
|
@@ -2701,6 +2701,68 @@ function ensurePluginByName(group) {
|
|
|
2701
2701
|
return ensurePlugin(currentUniver, group);
|
|
2702
2702
|
}
|
|
2703
2703
|
|
|
2704
|
+
// src/chrome/menu-model.ts
|
|
2705
|
+
function featureOn(feature, features) {
|
|
2706
|
+
if (!feature) return true;
|
|
2707
|
+
return features[feature] !== false;
|
|
2708
|
+
}
|
|
2709
|
+
function keepItem(item, features, canOpen) {
|
|
2710
|
+
if (!featureOn(item.feature, features)) return null;
|
|
2711
|
+
if (item.kind === "separator") return item;
|
|
2712
|
+
if (item.kind === "submenu") {
|
|
2713
|
+
const items = filterItems(item.items, features, canOpen);
|
|
2714
|
+
if (items.length === 0) return null;
|
|
2715
|
+
return { ...item, items };
|
|
2716
|
+
}
|
|
2717
|
+
if (item.dialog && !canOpen(item.dialog)) return null;
|
|
2718
|
+
return item;
|
|
2719
|
+
}
|
|
2720
|
+
function filterItems(items, features, canOpen) {
|
|
2721
|
+
const kept = items.map((i) => keepItem(i, features, canOpen)).filter((i) => i !== null);
|
|
2722
|
+
const out = [];
|
|
2723
|
+
for (const item of kept) {
|
|
2724
|
+
if (item.kind === "separator") {
|
|
2725
|
+
if (out.length === 0) continue;
|
|
2726
|
+
if (out[out.length - 1].kind === "separator") continue;
|
|
2727
|
+
}
|
|
2728
|
+
out.push(item);
|
|
2729
|
+
}
|
|
2730
|
+
while (out.length > 0 && out[out.length - 1].kind === "separator") out.pop();
|
|
2731
|
+
return out;
|
|
2732
|
+
}
|
|
2733
|
+
function withMenuExtensions(menus, ext) {
|
|
2734
|
+
if (!ext || ext.length === 0) return menus;
|
|
2735
|
+
const byMenu = /* @__PURE__ */ new Map();
|
|
2736
|
+
for (const e of ext) {
|
|
2737
|
+
const list = byMenu.get(e.menu) ?? [];
|
|
2738
|
+
list.push(e);
|
|
2739
|
+
byMenu.set(e.menu, list);
|
|
2740
|
+
}
|
|
2741
|
+
return menus.map((menu) => {
|
|
2742
|
+
const extras = byMenu.get(menu.id);
|
|
2743
|
+
if (!extras || extras.length === 0) return menu;
|
|
2744
|
+
const items = [...menu.items, { kind: "separator", id: `ext-sep-${menu.id}` }];
|
|
2745
|
+
for (const e of extras) {
|
|
2746
|
+
items.push({
|
|
2747
|
+
kind: "item",
|
|
2748
|
+
id: `ext-${e.id}`,
|
|
2749
|
+
label: e.label,
|
|
2750
|
+
icon: e.icon,
|
|
2751
|
+
shortcut: e.shortcut,
|
|
2752
|
+
dialog: e.dialog,
|
|
2753
|
+
run: e.onClick ? (api) => e.onClick?.(api) : void 0
|
|
2754
|
+
});
|
|
2755
|
+
}
|
|
2756
|
+
return { ...menu, items };
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
function computeVisibleMenus(menus, features, canOpen, ext) {
|
|
2760
|
+
return withMenuExtensions(menus, ext).map((menu) => ({
|
|
2761
|
+
...menu,
|
|
2762
|
+
items: filterItems(menu.items, features, canOpen)
|
|
2763
|
+
})).filter((menu) => featureOn(menu.feature, features) && menu.items.length > 0);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2704
2766
|
// src/chrome/MenuBar.tsx
|
|
2705
2767
|
import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2706
2768
|
function fmtShortcut(shortcut) {
|
|
@@ -3058,7 +3120,8 @@ var MENUS = [
|
|
|
3058
3120
|
id: "about",
|
|
3059
3121
|
label: "About casual sheets",
|
|
3060
3122
|
icon: "help_outline",
|
|
3061
|
-
dialog: "about"
|
|
3123
|
+
dialog: "about",
|
|
3124
|
+
feature: "branding"
|
|
3062
3125
|
}
|
|
3063
3126
|
]
|
|
3064
3127
|
},
|
|
@@ -3606,6 +3669,12 @@ var MENUS = [
|
|
|
3606
3669
|
{
|
|
3607
3670
|
id: "help",
|
|
3608
3671
|
label: "Help",
|
|
3672
|
+
// Whole-menu gate: an embedded host passes `features={{ help: false }}` to
|
|
3673
|
+
// drop the Help menu entirely (no editor-branded surface). Individual
|
|
3674
|
+
// branding links below also carry `feature: 'branding'` so a host that
|
|
3675
|
+
// keeps Help (for keyboard shortcuts) can still hide the About / GitHub
|
|
3676
|
+
// links with `features={{ branding: false }}`.
|
|
3677
|
+
feature: "help",
|
|
3609
3678
|
items: [
|
|
3610
3679
|
{
|
|
3611
3680
|
kind: "item",
|
|
@@ -3615,14 +3684,22 @@ var MENUS = [
|
|
|
3615
3684
|
shortcut: "Ctrl+/",
|
|
3616
3685
|
dialog: "keyboard-shortcuts"
|
|
3617
3686
|
},
|
|
3618
|
-
{ kind: "separator", id: "sep-help" },
|
|
3619
|
-
{
|
|
3687
|
+
{ kind: "separator", id: "sep-help", feature: "branding" },
|
|
3688
|
+
{
|
|
3689
|
+
kind: "item",
|
|
3690
|
+
id: "about",
|
|
3691
|
+
label: "About casual sheets",
|
|
3692
|
+
icon: "info",
|
|
3693
|
+
dialog: "about",
|
|
3694
|
+
feature: "branding"
|
|
3695
|
+
},
|
|
3620
3696
|
{
|
|
3621
3697
|
kind: "item",
|
|
3622
3698
|
id: "github",
|
|
3623
3699
|
label: "View on GitHub",
|
|
3624
3700
|
icon: "open_in_new",
|
|
3625
|
-
run: () => openExternal("https://github.com/CasualOffice/sheets")
|
|
3701
|
+
run: () => openExternal("https://github.com/CasualOffice/sheets"),
|
|
3702
|
+
feature: "branding"
|
|
3626
3703
|
}
|
|
3627
3704
|
]
|
|
3628
3705
|
}
|
|
@@ -3709,60 +3786,6 @@ var SUBMENU_PANEL_STYLE = {
|
|
|
3709
3786
|
boxShadow: "0 6px 20px rgba(0,0,0,0.16)",
|
|
3710
3787
|
zIndex: 1001
|
|
3711
3788
|
};
|
|
3712
|
-
function featureOn(feature, features) {
|
|
3713
|
-
if (!feature) return true;
|
|
3714
|
-
return features[feature] !== false;
|
|
3715
|
-
}
|
|
3716
|
-
function keepItem(item, features, canOpen) {
|
|
3717
|
-
if (!featureOn(item.feature, features)) return null;
|
|
3718
|
-
if (item.kind === "separator") return item;
|
|
3719
|
-
if (item.kind === "submenu") {
|
|
3720
|
-
const items = filterItems(item.items, features, canOpen);
|
|
3721
|
-
if (items.length === 0) return null;
|
|
3722
|
-
return { ...item, items };
|
|
3723
|
-
}
|
|
3724
|
-
if (item.dialog && !canOpen(item.dialog)) return null;
|
|
3725
|
-
return item;
|
|
3726
|
-
}
|
|
3727
|
-
function filterItems(items, features, canOpen) {
|
|
3728
|
-
const kept = items.map((i) => keepItem(i, features, canOpen)).filter((i) => i !== null);
|
|
3729
|
-
const out = [];
|
|
3730
|
-
for (const item of kept) {
|
|
3731
|
-
if (item.kind === "separator") {
|
|
3732
|
-
if (out.length === 0) continue;
|
|
3733
|
-
if (out[out.length - 1].kind === "separator") continue;
|
|
3734
|
-
}
|
|
3735
|
-
out.push(item);
|
|
3736
|
-
}
|
|
3737
|
-
while (out.length > 0 && out[out.length - 1].kind === "separator") out.pop();
|
|
3738
|
-
return out;
|
|
3739
|
-
}
|
|
3740
|
-
function withMenuExtensions(menus, ext) {
|
|
3741
|
-
if (!ext || ext.length === 0) return menus;
|
|
3742
|
-
const byMenu = /* @__PURE__ */ new Map();
|
|
3743
|
-
for (const e of ext) {
|
|
3744
|
-
const list = byMenu.get(e.menu) ?? [];
|
|
3745
|
-
list.push(e);
|
|
3746
|
-
byMenu.set(e.menu, list);
|
|
3747
|
-
}
|
|
3748
|
-
return menus.map((menu) => {
|
|
3749
|
-
const extras = byMenu.get(menu.id);
|
|
3750
|
-
if (!extras || extras.length === 0) return menu;
|
|
3751
|
-
const items = [...menu.items, { kind: "separator", id: `ext-sep-${menu.id}` }];
|
|
3752
|
-
for (const e of extras) {
|
|
3753
|
-
items.push({
|
|
3754
|
-
kind: "item",
|
|
3755
|
-
id: `ext-${e.id}`,
|
|
3756
|
-
label: e.label,
|
|
3757
|
-
icon: e.icon,
|
|
3758
|
-
shortcut: e.shortcut,
|
|
3759
|
-
dialog: e.dialog,
|
|
3760
|
-
run: e.onClick ? (api) => e.onClick?.(api) : void 0
|
|
3761
|
-
});
|
|
3762
|
-
}
|
|
3763
|
-
return { ...menu, items };
|
|
3764
|
-
});
|
|
3765
|
-
}
|
|
3766
3789
|
function MenuBar({ api, features = {}, extensions }) {
|
|
3767
3790
|
const dialogs = useDialogs();
|
|
3768
3791
|
const [open, setOpen] = useState10(null);
|
|
@@ -3806,11 +3829,7 @@ function MenuBar({ api, features = {}, extensions }) {
|
|
|
3806
3829
|
}
|
|
3807
3830
|
item.run?.(api);
|
|
3808
3831
|
};
|
|
3809
|
-
const
|
|
3810
|
-
const visibleMenus = baseMenus.map((menu) => ({
|
|
3811
|
-
...menu,
|
|
3812
|
-
items: filterItems(menu.items, features, dialogs.canOpen)
|
|
3813
|
-
})).filter((menu) => featureOn(menu.feature, features) && menu.items.length > 0);
|
|
3832
|
+
const visibleMenus = computeVisibleMenus(MENUS, features, dialogs.canOpen, extensions?.menu);
|
|
3814
3833
|
const renderItems = (items) => items.map((item) => {
|
|
3815
3834
|
if (item.kind === "separator") {
|
|
3816
3835
|
return /* @__PURE__ */ jsx12("div", { style: SEPARATOR_STYLE, role: "separator", "aria-hidden": true }, item.id);
|