@sofereditor/react 0.3.1 → 0.3.2

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.cts CHANGED
@@ -176,6 +176,10 @@ interface UseEditorResult {
176
176
  setBlockAttr: <K extends keyof BlockAttrs>(key: K, value: BlockAttrs[K] | null) => void;
177
177
  setAlign: (value: AlignValue) => void;
178
178
  getAlign: () => AlignValue | "mixed" | undefined;
179
+ /** Cor de fundo das células selecionadas (rect) ou da célula focada. `null` remove. No-op fora de tabela. */
180
+ setCellBackground: (color: string | null) => void;
181
+ /** Cor de fundo da célula focada; undefined fora de tabela ou sem cor. */
182
+ getCellBackground: () => string | undefined;
179
183
  isListActive: (kind: ListKind) => boolean;
180
184
  toggleList: (kind: ListKind) => void;
181
185
  indentList: () => void;
package/dist/index.d.ts CHANGED
@@ -176,6 +176,10 @@ interface UseEditorResult {
176
176
  setBlockAttr: <K extends keyof BlockAttrs>(key: K, value: BlockAttrs[K] | null) => void;
177
177
  setAlign: (value: AlignValue) => void;
178
178
  getAlign: () => AlignValue | "mixed" | undefined;
179
+ /** Cor de fundo das células selecionadas (rect) ou da célula focada. `null` remove. No-op fora de tabela. */
180
+ setCellBackground: (color: string | null) => void;
181
+ /** Cor de fundo da célula focada; undefined fora de tabela ou sem cor. */
182
+ getCellBackground: () => string | undefined;
179
183
  isListActive: (kind: ListKind) => boolean;
180
184
  toggleList: (kind: ListKind) => void;
181
185
  indentList: () => void;
package/dist/index.js CHANGED
@@ -2171,6 +2171,13 @@ function fragmentClass(f) {
2171
2171
  function alignClass(a) {
2172
2172
  return a ? ` ed-align-${a}` : "";
2173
2173
  }
2174
+ function cellStyle(attrs) {
2175
+ if (!attrs) return void 0;
2176
+ const style = {};
2177
+ if (attrs.align) style.textAlign = attrs.align;
2178
+ if (attrs.bgColor) style.backgroundColor = attrs.bgColor;
2179
+ return Object.keys(style).length > 0 ? style : void 0;
2180
+ }
2174
2181
  function clampLevel(l) {
2175
2182
  if (l === 2 || l === 3 || l === 4 || l === 5 || l === 6) return l;
2176
2183
  return 1;
@@ -2224,7 +2231,7 @@ function TableView({ block, index, tableFragment }) {
2224
2231
  "data-cell-colspan": colspan,
2225
2232
  rowSpan: rowspan > 1 ? rowspan : void 0,
2226
2233
  colSpan: colspan > 1 ? colspan : void 0,
2227
- style: cell?.attrs.align ? { textAlign: cell.attrs.align } : void 0,
2234
+ style: cellStyle(cell?.attrs),
2228
2235
  className: inRect ? "ed-cell ed-cell--selected" : "ed-cell",
2229
2236
  children: renderInline(delta, `t${index}-c${flat}`)
2230
2237
  },
@@ -3035,6 +3042,14 @@ function useEditor(opts = {}) {
3035
3042
  }
3036
3043
  return getBlockAttr("align");
3037
3044
  }, [doc, getBlockAttr]);
3045
+ const setCellBackground = useCallback6((color) => {
3046
+ cmdSetCellAttr(ctxRef.current, "bgColor", color);
3047
+ }, []);
3048
+ const getCellBackground = useCallback6(() => {
3049
+ const sel = selectionRef.current;
3050
+ if (sel.focus.cellIndex == null || !doc.isTable(sel.focus.blockIndex)) return void 0;
3051
+ return doc.getCellAttrs(sel.focus.blockIndex, sel.focus.cellIndex).bgColor;
3052
+ }, [doc]);
3038
3053
  const isListActive = useCallback6(
3039
3054
  (kind) => {
3040
3055
  const sel = selectionRef.current;
@@ -3274,6 +3289,8 @@ function useEditor(opts = {}) {
3274
3289
  setBlockAttr,
3275
3290
  setAlign,
3276
3291
  getAlign,
3292
+ setCellBackground,
3293
+ getCellBackground,
3277
3294
  isListActive,
3278
3295
  toggleList,
3279
3296
  indentList,
@@ -4753,6 +4770,32 @@ function TableMenu() {
4753
4770
  setOpen(false);
4754
4771
  editor.splitCell();
4755
4772
  }, children: "Dividir c\xE9lulas mescladas" }),
4773
+ /* @__PURE__ */ jsx13("hr", {}),
4774
+ /* @__PURE__ */ jsxs12("label", { className: "ed-toolbar-label ed-table-bgcolor", children: [
4775
+ /* @__PURE__ */ jsx13(
4776
+ "span",
4777
+ {
4778
+ className: "ed-toolbar-swatch",
4779
+ "aria-hidden": true,
4780
+ style: { background: editor.getCellBackground() ?? "#ffffff" }
4781
+ }
4782
+ ),
4783
+ "Cor de fundo da c\xE9lula",
4784
+ /* @__PURE__ */ jsx13(
4785
+ "input",
4786
+ {
4787
+ type: "color",
4788
+ value: editor.getCellBackground() ?? "#ffffff",
4789
+ onChange: (e) => editor.setCellBackground(e.target.value),
4790
+ "aria-label": "Cor de fundo da c\xE9lula"
4791
+ }
4792
+ )
4793
+ ] }),
4794
+ /* @__PURE__ */ jsx13("button", { type: "button", onClick: () => {
4795
+ setOpen(false);
4796
+ editor.setCellBackground(null);
4797
+ }, children: "Remover cor de fundo" }),
4798
+ /* @__PURE__ */ jsx13("hr", {}),
4756
4799
  /* @__PURE__ */ jsx13(
4757
4800
  "button",
4758
4801
  {