@sethumadhavan004/ink-editor 0.0.4 → 0.0.5

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.d.mts CHANGED
@@ -31,8 +31,12 @@ interface InkEditorProps {
31
31
  onOverflow?: (fitsJson: object, overflowJson: object) => void;
32
32
  /** Seed content (Tiptap JSON doc) — used to pre-fill a page, e.g. overflow from previous page. */
33
33
  initialContent?: object;
34
+ /** Called whenever the user changes colors via the color panel. */
35
+ onColorsChange?: (colors: ThemeColors) => void;
36
+ /** Color panel keys to hide — e.g. ['canvasBg'] when the host controls the background. */
37
+ hiddenColorKeys?: (keyof ThemeColors)[];
34
38
  }
35
- declare function InkEditor({ pageSize, onChange, theme, toolbar, initialFont, initialColors, toolbarStart, toolbarEnd, singlePage, onOverflow, initialContent, }: InkEditorProps): react_jsx_runtime.JSX.Element;
39
+ declare function InkEditor({ pageSize, onChange, theme, toolbar, initialFont, initialColors, toolbarStart, toolbarEnd, singlePage, onOverflow, initialContent, onColorsChange, hiddenColorKeys, }: InkEditorProps): react_jsx_runtime.JSX.Element;
36
40
 
37
41
  interface SinglePageOverflowOptions {
38
42
  pageSize: PageSize;
package/dist/index.d.ts CHANGED
@@ -31,8 +31,12 @@ interface InkEditorProps {
31
31
  onOverflow?: (fitsJson: object, overflowJson: object) => void;
32
32
  /** Seed content (Tiptap JSON doc) — used to pre-fill a page, e.g. overflow from previous page. */
33
33
  initialContent?: object;
34
+ /** Called whenever the user changes colors via the color panel. */
35
+ onColorsChange?: (colors: ThemeColors) => void;
36
+ /** Color panel keys to hide — e.g. ['canvasBg'] when the host controls the background. */
37
+ hiddenColorKeys?: (keyof ThemeColors)[];
34
38
  }
35
- declare function InkEditor({ pageSize, onChange, theme, toolbar, initialFont, initialColors, toolbarStart, toolbarEnd, singlePage, onOverflow, initialContent, }: InkEditorProps): react_jsx_runtime.JSX.Element;
39
+ declare function InkEditor({ pageSize, onChange, theme, toolbar, initialFont, initialColors, toolbarStart, toolbarEnd, singlePage, onOverflow, initialContent, onColorsChange, hiddenColorKeys, }: InkEditorProps): react_jsx_runtime.JSX.Element;
36
40
 
37
41
  interface SinglePageOverflowOptions {
38
42
  pageSize: PageSize;
package/dist/index.js CHANGED
@@ -2442,7 +2442,7 @@ var COLOR_LABELS = {
2442
2442
  accentColor: "Accent"
2443
2443
  };
2444
2444
  var COLOR_KEYS = Object.keys(SWATCHES);
2445
- function ColorPanel({ colors, onChange, open, onToggle, onClose }) {
2445
+ function ColorPanel({ colors, onChange, open, onToggle, onClose, hiddenKeys = [] }) {
2446
2446
  const ref = (0, import_react2.useRef)(null);
2447
2447
  (0, import_react2.useEffect)(() => {
2448
2448
  if (!open) return;
@@ -2467,7 +2467,7 @@ function ColorPanel({ colors, onChange, open, onToggle, onClose }) {
2467
2467
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react2.Palette, { size: 16 })
2468
2468
  }
2469
2469
  ),
2470
- open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ink-popover ink-popover--right ink-color-panel", role: "dialog", "aria-label": "Color customization", children: COLOR_KEYS.map((key) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ink-color-row", children: [
2470
+ open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ink-popover ink-popover--right ink-color-panel", role: "dialog", "aria-label": "Color customization", children: COLOR_KEYS.filter((k) => !hiddenKeys.includes(k)).map((key) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ink-color-row", children: [
2471
2471
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "ink-color-label", children: COLOR_LABELS[key] }),
2472
2472
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ink-swatches", children: [
2473
2473
  SWATCHES[key].map((swatch) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -2511,7 +2511,8 @@ function FloatingToolbar({
2511
2511
  colors,
2512
2512
  onColorsChange,
2513
2513
  toolbarStart,
2514
- toolbarEnd
2514
+ toolbarEnd,
2515
+ hiddenColorKeys
2515
2516
  }) {
2516
2517
  const [openPanel, setOpenPanel] = (0, import_react3.useState)(null);
2517
2518
  (0, import_react3.useEffect)(() => {
@@ -2655,7 +2656,8 @@ function FloatingToolbar({
2655
2656
  onChange: onColorsChange,
2656
2657
  open: openPanel === "color",
2657
2658
  onToggle: () => togglePanel("color"),
2658
- onClose: () => setOpenPanel(null)
2659
+ onClose: () => setOpenPanel(null),
2660
+ hiddenKeys: hiddenColorKeys
2659
2661
  }
2660
2662
  ),
2661
2663
  toolbarEnd && toolbarEnd.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
@@ -2680,7 +2682,8 @@ function PagedEditorContent({
2680
2682
  onColorsChange,
2681
2683
  toolbarStart,
2682
2684
  toolbarEnd,
2683
- singlePage = false
2685
+ singlePage = false,
2686
+ hiddenColorKeys
2684
2687
  }) {
2685
2688
  const widthPx = getPageWidthPx(pageSize);
2686
2689
  const bodyWidthPx = getBodyWidthPx(pageSize);
@@ -2688,53 +2691,62 @@ function PagedEditorContent({
2688
2691
  const pageHeightPx = Math.round(dims.heightMm * 3.7795);
2689
2692
  const hasToolbar = toolbar.length > 0;
2690
2693
  const bodyHeightPx = getBodyHeightPx(pageSize);
2691
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2694
+ const cssVars = {
2695
+ "--ink-bg": colors.canvasBg,
2696
+ "--ink-page": colors.paperColor,
2697
+ "--ink-text": colors.textColor,
2698
+ "--ink-border-line": colors.lineColor,
2699
+ "--ink-accent": colors.accentColor,
2700
+ "--ink-font-body": FONTS[font].family
2701
+ };
2702
+ const toolbar_el = editor && hasToolbar ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2703
+ FloatingToolbar,
2704
+ {
2705
+ editor,
2706
+ buttons: toolbar,
2707
+ ruled,
2708
+ onToggleRuled,
2709
+ font,
2710
+ onFontChange,
2711
+ colors,
2712
+ onColorsChange,
2713
+ toolbarStart,
2714
+ toolbarEnd,
2715
+ hiddenColorKeys
2716
+ }
2717
+ ) : null;
2718
+ const card_el = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2692
2719
  "div",
2693
2720
  {
2694
- className: `ink-page-wrap${singlePage ? " ink-page-wrap--single" : ""}`,
2695
- "data-theme": theme,
2721
+ className: `ink-page-card${ruled ? " ink-ruled" : ""}`,
2696
2722
  style: {
2697
- "--ink-bg": colors.canvasBg,
2698
- "--ink-page": colors.paperColor,
2699
- "--ink-text": colors.textColor,
2700
- "--ink-border-line": colors.lineColor,
2701
- "--ink-accent": colors.accentColor,
2702
- "--ink-font-body": FONTS[font].family
2723
+ width: widthPx,
2724
+ ...singlePage ? { height: pageHeightPx, overflow: "hidden" } : { minHeight: pageHeightPx },
2725
+ padding: `${dims.paddingTopMm}mm ${dims.paddingRightMm}mm ${dims.paddingBottomMm}mm ${dims.paddingLeftMm}mm`,
2726
+ ["--ink-padding-top"]: `${dims.paddingTopMm}mm`,
2727
+ ["--ink-padding-right"]: `${dims.paddingRightMm}mm`,
2728
+ ["--ink-padding-left"]: `${dims.paddingLeftMm}mm`,
2729
+ ["--ink-body-width"]: `${bodyWidthPx}px`,
2730
+ ["--ink-body-height"]: `${bodyHeightPx}px`
2703
2731
  },
2732
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.EditorContent, { editor })
2733
+ }
2734
+ );
2735
+ if (singlePage) {
2736
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-theme": theme, style: cssVars, children: [
2737
+ toolbar_el,
2738
+ card_el
2739
+ ] });
2740
+ }
2741
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2742
+ "div",
2743
+ {
2744
+ className: "ink-page-wrap",
2745
+ "data-theme": theme,
2746
+ style: cssVars,
2704
2747
  children: [
2705
- editor && hasToolbar && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2706
- FloatingToolbar,
2707
- {
2708
- editor,
2709
- buttons: toolbar,
2710
- ruled,
2711
- onToggleRuled,
2712
- font,
2713
- onFontChange,
2714
- colors,
2715
- onColorsChange,
2716
- toolbarStart,
2717
- toolbarEnd
2718
- }
2719
- ),
2720
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2721
- "div",
2722
- {
2723
- className: `ink-page-card${ruled ? " ink-ruled" : ""}`,
2724
- style: {
2725
- width: widthPx,
2726
- // In singlePage mode: fixed height + overflow hidden so content never visually spills
2727
- ...singlePage ? { height: pageHeightPx, overflow: "hidden" } : { minHeight: pageHeightPx },
2728
- padding: `${dims.paddingTopMm}mm ${dims.paddingRightMm}mm ${dims.paddingBottomMm}mm ${dims.paddingLeftMm}mm`,
2729
- ["--ink-padding-top"]: `${dims.paddingTopMm}mm`,
2730
- ["--ink-padding-right"]: `${dims.paddingRightMm}mm`,
2731
- ["--ink-padding-left"]: `${dims.paddingLeftMm}mm`,
2732
- ["--ink-body-width"]: `${bodyWidthPx}px`,
2733
- ["--ink-body-height"]: `${bodyHeightPx}px`
2734
- },
2735
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.EditorContent, { editor })
2736
- }
2737
- )
2748
+ toolbar_el,
2749
+ card_el
2738
2750
  ]
2739
2751
  }
2740
2752
  );
@@ -2754,7 +2766,9 @@ function InkEditor({
2754
2766
  toolbarEnd,
2755
2767
  singlePage = false,
2756
2768
  onOverflow,
2757
- initialContent
2769
+ initialContent,
2770
+ onColorsChange,
2771
+ hiddenColorKeys
2758
2772
  }) {
2759
2773
  const [ruled, setRuled] = (0, import_react6.useState)(false);
2760
2774
  const [font, setFont] = (0, import_react6.useState)(initialFont);
@@ -2794,10 +2808,14 @@ function InkEditor({
2794
2808
  font,
2795
2809
  onFontChange: setFont,
2796
2810
  colors,
2797
- onColorsChange: setColors,
2811
+ onColorsChange: (c) => {
2812
+ setColors(c);
2813
+ onColorsChange?.(c);
2814
+ },
2798
2815
  toolbarStart,
2799
2816
  toolbarEnd,
2800
- singlePage
2817
+ singlePage,
2818
+ hiddenColorKeys
2801
2819
  }
2802
2820
  );
2803
2821
  }