@dxos/react-ui-editor 0.4.3-main.aa1c078 → 0.4.3-main.ae16e35
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/lib/browser/index.mjs +91 -89
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts +3 -3
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts +3 -3
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +3 -3
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -3
- package/package.json +24 -24
- package/src/components/Toolbar/Toolbar.tsx +75 -68
- package/src/extensions/markdown/formatting.test.ts +1 -1
- package/src/extensions/markdown/formatting.ts +5 -2
- package/src/hooks/useActionHandler.ts +1 -1
- package/src/translations.ts +3 -3
|
@@ -2177,7 +2177,6 @@ var snippets = {
|
|
|
2177
2177
|
codeblock: snippet([
|
|
2178
2178
|
//
|
|
2179
2179
|
"```#{}",
|
|
2180
|
-
"#{}",
|
|
2181
2180
|
"```"
|
|
2182
2181
|
].join("\n")),
|
|
2183
2182
|
table: snippet([
|
|
@@ -2382,13 +2381,17 @@ var addList = (type) => ({ state, dispatch }) => {
|
|
|
2382
2381
|
if (!blocks.length) {
|
|
2383
2382
|
const { from, to } = state.doc.lineAt(state.selection.main.anchor);
|
|
2384
2383
|
if (from === to) {
|
|
2384
|
+
const insert = type === 1 ? "- " : type === 0 ? "1. " : "- [ ] ";
|
|
2385
2385
|
dispatch(state.update({
|
|
2386
2386
|
changes: [
|
|
2387
2387
|
{
|
|
2388
2388
|
from,
|
|
2389
|
-
insert
|
|
2389
|
+
insert
|
|
2390
2390
|
}
|
|
2391
2391
|
],
|
|
2392
|
+
selection: {
|
|
2393
|
+
anchor: from + insert.length
|
|
2394
|
+
},
|
|
2392
2395
|
userEvent: "format.list.add",
|
|
2393
2396
|
scrollIntoView: true
|
|
2394
2397
|
}));
|
|
@@ -4030,7 +4033,7 @@ var defaultMarkdownSlots = {
|
|
|
4030
4033
|
};
|
|
4031
4034
|
|
|
4032
4035
|
// packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
|
|
4033
|
-
import { ChatText, Code, CodeBlock, Link, ListBullets, ListChecks, ListNumbers, Paragraph, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic, Quotes
|
|
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";
|
|
4034
4037
|
import { createContext } from "@radix-ui/react-context";
|
|
4035
4038
|
import React2 from "react";
|
|
4036
4039
|
import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, useTranslation } from "@dxos/react-ui";
|
|
@@ -4046,9 +4049,9 @@ var translations_default = [
|
|
|
4046
4049
|
"emphasis label": "Emphasis",
|
|
4047
4050
|
"strikethrough label": "Strike-through",
|
|
4048
4051
|
"code label": "Code",
|
|
4049
|
-
"bullet label": "Bullet list",
|
|
4050
|
-
"ordered label": "Numbered list",
|
|
4051
|
-
"task label": "Task list",
|
|
4052
|
+
"list-bullet label": "Bullet list",
|
|
4053
|
+
"list-ordered label": "Numbered list",
|
|
4054
|
+
"list-task label": "Task list",
|
|
4052
4055
|
"blockquote label": "Block quote",
|
|
4053
4056
|
"codeblock label": "Code block",
|
|
4054
4057
|
"comment label": "Create comment",
|
|
@@ -4085,7 +4088,7 @@ var ToolbarRoot = ({ children, onAction, classNames, state }) => {
|
|
|
4085
4088
|
}, children))));
|
|
4086
4089
|
};
|
|
4087
4090
|
var buttonStyles = "min-bs-0 p-2";
|
|
4088
|
-
var iconStyles = getSize(
|
|
4091
|
+
var iconStyles = getSize(5);
|
|
4089
4092
|
var ToolbarButton = ({ Icon, children, ...props }) => {
|
|
4090
4093
|
return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroupItem, {
|
|
4091
4094
|
variant: "ghost",
|
|
@@ -4102,7 +4105,6 @@ var ToolbarSeparator = () => /* @__PURE__ */ React2.createElement("div", {
|
|
|
4102
4105
|
className: "grow"
|
|
4103
4106
|
});
|
|
4104
4107
|
var MarkdownHeading = () => {
|
|
4105
|
-
const { t } = useTranslation(translationKey);
|
|
4106
4108
|
const { onAction, state } = useToolbarContext("MarkdownFormatting");
|
|
4107
4109
|
const blockType = state ? state.blockType : "paragraph";
|
|
4108
4110
|
const header = blockType && /heading(\d)/.exec(blockType);
|
|
@@ -4115,21 +4117,13 @@ var MarkdownHeading = () => {
|
|
|
4115
4117
|
type: "heading",
|
|
4116
4118
|
data: parseInt(value2)
|
|
4117
4119
|
})
|
|
4118
|
-
}, /* @__PURE__ */ React2.createElement(Select.
|
|
4119
|
-
asChild: true
|
|
4120
|
-
}, /* @__PURE__ */ React2.createElement(NaturalToolbar.Button, {
|
|
4121
|
-
variant: "ghost",
|
|
4122
|
-
classNames: buttonStyles
|
|
4123
|
-
}, /* @__PURE__ */ React2.createElement("span", {
|
|
4124
|
-
className: "sr-only"
|
|
4125
|
-
}, t("heading label")), /* @__PURE__ */ React2.createElement(HeadingIcon, {
|
|
4120
|
+
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, null, /* @__PURE__ */ React2.createElement(HeadingIcon, {
|
|
4126
4121
|
className: iconStyles
|
|
4127
|
-
}), /* @__PURE__ */ React2.createElement(
|
|
4128
|
-
className: getSize(2),
|
|
4129
|
-
weight: "bold"
|
|
4130
|
-
}))), /* @__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, {
|
|
4131
4123
|
value: "0"
|
|
4132
|
-
},
|
|
4124
|
+
}, /* @__PURE__ */ React2.createElement(Paragraph, {
|
|
4125
|
+
className: iconStyles
|
|
4126
|
+
})), [
|
|
4133
4127
|
1,
|
|
4134
4128
|
2,
|
|
4135
4129
|
3,
|
|
@@ -4139,28 +4133,45 @@ var MarkdownHeading = () => {
|
|
|
4139
4133
|
].map((level) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
4140
4134
|
key: level,
|
|
4141
4135
|
value: String(level)
|
|
4142
|
-
},
|
|
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))));
|
|
4143
4149
|
};
|
|
4144
4150
|
var markdownStyles = [
|
|
4145
4151
|
{
|
|
4146
|
-
|
|
4147
|
-
Icon: TextB
|
|
4152
|
+
type: "strong",
|
|
4153
|
+
Icon: TextB,
|
|
4154
|
+
getState: (state) => state.strong
|
|
4148
4155
|
},
|
|
4149
4156
|
{
|
|
4150
|
-
|
|
4151
|
-
Icon: TextItalic
|
|
4157
|
+
type: "emphasis",
|
|
4158
|
+
Icon: TextItalic,
|
|
4159
|
+
getState: (state) => state.emphasis
|
|
4152
4160
|
},
|
|
4153
4161
|
{
|
|
4154
|
-
|
|
4155
|
-
Icon: TextStrikethrough
|
|
4162
|
+
type: "strikethrough",
|
|
4163
|
+
Icon: TextStrikethrough,
|
|
4164
|
+
getState: (state) => state.strikethrough
|
|
4156
4165
|
},
|
|
4157
4166
|
{
|
|
4158
|
-
|
|
4159
|
-
Icon: Code
|
|
4167
|
+
type: "code",
|
|
4168
|
+
Icon: Code,
|
|
4169
|
+
getState: (state) => state.code
|
|
4160
4170
|
},
|
|
4161
4171
|
{
|
|
4162
|
-
|
|
4163
|
-
Icon: Link
|
|
4172
|
+
type: "link",
|
|
4173
|
+
Icon: Link,
|
|
4174
|
+
getState: (state) => state.link
|
|
4164
4175
|
}
|
|
4165
4176
|
];
|
|
4166
4177
|
var MarkdownStyles = () => {
|
|
@@ -4168,33 +4179,33 @@ var MarkdownStyles = () => {
|
|
|
4168
4179
|
const { t } = useTranslation(translationKey);
|
|
4169
4180
|
return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
|
|
4170
4181
|
type: "multiple",
|
|
4171
|
-
value: markdownStyles.filter(({
|
|
4172
|
-
}, markdownStyles.map(({
|
|
4173
|
-
key,
|
|
4174
|
-
value:
|
|
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,
|
|
4175
4186
|
Icon,
|
|
4176
4187
|
disabled: state?.blockType === "codeblock",
|
|
4177
|
-
onClick: () => onAction?.({
|
|
4178
|
-
type
|
|
4179
|
-
data:
|
|
4180
|
-
})
|
|
4181
|
-
}, t(`${
|
|
4188
|
+
onClick: state ? () => onAction?.({
|
|
4189
|
+
type,
|
|
4190
|
+
data: !getState(state)
|
|
4191
|
+
}) : void 0
|
|
4192
|
+
}, t(`${type} label`))));
|
|
4182
4193
|
};
|
|
4183
4194
|
var markdownLists = [
|
|
4184
4195
|
{
|
|
4185
|
-
|
|
4196
|
+
type: "list-bullet",
|
|
4186
4197
|
Icon: ListBullets,
|
|
4187
|
-
|
|
4198
|
+
getState: (state) => state.listStyle === "bullet"
|
|
4188
4199
|
},
|
|
4189
4200
|
{
|
|
4190
|
-
|
|
4201
|
+
type: "list-ordered",
|
|
4191
4202
|
Icon: ListNumbers,
|
|
4192
|
-
|
|
4203
|
+
getState: (state) => state.listStyle === "ordered"
|
|
4193
4204
|
},
|
|
4194
4205
|
{
|
|
4195
|
-
|
|
4206
|
+
type: "list-task",
|
|
4196
4207
|
Icon: ListChecks,
|
|
4197
|
-
|
|
4208
|
+
getState: (state) => state.listStyle === "task"
|
|
4198
4209
|
}
|
|
4199
4210
|
];
|
|
4200
4211
|
var MarkdownLists = () => {
|
|
@@ -4203,61 +4214,52 @@ var MarkdownLists = () => {
|
|
|
4203
4214
|
return /* @__PURE__ */ React2.createElement(NaturalToolbar.ToggleGroup, {
|
|
4204
4215
|
type: "single",
|
|
4205
4216
|
value: state?.listStyle ?? void 0
|
|
4206
|
-
}, markdownLists.map(({
|
|
4207
|
-
key,
|
|
4208
|
-
value:
|
|
4217
|
+
}, markdownLists.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarButton, {
|
|
4218
|
+
key: type,
|
|
4219
|
+
value: type,
|
|
4209
4220
|
Icon,
|
|
4210
|
-
onClick: () => onAction?.({
|
|
4211
|
-
type
|
|
4212
|
-
data: state
|
|
4213
|
-
})
|
|
4214
|
-
}, t(`${
|
|
4221
|
+
onClick: state ? () => onAction?.({
|
|
4222
|
+
type,
|
|
4223
|
+
data: !getState(state)
|
|
4224
|
+
}) : void 0
|
|
4225
|
+
}, t(`${type} label`))));
|
|
4215
4226
|
};
|
|
4216
4227
|
var markdownBlocks = [
|
|
4217
4228
|
{
|
|
4218
|
-
|
|
4229
|
+
type: "blockquote",
|
|
4219
4230
|
Icon: Quotes,
|
|
4220
|
-
|
|
4221
|
-
action: (state) => ({
|
|
4222
|
-
type: "blockquote",
|
|
4223
|
-
data: state ? !state.blockQuote : null
|
|
4224
|
-
}),
|
|
4225
|
-
disabled: (state) => false
|
|
4231
|
+
getState: (state) => state.blockQuote
|
|
4226
4232
|
},
|
|
4227
4233
|
{
|
|
4228
|
-
|
|
4234
|
+
type: "codeblock",
|
|
4229
4235
|
Icon: CodeBlock,
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
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
|
|
4236
4244
|
}
|
|
4237
4245
|
];
|
|
4238
4246
|
var MarkdownBlocks = () => {
|
|
4239
4247
|
const { onAction, state } = useToolbarContext("MarkdownStyles");
|
|
4240
4248
|
const { t } = useTranslation(translationKey);
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
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,
|
|
4247
4256
|
Icon,
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
}),
|
|
4255
|
-
classNames: buttonStyles
|
|
4256
|
-
}, /* @__PURE__ */ React2.createElement(Table2, {
|
|
4257
|
-
className: iconStyles
|
|
4258
|
-
}), /* @__PURE__ */ React2.createElement("span", {
|
|
4259
|
-
className: "sr-only"
|
|
4260
|
-
}, 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`))));
|
|
4261
4263
|
};
|
|
4262
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));
|
|
4263
4265
|
var MarkdownExtended = () => {
|
|
@@ -4415,7 +4417,7 @@ var useActionHandler = (view) => {
|
|
|
4415
4417
|
break;
|
|
4416
4418
|
case "list-ordered":
|
|
4417
4419
|
case "list-bullet":
|
|
4418
|
-
case "list-
|
|
4420
|
+
case "list-task":
|
|
4419
4421
|
listType = action.type === "list-ordered" ? List.Ordered : action.type === "list-bullet" ? List.Bullet : List.Task;
|
|
4420
4422
|
(action.data === false ? removeList(listType) : action.data === true ? addList(listType) : toggleList(listType))(view);
|
|
4421
4423
|
break;
|