@dxos/react-ui-editor 0.4.3-main.dda98d3 → 0.4.3-main.e5bbcda

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.
@@ -1152,10 +1152,16 @@ var styles3 = EditorView6.baseTheme({
1152
1152
  }
1153
1153
  });
1154
1154
  var commentMark = Decoration3.mark({
1155
- class: "cm-comment"
1155
+ class: "cm-comment",
1156
+ attributes: {
1157
+ "data-testid": "cm-comment"
1158
+ }
1156
1159
  });
1157
1160
  var commentCurrentMark = Decoration3.mark({
1158
- class: "cm-comment-current"
1161
+ class: "cm-comment-current",
1162
+ attributes: {
1163
+ "data-testid": "cm-comment"
1164
+ }
1159
1165
  });
1160
1166
  var focusComment = (view, id, center = true) => {
1161
1167
  const comment = view.state.field(commentsState).comments.find((range2) => range2.comment.id === id);
@@ -2171,7 +2177,6 @@ var snippets = {
2171
2177
  codeblock: snippet([
2172
2178
  //
2173
2179
  "```#{}",
2174
- "#{}",
2175
2180
  "```"
2176
2181
  ].join("\n")),
2177
2182
  table: snippet([
@@ -2376,13 +2381,17 @@ var addList = (type) => ({ state, dispatch }) => {
2376
2381
  if (!blocks.length) {
2377
2382
  const { from, to } = state.doc.lineAt(state.selection.main.anchor);
2378
2383
  if (from === to) {
2384
+ const insert = type === 1 ? "- " : type === 0 ? "1. " : "- [ ] ";
2379
2385
  dispatch(state.update({
2380
2386
  changes: [
2381
2387
  {
2382
2388
  from,
2383
- insert: type === 1 ? "- " : type === 0 ? "1. " : "- [ ] "
2389
+ insert
2384
2390
  }
2385
2391
  ],
2392
+ selection: {
2393
+ anchor: from + insert.length
2394
+ },
2386
2395
  userEvent: "format.list.add",
2387
2396
  scrollIntoView: true
2388
2397
  }));
@@ -4024,7 +4033,7 @@ var defaultMarkdownSlots = {
4024
4033
  };
4025
4034
 
4026
4035
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
4027
- import { ChatText, Code, CodeBlock, Link, ListBullets, ListChecks, ListNumbers, Paragraph, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic, Quotes, CaretDown } from "@phosphor-icons/react";
4036
+ import { ChatText, Code, CodeBlock, Link, ListBullets, ListChecks, ListNumbers, Paragraph, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic, Quotes } from "@phosphor-icons/react";
4028
4037
  import { createContext } from "@radix-ui/react-context";
4029
4038
  import React2 from "react";
4030
4039
  import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, useTranslation } from "@dxos/react-ui";
@@ -4040,9 +4049,9 @@ var translations_default = [
4040
4049
  "emphasis label": "Emphasis",
4041
4050
  "strikethrough label": "Strike-through",
4042
4051
  "code label": "Code",
4043
- "bullet label": "Bullet list",
4044
- "ordered label": "Numbered list",
4045
- "task label": "Task list",
4052
+ "list-bullet label": "Bullet list",
4053
+ "list-ordered label": "Numbered list",
4054
+ "list-task label": "Task list",
4046
4055
  "blockquote label": "Block quote",
4047
4056
  "codeblock label": "Code block",
4048
4057
  "comment label": "Create comment",
@@ -4079,7 +4088,7 @@ var ToolbarRoot = ({ children, onAction, classNames, state }) => {
4079
4088
  }, children))));
4080
4089
  };
4081
4090
  var buttonStyles = "min-bs-0 p-2";
4082
- var iconStyles = getSize(4);
4091
+ var iconStyles = getSize(5);
4083
4092
  var ToolbarButton = ({ Icon, children, ...props }) => {
4084
4093
  return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroupItem, {
4085
4094
  variant: "ghost",
@@ -4096,7 +4105,6 @@ var ToolbarSeparator = () => /* @__PURE__ */ React2.createElement("div", {
4096
4105
  className: "grow"
4097
4106
  });
4098
4107
  var MarkdownHeading = () => {
4099
- const { t } = useTranslation(translationKey);
4100
4108
  const { onAction, state } = useToolbarContext("MarkdownFormatting");
4101
4109
  const blockType = state ? state.blockType : "paragraph";
4102
4110
  const header = blockType && /heading(\d)/.exec(blockType);
@@ -4109,21 +4117,13 @@ var MarkdownHeading = () => {
4109
4117
  type: "heading",
4110
4118
  data: parseInt(value2)
4111
4119
  })
4112
- }, /* @__PURE__ */ React2.createElement(Select.Trigger, {
4113
- asChild: true
4114
- }, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
4115
- variant: "ghost",
4116
- classNames: buttonStyles
4117
- }, /* @__PURE__ */ React2.createElement("span", {
4118
- className: "sr-only"
4119
- }, t("heading label")), /* @__PURE__ */ React2.createElement(HeadingIcon, {
4120
+ }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, null, /* @__PURE__ */ React2.createElement(HeadingIcon, {
4120
4121
  className: iconStyles
4121
- }), /* @__PURE__ */ React2.createElement(CaretDown, {
4122
- className: getSize(2),
4123
- weight: "bold"
4124
- }))), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
4122
+ })), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
4125
4123
  value: "0"
4126
- }, "Paragraph"), [
4124
+ }, /* @__PURE__ */ React2.createElement(Paragraph, {
4125
+ className: iconStyles
4126
+ })), [
4127
4127
  1,
4128
4128
  2,
4129
4129
  3,
@@ -4133,28 +4133,45 @@ var MarkdownHeading = () => {
4133
4133
  ].map((level) => /* @__PURE__ */ React2.createElement(Select.Option, {
4134
4134
  key: level,
4135
4135
  value: String(level)
4136
- }, "Heading ", level))), /* @__PURE__ */ React2.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React2.createElement(Select.Arrow, null))));
4136
+ }, level === 1 && /* @__PURE__ */ React2.createElement(TextHOne, {
4137
+ className: iconStyles
4138
+ }), level === 2 && /* @__PURE__ */ React2.createElement(TextHTwo, {
4139
+ className: iconStyles
4140
+ }), level === 3 && /* @__PURE__ */ React2.createElement(TextHThree, {
4141
+ className: iconStyles
4142
+ }), level === 4 && /* @__PURE__ */ React2.createElement(TextHFour, {
4143
+ className: iconStyles
4144
+ }), level === 5 && /* @__PURE__ */ React2.createElement(TextHFive, {
4145
+ className: iconStyles
4146
+ }), level === 6 && /* @__PURE__ */ React2.createElement(TextHSix, {
4147
+ className: iconStyles
4148
+ })))), /* @__PURE__ */ React2.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React2.createElement(Select.Arrow, null))));
4137
4149
  };
4138
4150
  var markdownStyles = [
4139
4151
  {
4140
- key: "strong",
4141
- Icon: TextB
4152
+ type: "strong",
4153
+ Icon: TextB,
4154
+ getState: (state) => state.strong
4142
4155
  },
4143
4156
  {
4144
- key: "emphasis",
4145
- Icon: TextItalic
4157
+ type: "emphasis",
4158
+ Icon: TextItalic,
4159
+ getState: (state) => state.emphasis
4146
4160
  },
4147
4161
  {
4148
- key: "strikethrough",
4149
- Icon: TextStrikethrough
4162
+ type: "strikethrough",
4163
+ Icon: TextStrikethrough,
4164
+ getState: (state) => state.strikethrough
4150
4165
  },
4151
4166
  {
4152
- key: "code",
4153
- Icon: Code
4167
+ type: "code",
4168
+ Icon: Code,
4169
+ getState: (state) => state.code
4154
4170
  },
4155
4171
  {
4156
- key: "link",
4157
- Icon: Link
4172
+ type: "link",
4173
+ Icon: Link,
4174
+ getState: (state) => state.link
4158
4175
  }
4159
4176
  ];
4160
4177
  var MarkdownStyles = () => {
@@ -4162,33 +4179,33 @@ var MarkdownStyles = () => {
4162
4179
  const { t } = useTranslation(translationKey);
4163
4180
  return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
4164
4181
  type: "multiple",
4165
- value: markdownStyles.filter(({ key }) => !!state?.[key]).map(({ key }) => key)
4166
- }, markdownStyles.map(({ key, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4167
- key,
4168
- value: key,
4182
+ value: markdownStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)
4183
+ }, markdownStyles.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4184
+ key: type,
4185
+ value: type,
4169
4186
  Icon,
4170
4187
  disabled: state?.blockType === "codeblock",
4171
- onClick: () => onAction?.({
4172
- type: key,
4173
- data: state ? !state[key] : null
4174
- })
4175
- }, t(`${key} label`))));
4188
+ onClick: state ? () => onAction?.({
4189
+ type,
4190
+ data: !getState(state)
4191
+ }) : void 0
4192
+ }, t(`${type} label`))));
4176
4193
  };
4177
4194
  var markdownLists = [
4178
4195
  {
4179
- key: "bullet",
4196
+ type: "list-bullet",
4180
4197
  Icon: ListBullets,
4181
- actionType: "list-bullet"
4198
+ getState: (state) => state.listStyle === "bullet"
4182
4199
  },
4183
4200
  {
4184
- key: "ordered",
4201
+ type: "list-ordered",
4185
4202
  Icon: ListNumbers,
4186
- actionType: "list-ordered"
4203
+ getState: (state) => state.listStyle === "ordered"
4187
4204
  },
4188
4205
  {
4189
- key: "task",
4206
+ type: "list-task",
4190
4207
  Icon: ListChecks,
4191
- actionType: "list-tasks"
4208
+ getState: (state) => state.listStyle === "task"
4192
4209
  }
4193
4210
  ];
4194
4211
  var MarkdownLists = () => {
@@ -4197,61 +4214,52 @@ var MarkdownLists = () => {
4197
4214
  return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
4198
4215
  type: "single",
4199
4216
  value: state?.listStyle ?? void 0
4200
- }, markdownLists.map(({ key, Icon, actionType }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4201
- key,
4202
- value: key,
4217
+ }, markdownLists.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4218
+ key: type,
4219
+ value: type,
4203
4220
  Icon,
4204
- onClick: () => onAction?.({
4205
- type: actionType,
4206
- data: state ? state.listStyle !== key : null
4207
- })
4208
- }, t(`${key} label`))));
4221
+ onClick: state ? () => onAction?.({
4222
+ type,
4223
+ data: !getState(state)
4224
+ }) : void 0
4225
+ }, t(`${type} label`))));
4209
4226
  };
4210
4227
  var markdownBlocks = [
4211
4228
  {
4212
- key: "blockquote",
4229
+ type: "blockquote",
4213
4230
  Icon: Quotes,
4214
- pressed: (state) => state?.blockQuote,
4215
- action: (state) => ({
4216
- type: "blockquote",
4217
- data: state ? !state.blockQuote : null
4218
- }),
4219
- disabled: (state) => false
4231
+ getState: (state) => state.blockQuote
4220
4232
  },
4221
4233
  {
4222
- key: "codeblock",
4234
+ type: "codeblock",
4223
4235
  Icon: CodeBlock,
4224
- pressed: (state) => state?.blockType === "codeblock",
4225
- action: (state) => ({
4226
- type: "blockquote",
4227
- data: state ? !state.blockQuote : null
4228
- }),
4229
- disabled: (state) => !state?.blankLine
4236
+ getState: (state) => state.blockQuote,
4237
+ disabled: (state) => !state.blankLine
4238
+ },
4239
+ {
4240
+ type: "table",
4241
+ Icon: Table2,
4242
+ getState: (state) => state.blockType === "tablecell",
4243
+ disabled: (state) => !state.blankLine
4230
4244
  }
4231
4245
  ];
4232
4246
  var MarkdownBlocks = () => {
4233
4247
  const { onAction, state } = useToolbarContext("MarkdownStyles");
4234
4248
  const { t } = useTranslation(translationKey);
4235
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
4236
- type: "multiple",
4237
- value: markdownBlocks.filter(({ pressed }) => pressed(state)).map(({ key }) => key)
4238
- }, markdownBlocks.map(({ key, Icon, action }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4239
- key,
4240
- value: key,
4249
+ const value = markdownBlocks.find(({ getState }) => state && getState(state));
4250
+ return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
4251
+ type: "single",
4252
+ value: value?.type
4253
+ }, markdownBlocks.map(({ type, disabled, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
4254
+ key: type,
4255
+ value: type,
4241
4256
  Icon,
4242
- onClick: () => onAction?.(action(state))
4243
- }, t(`${key} label`)))), /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
4244
- variant: "ghost",
4245
- disabled: !state?.blankLine,
4246
- onClick: () => onAction?.({
4247
- type: "table"
4248
- }),
4249
- classNames: buttonStyles
4250
- }, /* @__PURE__ */ React2.createElement(Table2, {
4251
- className: iconStyles
4252
- }), /* @__PURE__ */ React2.createElement("span", {
4253
- className: "sr-only"
4254
- }, t("table label"))));
4257
+ disabled: !state || disabled?.(state),
4258
+ onClick: state ? () => onAction?.({
4259
+ type,
4260
+ data: !getState(state)
4261
+ }) : void 0
4262
+ }, t(`${type} label`))));
4255
4263
  };
4256
4264
  var MarkdownStandard = () => /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(MarkdownHeading, null), /* @__PURE__ */ React2.createElement(MarkdownStyles, null), /* @__PURE__ */ React2.createElement(MarkdownLists, null), /* @__PURE__ */ React2.createElement(MarkdownBlocks, null));
4257
4265
  var MarkdownExtended = () => {
@@ -4259,6 +4267,7 @@ var MarkdownExtended = () => {
4259
4267
  const { t } = useTranslation(translationKey);
4260
4268
  return /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
4261
4269
  variant: "ghost",
4270
+ "data-testid": "editor.toolbar.comment",
4262
4271
  onClick: () => onAction?.({
4263
4272
  type: "comment"
4264
4273
  }),
@@ -4408,7 +4417,7 @@ var useActionHandler = (view) => {
4408
4417
  break;
4409
4418
  case "list-ordered":
4410
4419
  case "list-bullet":
4411
- case "list-tasks":
4420
+ case "list-task":
4412
4421
  listType = action.type === "list-ordered" ? List.Ordered : action.type === "list-bullet" ? List.Bullet : List.Task;
4413
4422
  (action.data === false ? removeList(listType) : action.data === true ? addList(listType) : toggleList(listType))(view);
4414
4423
  break;