@makeswift/runtime 0.9.5 → 0.9.7
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/LiveProvider.es.js +2 -2
- package/dist/PreviewProvider.es.js +2 -2
- package/dist/ReadOnlyText.cjs.js +2 -1
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +4 -3
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/ReadOnlyTextV2.cjs.js +2 -1
- package/dist/ReadOnlyTextV2.cjs.js.map +1 -1
- package/dist/ReadOnlyTextV2.es.js +4 -3
- package/dist/ReadOnlyTextV2.es.js.map +1 -1
- package/dist/api.cjs.js +20 -1
- package/dist/api.cjs.js.map +1 -1
- package/dist/api.es.js +20 -1
- package/dist/api.es.js.map +1 -1
- package/dist/control-serialization.es.js +1 -1
- package/dist/controls.cjs.js +1 -0
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +1 -1
- package/dist/index.cjs.js +58 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs10.js +2 -1
- package/dist/index.cjs10.js.map +1 -1
- package/dist/index.cjs5.js +29 -10
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.es.js +58 -33
- package/dist/index.es.js.map +1 -1
- package/dist/index.es10.js +4 -3
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es5.js +31 -12
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es6.js +1 -1
- package/dist/index.es9.js +2 -2
- package/dist/next.es.js +1 -1
- package/dist/react-page.cjs.js +16 -9
- package/dist/react-page.cjs.js.map +1 -1
- package/dist/react-page.es.js +16 -10
- package/dist/react-page.es.js.map +1 -1
- package/dist/slate.cjs.js +19 -61
- package/dist/slate.cjs.js.map +1 -1
- package/dist/slate.es.js +25 -65
- package/dist/slate.es.js.map +1 -1
- package/dist/state/breakpoints.cjs.js +13 -0
- package/dist/state/breakpoints.cjs.js.map +1 -1
- package/dist/state/breakpoints.es.js +13 -1
- package/dist/state/breakpoints.es.js.map +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts.map +1 -1
- package/dist/types/src/api/graphql/documents/queries.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/fragment-document-nodes.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/types.d.ts +12 -0
- package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/src/api/react.d.ts +3 -1
- package/dist/types/src/api/react.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
- package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
- package/dist/types/src/controls/icon-radio-group.d.ts +1 -1
- package/dist/types/src/controls/icon-radio-group.d.ts.map +1 -1
- package/dist/types/src/controls/link.d.ts +1 -1
- package/dist/types/src/controls/link.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts +2 -0
- package/dist/types/src/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/src/controls/select.d.ts +1 -1
- package/dist/types/src/controls/select.d.ts.map +1 -1
- package/dist/types/src/controls/typography.d.ts +1 -1
- package/dist/types/src/controls/typography.d.ts.map +1 -1
- package/dist/types/src/next/api-handler/index.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +2 -1
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/introspection.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/style-v2.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/controls/typography.d.ts +2 -2
- package/dist/types/src/runtimes/react/controls/typography.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts +1 -1
- package/dist/types/src/slate/InlinePlugin/getValue.d.ts.map +1 -1
- package/dist/types/src/slate/LinkPlugin/getValue.d.ts.map +1 -1
- package/dist/types/src/slate/TextAlignPlugin/getValue.d.ts +4 -0
- package/dist/types/src/slate/TextAlignPlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/TextAlignPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/TypographyPlugin/getValue.d.ts +4 -0
- package/dist/types/src/slate/TypographyPlugin/getValue.d.ts.map +1 -0
- package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -1
- package/dist/types/src/slate/index.d.ts +0 -1
- package/dist/types/src/slate/index.d.ts.map +1 -1
- package/dist/types/src/slate/utils/responsive.d.ts +3 -5
- package/dist/types/src/slate/utils/responsive.d.ts.map +1 -1
- package/dist/types/src/state/makeswift-api-client.d.ts +1 -1
- package/dist/types/src/state/makeswift-api-client.d.ts.map +1 -1
- package/dist/types/src/state/modules/breakpoints.d.ts +2 -0
- package/dist/types/src/state/modules/breakpoints.d.ts.map +1 -1
- package/dist/types/types/locale.d.ts +1 -1
- package/dist/types.cjs2.js.map +1 -1
- package/dist/types.es2.js +1 -1
- package/dist/types.es2.js.map +1 -1
- package/dist/typography.cjs.js.map +1 -1
- package/dist/typography.es.js.map +1 -1
- package/package.json +1 -1
- package/dist/types/src/slate/ColorPlugin/index.d.ts +0 -10
- package/dist/types/src/slate/ColorPlugin/index.d.ts.map +0 -1
package/dist/slate.cjs.js
CHANGED
|
@@ -27,10 +27,10 @@ var reactPage = require("./react-page.cjs.js");
|
|
|
27
27
|
require("./actions.cjs.js");
|
|
28
28
|
var typography = require("./typography.cjs.js");
|
|
29
29
|
var slate = require("slate");
|
|
30
|
-
var next = require("./index.cjs.js");
|
|
31
30
|
var jsxRuntime = require("react/jsx-runtime");
|
|
32
31
|
var index$3 = require("./index.cjs3.js");
|
|
33
32
|
var css = require("@emotion/css");
|
|
33
|
+
var next = require("./index.cjs.js");
|
|
34
34
|
require("./state/breakpoints.cjs.js");
|
|
35
35
|
require("zod");
|
|
36
36
|
require("is-hotkey");
|
|
@@ -40,6 +40,8 @@ require("redux-thunk");
|
|
|
40
40
|
require("react");
|
|
41
41
|
require("@emotion/serialize");
|
|
42
42
|
require("@emotion/utils");
|
|
43
|
+
require("scroll-into-view-if-needed");
|
|
44
|
+
require("next/link");
|
|
43
45
|
require("use-sync-external-store/shim/with-selector");
|
|
44
46
|
require("next/dynamic");
|
|
45
47
|
require("./combobox.cjs.js");
|
|
@@ -48,7 +50,6 @@ require("./types.cjs.js");
|
|
|
48
50
|
require("./box-models.cjs.js");
|
|
49
51
|
require("css-box-model");
|
|
50
52
|
require("color");
|
|
51
|
-
require("scroll-into-view-if-needed");
|
|
52
53
|
require("react-dom");
|
|
53
54
|
require("html-react-parser");
|
|
54
55
|
require("next/head");
|
|
@@ -62,7 +63,15 @@ require("set-cookie-parser");
|
|
|
62
63
|
require("./constants.cjs.js");
|
|
63
64
|
require("uuid");
|
|
64
65
|
require("corporate-ipsum");
|
|
65
|
-
|
|
66
|
+
function getValue$2(editor) {
|
|
67
|
+
const matchingValues = Array.from(slate.Editor.nodes(editor, {
|
|
68
|
+
at: types.getSelection(editor),
|
|
69
|
+
match: types.ElementUtils.isRootBlock
|
|
70
|
+
})).map(([node]) => node["textAlign"]);
|
|
71
|
+
return matchingValues.length === 0 ? void 0 : matchingValues.reduce((a, b) => {
|
|
72
|
+
return index.responsiveShallowEqual(a, b);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
66
75
|
const TEXT_ALIGN_KEY = "textAlign";
|
|
67
76
|
const withTextAlign = (editor) => {
|
|
68
77
|
const {
|
|
@@ -113,9 +122,7 @@ function TextAlignPlugin() {
|
|
|
113
122
|
match: types.ElementUtils.isRootBlock,
|
|
114
123
|
split: false
|
|
115
124
|
}),
|
|
116
|
-
getValue: (editor) =>
|
|
117
|
-
match: types.ElementUtils.isRootBlock
|
|
118
|
-
}),
|
|
125
|
+
getValue: (editor) => getValue$2(editor),
|
|
119
126
|
getElementValue: (element) => {
|
|
120
127
|
return types.ElementUtils.isRootBlock(element) ? element.textAlign : void 0;
|
|
121
128
|
}
|
|
@@ -130,56 +137,6 @@ function TextAlignPlugin() {
|
|
|
130
137
|
}
|
|
131
138
|
});
|
|
132
139
|
}
|
|
133
|
-
const COLOR_KEY = "color";
|
|
134
|
-
function ColorPlugin() {
|
|
135
|
-
return reactPage.createRichTextV2Plugin({
|
|
136
|
-
control: {
|
|
137
|
-
definition: reactPage.unstable_StyleV2({
|
|
138
|
-
type: reactPage.Color({
|
|
139
|
-
label: "Color"
|
|
140
|
-
}),
|
|
141
|
-
getStyle(color) {
|
|
142
|
-
return {
|
|
143
|
-
color
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}),
|
|
147
|
-
onChange: (editor, value) => {
|
|
148
|
-
index.setResponsiveValue(editor, COLOR_KEY, value, {
|
|
149
|
-
match: slate.Text.isText,
|
|
150
|
-
split: true
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
getValue: (editor) => index.getResponsiveValue(editor, COLOR_KEY, {
|
|
154
|
-
match: slate.Text.isText
|
|
155
|
-
}),
|
|
156
|
-
getLeafValue: (text) => {
|
|
157
|
-
return slate.Text.isText(text) ? text == null ? void 0 : text.color : void 0;
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
withPlugin: (editor) => {
|
|
161
|
-
const {
|
|
162
|
-
normalizeNode
|
|
163
|
-
} = editor;
|
|
164
|
-
editor.normalizeNode = (entry) => {
|
|
165
|
-
if (index.normalizeResponsiveValue(editor, COLOR_KEY, {
|
|
166
|
-
match: slate.Text.isText
|
|
167
|
-
})(entry)) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
normalizeNode(entry);
|
|
171
|
-
};
|
|
172
|
-
return editor;
|
|
173
|
-
},
|
|
174
|
-
renderLeaf: (renderLeaf, className) => (props) => {
|
|
175
|
-
return renderLeaf(__spreadProps(__spreadValues({}, props), {
|
|
176
|
-
leaf: __spreadProps(__spreadValues({}, props.leaf), {
|
|
177
|
-
className: `${props.leaf.className} ${className}`
|
|
178
|
-
})
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
140
|
function getSupportedInlinesAndTextInSelection(editor) {
|
|
184
141
|
return Array.from(slate.Editor.nodes(editor, {
|
|
185
142
|
at: types.getSelection(editor),
|
|
@@ -193,7 +150,8 @@ const getValue$1 = (editor) => {
|
|
|
193
150
|
if (!areAllRootsSupportedInlineTypesOrText)
|
|
194
151
|
return void 0;
|
|
195
152
|
const matchingValues = roots.filter(types.isSupportedInlineEntry).map(([node]) => node);
|
|
196
|
-
|
|
153
|
+
const match = matchingValues.reduce((a, b) => (a == null ? void 0 : a.type) === (b == null ? void 0 : b.type) ? b : null, (_a = matchingValues.at(0)) != null ? _a : void 0);
|
|
154
|
+
return match == null ? match : match.type;
|
|
197
155
|
};
|
|
198
156
|
const onChange$1 = (editor, value) => {
|
|
199
157
|
function unwrapAllSupportedTypes() {
|
|
@@ -296,7 +254,8 @@ const getValue = (editor) => {
|
|
|
296
254
|
if (!areAllRootsLinks)
|
|
297
255
|
return void 0;
|
|
298
256
|
const matchingValues = roots.map(([node]) => node).filter(isLinkElement);
|
|
299
|
-
|
|
257
|
+
const match = matchingValues.reduce((a, b) => next.deepEqual(a == null ? void 0 : a.link, b == null ? void 0 : b.link) ? b : null, (_a = matchingValues.at(0)) != null ? _a : void 0);
|
|
258
|
+
return match == null ? match : match.link;
|
|
300
259
|
};
|
|
301
260
|
const onChange = (editor, value) => {
|
|
302
261
|
if (value == null)
|
|
@@ -327,13 +286,14 @@ function InlinePluginComponent({
|
|
|
327
286
|
children,
|
|
328
287
|
renderElement
|
|
329
288
|
}) {
|
|
289
|
+
var _a;
|
|
330
290
|
const linkStyle = reactPage.useStyle({
|
|
331
291
|
textDecoration: "none"
|
|
332
292
|
});
|
|
333
293
|
switch (element.type) {
|
|
334
294
|
case reactPage.InlineType.Link:
|
|
335
295
|
return /* @__PURE__ */ jsxRuntime.jsx(index$3.Link, __spreadProps(__spreadValues({}, attributes), {
|
|
336
|
-
link: element.link,
|
|
296
|
+
link: (_a = element.link) != null ? _a : void 0,
|
|
337
297
|
className: css.cx(linkStyle, element.className),
|
|
338
298
|
children
|
|
339
299
|
}));
|
|
@@ -381,8 +341,6 @@ exports.BlockTextAlignment = reactPage.BlockTextAlignment;
|
|
|
381
341
|
exports.BlockType = reactPage.BlockType;
|
|
382
342
|
exports.InlineType = reactPage.InlineType;
|
|
383
343
|
exports.RootBlockType = reactPage.RootBlockType;
|
|
384
|
-
exports.COLOR_KEY = COLOR_KEY;
|
|
385
|
-
exports.ColorPlugin = ColorPlugin;
|
|
386
344
|
exports.InlinePlugin = InlinePlugin;
|
|
387
345
|
exports.LinkPlugin = LinkPlugin;
|
|
388
346
|
exports.TextAlignPlugin = TextAlignPlugin;
|
package/dist/slate.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slate.cjs.js","sources":["../src/slate/TextAlignPlugin/index.tsx","../src/slate/ColorPlugin/index.tsx","../src/slate/InlinePlugin/getValue.ts","../src/slate/InlinePlugin/onChange.ts","../src/slate/InlinePlugin/index.tsx","../src/slate/LinkPlugin/types.ts","../src/slate/LinkPlugin/getValue.ts","../src/slate/LinkPlugin/onChange.ts","../src/slate/LinkPlugin/index.tsx"],"sourcesContent":["import { Editor, Element } from 'slate'\nimport {\n createRichTextV2Plugin,\n unstable_IconRadioGroup,\n unstable_IconRadioGroupIcon,\n unstable_StyleV2,\n} from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { TextAlignProperty } from 'csstype'\nimport {\n getResponsiveValue,\n normalizeResponsiveValue,\n setResponsiveValue,\n} from '../utils/responsive'\n\nconst TEXT_ALIGN_KEY = 'textAlign'\n\nexport const withTextAlign = (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (\n normalizeResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock })(entry)\n ) {\n return\n }\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TextAlignPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: unstable_IconRadioGroup({\n label: 'Alignment',\n options: [\n {\n icon: unstable_IconRadioGroupIcon.TextAlignLeft,\n label: 'Left Align',\n value: 'left',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignCenter,\n label: 'Center Align',\n value: 'center',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignRight,\n label: 'Right Align',\n value: 'right',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignJustify,\n label: 'Justify',\n value: 'justify',\n },\n ],\n defaultValue: 'left',\n }),\n getStyle(textAlign: TextAlignProperty) {\n return { textAlign }\n },\n }),\n onChange: (editor, value) =>\n setResponsiveValue(editor, TEXT_ALIGN_KEY, value, {\n match: ElementUtils.isRootBlock,\n split: false,\n }),\n getValue: editor =>\n getResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock }),\n getElementValue: (element: Element) => {\n return ElementUtils.isRootBlock(element) ? element.textAlign : undefined\n },\n },\n withPlugin: withTextAlign,\n renderElement: (renderElement, className) => props => {\n return renderElement({\n ...props,\n element: {\n ...props.element,\n className,\n },\n })\n },\n })\n}\n","import { Editor, Text } from 'slate'\nimport {\n Color,\n createRichTextV2Plugin,\n unstable_StyleV2,\n ColorControlDefinition,\n} from '../../controls'\nimport { ControlDefinitionValue } from '../../runtimes/react/controls/control'\nimport {\n getResponsiveValue,\n normalizeResponsiveValue,\n setResponsiveValue,\n} from '../utils/responsive'\n\nexport const COLOR_KEY = 'color'\n\nexport function ColorPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: Color({\n label: 'Color',\n }),\n getStyle(color: ControlDefinitionValue<ColorControlDefinition>) {\n return { color }\n },\n }),\n onChange: (editor, value) => {\n setResponsiveValue(editor, COLOR_KEY, value, {\n match: Text.isText,\n split: true,\n })\n },\n getValue: editor => getResponsiveValue(editor, COLOR_KEY, { match: Text.isText }),\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text?.color : undefined\n },\n },\n withPlugin: (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (normalizeResponsiveValue(editor, COLOR_KEY, { match: Text.isText })(entry)) {\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className: `${props.leaf.className} ${className}`,\n },\n })\n },\n })\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport deepEqual from '../../utils/deepEqual'\nimport { SupportedInline, isSupportedInlineType, isSupportedInlineEntry } from './types'\n\nexport function getSupportedInlinesAndTextInSelection(\n editor: Editor,\n): NodeEntry<SupportedInline | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node =>\n (ElementUtils.isInline(node) && isSupportedInlineType(node.type)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | SupportedInline>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n\n const areAllRootsSupportedInlineTypesOrText = roots.every(\n entry => isSupportedInlineEntry(entry) || Text.isText(entry[0]),\n )\n\n if (!areAllRootsSupportedInlineTypesOrText) return undefined\n\n const matchingValues = roots.filter(isSupportedInlineEntry).map(([node]) => node)\n\n return matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined), matchingValues.at(0))\n ?.type\n}\n","import { getSupportedInlinesAndTextInSelection } from './getValue'\nimport { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport {\n SupportedInlineType,\n isSupportedInlineEntry,\n isSupportedInlineType,\n supportedInlineOptions,\n} from './types'\n\nexport const onChange = (editor: Editor, value: SupportedInlineType) => {\n function unwrapAllSupportedTypes() {\n supportedInlineOptions.forEach(({ value: optionValue }) => unwrapInline(editor, optionValue))\n }\n\n function unwrapAllInlines() {\n Transforms.unwrapNodes(editor, {\n match: node => ElementUtils.isInline(node),\n at: getSelection(editor),\n })\n }\n\n if (value == null) return unwrapAllSupportedTypes()\n\n if (!isSupportedInlineType(value)) return\n\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n const root = roots.at(0)\n\n if (\n roots.length === 1 &&\n root != null &&\n isSupportedInlineEntry(root) &&\n root[0].type === value\n ) {\n unwrapInline(editor, value)\n } else {\n unwrapAllInlines()\n wrapInline(editor, { type: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { RenderElement, createRichTextV2Plugin, unstable_IconRadioGroup } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { supportedInlineOptions } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withInline = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nexport function InlinePlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_IconRadioGroup({\n label: 'Inline',\n options: supportedInlineOptions,\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) ? element.type : undefined\n },\n },\n withPlugin: withInline,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n\n default:\n return (\n <>\n {renderElement({\n element,\n attributes,\n children,\n })}\n </>\n )\n }\n}\n","import { Node, NodeEntry } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType, LinkElement } from '../types'\n\nexport function isLinkElement(node: Node): node is LinkElement {\n return ElementUtils.isInline(node) && node.type === InlineType.Link\n}\n\nexport function isLinkEntry(inline: NodeEntry<Node>): inline is NodeEntry<LinkElement> {\n return ElementUtils.isInline(inline[0]) && inline[0].type === InlineType.Link\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LinkElement } from '../types'\nimport deepEqual from '../../utils/deepEqual'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkElement } from './types'\n\nexport function getLinksAndTextInSelection(editor: Editor): NodeEntry<LinkElement | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => (ElementUtils.isInline(node) && isLinkElement(node)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | LinkElement>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n\n const areAllRootsLinks = roots.every(([root]) => isLinkElement(root) || Text.isText(root))\n\n if (!areAllRootsLinks) return undefined\n\n const matchingValues = roots.map(([node]) => node).filter(isLinkElement)\n\n return matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined), matchingValues.at(0))\n ?.link\n}\n","import { Editor, Transforms } from 'slate'\nimport { LinkControlData } from '../../controls'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { InlineType } from '../types'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkEntry } from './types'\nimport { getLinksAndTextInSelection } from './getValue'\n\nexport const onChange = (editor: Editor, value: LinkControlData) => {\n if (value == null) return unwrapInline(editor, InlineType.Link)\n\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n const root = roots.at(0)\n\n // If the root of our selection is a link we just want to modify it\n if (roots.length === 1 && root != null && isLinkEntry(root)) {\n Transforms.setNodes(\n editor,\n {\n link: value,\n },\n { at: root[1] },\n )\n }\n // In all other cases we want to remove all existing links and wrap the current selection in a new link\n else {\n unwrapInline(editor, InlineType.Link)\n wrapInline(editor, { type: InlineType.Link, link: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { Link, RenderElement, createRichTextV2Plugin } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../runtimes/react/use-style'\nimport { Link as LinkComponent } from '../../components/shared/Link'\nimport { cx } from '@emotion/css'\nimport { isLinkElement } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withLink = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n const linkStyle = useStyle({ textDecoration: 'none' })\n switch (element.type) {\n case InlineType.Link:\n return (\n <LinkComponent\n {...attributes}\n link={element.link}\n className={cx(linkStyle, element.className)}\n >\n {children}\n </LinkComponent>\n )\n\n default:\n return renderElement({\n element,\n attributes,\n children,\n })\n }\n}\n\nexport function LinkPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: Link({\n label: 'On Click',\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) && isLinkElement(element) ? element.link : undefined\n },\n },\n withPlugin: withLink,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n"],"names":["TEXT_ALIGN_KEY","withTextAlign","editor","normalizeNode","entry","normalizeResponsiveValue","match","ElementUtils","isRootBlock","createRichTextV2Plugin","control","definition","unstable_StyleV2","type","unstable_IconRadioGroup","label","options","icon","unstable_IconRadioGroupIcon","TextAlignLeft","value","TextAlignCenter","TextAlignRight","TextAlignJustify","defaultValue","getStyle","textAlign","onChange","setResponsiveValue","split","getValue","getResponsiveValue","getElementValue","element","undefined","withPlugin","renderElement","className","props","COLOR_KEY","Color","color","Text","isText","getLeafValue","text","renderLeaf","leaf","Editor","getSelection","isSupportedInlineType","filterForSubtreeRoots","isSupportedInlineEntry","deepEqual","supportedInlineOptions","unwrapInline","Transforms","wrapInline","withInline","isInline","InlinePluginComponent","attributes","children","InlineType","Code","SuperScript","SubScript","_Fragment","withLink","linkStyle","useStyle","textDecoration","Link","LinkComponent","link","cx","isLinkElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAMA,iBAAiB;AAEVC,MAAAA,gBAAgB,CAACC,WAAmB;AACzC,QAAA;AAAA,IAAEC;AAAAA,MAAkBD;AAC1BA,SAAOC,gBAAgBC,CAAS,UAAA;AAE5BC,QAAAA,MAAAA,yBAAyBH,QAAQF,gBAAgB;AAAA,MAAEM,OAAOC,MAAaC,aAAAA;AAAAA,IAAAA,CAA/C,EAA8DJ,KAAtF,GACA;AACA;AAAA,IACD;AACDD,kBAAcC,KAAD;AAAA,EAAA;AAGRF,SAAAA;AACR;AAEiC,2BAAA;AAChC,SAAOO,iCAAuB;AAAA,IAC5BC,SAAS;AAAA,MACPC,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,MAAAA,aAAaoD,SAAS1B,OAAtB,KAAkC2C,cAAc3C,OAAD,IAAYA,QAAQyC,OAAOxC;AAAAA,MAClF;AAAA,IATyB;AAAA,IAW5BC,YAAYiC;AAAAA,IACZhC,eAAeA,mBAAiBE,CAAS,UAAA;AAChC,4CAAC,uBAAD,iCAA2BA,QAA3B;AAAA,QAAkC;AAAA,MAAA,EAAzC;AAAA,IACD;AAAA,EAAA,CAd0B;AAgB9B;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"slate.cjs.js","sources":["../src/slate/TextAlignPlugin/getValue.ts","../src/slate/TextAlignPlugin/index.tsx","../src/slate/InlinePlugin/getValue.ts","../src/slate/InlinePlugin/onChange.ts","../src/slate/InlinePlugin/index.tsx","../src/slate/LinkPlugin/types.ts","../src/slate/LinkPlugin/getValue.ts","../src/slate/LinkPlugin/onChange.ts","../src/slate/LinkPlugin/index.tsx"],"sourcesContent":["import { Editor } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { ResponsiveBlockTextAlignment } from '../types'\nimport { getSelection } from '../selectors'\nimport { responsiveShallowEqual } from '../utils/responsive'\n\nexport function getValue(editor: Editor): ResponsiveBlockTextAlignment | undefined {\n const matchingValues = Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: ElementUtils.isRootBlock,\n }),\n ).map(([node]) => node['textAlign']) as (ResponsiveBlockTextAlignment | undefined)[]\n\n return matchingValues.length === 0\n ? undefined\n : matchingValues.reduce((a, b) => {\n return responsiveShallowEqual(a, b)\n })\n}\n","import { Editor, Element } from 'slate'\nimport {\n createRichTextV2Plugin,\n unstable_IconRadioGroup,\n unstable_IconRadioGroupIcon,\n unstable_StyleV2,\n} from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { TextAlignProperty } from 'csstype'\nimport { normalizeResponsiveValue, setResponsiveValue } from '../utils/responsive'\nimport { getValue } from './getValue'\n\nconst TEXT_ALIGN_KEY = 'textAlign'\n\nexport const withTextAlign = (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (\n normalizeResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock })(entry)\n ) {\n return\n }\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TextAlignPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: unstable_IconRadioGroup({\n label: 'Alignment',\n options: [\n {\n icon: unstable_IconRadioGroupIcon.TextAlignLeft,\n label: 'Left Align',\n value: 'left',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignCenter,\n label: 'Center Align',\n value: 'center',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignRight,\n label: 'Right Align',\n value: 'right',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignJustify,\n label: 'Justify',\n value: 'justify',\n },\n ],\n defaultValue: 'left',\n }),\n getStyle(textAlign: TextAlignProperty) {\n return { textAlign }\n },\n }),\n onChange: (editor, value) =>\n setResponsiveValue(editor, TEXT_ALIGN_KEY, value, {\n match: ElementUtils.isRootBlock,\n split: false,\n }),\n getValue: editor => getValue(editor),\n getElementValue: (element: Element) => {\n return ElementUtils.isRootBlock(element) ? element.textAlign : undefined\n },\n },\n withPlugin: withTextAlign,\n renderElement: (renderElement, className) => props => {\n return renderElement({\n ...props,\n element: {\n ...props.element,\n className,\n },\n })\n },\n })\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { SupportedInline, isSupportedInlineType, isSupportedInlineEntry } from './types'\n\nexport function getSupportedInlinesAndTextInSelection(\n editor: Editor,\n): NodeEntry<SupportedInline | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node =>\n (ElementUtils.isInline(node) && isSupportedInlineType(node.type)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | SupportedInline>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n\n const areAllRootsSupportedInlineTypesOrText = roots.every(\n entry => isSupportedInlineEntry(entry) || Text.isText(entry[0]),\n )\n\n if (!areAllRootsSupportedInlineTypesOrText) return undefined\n\n const matchingValues = roots.filter(isSupportedInlineEntry).map(([node]) => node) as (\n | SupportedInline\n | null\n | undefined\n )[]\n\n const match = matchingValues.reduce(\n (a, b) => (a?.type === b?.type ? b : null),\n matchingValues.at(0) ?? undefined,\n )\n\n return match == null ? match : match.type\n}\n","import { getSupportedInlinesAndTextInSelection } from './getValue'\nimport { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport {\n SupportedInlineType,\n isSupportedInlineEntry,\n isSupportedInlineType,\n supportedInlineOptions,\n} from './types'\n\nexport const onChange = (editor: Editor, value: SupportedInlineType) => {\n function unwrapAllSupportedTypes() {\n supportedInlineOptions.forEach(({ value: optionValue }) => unwrapInline(editor, optionValue))\n }\n\n function unwrapAllInlines() {\n Transforms.unwrapNodes(editor, {\n match: node => ElementUtils.isInline(node),\n at: getSelection(editor),\n })\n }\n\n if (value == null) return unwrapAllSupportedTypes()\n\n if (!isSupportedInlineType(value)) return\n\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n const root = roots.at(0)\n\n if (\n roots.length === 1 &&\n root != null &&\n isSupportedInlineEntry(root) &&\n root[0].type === value\n ) {\n unwrapInline(editor, value)\n } else {\n unwrapAllInlines()\n wrapInline(editor, { type: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { RenderElement, createRichTextV2Plugin, unstable_IconRadioGroup } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { supportedInlineOptions } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withInline = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nexport function InlinePlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_IconRadioGroup({\n label: 'Inline',\n options: supportedInlineOptions,\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) ? element.type : undefined\n },\n },\n withPlugin: withInline,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n\n default:\n return (\n <>\n {renderElement({\n element,\n attributes,\n children,\n })}\n </>\n )\n }\n}\n","import { Node, NodeEntry } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType, LinkElement } from '../types'\n\nexport function isLinkElement(node: Node): node is LinkElement {\n return ElementUtils.isInline(node) && node.type === InlineType.Link\n}\n\nexport function isLinkEntry(inline: NodeEntry<Node>): inline is NodeEntry<LinkElement> {\n return ElementUtils.isInline(inline[0]) && inline[0].type === InlineType.Link\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LinkElement } from '../types'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkElement } from './types'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function getLinksAndTextInSelection(editor: Editor): NodeEntry<LinkElement | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => (ElementUtils.isInline(node) && isLinkElement(node)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | LinkElement>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n\n const areAllRootsLinks = roots.every(([root]) => isLinkElement(root) || Text.isText(root))\n\n if (!areAllRootsLinks) return undefined\n\n const matchingValues = roots.map(([node]) => node).filter(isLinkElement) as (\n | LinkElement\n | null\n | undefined\n )[]\n\n const match = matchingValues.reduce(\n (a, b) => (deepEqual(a?.link, b?.link) ? b : null),\n matchingValues.at(0) ?? undefined,\n )\n\n return match == null ? match : match.link\n}\n","import { Editor, Transforms } from 'slate'\nimport { LinkControlData } from '../../controls'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { InlineType } from '../types'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkEntry } from './types'\nimport { getLinksAndTextInSelection } from './getValue'\n\nexport const onChange = (editor: Editor, value: LinkControlData) => {\n if (value == null) return unwrapInline(editor, InlineType.Link)\n\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n const root = roots.at(0)\n\n // If the root of our selection is a link we just want to modify it\n if (roots.length === 1 && root != null && isLinkEntry(root)) {\n Transforms.setNodes(\n editor,\n {\n link: value,\n },\n { at: root[1] },\n )\n }\n // In all other cases we want to remove all existing links and wrap the current selection in a new link\n else {\n unwrapInline(editor, InlineType.Link)\n wrapInline(editor, { type: InlineType.Link, link: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { Link, RenderElement, createRichTextV2Plugin } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../runtimes/react/use-style'\nimport { Link as LinkComponent } from '../../components/shared/Link'\nimport { cx } from '@emotion/css'\nimport { isLinkElement } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withLink = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n const linkStyle = useStyle({ textDecoration: 'none' })\n switch (element.type) {\n case InlineType.Link:\n return (\n <LinkComponent\n {...attributes}\n link={element.link ?? undefined}\n className={cx(linkStyle, element.className)}\n >\n {children}\n </LinkComponent>\n )\n\n default:\n return renderElement({\n element,\n attributes,\n children,\n })\n }\n}\n\nexport function LinkPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: Link({\n label: 'On Click',\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) && isLinkElement(element) ? element.link : undefined\n },\n },\n withPlugin: withLink,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n"],"names":["Editor","getSelection","ElementUtils","responsiveShallowEqual","TEXT_ALIGN_KEY","withTextAlign","editor","normalizeNode","entry","normalizeResponsiveValue","match","isRootBlock","createRichTextV2Plugin","control","definition","unstable_StyleV2","type","unstable_IconRadioGroup","label","options","icon","unstable_IconRadioGroupIcon","TextAlignLeft","value","TextAlignCenter","TextAlignRight","TextAlignJustify","defaultValue","getStyle","textAlign","onChange","setResponsiveValue","split","getValue","getElementValue","element","undefined","withPlugin","renderElement","className","props","isSupportedInlineType","Text","filterForSubtreeRoots","isSupportedInlineEntry","supportedInlineOptions","unwrapInline","Transforms","wrapInline","withInline","isInline","InlinePluginComponent","attributes","children","InlineType","Code","SuperScript","SubScript","_Fragment","deepEqual","withLink","linkStyle","useStyle","textDecoration","Link","LinkComponent","link","cx","isLinkElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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S1C,KAAD;AAAA,EAAA;AAG1CF,SAAAA;AACR;AAED,+BAA+B;AAAA,EAC7B6B;AAAAA,EACAiB;AAAAA,EACAC;AAAAA,EACAf;AAAAA,GACwD;;AAClDuB,QAAAA,YAAYC,UAAAA,SAAS;AAAA,IAAEC,gBAAgB;AAAA,EAAA,CAAnB;AAClB5B,UAAAA,QAAQnB;AAAAA,SACTsC,UAAWU,WAAAA;AAEZ,4CAACC,QAAAA,MAAD,iCACMb,aADN;AAAA,QAEE,MAAMjB,cAAQ+B,SAAR/B,YAAgBC;AAAAA,QACtB,WAAW+B,IAAAA,GAAGN,WAAW1B,QAAQI,SAApB;AAAA,QAEZc;AAAAA,MAAAA,EANL;AAAA;AAWA,aAAOf,cAAc;AAAA,QACnBH;AAAAA,QACAiB;AAAAA,QACAC;AAAAA,MAAAA,CAHkB;AAAA;AAMzB;AAE4B,sBAAA;AAC3B,SAAOzC,iCAAuB;AAAA,IAC5BC,SAAS;AAAA,MACPC,YAAYkD,UAAAA,OAAK;AAAA,QACf9C,OAAO;AAAA,MAAA,CADO;AAAA,MAGhBY;AAAAA,MACAG;AAAAA,MACAC,iBAAiB,CAACC,YAAqB;AAC9BjC,eAAAA,MAAAA,aAAagD,SAASf,OAAtB,KAAkCiC,cAAcjC,OAAD,IAAYA,QAAQ+B,OAAO9B;AAAAA,MAClF;AAAA,IATyB;AAAA,IAW5BC,YAAYuB;AAAAA,IACZtB,eAAeA,mBAAiBE,CAAS,UAAA;AAChC,4CAAC,uBAAD,iCAA2BA,QAA3B;AAAA,QAAkC;AAAA,MAAA,EAAzC;AAAA,IACD;AAAA,EAAA,CAd0B;AAgB9B;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/slate.es.js
CHANGED
|
@@ -17,21 +17,21 @@ var __spreadValues = (a2, b3) => {
|
|
|
17
17
|
return a2;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a2, b3) => __defProps(a2, __getOwnPropDescs(b3));
|
|
20
|
-
import {
|
|
20
|
+
import { r as responsiveShallowEqual, n as normalizeResponsiveValue, s as setResponsiveValue } from "./index.es5.js";
|
|
21
21
|
export { a as TYPOGRAPHY_KEY, T as TypographyActions, b as TypographyPlugin, w as withTypography } from "./index.es5.js";
|
|
22
|
-
import {
|
|
22
|
+
import { g as getSelection, E as ElementUtils, f as filterForSubtreeRoots, i as isSupportedInlineType, a as isSupportedInlineEntry, u as unwrapInline, w as wrapInline, s as supportedInlineOptions } from "./types.es2.js";
|
|
23
23
|
export { B as BlockActions, c as BlockPlugin, L as ListActions, o as onKeyDown, b as withBlock } from "./types.es2.js";
|
|
24
24
|
export { I as InlineModePlugin, w as withInlineMode } from "./index.es6.js";
|
|
25
25
|
export { w as withBuilder } from "./index.es7.js";
|
|
26
|
-
import {
|
|
27
|
-
export {
|
|
26
|
+
import { ba as createRichTextV2Plugin, a_ as unstable_StyleV2, be as InlineType, aE as Link, U as useStyle } from "./react-page.es.js";
|
|
27
|
+
export { bh as BlockTextAlignment, bg as BlockType, be as InlineType, bf as RootBlockType } from "./react-page.es.js";
|
|
28
28
|
import "./actions.es.js";
|
|
29
29
|
import { d as unstable_IconRadioGroup, u as unstable_IconRadioGroupIcon } from "./typography.es.js";
|
|
30
|
-
import {
|
|
31
|
-
import { K as deepEqual } from "./index.es.js";
|
|
30
|
+
import { Editor, Text, Transforms } from "slate";
|
|
32
31
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
33
32
|
import { L as Link$1 } from "./index.es3.js";
|
|
34
33
|
import { cx } from "@emotion/css";
|
|
34
|
+
import { K as deepEqual } from "./index.es.js";
|
|
35
35
|
import "./state/breakpoints.es.js";
|
|
36
36
|
import "zod";
|
|
37
37
|
import "is-hotkey";
|
|
@@ -41,6 +41,8 @@ import "redux-thunk";
|
|
|
41
41
|
import "react";
|
|
42
42
|
import "@emotion/serialize";
|
|
43
43
|
import "@emotion/utils";
|
|
44
|
+
import "scroll-into-view-if-needed";
|
|
45
|
+
import "next/link";
|
|
44
46
|
import "use-sync-external-store/shim/with-selector";
|
|
45
47
|
import "next/dynamic";
|
|
46
48
|
import "./combobox.es.js";
|
|
@@ -49,7 +51,6 @@ import "./types.es.js";
|
|
|
49
51
|
import "./box-models.es.js";
|
|
50
52
|
import "css-box-model";
|
|
51
53
|
import "color";
|
|
52
|
-
import "scroll-into-view-if-needed";
|
|
53
54
|
import "react-dom";
|
|
54
55
|
import "html-react-parser";
|
|
55
56
|
import "next/head";
|
|
@@ -63,7 +64,15 @@ import "set-cookie-parser";
|
|
|
63
64
|
import "./constants.es.js";
|
|
64
65
|
import "uuid";
|
|
65
66
|
import "corporate-ipsum";
|
|
66
|
-
|
|
67
|
+
function getValue$2(editor) {
|
|
68
|
+
const matchingValues = Array.from(Editor.nodes(editor, {
|
|
69
|
+
at: getSelection(editor),
|
|
70
|
+
match: ElementUtils.isRootBlock
|
|
71
|
+
})).map(([node]) => node["textAlign"]);
|
|
72
|
+
return matchingValues.length === 0 ? void 0 : matchingValues.reduce((a2, b3) => {
|
|
73
|
+
return responsiveShallowEqual(a2, b3);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
67
76
|
const TEXT_ALIGN_KEY = "textAlign";
|
|
68
77
|
const withTextAlign = (editor) => {
|
|
69
78
|
const {
|
|
@@ -114,9 +123,7 @@ function TextAlignPlugin() {
|
|
|
114
123
|
match: ElementUtils.isRootBlock,
|
|
115
124
|
split: false
|
|
116
125
|
}),
|
|
117
|
-
getValue: (editor) =>
|
|
118
|
-
match: ElementUtils.isRootBlock
|
|
119
|
-
}),
|
|
126
|
+
getValue: (editor) => getValue$2(editor),
|
|
120
127
|
getElementValue: (element) => {
|
|
121
128
|
return ElementUtils.isRootBlock(element) ? element.textAlign : void 0;
|
|
122
129
|
}
|
|
@@ -131,56 +138,6 @@ function TextAlignPlugin() {
|
|
|
131
138
|
}
|
|
132
139
|
});
|
|
133
140
|
}
|
|
134
|
-
const COLOR_KEY = "color";
|
|
135
|
-
function ColorPlugin() {
|
|
136
|
-
return createRichTextV2Plugin({
|
|
137
|
-
control: {
|
|
138
|
-
definition: unstable_StyleV2({
|
|
139
|
-
type: Color({
|
|
140
|
-
label: "Color"
|
|
141
|
-
}),
|
|
142
|
-
getStyle(color) {
|
|
143
|
-
return {
|
|
144
|
-
color
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}),
|
|
148
|
-
onChange: (editor, value) => {
|
|
149
|
-
setResponsiveValue(editor, COLOR_KEY, value, {
|
|
150
|
-
match: Text.isText,
|
|
151
|
-
split: true
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
getValue: (editor) => getResponsiveValue(editor, COLOR_KEY, {
|
|
155
|
-
match: Text.isText
|
|
156
|
-
}),
|
|
157
|
-
getLeafValue: (text) => {
|
|
158
|
-
return Text.isText(text) ? text == null ? void 0 : text.color : void 0;
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
withPlugin: (editor) => {
|
|
162
|
-
const {
|
|
163
|
-
normalizeNode
|
|
164
|
-
} = editor;
|
|
165
|
-
editor.normalizeNode = (entry) => {
|
|
166
|
-
if (normalizeResponsiveValue(editor, COLOR_KEY, {
|
|
167
|
-
match: Text.isText
|
|
168
|
-
})(entry)) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
normalizeNode(entry);
|
|
172
|
-
};
|
|
173
|
-
return editor;
|
|
174
|
-
},
|
|
175
|
-
renderLeaf: (renderLeaf, className) => (props) => {
|
|
176
|
-
return renderLeaf(__spreadProps(__spreadValues({}, props), {
|
|
177
|
-
leaf: __spreadProps(__spreadValues({}, props.leaf), {
|
|
178
|
-
className: `${props.leaf.className} ${className}`
|
|
179
|
-
})
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
141
|
function getSupportedInlinesAndTextInSelection(editor) {
|
|
185
142
|
return Array.from(Editor.nodes(editor, {
|
|
186
143
|
at: getSelection(editor),
|
|
@@ -194,7 +151,8 @@ const getValue$1 = (editor) => {
|
|
|
194
151
|
if (!areAllRootsSupportedInlineTypesOrText)
|
|
195
152
|
return void 0;
|
|
196
153
|
const matchingValues = roots.filter(isSupportedInlineEntry).map(([node]) => node);
|
|
197
|
-
|
|
154
|
+
const match = matchingValues.reduce((a2, b3) => (a2 == null ? void 0 : a2.type) === (b3 == null ? void 0 : b3.type) ? b3 : null, (_a = matchingValues.at(0)) != null ? _a : void 0);
|
|
155
|
+
return match == null ? match : match.type;
|
|
198
156
|
};
|
|
199
157
|
const onChange$1 = (editor, value) => {
|
|
200
158
|
function unwrapAllSupportedTypes() {
|
|
@@ -297,7 +255,8 @@ const getValue = (editor) => {
|
|
|
297
255
|
if (!areAllRootsLinks)
|
|
298
256
|
return void 0;
|
|
299
257
|
const matchingValues = roots.map(([node]) => node).filter(isLinkElement);
|
|
300
|
-
|
|
258
|
+
const match = matchingValues.reduce((a2, b3) => deepEqual(a2 == null ? void 0 : a2.link, b3 == null ? void 0 : b3.link) ? b3 : null, (_a = matchingValues.at(0)) != null ? _a : void 0);
|
|
259
|
+
return match == null ? match : match.link;
|
|
301
260
|
};
|
|
302
261
|
const onChange = (editor, value) => {
|
|
303
262
|
if (value == null)
|
|
@@ -328,13 +287,14 @@ function InlinePluginComponent({
|
|
|
328
287
|
children,
|
|
329
288
|
renderElement
|
|
330
289
|
}) {
|
|
290
|
+
var _a;
|
|
331
291
|
const linkStyle = useStyle({
|
|
332
292
|
textDecoration: "none"
|
|
333
293
|
});
|
|
334
294
|
switch (element.type) {
|
|
335
295
|
case InlineType.Link:
|
|
336
296
|
return /* @__PURE__ */ jsx(Link$1, __spreadProps(__spreadValues({}, attributes), {
|
|
337
|
-
link: element.link,
|
|
297
|
+
link: (_a = element.link) != null ? _a : void 0,
|
|
338
298
|
className: cx(linkStyle, element.className),
|
|
339
299
|
children
|
|
340
300
|
}));
|
|
@@ -366,5 +326,5 @@ function LinkPlugin() {
|
|
|
366
326
|
}
|
|
367
327
|
});
|
|
368
328
|
}
|
|
369
|
-
export {
|
|
329
|
+
export { InlinePlugin, LinkPlugin, TextAlignPlugin, withInline, withLink, withTextAlign };
|
|
370
330
|
//# sourceMappingURL=slate.es.js.map
|
package/dist/slate.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slate.es.js","sources":["../src/slate/TextAlignPlugin/index.tsx","../src/slate/ColorPlugin/index.tsx","../src/slate/InlinePlugin/getValue.ts","../src/slate/InlinePlugin/onChange.ts","../src/slate/InlinePlugin/index.tsx","../src/slate/LinkPlugin/types.ts","../src/slate/LinkPlugin/getValue.ts","../src/slate/LinkPlugin/onChange.ts","../src/slate/LinkPlugin/index.tsx"],"sourcesContent":["import { Editor, Element } from 'slate'\nimport {\n createRichTextV2Plugin,\n unstable_IconRadioGroup,\n unstable_IconRadioGroupIcon,\n unstable_StyleV2,\n} from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { TextAlignProperty } from 'csstype'\nimport {\n getResponsiveValue,\n normalizeResponsiveValue,\n setResponsiveValue,\n} from '../utils/responsive'\n\nconst TEXT_ALIGN_KEY = 'textAlign'\n\nexport const withTextAlign = (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (\n normalizeResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock })(entry)\n ) {\n return\n }\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TextAlignPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: unstable_IconRadioGroup({\n label: 'Alignment',\n options: [\n {\n icon: unstable_IconRadioGroupIcon.TextAlignLeft,\n label: 'Left Align',\n value: 'left',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignCenter,\n label: 'Center Align',\n value: 'center',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignRight,\n label: 'Right Align',\n value: 'right',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignJustify,\n label: 'Justify',\n value: 'justify',\n },\n ],\n defaultValue: 'left',\n }),\n getStyle(textAlign: TextAlignProperty) {\n return { textAlign }\n },\n }),\n onChange: (editor, value) =>\n setResponsiveValue(editor, TEXT_ALIGN_KEY, value, {\n match: ElementUtils.isRootBlock,\n split: false,\n }),\n getValue: editor =>\n getResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock }),\n getElementValue: (element: Element) => {\n return ElementUtils.isRootBlock(element) ? element.textAlign : undefined\n },\n },\n withPlugin: withTextAlign,\n renderElement: (renderElement, className) => props => {\n return renderElement({\n ...props,\n element: {\n ...props.element,\n className,\n },\n })\n },\n })\n}\n","import { Editor, Text } from 'slate'\nimport {\n Color,\n createRichTextV2Plugin,\n unstable_StyleV2,\n ColorControlDefinition,\n} from '../../controls'\nimport { ControlDefinitionValue } from '../../runtimes/react/controls/control'\nimport {\n getResponsiveValue,\n normalizeResponsiveValue,\n setResponsiveValue,\n} from '../utils/responsive'\n\nexport const COLOR_KEY = 'color'\n\nexport function ColorPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: Color({\n label: 'Color',\n }),\n getStyle(color: ControlDefinitionValue<ColorControlDefinition>) {\n return { color }\n },\n }),\n onChange: (editor, value) => {\n setResponsiveValue(editor, COLOR_KEY, value, {\n match: Text.isText,\n split: true,\n })\n },\n getValue: editor => getResponsiveValue(editor, COLOR_KEY, { match: Text.isText }),\n getLeafValue: (text: Text) => {\n return Text.isText(text) ? text?.color : undefined\n },\n },\n withPlugin: (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (normalizeResponsiveValue(editor, COLOR_KEY, { match: Text.isText })(entry)) {\n return\n }\n\n normalizeNode(entry)\n }\n\n return editor\n },\n renderLeaf: (renderLeaf, className) => props => {\n return renderLeaf({\n ...props,\n leaf: {\n ...props.leaf,\n className: `${props.leaf.className} ${className}`,\n },\n })\n },\n })\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport deepEqual from '../../utils/deepEqual'\nimport { SupportedInline, isSupportedInlineType, isSupportedInlineEntry } from './types'\n\nexport function getSupportedInlinesAndTextInSelection(\n editor: Editor,\n): NodeEntry<SupportedInline | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node =>\n (ElementUtils.isInline(node) && isSupportedInlineType(node.type)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | SupportedInline>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n\n const areAllRootsSupportedInlineTypesOrText = roots.every(\n entry => isSupportedInlineEntry(entry) || Text.isText(entry[0]),\n )\n\n if (!areAllRootsSupportedInlineTypesOrText) return undefined\n\n const matchingValues = roots.filter(isSupportedInlineEntry).map(([node]) => node)\n\n return matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined), matchingValues.at(0))\n ?.type\n}\n","import { getSupportedInlinesAndTextInSelection } from './getValue'\nimport { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport {\n SupportedInlineType,\n isSupportedInlineEntry,\n isSupportedInlineType,\n supportedInlineOptions,\n} from './types'\n\nexport const onChange = (editor: Editor, value: SupportedInlineType) => {\n function unwrapAllSupportedTypes() {\n supportedInlineOptions.forEach(({ value: optionValue }) => unwrapInline(editor, optionValue))\n }\n\n function unwrapAllInlines() {\n Transforms.unwrapNodes(editor, {\n match: node => ElementUtils.isInline(node),\n at: getSelection(editor),\n })\n }\n\n if (value == null) return unwrapAllSupportedTypes()\n\n if (!isSupportedInlineType(value)) return\n\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n const root = roots.at(0)\n\n if (\n roots.length === 1 &&\n root != null &&\n isSupportedInlineEntry(root) &&\n root[0].type === value\n ) {\n unwrapInline(editor, value)\n } else {\n unwrapAllInlines()\n wrapInline(editor, { type: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { RenderElement, createRichTextV2Plugin, unstable_IconRadioGroup } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { supportedInlineOptions } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withInline = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nexport function InlinePlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_IconRadioGroup({\n label: 'Inline',\n options: supportedInlineOptions,\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) ? element.type : undefined\n },\n },\n withPlugin: withInline,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n\n default:\n return (\n <>\n {renderElement({\n element,\n attributes,\n children,\n })}\n </>\n )\n }\n}\n","import { Node, NodeEntry } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType, LinkElement } from '../types'\n\nexport function isLinkElement(node: Node): node is LinkElement {\n return ElementUtils.isInline(node) && node.type === InlineType.Link\n}\n\nexport function isLinkEntry(inline: NodeEntry<Node>): inline is NodeEntry<LinkElement> {\n return ElementUtils.isInline(inline[0]) && inline[0].type === InlineType.Link\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LinkElement } from '../types'\nimport deepEqual from '../../utils/deepEqual'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkElement } from './types'\n\nexport function getLinksAndTextInSelection(editor: Editor): NodeEntry<LinkElement | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => (ElementUtils.isInline(node) && isLinkElement(node)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | LinkElement>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n\n const areAllRootsLinks = roots.every(([root]) => isLinkElement(root) || Text.isText(root))\n\n if (!areAllRootsLinks) return undefined\n\n const matchingValues = roots.map(([node]) => node).filter(isLinkElement)\n\n return matchingValues.reduce((a, b) => (deepEqual(a, b) ? b : undefined), matchingValues.at(0))\n ?.link\n}\n","import { Editor, Transforms } from 'slate'\nimport { LinkControlData } from '../../controls'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { InlineType } from '../types'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkEntry } from './types'\nimport { getLinksAndTextInSelection } from './getValue'\n\nexport const onChange = (editor: Editor, value: LinkControlData) => {\n if (value == null) return unwrapInline(editor, InlineType.Link)\n\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n const root = roots.at(0)\n\n // If the root of our selection is a link we just want to modify it\n if (roots.length === 1 && root != null && isLinkEntry(root)) {\n Transforms.setNodes(\n editor,\n {\n link: value,\n },\n { at: root[1] },\n )\n }\n // In all other cases we want to remove all existing links and wrap the current selection in a new link\n else {\n unwrapInline(editor, InlineType.Link)\n wrapInline(editor, { type: InlineType.Link, link: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { Link, RenderElement, createRichTextV2Plugin } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../runtimes/react/use-style'\nimport { Link as LinkComponent } from '../../components/shared/Link'\nimport { cx } from '@emotion/css'\nimport { isLinkElement } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withLink = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n const linkStyle = useStyle({ textDecoration: 'none' })\n switch (element.type) {\n case InlineType.Link:\n return (\n <LinkComponent\n {...attributes}\n link={element.link}\n className={cx(linkStyle, element.className)}\n >\n {children}\n </LinkComponent>\n )\n\n default:\n return renderElement({\n element,\n attributes,\n children,\n })\n }\n}\n\nexport function LinkPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: Link({\n label: 'On Click',\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) && isLinkElement(element) ? element.link : undefined\n },\n },\n withPlugin: withLink,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n"],"names":["TEXT_ALIGN_KEY","withTextAlign","editor","normalizeNode","entry","normalizeResponsiveValue","match","ElementUtils","isRootBlock","createRichTextV2Plugin","control","definition","unstable_StyleV2","type","unstable_IconRadioGroup","label","options","icon","unstable_IconRadioGroupIcon","TextAlignLeft","value","TextAlignCenter","TextAlignRight","TextAlignJustify","defaultValue","getStyle","textAlign","onChange","setResponsiveValue","split","getValue","getResponsiveValue","getElementValue","element","undefined","withPlugin","renderElement","className","props","COLOR_KEY","Color","color","Text","isText","getLeafValue","text","renderLeaf","leaf","withInline","isInline","supportedInlineOptions","InlinePluginComponent","attributes","children","InlineType","Code","SuperScript","SubScript","_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A,QACfhD,OAAO;AAAA,MAAA,CADO;AAAA,MAGhBY;AAAAA,MACAG;AAAAA,MACAE,iBAAiB,CAACC,YAAqB;AAC9B1B,eAAAA,aAAa0C,SAAShB,OAAtB,KAAkCkC,cAAclC,OAAD,IAAYA,QAAQgC,OAAO/B;AAAAA,MAClF;AAAA,IATyB;AAAA,IAW5BC,YAAYwB;AAAAA,IACZvB,eAAeA,mBAAiBE,CAAS,UAAA;AAChC,iCAAC,uBAAD,iCAA2BA,QAA3B;AAAA,QAAkC;AAAA,MAAA,EAAzC;AAAA,IACD;AAAA,EAAA,CAd0B;AAgB9B;;"}
|
|
1
|
+
{"version":3,"file":"slate.es.js","sources":["../src/slate/TextAlignPlugin/getValue.ts","../src/slate/TextAlignPlugin/index.tsx","../src/slate/InlinePlugin/getValue.ts","../src/slate/InlinePlugin/onChange.ts","../src/slate/InlinePlugin/index.tsx","../src/slate/LinkPlugin/types.ts","../src/slate/LinkPlugin/getValue.ts","../src/slate/LinkPlugin/onChange.ts","../src/slate/LinkPlugin/index.tsx"],"sourcesContent":["import { Editor } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { ResponsiveBlockTextAlignment } from '../types'\nimport { getSelection } from '../selectors'\nimport { responsiveShallowEqual } from '../utils/responsive'\n\nexport function getValue(editor: Editor): ResponsiveBlockTextAlignment | undefined {\n const matchingValues = Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: ElementUtils.isRootBlock,\n }),\n ).map(([node]) => node['textAlign']) as (ResponsiveBlockTextAlignment | undefined)[]\n\n return matchingValues.length === 0\n ? undefined\n : matchingValues.reduce((a, b) => {\n return responsiveShallowEqual(a, b)\n })\n}\n","import { Editor, Element } from 'slate'\nimport {\n createRichTextV2Plugin,\n unstable_IconRadioGroup,\n unstable_IconRadioGroupIcon,\n unstable_StyleV2,\n} from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { TextAlignProperty } from 'csstype'\nimport { normalizeResponsiveValue, setResponsiveValue } from '../utils/responsive'\nimport { getValue } from './getValue'\n\nconst TEXT_ALIGN_KEY = 'textAlign'\n\nexport const withTextAlign = (editor: Editor) => {\n const { normalizeNode } = editor\n editor.normalizeNode = entry => {\n if (\n normalizeResponsiveValue(editor, TEXT_ALIGN_KEY, { match: ElementUtils.isRootBlock })(entry)\n ) {\n return\n }\n normalizeNode(entry)\n }\n\n return editor\n}\n\nexport function TextAlignPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_StyleV2({\n type: unstable_IconRadioGroup({\n label: 'Alignment',\n options: [\n {\n icon: unstable_IconRadioGroupIcon.TextAlignLeft,\n label: 'Left Align',\n value: 'left',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignCenter,\n label: 'Center Align',\n value: 'center',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignRight,\n label: 'Right Align',\n value: 'right',\n },\n {\n icon: unstable_IconRadioGroupIcon.TextAlignJustify,\n label: 'Justify',\n value: 'justify',\n },\n ],\n defaultValue: 'left',\n }),\n getStyle(textAlign: TextAlignProperty) {\n return { textAlign }\n },\n }),\n onChange: (editor, value) =>\n setResponsiveValue(editor, TEXT_ALIGN_KEY, value, {\n match: ElementUtils.isRootBlock,\n split: false,\n }),\n getValue: editor => getValue(editor),\n getElementValue: (element: Element) => {\n return ElementUtils.isRootBlock(element) ? element.textAlign : undefined\n },\n },\n withPlugin: withTextAlign,\n renderElement: (renderElement, className) => props => {\n return renderElement({\n ...props,\n element: {\n ...props.element,\n className,\n },\n })\n },\n })\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { SupportedInline, isSupportedInlineType, isSupportedInlineEntry } from './types'\n\nexport function getSupportedInlinesAndTextInSelection(\n editor: Editor,\n): NodeEntry<SupportedInline | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node =>\n (ElementUtils.isInline(node) && isSupportedInlineType(node.type)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | SupportedInline>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n\n const areAllRootsSupportedInlineTypesOrText = roots.every(\n entry => isSupportedInlineEntry(entry) || Text.isText(entry[0]),\n )\n\n if (!areAllRootsSupportedInlineTypesOrText) return undefined\n\n const matchingValues = roots.filter(isSupportedInlineEntry).map(([node]) => node) as (\n | SupportedInline\n | null\n | undefined\n )[]\n\n const match = matchingValues.reduce(\n (a, b) => (a?.type === b?.type ? b : null),\n matchingValues.at(0) ?? undefined,\n )\n\n return match == null ? match : match.type\n}\n","import { getSupportedInlinesAndTextInSelection } from './getValue'\nimport { Editor, Transforms } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport {\n SupportedInlineType,\n isSupportedInlineEntry,\n isSupportedInlineType,\n supportedInlineOptions,\n} from './types'\n\nexport const onChange = (editor: Editor, value: SupportedInlineType) => {\n function unwrapAllSupportedTypes() {\n supportedInlineOptions.forEach(({ value: optionValue }) => unwrapInline(editor, optionValue))\n }\n\n function unwrapAllInlines() {\n Transforms.unwrapNodes(editor, {\n match: node => ElementUtils.isInline(node),\n at: getSelection(editor),\n })\n }\n\n if (value == null) return unwrapAllSupportedTypes()\n\n if (!isSupportedInlineType(value)) return\n\n const roots = filterForSubtreeRoots(getSupportedInlinesAndTextInSelection(editor))\n const root = roots.at(0)\n\n if (\n roots.length === 1 &&\n root != null &&\n isSupportedInlineEntry(root) &&\n root[0].type === value\n ) {\n unwrapInline(editor, value)\n } else {\n unwrapAllInlines()\n wrapInline(editor, { type: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { RenderElement, createRichTextV2Plugin, unstable_IconRadioGroup } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { supportedInlineOptions } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withInline = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nexport function InlinePlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: unstable_IconRadioGroup({\n label: 'Inline',\n options: supportedInlineOptions,\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) ? element.type : undefined\n },\n },\n withPlugin: withInline,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n switch (element.type) {\n case InlineType.Code:\n return <code {...attributes}>{children}</code>\n case InlineType.SuperScript:\n return <sup {...attributes}>{children}</sup>\n case InlineType.SubScript:\n return <sub {...attributes}>{children}</sub>\n\n default:\n return (\n <>\n {renderElement({\n element,\n attributes,\n children,\n })}\n </>\n )\n }\n}\n","import { Node, NodeEntry } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType, LinkElement } from '../types'\n\nexport function isLinkElement(node: Node): node is LinkElement {\n return ElementUtils.isInline(node) && node.type === InlineType.Link\n}\n\nexport function isLinkEntry(inline: NodeEntry<Node>): inline is NodeEntry<LinkElement> {\n return ElementUtils.isInline(inline[0]) && inline[0].type === InlineType.Link\n}\n","import { Editor, NodeEntry, Text } from 'slate'\nimport { ElementUtils } from '../utils/element'\nimport { LinkElement } from '../types'\nimport { getSelection } from '../selectors'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkElement } from './types'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function getLinksAndTextInSelection(editor: Editor): NodeEntry<LinkElement | Text>[] {\n return Array.from(\n Editor.nodes(editor, {\n at: getSelection(editor),\n match: node => (ElementUtils.isInline(node) && isLinkElement(node)) || Text.isText(node),\n }),\n ) as NodeEntry<Text | LinkElement>[]\n}\n\nexport const getValue = (editor: Editor) => {\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n\n const areAllRootsLinks = roots.every(([root]) => isLinkElement(root) || Text.isText(root))\n\n if (!areAllRootsLinks) return undefined\n\n const matchingValues = roots.map(([node]) => node).filter(isLinkElement) as (\n | LinkElement\n | null\n | undefined\n )[]\n\n const match = matchingValues.reduce(\n (a, b) => (deepEqual(a?.link, b?.link) ? b : null),\n matchingValues.at(0) ?? undefined,\n )\n\n return match == null ? match : match.link\n}\n","import { Editor, Transforms } from 'slate'\nimport { LinkControlData } from '../../controls'\nimport { unwrapInline } from '../BlockPlugin/unwrapInline'\nimport { wrapInline } from '../BlockPlugin/wrapInline'\nimport { InlineType } from '../types'\nimport { filterForSubtreeRoots } from '../BlockPlugin/utils/filterForSubtreeRoots'\nimport { isLinkEntry } from './types'\nimport { getLinksAndTextInSelection } from './getValue'\n\nexport const onChange = (editor: Editor, value: LinkControlData) => {\n if (value == null) return unwrapInline(editor, InlineType.Link)\n\n const roots = filterForSubtreeRoots(getLinksAndTextInSelection(editor))\n const root = roots.at(0)\n\n // If the root of our selection is a link we just want to modify it\n if (roots.length === 1 && root != null && isLinkEntry(root)) {\n Transforms.setNodes(\n editor,\n {\n link: value,\n },\n { at: root[1] },\n )\n }\n // In all other cases we want to remove all existing links and wrap the current selection in a new link\n else {\n unwrapInline(editor, InlineType.Link)\n wrapInline(editor, { type: InlineType.Link, link: value, children: [] })\n }\n}\n","import { Editor, Element } from 'slate'\nimport { Link, RenderElement, createRichTextV2Plugin } from '../../controls'\nimport { ElementUtils } from '../utils/element'\nimport { InlineType } from '../types'\nimport { RenderElementProps } from 'slate-react'\nimport { useStyle } from '../../runtimes/react/use-style'\nimport { Link as LinkComponent } from '../../components/shared/Link'\nimport { cx } from '@emotion/css'\nimport { isLinkElement } from './types'\nimport { onChange } from './onChange'\nimport { getValue } from './getValue'\n\nexport const withLink = (editor: Editor) => {\n const { isInline } = editor\n\n editor.isInline = entry => {\n return ElementUtils.isInline(entry) && isInline(entry)\n }\n\n return editor\n}\n\nfunction InlinePluginComponent({\n element,\n attributes,\n children,\n renderElement,\n}: RenderElementProps & { renderElement: RenderElement }) {\n const linkStyle = useStyle({ textDecoration: 'none' })\n switch (element.type) {\n case InlineType.Link:\n return (\n <LinkComponent\n {...attributes}\n link={element.link ?? undefined}\n className={cx(linkStyle, element.className)}\n >\n {children}\n </LinkComponent>\n )\n\n default:\n return renderElement({\n element,\n attributes,\n children,\n })\n }\n}\n\nexport function LinkPlugin() {\n return createRichTextV2Plugin({\n control: {\n definition: Link({\n label: 'On Click',\n }),\n onChange,\n getValue,\n getElementValue: (element: Element) => {\n return ElementUtils.isInline(element) && isLinkElement(element) ? element.link : undefined\n },\n },\n withPlugin: withLink,\n renderElement: renderElement => props => {\n return <InlinePluginComponent {...props} renderElement={renderElement} />\n },\n })\n}\n"],"names":["TEXT_ALIGN_KEY","withTextAlign","editor","normalizeNode","entry","normalizeResponsiveValue","match","ElementUtils","isRootBlock","createRichTextV2Plugin","control","definition","unstable_StyleV2","type","unstable_IconRadioGroup","label","options","icon","unstable_IconRadioGroupIcon","TextAlignLeft","value","TextAlignCenter","TextAlignRight","TextAlignJustify","defaultValue","getStyle","textAlign","onChange","setResponsiveValue","split","getValue","getElementValue","element","undefined","withPlugin","renderElement","className","props","withInline","isInline","supportedInlineOptions","InlinePluginComponent","attributes","children","InlineType","Code","SuperScript","SubScript","_Fragment","withLink","linkStyle","useStyle","textDecoration","Link","LinkComponent","link","cx","isLinkElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,oBAAkB,QAA0D;AACjF,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AAAA,EANL;AAAA;AAWA,aAAOR,cAAc;AAAA,QACnBH;AAAAA,QACAU;AAAAA,QACAC;AAAAA,MAAAA,CAHkB;AAAA;AAMzB;AAE4B,sBAAA;AAC3B,SAAOlC,uBAAuB;AAAA,IAC5BC,SAAS;AAAA,MACPC,YAAY0C,KAAK;AAAA,QACftC,OAAO;AAAA,MAAA,CADO;AAAA,MAGhBY;AAAAA,MACAG;AAAAA,MACAC,iBAAiB,CAACC,YAAqB;AAC9BzB,eAAAA,aAAagC,SAASP,OAAtB,KAAkCyB,cAAczB,OAAD,IAAYA,QAAQuB,OAAOtB;AAAAA,MAClF;AAAA,IATyB;AAAA,IAW5BC,YAAYe;AAAAA,IACZd,eAAeA,mBAAiBE,CAAS,UAAA;AAChC,iCAAC,uBAAD,iCAA2BA,QAA3B;AAAA,QAAkC;AAAA,MAAA,EAAzC;AAAA,IACD;AAAA,EAAA,CAd0B;AAgB9B;;"}
|
|
@@ -151,6 +151,18 @@ function shallowMergeFallbacks(value, fallbacks) {
|
|
|
151
151
|
value: shallowMerge(a.value, b.value)
|
|
152
152
|
}));
|
|
153
153
|
}
|
|
154
|
+
function mergeOrCoalesce(a, b) {
|
|
155
|
+
if (typeof a === "object" && a !== null && !Array.isArray(a) && typeof b === "object" && b !== null && !Array.isArray(b)) {
|
|
156
|
+
return shallowMerge(a, b);
|
|
157
|
+
}
|
|
158
|
+
return coalesce(a, b);
|
|
159
|
+
}
|
|
160
|
+
function mergeOrCoalesceFallbacks(value, fallbacks) {
|
|
161
|
+
return [value, ...fallbacks].filter((override) => Boolean(override)).reduce((a, b) => ({
|
|
162
|
+
deviceId: a.deviceId || b.deviceId,
|
|
163
|
+
value: mergeOrCoalesce(a.value, b.value)
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
154
166
|
function join(breakpoints, responsiveValues, joinFn, strategy) {
|
|
155
167
|
return breakpoints.map(({ id }) => id).map((deviceId) => {
|
|
156
168
|
const value = joinFn(responsiveValues.map((responsiveValue) => {
|
|
@@ -203,6 +215,7 @@ exports.getBreakpointMediaQuery = getBreakpointMediaQuery;
|
|
|
203
215
|
exports.getInitialState = getInitialState;
|
|
204
216
|
exports.getViewportStyle = getViewportStyle;
|
|
205
217
|
exports.join = join;
|
|
218
|
+
exports.mergeOrCoalesceFallbacks = mergeOrCoalesceFallbacks;
|
|
206
219
|
exports.mergeResponsiveValues = mergeResponsiveValues;
|
|
207
220
|
exports.parseBreakpointsInput = parseBreakpointsInput;
|
|
208
221
|
exports.reducer = reducer;
|