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