@sofereditor/react 0.9.0 → 0.10.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.cjs CHANGED
@@ -139,6 +139,11 @@ function isWrapAnchorImg(n) {
139
139
  function isPhantomEmbed(n) {
140
140
  return n.nodeType === Node.ELEMENT_NODE && n.dataset.embedPhantom === "true";
141
141
  }
142
+ function isCellLineBoundary(n) {
143
+ if (n.nodeType !== Node.ELEMENT_NODE) return false;
144
+ const line = n.dataset.cellLine;
145
+ return line != null && Number(line) > 0;
146
+ }
142
147
  function indexInParent(n) {
143
148
  const parent = n.parentNode;
144
149
  if (!parent) return 0;
@@ -166,6 +171,7 @@ function textOffsetWithin(container, node, offsetInNode) {
166
171
  let done = false;
167
172
  function visit(n) {
168
173
  if (done) return;
174
+ if (isCellLineBoundary(n)) offset += 1;
169
175
  if (n === target) {
170
176
  if (n.nodeType === Node.TEXT_NODE) {
171
177
  offset += targetOff;
@@ -266,6 +272,7 @@ function locatePoint(root, pos) {
266
272
  let remaining = Math.max(0, pos.offset - containerStart);
267
273
  let result = null;
268
274
  let lastImg = null;
275
+ let lastBoundary = null;
269
276
  let lastText = null;
270
277
  function visit(n) {
271
278
  if (result) return;
@@ -277,6 +284,7 @@ function locatePoint(root, pos) {
277
284
  }
278
285
  remaining -= len;
279
286
  lastImg = null;
287
+ lastBoundary = null;
280
288
  lastText = n;
281
289
  return;
282
290
  }
@@ -284,6 +292,25 @@ function locatePoint(root, pos) {
284
292
  const el = n;
285
293
  if (isRejectedSubtree(el, container)) return;
286
294
  if (isImgEmbed(el) && isWrapAnchorImg(el)) return;
295
+ if (isCellLineBoundary(el)) {
296
+ if (remaining === 0) {
297
+ if (lastImg) {
298
+ const parent = lastImg.parentNode;
299
+ if (parent) {
300
+ result = { node: parent, offset: indexInParent(lastImg) + 1 };
301
+ return;
302
+ }
303
+ }
304
+ const prevLine = lastBoundary ?? el.previousElementSibling;
305
+ if (prevLine) {
306
+ result = { node: prevLine, offset: 0 };
307
+ return;
308
+ }
309
+ }
310
+ remaining -= 1;
311
+ lastBoundary = el;
312
+ lastImg = null;
313
+ }
287
314
  if (isImgEmbed(el) || isPhantomEmbed(el)) {
288
315
  if (remaining === 0) {
289
316
  const parent = el.parentNode;
@@ -294,6 +321,7 @@ function locatePoint(root, pos) {
294
321
  }
295
322
  remaining -= 1;
296
323
  lastImg = el;
324
+ lastBoundary = null;
297
325
  return;
298
326
  }
299
327
  for (const child of Array.from(el.childNodes)) {
@@ -303,7 +331,10 @@ function locatePoint(root, pos) {
303
331
  }
304
332
  visit(container);
305
333
  if (result) return result;
306
- if (lastImg && remaining === 0) {
334
+ if (lastBoundary) {
335
+ return { node: lastBoundary, offset: 0 };
336
+ }
337
+ if (lastImg) {
307
338
  const parent = lastImg.parentNode;
308
339
  if (parent) return { node: parent, offset: indexInParent(lastImg) + 1 };
309
340
  }
@@ -2835,11 +2866,11 @@ var import_core8 = require("@sofereditor/core");
2835
2866
  var import_react9 = require("react");
2836
2867
  var import_core6 = require("@sofereditor/core");
2837
2868
  var import_jsx_runtime10 = require("react/jsx-runtime");
2838
- function renderInline(delta, keyPrefix) {
2869
+ function renderInline(delta, keyPrefix, baseOffset = 0) {
2839
2870
  if (delta.length === 0 || delta.length === 1 && typeof delta[0].insert === "string" && delta[0].insert === "") {
2840
2871
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("br", { "data-empty": "true" });
2841
2872
  }
2842
- let offset = 0;
2873
+ let offset = baseOffset;
2843
2874
  const wrapAnchors = [];
2844
2875
  const body = [];
2845
2876
  for (const op of delta) {
@@ -3501,6 +3532,27 @@ function clampListLevel(l) {
3501
3532
  if (typeof l !== "number" || !Number.isFinite(l)) return 0;
3502
3533
  return Math.max(0, Math.min(5, Math.trunc(l)));
3503
3534
  }
3535
+ function renderCellContent(attrs, delta, keyPrefix) {
3536
+ const kind = attrs?.listKind;
3537
+ if (!kind) return renderInline(delta, keyPrefix);
3538
+ const linhas = (0, import_core8.splitDeltaByLines)(delta);
3539
+ const Tag = kind === "ordered" ? "ol" : "ul";
3540
+ let baseOffset = 0;
3541
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3542
+ Tag,
3543
+ {
3544
+ className: `ed-list ed-list-${kind}`,
3545
+ "data-list-kind": kind,
3546
+ start: kind === "ordered" && typeof attrs?.listStart === "number" ? attrs.listStart : void 0,
3547
+ style: attrs?.listStyle ? { listStyleType: attrs.listStyle } : void 0,
3548
+ children: linhas.map((linha, i) => {
3549
+ const li = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("li", { className: "ed-listitem", "data-cell-line": i, children: renderInline(linha, `${keyPrefix}-l${i}`, baseOffset) }, i);
3550
+ baseOffset += (0, import_core8.deltaLength)(linha) + 1;
3551
+ return li;
3552
+ })
3553
+ }
3554
+ );
3555
+ }
3504
3556
  function TableView({ block, index, tableFragment }) {
3505
3557
  const rows = clampPositive(block.attrs.rows);
3506
3558
  const cols = clampPositive(block.attrs.cols);
@@ -3566,7 +3618,7 @@ function TableView({ block, index, tableFragment }) {
3566
3618
  )
3567
3619
  ),
3568
3620
  className: inRect ? "ed-cell ed-cell--selected" : "ed-cell",
3569
- children: renderInline(delta, `t${index}-c${flat}`)
3621
+ children: renderCellContent(cell?.attrs, delta, `t${index}-c${flat}`)
3570
3622
  },
3571
3623
  c
3572
3624
  );
@@ -4363,6 +4415,10 @@ function useEditor(opts = {}) {
4363
4415
  const isListActive = (0, import_react14.useCallback)(
4364
4416
  (kind) => {
4365
4417
  const sel = selectionRef.current;
4418
+ if (sel.focus.cellIndex != null && doc.isTable(sel.focus.blockIndex)) {
4419
+ const real = doc.realCellIndex(sel.focus.blockIndex, sel.focus.cellIndex);
4420
+ return real != null && doc.getCellAttrs(sel.focus.blockIndex, real).listKind === kind;
4421
+ }
4366
4422
  const { start, end } = (0, import_core9.orderedRange)(sel);
4367
4423
  for (let i = start.blockIndex; i <= end.blockIndex; i++) {
4368
4424
  if (doc.getBlockType(i) !== "listItem") return false;
@@ -5799,7 +5855,6 @@ function TableBorderPanel({
5799
5855
 
5800
5856
  // src/Toolbar.tsx
5801
5857
  var import_jsx_runtime15 = require("react/jsx-runtime");
5802
- var FONT_FAMILIES = ["Arial"];
5803
5858
  var FONT_SIZES = ["8pt", "10pt", "11pt", "12pt", "14pt", "16pt", "18pt", "24pt", "32pt", "48pt"];
5804
5859
  var BLOCK_OPTIONS = [
5805
5860
  { value: "paragraph", label: "Par\xE1grafo", type: "paragraph" },
@@ -5873,11 +5928,6 @@ function Toolbar({ className }) {
5873
5928
  const onHighlightChange = (e) => {
5874
5929
  setMark("highlight", e.target.value);
5875
5930
  };
5876
- const onFontFamilyChange = (e) => {
5877
- const v = e.target.value;
5878
- if (v === "") removeMark("fontFamily");
5879
- else setMark("fontFamily", v);
5880
- };
5881
5931
  const onFontSizeChange = (e) => {
5882
5932
  const v = e.target.value;
5883
5933
  if (v === "") removeMark("fontSize");
@@ -5938,7 +5988,6 @@ function Toolbar({ className }) {
5938
5988
  );
5939
5989
  const colorValue = typeof active.color === "string" ? active.color : "#000000";
5940
5990
  const highlightValue = typeof active.highlight === "string" ? active.highlight : "#fff176";
5941
- const fontFamilyValue = typeof active.fontFamily === "string" ? active.fontFamily : "";
5942
5991
  const fontSizeValue = typeof active.fontSize === "string" ? active.fontSize : "";
5943
5992
  const blockValue = blockSelectValue(blockType, blockLevel);
5944
5993
  const selectedEmbed = editor.getSelectedEmbed();
@@ -6037,36 +6086,20 @@ function Toolbar({ className }) {
6037
6086
  }
6038
6087
  )
6039
6088
  ] }),
6040
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Group, { children: [
6041
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
6042
- "select",
6043
- {
6044
- className: "ed-toolbar-select",
6045
- value: fontFamilyValue,
6046
- onChange: onFontFamilyChange,
6047
- onMouseDown: stop,
6048
- "aria-label": "Fam\xEDlia da fonte",
6049
- children: [
6050
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "", children: "Fonte\u2026" }),
6051
- FONT_FAMILIES.map((f) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: f, children: f }, f))
6052
- ]
6053
- }
6054
- ),
6055
- /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
6056
- "select",
6057
- {
6058
- className: "ed-toolbar-select",
6059
- value: fontSizeValue,
6060
- onChange: onFontSizeChange,
6061
- onMouseDown: stop,
6062
- "aria-label": "Tamanho da fonte",
6063
- children: [
6064
- /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "", children: "Tamanho\u2026" }),
6065
- FONT_SIZES.map((s) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: s, children: s }, s))
6066
- ]
6067
- }
6068
- )
6069
- ] }),
6089
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Group, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
6090
+ "select",
6091
+ {
6092
+ className: "ed-toolbar-select",
6093
+ value: fontSizeValue,
6094
+ onChange: onFontSizeChange,
6095
+ onMouseDown: stop,
6096
+ "aria-label": "Tamanho da fonte",
6097
+ children: [
6098
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "", children: "Tamanho\u2026" }),
6099
+ FONT_SIZES.map((s) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: s, children: s }, s))
6100
+ ]
6101
+ }
6102
+ ) }),
6070
6103
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Group, { children: ALIGN_OPTIONS.map((a) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
6071
6104
  "button",
6072
6105
  {