@sofereditor/react 0.4.0 → 0.5.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.d.cts CHANGED
@@ -184,6 +184,10 @@ interface UseEditorResult {
184
184
  setTableBorderPreset: (preset: TableBorderPreset) => void;
185
185
  /** Preset da tabela focada; "all" fora de tabela ou quando ausente. */
186
186
  getTableBorderPreset: () => TableBorderPreset;
187
+ /** Cor das linhas da grade da tabela focada. `null` restaura o padrão. No-op fora de tabela. */
188
+ setTableBorderColor: (color: string | null) => void;
189
+ /** Cor da tabela focada; undefined fora de tabela ou quando usa o padrão. */
190
+ getTableBorderColor: () => string | undefined;
187
191
  isListActive: (kind: ListKind) => boolean;
188
192
  toggleList: (kind: ListKind) => void;
189
193
  indentList: () => void;
package/dist/index.d.ts CHANGED
@@ -184,6 +184,10 @@ interface UseEditorResult {
184
184
  setTableBorderPreset: (preset: TableBorderPreset) => void;
185
185
  /** Preset da tabela focada; "all" fora de tabela ou quando ausente. */
186
186
  getTableBorderPreset: () => TableBorderPreset;
187
+ /** Cor das linhas da grade da tabela focada. `null` restaura o padrão. No-op fora de tabela. */
188
+ setTableBorderColor: (color: string | null) => void;
189
+ /** Cor da tabela focada; undefined fora de tabela ou quando usa o padrão. */
190
+ getTableBorderColor: () => string | undefined;
187
191
  isListActive: (kind: ListKind) => boolean;
188
192
  toggleList: (kind: ListKind) => void;
189
193
  indentList: () => void;
package/dist/index.js CHANGED
@@ -2254,7 +2254,8 @@ function TableView({ block, index, tableFragment }) {
2254
2254
  cellBorderStyle(
2255
2255
  block.attrs.borderPreset,
2256
2256
  { row: r, col: c, rowspan, colspan, cols, rowStart, rowEnd },
2257
- "screen"
2257
+ "screen",
2258
+ block.attrs.borderColor
2258
2259
  )
2259
2260
  ),
2260
2261
  className: inRect ? "ed-cell ed-cell--selected" : "ed-cell",
@@ -3087,6 +3088,16 @@ function useEditor(opts = {}) {
3087
3088
  if (!doc.isTable(sel.focus.blockIndex)) return "all";
3088
3089
  return doc.getBlockAttrs(sel.focus.blockIndex).borderPreset ?? "all";
3089
3090
  }, [doc]);
3091
+ const setTableBorderColor = useCallback6((color) => {
3092
+ const sel = selectionRef.current;
3093
+ if (!doc.isTable(sel.focus.blockIndex)) return;
3094
+ cmdSetBlockAttrAtIndex(ctxRef.current, sel.focus.blockIndex, "borderColor", color);
3095
+ }, [doc]);
3096
+ const getTableBorderColor = useCallback6(() => {
3097
+ const sel = selectionRef.current;
3098
+ if (!doc.isTable(sel.focus.blockIndex)) return void 0;
3099
+ return doc.getBlockAttrs(sel.focus.blockIndex).borderColor;
3100
+ }, [doc]);
3090
3101
  const isListActive = useCallback6(
3091
3102
  (kind) => {
3092
3103
  const sel = selectionRef.current;
@@ -3333,6 +3344,8 @@ function useEditor(opts = {}) {
3333
3344
  getCellBackground,
3334
3345
  setTableBorderPreset,
3335
3346
  getTableBorderPreset,
3347
+ setTableBorderColor,
3348
+ getTableBorderColor,
3336
3349
  isListActive,
3337
3350
  toggleList,
3338
3351
  indentList,
@@ -4303,7 +4316,7 @@ import {
4303
4316
  useRef as useRef12,
4304
4317
  useState as useState11
4305
4318
  } from "react";
4306
- import { ANSWER_LINE_MAX } from "@sofereditor/core";
4319
+ import { ANSWER_LINE_MAX, TABLE_BORDER_COLOR } from "@sofereditor/core";
4307
4320
  import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
4308
4321
  var FONT_FAMILIES = ["Arial"];
4309
4322
  var FONT_SIZES = ["8pt", "10pt", "11pt", "12pt", "14pt", "16pt", "18pt", "24pt", "32pt", "48pt"];
@@ -4325,6 +4338,15 @@ var ALIGN_OPTIONS = [
4325
4338
  { value: "justify", label: "\u2630", title: "Justificar" }
4326
4339
  ];
4327
4340
  var IMAGE_ALIGN_VALUES = /* @__PURE__ */ new Set(["left", "center", "right"]);
4341
+ var NATIVE_CONTROL_TAGS = /* @__PURE__ */ new Set(["SELECT", "INPUT", "OPTION"]);
4342
+ function isNativeControl(t) {
4343
+ const el = t;
4344
+ return !!el && NATIVE_CONTROL_TAGS.has(el.tagName);
4345
+ }
4346
+ function keepsOwnMouseDown(t) {
4347
+ const el = t;
4348
+ return !!el && (NATIVE_CONTROL_TAGS.has(el.tagName) || el.tagName === "BUTTON");
4349
+ }
4328
4350
  var IMAGE_LAYOUT_OPTIONS = [
4329
4351
  { value: "inline", label: "\u2194", title: "Inline (no fluxo do texto)" },
4330
4352
  { value: "wrap-left", label: "\u25E7", title: "Texto contorna \xE0 direita" },
@@ -4357,10 +4379,7 @@ function Toolbar({ className }) {
4357
4379
  const blockAlign = getAlign();
4358
4380
  const blockDir = getBlockAttr("dir");
4359
4381
  const stop = (e) => {
4360
- const t = e.target;
4361
- if (t && (t.tagName === "SELECT" || t.tagName === "INPUT" || t.tagName === "OPTION")) {
4362
- return;
4363
- }
4382
+ if (isNativeControl(e.target)) return;
4364
4383
  e.preventDefault();
4365
4384
  };
4366
4385
  const onToggle = (name) => (e) => {
@@ -4792,10 +4811,7 @@ function AnswerLinesMenu() {
4792
4811
  className: "ed-table-popover ed-answerlines-popover",
4793
4812
  role: "menu",
4794
4813
  onMouseDown: (e) => {
4795
- const t = e.target;
4796
- if (!t || t.tagName !== "INPUT" && t.tagName !== "BUTTON" && t.tagName !== "SELECT") {
4797
- e.preventDefault();
4798
- }
4814
+ if (!keepsOwnMouseDown(e.target)) e.preventDefault();
4799
4815
  },
4800
4816
  children: [
4801
4817
  /* @__PURE__ */ jsxs12("label", { className: "ed-toolbar-label", children: [
@@ -4886,10 +4902,7 @@ function TableMenu() {
4886
4902
  className: "ed-table-popover",
4887
4903
  role: "menu",
4888
4904
  onMouseDown: (e) => {
4889
- const t = e.target;
4890
- if (!t || t.tagName !== "INPUT" && t.tagName !== "BUTTON") {
4891
- e.preventDefault();
4892
- }
4905
+ if (!keepsOwnMouseDown(e.target)) e.preventDefault();
4893
4906
  },
4894
4907
  children: [
4895
4908
  /* @__PURE__ */ jsx13(
@@ -4995,6 +5008,37 @@ function TableMenu() {
4995
5008
  }
4996
5009
  )
4997
5010
  ] }),
5011
+ /* @__PURE__ */ jsxs12("label", { className: "ed-toolbar-label ed-table-bgcolor", children: [
5012
+ /* @__PURE__ */ jsx13(
5013
+ "span",
5014
+ {
5015
+ className: "ed-toolbar-swatch",
5016
+ "aria-hidden": true,
5017
+ style: { background: editor.getTableBorderColor() ?? TABLE_BORDER_COLOR }
5018
+ }
5019
+ ),
5020
+ "Cor da borda",
5021
+ /* @__PURE__ */ jsx13(
5022
+ "input",
5023
+ {
5024
+ type: "color",
5025
+ value: editor.getTableBorderColor() ?? TABLE_BORDER_COLOR,
5026
+ onChange: (e) => editor.setTableBorderColor(e.target.value),
5027
+ "aria-label": "Cor da borda"
5028
+ }
5029
+ )
5030
+ ] }),
5031
+ /* @__PURE__ */ jsx13(
5032
+ "button",
5033
+ {
5034
+ type: "button",
5035
+ onClick: () => {
5036
+ setOpen(false);
5037
+ editor.setTableBorderColor(null);
5038
+ },
5039
+ children: "Restaurar cor padr\xE3o"
5040
+ }
5041
+ ),
4998
5042
  /* @__PURE__ */ jsx13("hr", {}),
4999
5043
  /* @__PURE__ */ jsx13(
5000
5044
  "button",