@broadpaper/editor 0.3.0 → 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/dist/index.js CHANGED
@@ -4527,6 +4527,23 @@ function SubFormList({ value, onChange, fields, itemLabel, summary, renderField
4527
4527
  );
4528
4528
  }
4529
4529
 
4530
+ // src/inspector/font-options.ts
4531
+ function fontOptions(theme, current) {
4532
+ const first = (stack) => stack.split(",")[0].trim().replace(/^['"]|['"]$/g, "");
4533
+ const options = [
4534
+ { value: "$typography.headingFont", label: `Heading font (${first(theme.typography.headingFont)})` },
4535
+ { value: "$typography.bodyFont", label: `Body font (${first(theme.typography.bodyFont)})` },
4536
+ ...theme.typography.monoFont ? [{ value: "$typography.monoFont", label: `Mono font (${first(theme.typography.monoFont)})` }] : []
4537
+ ];
4538
+ for (const face of theme.fonts ?? []) {
4539
+ if (!options.some((o) => o.value === face.family)) options.push({ value: face.family, label: face.family });
4540
+ }
4541
+ if (current && !options.some((o) => o.value === current)) {
4542
+ options.push({ value: current, label: `${current.startsWith("$typography.") ? current.slice("$typography.".length) : current} (not in this theme)` });
4543
+ }
4544
+ return options;
4545
+ }
4546
+
4530
4547
  // src/inspector/fields/FieldRenderer.tsx
4531
4548
  import { jsx as jsx21, jsxs as jsxs20 } from "react/jsx-runtime";
4532
4549
  function getPath(obj, path) {
@@ -4537,7 +4554,6 @@ function getPath(obj, path) {
4537
4554
  }
4538
4555
  return cur;
4539
4556
  }
4540
- var COMMON_FONTS = ["Inter", "Roboto", "Open Sans", "Lato", "Source Sans 3", "Helvetica Neue", "Arial", "Georgia", "Times New Roman", "Merriweather", "Playfair Display", "Courier New", "JetBrains Mono"];
4541
4557
  function FieldRenderer({ field, value, onChange, ctx }) {
4542
4558
  const description = typeof field.description === "function" ? field.description(ctx.props) : field.description;
4543
4559
  const humanise = useTokenText(ctx.dataSources, ctx.scopeVars);
@@ -4665,13 +4681,7 @@ function coerce(v, options) {
4665
4681
  return match ? match.value : v;
4666
4682
  }
4667
4683
  function FontSelect({ value, onChange, theme }) {
4668
- const themeFonts = [
4669
- { value: "$typography.headingFont", label: `Heading font (${theme.typography.headingFont.split(",")[0]})` },
4670
- { value: "$typography.bodyFont", label: `Body font (${theme.typography.bodyFont.split(",")[0]})` },
4671
- ...theme.typography.monoFont ? [{ value: "$typography.monoFont", label: "Mono font" }] : []
4672
- ];
4673
- const fonts = [...(theme.fonts ?? []).map((f) => f.family), ...COMMON_FONTS].filter((f, i, a) => a.indexOf(f) === i);
4674
- return /* @__PURE__ */ jsx21(Select, { value, onChange, placeholder: "Default", options: [...themeFonts, ...fonts.map((f) => ({ value: f, label: f }))] });
4684
+ return /* @__PURE__ */ jsx21(Select, { value, onChange, placeholder: "Default", options: fontOptions(theme, value) });
4675
4685
  }
4676
4686
  function CustomFieldHost({ field, value, onChange, ctx }) {
4677
4687
  const session = useSession();
@@ -4751,7 +4761,7 @@ function StyleGroups({ node, groups, theme, textStyles, setStyle, setFlow, allow
4751
4761
  allowOverrides && (has("textStyle") || has("typography") || has("alignment")) ? /* @__PURE__ */ jsx22(Section, { title: "Typography", actions: hasOverrides ? /* @__PURE__ */ jsx22(Button, { size: "sm", variant: "ghost", icon: "rotate-ccw", tooltip: "Reset style overrides", onClick: () => setStyle(null) }) : null, children: /* @__PURE__ */ jsxs21("div", { className: "bpe-prop-grid", children: [
4752
4762
  has("textStyle") ? /* @__PURE__ */ jsx22(Field, { label: "Text style", children: /* @__PURE__ */ jsx22(Select, { value: s.textStyle ?? "", onChange: (v) => setStyle({ textStyle: v || void 0 }), placeholder: "Block default", options: textStyles.map((t) => ({ value: t, label: textStyleLabel2(t) })) }) }) : null,
4753
4763
  has("typography") ? /* @__PURE__ */ jsxs21(Fragment4, { children: [
4754
- /* @__PURE__ */ jsx22(Field, { label: "Font", children: /* @__PURE__ */ jsx22(Select, { value: s.fontFamily ?? "", onChange: (v) => setStyle({ fontFamily: v || void 0 }), placeholder: "Inherit", options: [{ value: "$typography.headingFont", label: "Heading font" }, { value: "$typography.bodyFont", label: "Body font" }, ...(theme.fonts ?? []).map((x) => ({ value: x.family, label: x.family })), ...["Inter", "Roboto", "Georgia", "Arial", "Times New Roman"].map((x) => ({ value: x, label: x }))] }) }),
4764
+ /* @__PURE__ */ jsx22(Field, { label: "Font", children: /* @__PURE__ */ jsx22(Select, { value: s.fontFamily ?? "", onChange: (v) => setStyle({ fontFamily: v || void 0 }), placeholder: "Inherit", options: fontOptions(theme, s.fontFamily) }) }),
4755
4765
  /* @__PURE__ */ jsx22(Field, { label: "Size", children: /* @__PURE__ */ jsx22(NumberInput, { value: s.fontSize ?? null, onChange: (v) => setStyle({ fontSize: v ?? void 0 }), min: 4, max: 200, unit: "px", placeholder: "inherit" }) }),
4756
4766
  /* @__PURE__ */ jsx22(Field, { label: "Weight", children: /* @__PURE__ */ jsx22(Select, { value: s.fontWeight === void 0 ? "" : String(s.fontWeight), onChange: (v) => setStyle({ fontWeight: v ? Number(v) : void 0 }), placeholder: "Inherit", options: [300, 400, 500, 600, 700, 800].map((w) => ({ value: String(w), label: w === 400 ? "Regular" : w === 700 ? "Bold" : String(w) })) }) }),
4757
4767
  /* @__PURE__ */ jsx22(Field, { label: "Line height", children: /* @__PURE__ */ jsx22(NumberInput, { value: s.lineHeight ?? null, onChange: (v) => setStyle({ lineHeight: v ?? void 0 }), min: 0.6, max: 4, step: 0.05, placeholder: "inherit" }) }),
@@ -5003,7 +5013,7 @@ function TextStyleEditor({ id, style, onChange, onBack }) {
5003
5013
  /* @__PURE__ */ jsx24(Button, { size: "sm", variant: "ghost", icon: "chevron-right", style: { transform: "rotate(180deg)" }, onClick: onBack, tooltip: "Back" }),
5004
5014
  /* @__PURE__ */ jsx24("strong", { children: id })
5005
5015
  ] }),
5006
- /* @__PURE__ */ jsx24(Field, { label: "Font", children: /* @__PURE__ */ jsx24(Select, { value: style.fontFamily ?? "", onChange: (v) => onChange({ fontFamily: v || void 0 }), placeholder: "Theme body font", options: [{ value: "$typography.headingFont", label: "Theme heading font" }, { value: "$typography.bodyFont", label: "Theme body font" }, ...(theme.fonts ?? []).map((f) => ({ value: f.family, label: f.family }))] }) }),
5016
+ /* @__PURE__ */ jsx24(Field, { label: "Font", children: /* @__PURE__ */ jsx24(Select, { value: style.fontFamily ?? "", onChange: (v) => onChange({ fontFamily: v || void 0 }), placeholder: "Theme body font", options: fontOptions(theme, style.fontFamily) }) }),
5007
5017
  /* @__PURE__ */ jsx24(Field, { label: "Size", children: /* @__PURE__ */ jsx24(NumberInput, { value: style.fontSize ?? null, onChange: (v) => onChange({ fontSize: v ?? void 0 }), min: 4, max: 120, unit: "px" }) }),
5008
5018
  /* @__PURE__ */ jsx24(Field, { label: "Weight", children: /* @__PURE__ */ jsx24(Select, { value: style.fontWeight === void 0 ? "" : String(style.fontWeight), onChange: (v) => onChange({ fontWeight: v ? Number(v) : void 0 }), placeholder: "Regular", options: [300, 400, 500, 600, 700, 800].map((w) => ({ value: String(w), label: String(w) })) }) }),
5009
5019
  /* @__PURE__ */ jsx24(Field, { label: "Line height", children: /* @__PURE__ */ jsx24(NumberInput, { value: style.lineHeight ?? null, onChange: (v) => onChange({ lineHeight: v ?? void 0 }), min: 0.8, max: 3, step: 0.05 }) }),