@zipify/wysiwyg 3.1.0-0 → 3.1.0-2

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.
Files changed (32) hide show
  1. package/config/build/cli.config.js +1 -1
  2. package/config/build/lib.config.js +1 -1
  3. package/dist/cli.js +3 -3
  4. package/dist/wysiwyg.css +25 -22
  5. package/dist/wysiwyg.mjs +1337 -1302
  6. package/example/ExampleApp.vue +1 -1
  7. package/example/presets.js +7 -7
  8. package/example/tooltip/Tooltip.js +3 -1
  9. package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +5 -2
  10. package/lib/__tests__/utils/buildTestExtensions.js +24 -2
  11. package/lib/components/base/composables/useModalToggler.js +4 -1
  12. package/lib/components/base/dropdown/DropdownActivator.vue +4 -0
  13. package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
  14. package/lib/{entry-cli.js → entryCli.js} +0 -0
  15. package/lib/{entry-lib.js → entryLib.js} +0 -0
  16. package/lib/extensions/Alignment.js +6 -6
  17. package/lib/extensions/StylePreset.js +8 -46
  18. package/lib/extensions/__tests__/Alignment.test.js +1 -1
  19. package/lib/extensions/__tests__/StylePreset.test.js +90 -119
  20. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
  21. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +0 -2
  22. package/lib/extensions/core/NodeProcessor.js +6 -2
  23. package/lib/extensions/index.js +7 -3
  24. package/lib/extensions/list/__tests__/List.test.js +6 -1
  25. package/lib/services/ContentSerializer.js +1 -1
  26. package/lib/services/{ContextWidnow.js → ContextWindow.js} +0 -0
  27. package/lib/services/StylePresetRenderer.js +73 -0
  28. package/lib/services/__tests__/StylePresetRenderer.test.js +98 -0
  29. package/lib/services/__tests__/__snapshots__/StylePresetRenderer.test.js.snap +5 -0
  30. package/lib/services/index.js +2 -1
  31. package/lib/styles/content.css +10 -10
  32. package/package.json +4 -4
package/dist/wysiwyg.mjs CHANGED
@@ -26,7 +26,7 @@ var __privateMethod = (obj, member, method) => {
26
26
  __accessCheck(obj, member, "access private method");
27
27
  return method;
28
28
  };
29
- var _buildDecorations, buildDecorations_fn, _domParser, _parser, _NodeFilter, NodeFilter_get, _Node, Node_get, _removeComments, removeComments_fn, _normalizeRootTags, normalizeRootTags_fn, _createNodeIterator, createNodeIterator_fn, _iterateNodes, iterateNodes_fn, _runIterator, runIterator_fn, _removeEmptyNodes, removeEmptyNodes_fn, _normalizeListItems, normalizeListItems_fn, _isBlockNode, isBlockNode_fn, _isRootNode, isRootNode_fn, _assignElementProperties, assignElementProperties_fn, _removeStyleProperties, removeStyleProperties_fn, _normalizeBreakLines, normalizeBreakLines_fn, _normalizeBlockTextDecoration, normalizeBlockTextDecoration_fn, _moveTextDecorationToChildren, moveTextDecorationToChildren_fn, _parseTextDecoration, parseTextDecoration_fn, _normalizeBlockBackgroundColor, normalizeBlockBackgroundColor_fn, _moveBackgroundColorToChildren, moveBackgroundColorToChildren_fn, _wrapTextNode, wrapTextNode_fn, _iterateNodes2, iterateNodes_fn2, _iterateChildNodes, iterateChildNodes_fn, _bubbleMarks, bubbleMarks_fn, _canBubbleMark, canBubbleMark_fn, _includesMark, includesMark_fn, _includesMarkType, includesMarkType_fn, _removeMark, removeMark_fn, _addMark, addMark_fn, _findMarkIndexByType, findMarkIndexByType_fn, _buildHtml, buildHtml_fn, _buildJson, buildJson_fn, _schema, _domParser2, _nodeDomParser, _textBlock, textBlock_fn, _normalizeTextBlockArgs, normalizeTextBlockArgs_fn, _contentSerializer, _getWeights, getWeights_fn;
29
+ var _buildDecorations, buildDecorations_fn, _domParser, _parser, _NodeFilter, NodeFilter_get, _Node, Node_get, _removeComments, removeComments_fn, _normalizeRootTags, normalizeRootTags_fn, _createNodeIterator, createNodeIterator_fn, _iterateNodes, iterateNodes_fn, _runIterator, runIterator_fn, _removeEmptyNodes, removeEmptyNodes_fn, _normalizeListItems, normalizeListItems_fn, _isBlockNode, isBlockNode_fn, _isRootNode, isRootNode_fn, _assignElementProperties, assignElementProperties_fn, _removeStyleProperties, removeStyleProperties_fn, _normalizeBreakLines, normalizeBreakLines_fn, _normalizeBlockTextDecoration, normalizeBlockTextDecoration_fn, _moveTextDecorationToChildren, moveTextDecorationToChildren_fn, _parseTextDecoration, parseTextDecoration_fn, _normalizeBlockBackgroundColor, normalizeBlockBackgroundColor_fn, _moveBackgroundColorToChildren, moveBackgroundColorToChildren_fn, _wrapTextNode, wrapTextNode_fn, _iterateNodes2, iterateNodes_fn2, _iterateChildNodes, iterateChildNodes_fn, _bubbleMarks, bubbleMarks_fn, _canBubbleMark, canBubbleMark_fn, _includesMark, includesMark_fn, _includesMarkType, includesMarkType_fn, _removeMark, removeMark_fn, _addMark, addMark_fn, _findMarkIndexByType, findMarkIndexByType_fn, _buildHtml, buildHtml_fn, _buildJson, buildJson_fn, _schema, _domParser2, _nodeDomParser, _textBlock, textBlock_fn, _normalizeTextBlockArgs, normalizeTextBlockArgs_fn, _contentSerializer, _baseClass, _makeVariable, _linkPresetId, _makeInternalVariableName, makeInternalVariableName_fn, _getWeights, getWeights_fn;
30
30
  import { computed, unref, toRef, reactive, watch, ref, inject, nextTick, onUnmounted, provide, onMounted } from "vue";
31
31
  import { ColorModel, ZipifyColorPicker } from "@zipify/colorpicker";
32
32
  function OrderedMap(content) {
@@ -12951,1423 +12951,1397 @@ class JsonSerializer {
12951
12951
  return JSON.stringify(json);
12952
12952
  }
12953
12953
  }
12954
- const FontFamily = Mark.create({
12955
- name: TextSettings.FONT_FAMILY,
12956
- group: MarkGroups.SETTINGS,
12957
- addOptions: () => ({
12958
- fonts: []
12959
- }),
12960
- addAttributes: () => ({
12961
- value: { required: true }
12962
- }),
12963
- addCommands() {
12964
- return {
12965
- applyFontFamily: createCommand(({ commands: commands2 }, value) => {
12966
- commands2.applyMark(this.name, { value });
12967
- const font = commands2.findFontByName(value);
12968
- let fontWeight = unref(commands2.getFontWeight());
12969
- if (!font.isWeightSupported(fontWeight)) {
12970
- fontWeight = font.findClosestWeight(fontWeight);
12971
- commands2.applyFontWeight(fontWeight);
12954
+ const Text$1 = Node.create({
12955
+ name: "text",
12956
+ group: "inline"
12957
+ });
12958
+ var GOOD_LEAF_SIZE = 200;
12959
+ var RopeSequence = function RopeSequence2() {
12960
+ };
12961
+ RopeSequence.prototype.append = function append(other) {
12962
+ if (!other.length) {
12963
+ return this;
12964
+ }
12965
+ other = RopeSequence.from(other);
12966
+ return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other);
12967
+ };
12968
+ RopeSequence.prototype.prepend = function prepend(other) {
12969
+ if (!other.length) {
12970
+ return this;
12971
+ }
12972
+ return RopeSequence.from(other).append(this);
12973
+ };
12974
+ RopeSequence.prototype.appendInner = function appendInner(other) {
12975
+ return new Append(this, other);
12976
+ };
12977
+ RopeSequence.prototype.slice = function slice(from2, to) {
12978
+ if (from2 === void 0)
12979
+ from2 = 0;
12980
+ if (to === void 0)
12981
+ to = this.length;
12982
+ if (from2 >= to) {
12983
+ return RopeSequence.empty;
12984
+ }
12985
+ return this.sliceInner(Math.max(0, from2), Math.min(this.length, to));
12986
+ };
12987
+ RopeSequence.prototype.get = function get(i) {
12988
+ if (i < 0 || i >= this.length) {
12989
+ return void 0;
12990
+ }
12991
+ return this.getInner(i);
12992
+ };
12993
+ RopeSequence.prototype.forEach = function forEach(f, from2, to) {
12994
+ if (from2 === void 0)
12995
+ from2 = 0;
12996
+ if (to === void 0)
12997
+ to = this.length;
12998
+ if (from2 <= to) {
12999
+ this.forEachInner(f, from2, to, 0);
13000
+ } else {
13001
+ this.forEachInvertedInner(f, from2, to, 0);
13002
+ }
13003
+ };
13004
+ RopeSequence.prototype.map = function map(f, from2, to) {
13005
+ if (from2 === void 0)
13006
+ from2 = 0;
13007
+ if (to === void 0)
13008
+ to = this.length;
13009
+ var result = [];
13010
+ this.forEach(function(elt, i) {
13011
+ return result.push(f(elt, i));
13012
+ }, from2, to);
13013
+ return result;
13014
+ };
13015
+ RopeSequence.from = function from(values2) {
13016
+ if (values2 instanceof RopeSequence) {
13017
+ return values2;
13018
+ }
13019
+ return values2 && values2.length ? new Leaf(values2) : RopeSequence.empty;
13020
+ };
13021
+ var Leaf = /* @__PURE__ */ function(RopeSequence3) {
13022
+ function Leaf2(values2) {
13023
+ RopeSequence3.call(this);
13024
+ this.values = values2;
13025
+ }
13026
+ if (RopeSequence3)
13027
+ Leaf2.__proto__ = RopeSequence3;
13028
+ Leaf2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype);
13029
+ Leaf2.prototype.constructor = Leaf2;
13030
+ var prototypeAccessors = { length: { configurable: true }, depth: { configurable: true } };
13031
+ Leaf2.prototype.flatten = function flatten() {
13032
+ return this.values;
13033
+ };
13034
+ Leaf2.prototype.sliceInner = function sliceInner(from2, to) {
13035
+ if (from2 == 0 && to == this.length) {
13036
+ return this;
13037
+ }
13038
+ return new Leaf2(this.values.slice(from2, to));
13039
+ };
13040
+ Leaf2.prototype.getInner = function getInner(i) {
13041
+ return this.values[i];
13042
+ };
13043
+ Leaf2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
13044
+ for (var i = from2; i < to; i++) {
13045
+ if (f(this.values[i], start + i) === false) {
13046
+ return false;
13047
+ }
13048
+ }
13049
+ };
13050
+ Leaf2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
13051
+ for (var i = from2 - 1; i >= to; i--) {
13052
+ if (f(this.values[i], start + i) === false) {
13053
+ return false;
13054
+ }
13055
+ }
13056
+ };
13057
+ Leaf2.prototype.leafAppend = function leafAppend(other) {
13058
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
13059
+ return new Leaf2(this.values.concat(other.flatten()));
13060
+ }
13061
+ };
13062
+ Leaf2.prototype.leafPrepend = function leafPrepend(other) {
13063
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
13064
+ return new Leaf2(other.flatten().concat(this.values));
13065
+ }
13066
+ };
13067
+ prototypeAccessors.length.get = function() {
13068
+ return this.values.length;
13069
+ };
13070
+ prototypeAccessors.depth.get = function() {
13071
+ return 0;
13072
+ };
13073
+ Object.defineProperties(Leaf2.prototype, prototypeAccessors);
13074
+ return Leaf2;
13075
+ }(RopeSequence);
13076
+ RopeSequence.empty = new Leaf([]);
13077
+ var Append = /* @__PURE__ */ function(RopeSequence3) {
13078
+ function Append2(left, right) {
13079
+ RopeSequence3.call(this);
13080
+ this.left = left;
13081
+ this.right = right;
13082
+ this.length = left.length + right.length;
13083
+ this.depth = Math.max(left.depth, right.depth) + 1;
13084
+ }
13085
+ if (RopeSequence3)
13086
+ Append2.__proto__ = RopeSequence3;
13087
+ Append2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype);
13088
+ Append2.prototype.constructor = Append2;
13089
+ Append2.prototype.flatten = function flatten() {
13090
+ return this.left.flatten().concat(this.right.flatten());
13091
+ };
13092
+ Append2.prototype.getInner = function getInner(i) {
13093
+ return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length);
13094
+ };
13095
+ Append2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
13096
+ var leftLen = this.left.length;
13097
+ if (from2 < leftLen && this.left.forEachInner(f, from2, Math.min(to, leftLen), start) === false) {
13098
+ return false;
13099
+ }
13100
+ if (to > leftLen && this.right.forEachInner(f, Math.max(from2 - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) {
13101
+ return false;
13102
+ }
13103
+ };
13104
+ Append2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
13105
+ var leftLen = this.left.length;
13106
+ if (from2 > leftLen && this.right.forEachInvertedInner(f, from2 - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) {
13107
+ return false;
13108
+ }
13109
+ if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from2, leftLen), to, start) === false) {
13110
+ return false;
13111
+ }
13112
+ };
13113
+ Append2.prototype.sliceInner = function sliceInner(from2, to) {
13114
+ if (from2 == 0 && to == this.length) {
13115
+ return this;
13116
+ }
13117
+ var leftLen = this.left.length;
13118
+ if (to <= leftLen) {
13119
+ return this.left.slice(from2, to);
13120
+ }
13121
+ if (from2 >= leftLen) {
13122
+ return this.right.slice(from2 - leftLen, to - leftLen);
13123
+ }
13124
+ return this.left.slice(from2, leftLen).append(this.right.slice(0, to - leftLen));
13125
+ };
13126
+ Append2.prototype.leafAppend = function leafAppend(other) {
13127
+ var inner = this.right.leafAppend(other);
13128
+ if (inner) {
13129
+ return new Append2(this.left, inner);
13130
+ }
13131
+ };
13132
+ Append2.prototype.leafPrepend = function leafPrepend(other) {
13133
+ var inner = this.left.leafPrepend(other);
13134
+ if (inner) {
13135
+ return new Append2(inner, this.right);
13136
+ }
13137
+ };
13138
+ Append2.prototype.appendInner = function appendInner2(other) {
13139
+ if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) {
13140
+ return new Append2(this.left, new Append2(this.right, other));
13141
+ }
13142
+ return new Append2(this, other);
13143
+ };
13144
+ return Append2;
13145
+ }(RopeSequence);
13146
+ var ropeSequence = RopeSequence;
13147
+ const max_empty_items = 500;
13148
+ class Branch {
13149
+ constructor(items, eventCount) {
13150
+ this.items = items;
13151
+ this.eventCount = eventCount;
13152
+ }
13153
+ popEvent(state, preserveItems) {
13154
+ if (this.eventCount == 0)
13155
+ return null;
13156
+ let end = this.items.length;
13157
+ for (; ; end--) {
13158
+ let next2 = this.items.get(end - 1);
13159
+ if (next2.selection) {
13160
+ --end;
13161
+ break;
13162
+ }
13163
+ }
13164
+ let remap, mapFrom;
13165
+ if (preserveItems) {
13166
+ remap = this.remapping(end, this.items.length);
13167
+ mapFrom = remap.maps.length;
13168
+ }
13169
+ let transform = state.tr;
13170
+ let selection, remaining;
13171
+ let addAfter = [], addBefore = [];
13172
+ this.items.forEach((item, i) => {
13173
+ if (!item.step) {
13174
+ if (!remap) {
13175
+ remap = this.remapping(end, i + 1);
13176
+ mapFrom = remap.maps.length;
12972
13177
  }
12973
- if (!font.isItalicSupported(fontWeight)) {
12974
- commands2.removeItalic();
13178
+ mapFrom--;
13179
+ addBefore.push(item);
13180
+ return;
13181
+ }
13182
+ if (remap) {
13183
+ addBefore.push(new Item(item.map));
13184
+ let step = item.step.map(remap.slice(mapFrom)), map2;
13185
+ if (step && transform.maybeStep(step).doc) {
13186
+ map2 = transform.mapping.maps[transform.mapping.maps.length - 1];
13187
+ addAfter.push(new Item(map2, void 0, void 0, addAfter.length + addBefore.length));
13188
+ }
13189
+ mapFrom--;
13190
+ if (map2)
13191
+ remap.appendMap(map2, mapFrom);
13192
+ } else {
13193
+ transform.maybeStep(item.step);
13194
+ }
13195
+ if (item.selection) {
13196
+ selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
13197
+ remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
13198
+ return false;
13199
+ }
13200
+ }, this.items.length, 0);
13201
+ return { remaining, transform, selection };
13202
+ }
13203
+ addTransform(transform, selection, histOptions, preserveItems) {
13204
+ let newItems = [], eventCount = this.eventCount;
13205
+ let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
13206
+ for (let i = 0; i < transform.steps.length; i++) {
13207
+ let step = transform.steps[i].invert(transform.docs[i]);
13208
+ let item = new Item(transform.mapping.maps[i], step, selection), merged;
13209
+ if (merged = lastItem && lastItem.merge(item)) {
13210
+ item = merged;
13211
+ if (i)
13212
+ newItems.pop();
13213
+ else
13214
+ oldItems = oldItems.slice(0, oldItems.length - 1);
13215
+ }
13216
+ newItems.push(item);
13217
+ if (selection) {
13218
+ eventCount++;
13219
+ selection = void 0;
13220
+ }
13221
+ if (!preserveItems)
13222
+ lastItem = item;
13223
+ }
13224
+ let overflow = eventCount - histOptions.depth;
13225
+ if (overflow > DEPTH_OVERFLOW) {
13226
+ oldItems = cutOffEvents(oldItems, overflow);
13227
+ eventCount -= overflow;
13228
+ }
13229
+ return new Branch(oldItems.append(newItems), eventCount);
13230
+ }
13231
+ remapping(from2, to) {
13232
+ let maps = new Mapping();
13233
+ this.items.forEach((item, i) => {
13234
+ let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from2 ? maps.maps.length - item.mirrorOffset : void 0;
13235
+ maps.appendMap(item.map, mirrorPos);
13236
+ }, from2, to);
13237
+ return maps;
13238
+ }
13239
+ addMaps(array) {
13240
+ if (this.eventCount == 0)
13241
+ return this;
13242
+ return new Branch(this.items.append(array.map((map2) => new Item(map2))), this.eventCount);
13243
+ }
13244
+ rebased(rebasedTransform, rebasedCount) {
13245
+ if (!this.eventCount)
13246
+ return this;
13247
+ let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount);
13248
+ let mapping = rebasedTransform.mapping;
13249
+ let newUntil = rebasedTransform.steps.length;
13250
+ let eventCount = this.eventCount;
13251
+ this.items.forEach((item) => {
13252
+ if (item.selection)
13253
+ eventCount--;
13254
+ }, start);
13255
+ let iRebased = rebasedCount;
13256
+ this.items.forEach((item) => {
13257
+ let pos = mapping.getMirror(--iRebased);
13258
+ if (pos == null)
13259
+ return;
13260
+ newUntil = Math.min(newUntil, pos);
13261
+ let map2 = mapping.maps[pos];
13262
+ if (item.step) {
13263
+ let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
13264
+ let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
13265
+ if (selection)
13266
+ eventCount++;
13267
+ rebasedItems.push(new Item(map2, step, selection));
13268
+ } else {
13269
+ rebasedItems.push(new Item(map2));
13270
+ }
13271
+ }, start);
13272
+ let newMaps = [];
13273
+ for (let i = rebasedCount; i < newUntil; i++)
13274
+ newMaps.push(new Item(mapping.maps[i]));
13275
+ let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
13276
+ let branch = new Branch(items, eventCount);
13277
+ if (branch.emptyItemCount() > max_empty_items)
13278
+ branch = branch.compress(this.items.length - rebasedItems.length);
13279
+ return branch;
13280
+ }
13281
+ emptyItemCount() {
13282
+ let count = 0;
13283
+ this.items.forEach((item) => {
13284
+ if (!item.step)
13285
+ count++;
13286
+ });
13287
+ return count;
13288
+ }
13289
+ compress(upto = this.items.length) {
13290
+ let remap = this.remapping(0, upto), mapFrom = remap.maps.length;
13291
+ let items = [], events2 = 0;
13292
+ this.items.forEach((item, i) => {
13293
+ if (i >= upto) {
13294
+ items.push(item);
13295
+ if (item.selection)
13296
+ events2++;
13297
+ } else if (item.step) {
13298
+ let step = item.step.map(remap.slice(mapFrom)), map2 = step && step.getMap();
13299
+ mapFrom--;
13300
+ if (map2)
13301
+ remap.appendMap(map2, mapFrom);
13302
+ if (step) {
13303
+ let selection = item.selection && item.selection.map(remap.slice(mapFrom));
13304
+ if (selection)
13305
+ events2++;
13306
+ let newItem = new Item(map2.invert(), step, selection), merged, last = items.length - 1;
13307
+ if (merged = items.length && items[last].merge(newItem))
13308
+ items[last] = merged;
13309
+ else
13310
+ items.push(newItem);
13311
+ }
13312
+ } else if (item.map) {
13313
+ mapFrom--;
13314
+ }
13315
+ }, this.items.length, 0);
13316
+ return new Branch(ropeSequence.from(items.reverse()), events2);
13317
+ }
13318
+ }
13319
+ Branch.empty = new Branch(ropeSequence.empty, 0);
13320
+ function cutOffEvents(items, n) {
13321
+ let cutPoint;
13322
+ items.forEach((item, i) => {
13323
+ if (item.selection && n-- == 0) {
13324
+ cutPoint = i;
13325
+ return false;
13326
+ }
13327
+ });
13328
+ return items.slice(cutPoint);
13329
+ }
13330
+ class Item {
13331
+ constructor(map2, step, selection, mirrorOffset) {
13332
+ this.map = map2;
13333
+ this.step = step;
13334
+ this.selection = selection;
13335
+ this.mirrorOffset = mirrorOffset;
13336
+ }
13337
+ merge(other) {
13338
+ if (this.step && other.step && !other.selection) {
13339
+ let step = other.step.merge(this.step);
13340
+ if (step)
13341
+ return new Item(step.getMap().invert(), step, this.selection);
13342
+ }
13343
+ }
13344
+ }
13345
+ class HistoryState {
13346
+ constructor(done, undone, prevRanges, prevTime) {
13347
+ this.done = done;
13348
+ this.undone = undone;
13349
+ this.prevRanges = prevRanges;
13350
+ this.prevTime = prevTime;
13351
+ }
13352
+ }
13353
+ const DEPTH_OVERFLOW = 20;
13354
+ function applyTransaction(history2, state, tr, options) {
13355
+ let historyTr = tr.getMeta(historyKey), rebased;
13356
+ if (historyTr)
13357
+ return historyTr.historyState;
13358
+ if (tr.getMeta(closeHistoryKey))
13359
+ history2 = new HistoryState(history2.done, history2.undone, null, 0);
13360
+ let appended = tr.getMeta("appendedTransaction");
13361
+ if (tr.steps.length == 0) {
13362
+ return history2;
13363
+ } else if (appended && appended.getMeta(historyKey)) {
13364
+ if (appended.getMeta(historyKey).redo)
13365
+ return new HistoryState(history2.done.addTransform(tr, void 0, options, mustPreserveItems(state)), history2.undone, rangesFor(tr.mapping.maps[tr.steps.length - 1]), history2.prevTime);
13366
+ else
13367
+ return new HistoryState(history2.done, history2.undone.addTransform(tr, void 0, options, mustPreserveItems(state)), null, history2.prevTime);
13368
+ } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
13369
+ let newGroup = history2.prevTime == 0 || !appended && (history2.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history2.prevRanges));
13370
+ let prevRanges = appended ? mapRanges(history2.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps[tr.steps.length - 1]);
13371
+ return new HistoryState(history2.done.addTransform(tr, newGroup ? state.selection.getBookmark() : void 0, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time);
13372
+ } else if (rebased = tr.getMeta("rebased")) {
13373
+ return new HistoryState(history2.done.rebased(tr, rebased), history2.undone.rebased(tr, rebased), mapRanges(history2.prevRanges, tr.mapping), history2.prevTime);
13374
+ } else {
13375
+ return new HistoryState(history2.done.addMaps(tr.mapping.maps), history2.undone.addMaps(tr.mapping.maps), mapRanges(history2.prevRanges, tr.mapping), history2.prevTime);
13376
+ }
13377
+ }
13378
+ function isAdjacentTo(transform, prevRanges) {
13379
+ if (!prevRanges)
13380
+ return false;
13381
+ if (!transform.docChanged)
13382
+ return true;
13383
+ let adjacent = false;
13384
+ transform.mapping.maps[0].forEach((start, end) => {
13385
+ for (let i = 0; i < prevRanges.length; i += 2)
13386
+ if (start <= prevRanges[i + 1] && end >= prevRanges[i])
13387
+ adjacent = true;
13388
+ });
13389
+ return adjacent;
13390
+ }
13391
+ function rangesFor(map2) {
13392
+ let result = [];
13393
+ map2.forEach((_from, _to, from2, to) => result.push(from2, to));
13394
+ return result;
13395
+ }
13396
+ function mapRanges(ranges, mapping) {
13397
+ if (!ranges)
13398
+ return null;
13399
+ let result = [];
13400
+ for (let i = 0; i < ranges.length; i += 2) {
13401
+ let from2 = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);
13402
+ if (from2 <= to)
13403
+ result.push(from2, to);
13404
+ }
13405
+ return result;
13406
+ }
13407
+ function histTransaction(history2, state, dispatch, redo2) {
13408
+ let preserveItems = mustPreserveItems(state);
13409
+ let histOptions = historyKey.get(state).spec.config;
13410
+ let pop = (redo2 ? history2.undone : history2.done).popEvent(state, preserveItems);
13411
+ if (!pop)
13412
+ return;
13413
+ let selection = pop.selection.resolve(pop.transform.doc);
13414
+ let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
13415
+ let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0);
13416
+ dispatch(pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist }).scrollIntoView());
13417
+ }
13418
+ let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
13419
+ function mustPreserveItems(state) {
13420
+ let plugins = state.plugins;
13421
+ if (cachedPreserveItemsPlugins != plugins) {
13422
+ cachedPreserveItems = false;
13423
+ cachedPreserveItemsPlugins = plugins;
13424
+ for (let i = 0; i < plugins.length; i++)
13425
+ if (plugins[i].spec.historyPreserveItems) {
13426
+ cachedPreserveItems = true;
13427
+ break;
13428
+ }
13429
+ }
13430
+ return cachedPreserveItems;
13431
+ }
13432
+ const historyKey = new PluginKey("history");
13433
+ const closeHistoryKey = new PluginKey("closeHistory");
13434
+ function history(config = {}) {
13435
+ config = {
13436
+ depth: config.depth || 100,
13437
+ newGroupDelay: config.newGroupDelay || 500
13438
+ };
13439
+ return new Plugin({
13440
+ key: historyKey,
13441
+ state: {
13442
+ init() {
13443
+ return new HistoryState(Branch.empty, Branch.empty, null, 0);
13444
+ },
13445
+ apply(tr, hist, state) {
13446
+ return applyTransaction(hist, state, tr, config);
13447
+ }
13448
+ },
13449
+ config,
13450
+ props: {
13451
+ handleDOMEvents: {
13452
+ beforeinput(view, e) {
13453
+ let inputType = e.inputType;
13454
+ let command2 = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
13455
+ if (!command2)
13456
+ return false;
13457
+ e.preventDefault();
13458
+ return command2(view.state, view.dispatch);
12975
13459
  }
12976
- }),
12977
- getFont: createCommand(({ commands: commands2 }) => {
12978
- const defaultPreset = unref(this.options.defaultPreset);
12979
- const defaultFont = commands2.findFontByName(defaultPreset.common.font_family);
12980
- const fontFamily = commands2.getFontFamily();
12981
- return computed(() => commands2.findFontByName(unref(fontFamily)) || defaultFont);
12982
- }),
12983
- findFontByName: createCommand((_, name) => {
12984
- return this.options.fonts.find((font) => font.name === name);
12985
- }),
12986
- getFontFamily: createCommand(({ commands: commands2 }) => {
12987
- return commands2.getCommonSettingMark(this.name, commands2.getDefaultFontFamily());
12988
- }),
12989
- getDefaultFontFamily: createCommand(({ commands: commands2 }) => {
12990
- const preset = commands2.getPreset();
12991
- return computed(() => unref(preset).common.font_family);
12992
- })
13460
+ }
13461
+ }
13462
+ });
13463
+ }
13464
+ const undo = (state, dispatch) => {
13465
+ let hist = historyKey.getState(state);
13466
+ if (!hist || hist.done.eventCount == 0)
13467
+ return false;
13468
+ if (dispatch)
13469
+ histTransaction(hist, state, dispatch, false);
13470
+ return true;
13471
+ };
13472
+ const redo = (state, dispatch) => {
13473
+ let hist = historyKey.getState(state);
13474
+ if (!hist || hist.undone.eventCount == 0)
13475
+ return false;
13476
+ if (dispatch)
13477
+ histTransaction(hist, state, dispatch, true);
13478
+ return true;
13479
+ };
13480
+ const History = Extension.create({
13481
+ name: "history",
13482
+ addOptions() {
13483
+ return {
13484
+ depth: 100,
13485
+ newGroupDelay: 500
12993
13486
  };
12994
13487
  },
12995
- parseHTML() {
12996
- const getAttrs = (input) => ({ value: input.replace(/["']/g, "") });
12997
- return [
12998
- {
12999
- style: "--zw-font-family",
13000
- getAttrs
13488
+ addCommands() {
13489
+ return {
13490
+ undo: () => ({ state, dispatch }) => {
13491
+ return undo(state, dispatch);
13001
13492
  },
13002
- {
13003
- style: "font-family",
13004
- getAttrs
13493
+ redo: () => ({ state, dispatch }) => {
13494
+ return redo(state, dispatch);
13005
13495
  }
13496
+ };
13497
+ },
13498
+ addProseMirrorPlugins() {
13499
+ return [
13500
+ history(this.options)
13006
13501
  ];
13007
13502
  },
13008
- renderHTML({ HTMLAttributes: attrs }) {
13009
- const font_family = attrs.value ? `"${attrs.value}"` : null;
13010
- return renderMark({ font_family });
13503
+ addKeyboardShortcuts() {
13504
+ return {
13505
+ "Mod-z": () => this.editor.commands.undo(),
13506
+ "Mod-y": () => this.editor.commands.redo(),
13507
+ "Shift-Mod-z": () => this.editor.commands.redo(),
13508
+ "Mod-\u044F": () => this.editor.commands.undo(),
13509
+ "Shift-Mod-\u044F": () => this.editor.commands.redo()
13510
+ };
13011
13511
  }
13012
13512
  });
13013
- function makePresetClass(base2, preset) {
13014
- const baseClass = base2.split(" ").map((part) => `.${part}`).join("");
13015
- return baseClass + preset.id;
13513
+ class RemoveNodeMarkStep extends Step {
13514
+ static fromJSON(schema, json) {
13515
+ if (typeof json.pos != "number") {
13516
+ throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
13517
+ }
13518
+ return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
13519
+ }
13520
+ constructor(pos, mark) {
13521
+ super();
13522
+ this.pos = pos;
13523
+ this.mark = mark;
13524
+ }
13525
+ apply(doc2) {
13526
+ const node = doc2.nodeAt(this.pos);
13527
+ if (!node)
13528
+ return StepResult.fail("No node at mark step's position");
13529
+ const updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
13530
+ const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13531
+ return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13532
+ }
13533
+ invert(doc2) {
13534
+ const node = doc2.nodeAt(this.pos);
13535
+ if (!node || !this.mark.isInSet(node.marks))
13536
+ return this;
13537
+ return new AddNodeMarkStep(this.pos, this.mark);
13538
+ }
13539
+ map(mapping) {
13540
+ const pos = mapping.mapResult(this.pos, 1);
13541
+ return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
13542
+ }
13543
+ toJSON() {
13544
+ return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
13545
+ }
13016
13546
  }
13017
- const StylePreset = Extension.create({
13018
- name: TextSettings.STYLE_PRESET,
13019
- addStorage: () => ({
13020
- presetStyleEl: null
13021
- }),
13022
- addGlobalAttributes() {
13023
- return [
13024
- {
13025
- types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
13026
- attributes: {
13027
- preset: {
13028
- isRequired: false,
13029
- default: { id: this.options.defaultId },
13030
- parseHTML: (element) => {
13031
- const presets = unref(this.options.presets);
13032
- if (element.parentElement.tagName === "LI")
13033
- return null;
13034
- for (const { id: id2, node, fallbackClass } of presets) {
13035
- const isFallback = fallbackClass && element.classList.contains(fallbackClass);
13036
- if (isFallback)
13037
- return { id: id2 };
13038
- const className = makePresetClass(this.options.baseClass, { id: id2 });
13039
- if (element.matches(className))
13040
- return { id: id2 };
13041
- if (element.tagName === `H${node == null ? void 0 : node.level}`)
13042
- return { id: id2 };
13043
- }
13044
- return element.tagName === "P" ? { id: this.options.defaultId } : null;
13045
- },
13046
- renderHTML: (attrs) => {
13047
- if (!attrs.preset)
13048
- return null;
13049
- return { class: this.options.baseClass + attrs.preset.id };
13050
- }
13547
+ Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
13548
+ class AddNodeMarkStep extends Step {
13549
+ static fromJSON(schema, json) {
13550
+ if (typeof json.pos != "number") {
13551
+ throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
13552
+ }
13553
+ return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
13554
+ }
13555
+ constructor(pos, mark) {
13556
+ super();
13557
+ this.pos = pos;
13558
+ this.mark = mark;
13559
+ }
13560
+ apply(doc2) {
13561
+ const node = doc2.nodeAt(this.pos);
13562
+ if (!node)
13563
+ return StepResult.fail("No node at mark step's position");
13564
+ const updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
13565
+ const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13566
+ return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13567
+ }
13568
+ invert(doc2) {
13569
+ const node = doc2.nodeAt(this.pos);
13570
+ if (node) {
13571
+ const newSet = this.mark.addToSet(node.marks);
13572
+ if (newSet.length === node.marks.length) {
13573
+ for (const mark of node.marks) {
13574
+ if (!mark.isInSet(newSet)) {
13575
+ return new AddNodeMarkStep(this.pos, mark);
13051
13576
  }
13052
13577
  }
13578
+ return new AddNodeMarkStep(this.pos, this.mark);
13053
13579
  }
13054
- ];
13055
- },
13056
- addCommands() {
13057
- function findPresetById(presets, id2) {
13058
- return presets.find((preset) => id2 === preset.id);
13059
13580
  }
13060
- function mergeSettings(source, target) {
13061
- const settings = {};
13062
- for (const name of Object.keys(source)) {
13063
- const sourceValue = source[name];
13064
- const targetValue = target[name];
13065
- const isInherit = !targetValue || targetValue.toLowerCase() === "inherit";
13066
- settings[name] = isInherit ? sourceValue : targetValue;
13067
- }
13068
- return settings;
13581
+ return new RemoveNodeMarkStep(this.pos, this.mark);
13582
+ }
13583
+ map(mapping) {
13584
+ const pos = mapping.mapResult(this.pos, 1);
13585
+ return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
13586
+ }
13587
+ toJSON() {
13588
+ return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
13589
+ }
13590
+ }
13591
+ Step.jsonID("addNodeMark", AddNodeMarkStep);
13592
+ class AttrStep extends Step {
13593
+ static fromJSON(schema, json) {
13594
+ if (typeof json.pos != "number" || typeof json.attr != "string") {
13595
+ throw new RangeError("Invalid input for AttrStep.fromJSON");
13069
13596
  }
13597
+ return new AttrStep(json.pos, json.attr, json.value);
13598
+ }
13599
+ constructor(pos, attr, value) {
13600
+ super();
13601
+ this.pos = pos;
13602
+ this.attr = attr;
13603
+ this.value = value;
13604
+ }
13605
+ apply(doc2) {
13606
+ const node = doc2.nodeAt(this.pos);
13607
+ if (!node)
13608
+ return StepResult.fail("No node at attribute step's position");
13609
+ const attrs = /* @__PURE__ */ Object.create(null);
13610
+ for (let name in node.attrs)
13611
+ attrs[name] = node.attrs[name];
13612
+ attrs[this.attr] = this.value;
13613
+ const updated = node.type.create(attrs, null, node.marks);
13614
+ const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13615
+ return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13616
+ }
13617
+ getMap() {
13618
+ return StepMap.empty;
13619
+ }
13620
+ invert(doc2) {
13621
+ return new AttrStep(this.pos, this.attr, doc2.nodeAt(this.pos).attrs[this.attr]);
13622
+ }
13623
+ map(mapping) {
13624
+ let pos = mapping.mapResult(this.pos, 1);
13625
+ return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
13626
+ }
13627
+ toJSON() {
13628
+ return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
13629
+ }
13630
+ }
13631
+ Step.jsonID("attr", AttrStep);
13632
+ const NodeProcessor = Extension.create({
13633
+ name: "node_processor",
13634
+ addCommands() {
13070
13635
  return {
13071
- getPresetList: createCommand(() => computed(() => {
13072
- return this.options.presets.filter((preset) => !preset.hidden);
13073
- })),
13074
- getPreset: createCommand(({ commands: commands2 }) => {
13075
- const selectionRef = commands2.getBlockAttributes("preset", { id: this.options.defaultId });
13076
- const presetsRef = commands2.getPresetList();
13077
- const isLinkRef = commands2.isLink();
13078
- const linkPresetRef = commands2.getLinkPreset();
13079
- return computed(() => {
13080
- const preset = findPresetById(unref(presetsRef), unref(selectionRef).id);
13081
- if (!unref(isLinkRef))
13082
- return preset;
13083
- const linkPreset = unref(linkPresetRef);
13084
- return {
13085
- id: preset.id,
13086
- common: mergeSettings(preset.common, linkPreset.common),
13087
- mobile: mergeSettings(preset.mobile, linkPreset.mobile),
13088
- tablet: mergeSettings(preset.tablet, linkPreset.tablet),
13089
- desktop: mergeSettings(preset.desktop, linkPreset.desktop)
13090
- };
13636
+ setBlockAttributes: createCommand(({ commands: commands2, state }, name, attrs, defaults2 = {}) => {
13637
+ var _a;
13638
+ const current = (_a = unref(commands2.getBlockAttributes(name))) != null ? _a : {};
13639
+ const { doc: doc2, tr } = state;
13640
+ const { from: from2, to } = tr.selection;
13641
+ doc2.nodesBetween(from2, to, (node, position) => {
13642
+ if (!NodeTypes.blocks.includes(node.type.name))
13643
+ return;
13644
+ tr.step(new AttrStep(position, name, { ...defaults2, ...current, ...attrs }));
13091
13645
  });
13092
13646
  }),
13093
- applyPreset: createCommand(({ commands: commands2, chain }, presetId) => {
13094
- var _a, _b;
13095
- const presets = unref(commands2.getPresetList());
13096
- const preset = findPresetById(presets, presetId);
13097
- const nodeType = (_b = (_a = preset.node) == null ? void 0 : _a.type) != null ? _b : NodeTypes.PARAGRAPH;
13098
- const attrs = {
13099
- preset: { id: presetId }
13100
- };
13101
- if (preset.node) {
13102
- attrs.level = preset.node.level;
13647
+ getBlockAttributes: createCommand(({ editor }, name, defaults2) => computed(() => {
13648
+ var _a;
13649
+ let attrs = Object.assign({}, defaults2 || {});
13650
+ for (const type of NodeTypes.blocks) {
13651
+ Object.assign(attrs, ((_a = editor.getAttributes(type)) == null ? void 0 : _a[name]) || {});
13103
13652
  }
13104
- for (const textAttribute of TextSettings.attributes) {
13105
- attrs[textAttribute] = unref(commands2.getBlockAttributes(textAttribute));
13653
+ return Object.keys(attrs).length ? attrs : null;
13654
+ })),
13655
+ removeBlockAttributes: createCommand(({ commands: commands2 }, names) => {
13656
+ for (const type of NodeTypes.blocks) {
13657
+ commands2.resetAttributes(type, names);
13106
13658
  }
13107
- chain().removeList().setNode(nodeType, attrs).run();
13108
13659
  }),
13109
- applyDefaultPreset: createCommand(({ commands: commands2 }) => {
13110
- commands2.applyPreset(this.options.defaultId);
13660
+ applyMark: createCommand(({ state, commands: commands2 }, name, value, customizer = {}) => {
13661
+ const { tr, doc: doc2, schema } = state;
13662
+ const { $from, $to } = tr.selection;
13663
+ const linkMarkType = getMarkType(TextSettings.LINK, schema);
13664
+ const markType = getMarkType(name, schema);
13665
+ const markGroup = markType.spec.group || "";
13666
+ if (!markGroup.includes(MarkGroups.SETTINGS)) {
13667
+ return commands2.setMark(name, value);
13668
+ }
13669
+ if ($from.pos === $to.pos)
13670
+ return;
13671
+ const onAppliedToParent = (context) => {
13672
+ if (!customizer.onAppliedToParent || customizer.onAppliedToParent(context) === false) {
13673
+ const { tr: tr2, node, position, mark } = context;
13674
+ commands2._removeNodeMark({ tr: tr2, node, position, mark: mark.type });
13675
+ }
13676
+ };
13677
+ doc2.nodesBetween($from.pos, $to.pos, (node, position) => {
13678
+ if (node.type.name === NodeTypes.LIST)
13679
+ return;
13680
+ const initialMark = findMarkByType(node.marks, name);
13681
+ const applyingMark = markType.create({ ...(initialMark == null ? void 0 : initialMark.attrs) || {}, ...value });
13682
+ const textPosition = resolveTextPosition($from, $to, node, position);
13683
+ const isAppliedToParent = !linkMarkType.isInSet(node.marks) && isMarkAppliedToParent(tr.doc, position, applyingMark, customizer.isAppliedToParent);
13684
+ if (isAppliedToParent) {
13685
+ return onAppliedToParent({ tr, node, position, mark: applyingMark });
13686
+ }
13687
+ if (node.isText) {
13688
+ tr.addMark(textPosition.from, textPosition.to, applyingMark);
13689
+ return;
13690
+ }
13691
+ if (isNodeFullySelected(tr.doc, tr.selection, node, position)) {
13692
+ tr.step(new AddNodeMarkStep(position, applyingMark));
13693
+ }
13694
+ });
13111
13695
  }),
13112
- removePreset: createCommand(({ commands: commands2 }) => {
13113
- commands2.setNode(NodeTypes.PARAGRAPH, { preset: null });
13696
+ getMarks: createCommand(({ editor }, name) => {
13697
+ const stateRef = toRef(editor, "state");
13698
+ return computed(() => {
13699
+ const { selection, doc: doc2 } = unref(stateRef);
13700
+ const { from: from2, to } = unref(selection);
13701
+ const marks = [];
13702
+ doc2.nodesBetween(from2, to, (node) => {
13703
+ for (const mark of node.marks) {
13704
+ if (mark.type.name === name)
13705
+ marks.unshift(mark.attrs);
13706
+ }
13707
+ });
13708
+ return marks;
13709
+ });
13114
13710
  }),
13115
- getPresetCustomization: createCommand(({ editor, commands: commands2 }) => {
13116
- const state = toRef(editor, "state");
13711
+ getMark: createCommand(({ commands: commands2 }, name) => {
13712
+ const marksRef = commands2.getMarks(name);
13117
13713
  return computed(() => {
13118
- const { selection, doc: doc2 } = unref(state);
13119
- const { from: from2, to } = selection;
13120
- return commands2._getSettingCustomization(doc2, from2, to);
13714
+ var _a;
13715
+ return (_a = unref(marksRef)[0]) != null ? _a : null;
13121
13716
  });
13122
13717
  }),
13123
- isSettingCustomized: createCommand(({ commands: commands2 }, name) => {
13124
- const customization = commands2.getPresetCustomization();
13125
- const group = TextSettings.attributes.includes(name) ? "attributes" : "marks";
13718
+ hasMark: createCommand(({ commands: commands2 }, name) => {
13719
+ const mark = commands2.getMark(name);
13720
+ return computed(() => !!unref(mark));
13721
+ }),
13722
+ getCommonSettingMark: createCommand(({ commands: commands2 }, name, defaultRef) => {
13723
+ const selectionRef = commands2.getMark(name);
13126
13724
  return computed(() => {
13127
13725
  var _a, _b;
13128
- return (_b = (_a = unref(customization)[group]) == null ? void 0 : _a.includes(name)) != null ? _b : false;
13726
+ return (_b = (_a = unref(selectionRef)) == null ? void 0 : _a.value) != null ? _b : unref(defaultRef);
13129
13727
  });
13130
13728
  }),
13131
- getContentCustomization: createCommand(({ editor, commands: commands2 }) => {
13132
- const state = toRef(editor, "state");
13729
+ getDeviceSettingMark: createCommand(({ commands: commands2 }, name, defaultRef) => {
13730
+ const selectionRef = commands2.getMarks(name);
13731
+ const deviceRef = commands2.getDevice();
13133
13732
  return computed(() => {
13134
- const { doc: doc2 } = unref(state);
13135
- return commands2._getSettingCustomization(doc2, 0, doc2.content.size);
13733
+ for (const attrs of unref(selectionRef)) {
13734
+ const value = attrs[unref(deviceRef)];
13735
+ if (value)
13736
+ return value;
13737
+ }
13738
+ return unref(defaultRef);
13136
13739
  });
13137
13740
  }),
13138
- _getSettingCustomization: createCommand((_, doc2, from2, to) => {
13139
- const marks = /* @__PURE__ */ new Set();
13140
- const attributes = /* @__PURE__ */ new Set();
13141
- doc2.nodesBetween(from2, to, (node) => {
13142
- for (const [name, value] of Object.entries(node.attrs)) {
13143
- const isSetting = TextSettings.attributes.includes(name);
13144
- if (isSetting && value)
13145
- attributes.add(name);
13741
+ removeAllMarks: createCommand(({ state, commands: commands2 }) => {
13742
+ const { tr, doc: doc2 } = state;
13743
+ const { from: from2, to } = tr.selection;
13744
+ doc2.nodesBetween(from2, to, (node, position) => {
13745
+ for (const mark of node.marks) {
13746
+ commands2._removeNodeMark({ tr, node, position, mark });
13146
13747
  }
13147
- for (const { type } of node.marks) {
13148
- if (TextSettings.marks.includes(type.name)) {
13149
- marks.add(type.name);
13150
- }
13748
+ });
13749
+ }),
13750
+ removeMarks: createCommand(({ state, commands: commands2 }, marks) => {
13751
+ const { tr, doc: doc2 } = state;
13752
+ const { from: from2, to } = tr.selection;
13753
+ doc2.nodesBetween(from2, to, (node, position) => {
13754
+ const removingMarks = node.marks.filter((mark) => marks.includes(mark.type.name));
13755
+ for (const mark of removingMarks) {
13756
+ commands2._removeNodeMark({ tr, node, position, mark });
13151
13757
  }
13152
13758
  });
13153
- return {
13154
- attributes: Array.from(attributes),
13155
- marks: Array.from(marks)
13156
- };
13157
13759
  }),
13158
- removePresetCustomization: createCommand(({ chain }) => {
13159
- chain().storeSelection().expandSelectionToBlock().removeMarks(TextSettings.marks).resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes).resetAttributes(NodeTypes.HEADING, TextSettings.attributes).restoreSelection().run();
13760
+ _removeNodeMark: createCommand((context, { tr, node, position, mark }) => {
13761
+ return node.isText ? tr.removeMark(position, position + node.nodeSize, mark) : tr.step(new RemoveNodeMarkStep(position, mark));
13762
+ })
13763
+ };
13764
+ }
13765
+ });
13766
+ const TextProcessor = Extension.create({
13767
+ name: "text_processor",
13768
+ addCommands() {
13769
+ return {
13770
+ getSelectedText: createCommand(({ state }) => {
13771
+ const { from: from2, to } = state.selection;
13772
+ return state.doc.textBetween(from2, to, " ");
13160
13773
  }),
13161
- removeFormat: createCommand(({ chain }) => {
13162
- chain().storeSelection().expandSelectionToBlock().removeAllMarks().applyDefaultPreset().restoreSelection().run();
13774
+ transformText: createCommand(({ state }, transform) => {
13775
+ const { $from, $to } = state.tr.selection;
13776
+ if ($from.pos === $to.pos)
13777
+ return;
13778
+ state.doc.nodesBetween($from.pos, $to.pos, (node, position) => {
13779
+ if (!node.isText)
13780
+ return;
13781
+ const textPosition = resolveTextPosition($from, $to, node, position);
13782
+ const substringFrom = Math.max(0, $from.pos - position);
13783
+ const substringTo = Math.max(0, $to.pos - position);
13784
+ const updatedText = transform({
13785
+ text: node.textContent.substring(substringFrom, substringTo)
13786
+ });
13787
+ const updatedNode = state.schema.text(updatedText, node.marks);
13788
+ state.tr.replaceWith(textPosition.from, textPosition.to, updatedNode);
13789
+ });
13163
13790
  })
13164
13791
  };
13165
- },
13166
- onCreate() {
13167
- const existingStyleEl = ContextWindow.document.querySelector("[data-zw-styles]");
13168
- if (existingStyleEl) {
13169
- this.storage.presetStyleEl = existingStyleEl;
13170
- return;
13171
- }
13172
- this.storage.presetStyleEl = ContextWindow.document.createElement("style");
13173
- this.storage.presetStyleEl.dataset.zwStyles = "";
13174
- for (const preset of this.options.presets) {
13175
- const className = makePresetClass(this.options.baseClass, preset);
13176
- const css = [` ${className} {`];
13177
- for (const device of Devices.values) {
13178
- for (const setting of Object.keys(preset[device])) {
13179
- const variable = this.options.makeVariable({ device, preset, property: setting });
13180
- const property = setting.replace(/_/i, "-");
13181
- const prefix = device === Devices.COMMON ? "preset" : `preset-${device}`;
13182
- css.push(`--zw-${prefix}-${property}: var(${variable}, inherit);`);
13183
- }
13184
- }
13185
- css.push("}");
13186
- this.storage.presetStyleEl.innerHTML += css.join(" ");
13187
- }
13188
- ContextWindow.head.append(this.storage.presetStyleEl);
13189
13792
  }
13190
13793
  });
13191
- const FontWeight = Mark.create({
13192
- name: TextSettings.FONT_WEIGHT,
13193
- group: MarkGroups.SETTINGS,
13194
- addAttributes: () => ({
13195
- value: { required: true }
13794
+ const SelectionProcessor = Extension.create({
13795
+ name: "selection_processor",
13796
+ addStorage: () => ({
13797
+ selection: null
13196
13798
  }),
13197
13799
  addCommands() {
13198
13800
  return {
13199
- applyFontWeight: createCommand(({ commands: commands2 }, value) => {
13200
- commands2.applyMark(this.name, { value });
13201
- const font = unref(commands2.getFont());
13202
- if (!font.isItalicSupported(value)) {
13203
- commands2.removeItalic();
13204
- }
13801
+ storeSelection: createCommand(({ state }) => {
13802
+ this.storage.selection = state.selection;
13205
13803
  }),
13206
- toggleBold: createCommand(({ commands: commands2 }) => {
13207
- const currentWeight = unref(commands2.getFontWeight());
13208
- const currentFont = unref(commands2.getFont());
13209
- const isBold = Number(currentWeight) >= 600;
13210
- const wantedWeight = isBold ? "400" : "700";
13211
- const nextWeight = currentFont.findClosestWeight(wantedWeight);
13212
- commands2.applyFontWeight(nextWeight);
13804
+ restoreSelection: createCommand(({ commands: commands2 }) => {
13805
+ this.storage.selection && commands2.setTextSelection(this.storage.selection);
13213
13806
  }),
13214
- getFontWeight: createCommand(({ commands: commands2 }) => {
13215
- const selectionRef = commands2.getCommonSettingMark(this.name, commands2.getDefaultFontWeight());
13216
- const fontRef = commands2.getFont();
13217
- return computed(() => {
13218
- const weight = unref(selectionRef);
13219
- const font = unref(fontRef);
13220
- return font.isWeightSupported(weight) ? weight : font.findClosestWeight(weight);
13807
+ expandSelection: createCommand(({ tr, commands: commands2 }, predicate) => {
13808
+ let from2 = tr.selection.from;
13809
+ let to = tr.selection.to;
13810
+ tr.doc.nodesBetween(from2, to, (node, position, parent) => {
13811
+ if (predicate({ node, parent })) {
13812
+ const offset2 = node.isText ? 0 : resolvePositionOffset(tr.doc, position);
13813
+ from2 = Math.min(from2, position + offset2);
13814
+ to = Math.max(to, position + node.nodeSize - offset2);
13815
+ }
13221
13816
  });
13817
+ commands2.setTextSelection({ from: from2, to });
13222
13818
  }),
13223
- getDefaultFontWeight: createCommand(({ commands: commands2 }) => {
13224
- const preset = commands2.getPreset();
13225
- return computed(() => unref(preset).common.font_weight);
13819
+ expandSelectionToBlock: createCommand(({ commands: commands2 }) => {
13820
+ commands2.expandSelection(({ parent }) => parent.type.name === NodeTypes.DOCUMENT);
13226
13821
  })
13227
13822
  };
13228
- },
13229
- addKeyboardShortcuts: () => ({
13230
- "Mod-b": createKeyboardShortcut("toggleBold"),
13231
- "Mod-B": createKeyboardShortcut("toggleBold")
13232
- }),
13233
- parseHTML() {
13234
- const getAttrs = (value) => {
13235
- if (value === "bold")
13236
- return { value: "700" };
13237
- return Number(value) ? { value } : false;
13238
- };
13239
- return [
13240
- {
13241
- style: "--zw-font-weight",
13242
- getAttrs
13243
- },
13244
- {
13245
- style: "font-weight",
13246
- getAttrs
13247
- },
13248
- {
13249
- tag: "b",
13250
- attrs: { value: "700" }
13251
- },
13252
- {
13253
- tag: "strong",
13254
- attrs: { value: "700" }
13255
- }
13256
- ];
13257
- },
13258
- renderHTML({ HTMLAttributes: attrs }) {
13259
- return renderMark({ font_weight: attrs.value });
13260
13823
  }
13261
13824
  });
13262
- const Text$1 = Node.create({
13263
- name: "text",
13264
- group: "inline"
13825
+ const Document$1 = Node.create({
13826
+ name: "doc",
13827
+ topNode: true,
13828
+ content: "block+"
13265
13829
  });
13266
- var GOOD_LEAF_SIZE = 200;
13267
- var RopeSequence = function RopeSequence2() {
13268
- };
13269
- RopeSequence.prototype.append = function append(other) {
13270
- if (!other.length) {
13271
- return this;
13272
- }
13273
- other = RopeSequence.from(other);
13274
- return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other);
13275
- };
13276
- RopeSequence.prototype.prepend = function prepend(other) {
13277
- if (!other.length) {
13278
- return this;
13279
- }
13280
- return RopeSequence.from(other).append(this);
13281
- };
13282
- RopeSequence.prototype.appendInner = function appendInner(other) {
13283
- return new Append(this, other);
13284
- };
13285
- RopeSequence.prototype.slice = function slice(from2, to) {
13286
- if (from2 === void 0)
13287
- from2 = 0;
13288
- if (to === void 0)
13289
- to = this.length;
13290
- if (from2 >= to) {
13291
- return RopeSequence.empty;
13292
- }
13293
- return this.sliceInner(Math.max(0, from2), Math.min(this.length, to));
13294
- };
13295
- RopeSequence.prototype.get = function get(i) {
13296
- if (i < 0 || i >= this.length) {
13297
- return void 0;
13298
- }
13299
- return this.getInner(i);
13300
- };
13301
- RopeSequence.prototype.forEach = function forEach(f, from2, to) {
13302
- if (from2 === void 0)
13303
- from2 = 0;
13304
- if (to === void 0)
13305
- to = this.length;
13306
- if (from2 <= to) {
13307
- this.forEachInner(f, from2, to, 0);
13308
- } else {
13309
- this.forEachInvertedInner(f, from2, to, 0);
13310
- }
13311
- };
13312
- RopeSequence.prototype.map = function map(f, from2, to) {
13313
- if (from2 === void 0)
13314
- from2 = 0;
13315
- if (to === void 0)
13316
- to = this.length;
13317
- var result = [];
13318
- this.forEach(function(elt, i) {
13319
- return result.push(f(elt, i));
13320
- }, from2, to);
13321
- return result;
13322
- };
13323
- RopeSequence.from = function from(values2) {
13324
- if (values2 instanceof RopeSequence) {
13325
- return values2;
13326
- }
13327
- return values2 && values2.length ? new Leaf(values2) : RopeSequence.empty;
13328
- };
13329
- var Leaf = /* @__PURE__ */ function(RopeSequence3) {
13330
- function Leaf2(values2) {
13331
- RopeSequence3.call(this);
13332
- this.values = values2;
13333
- }
13334
- if (RopeSequence3)
13335
- Leaf2.__proto__ = RopeSequence3;
13336
- Leaf2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype);
13337
- Leaf2.prototype.constructor = Leaf2;
13338
- var prototypeAccessors = { length: { configurable: true }, depth: { configurable: true } };
13339
- Leaf2.prototype.flatten = function flatten() {
13340
- return this.values;
13341
- };
13342
- Leaf2.prototype.sliceInner = function sliceInner(from2, to) {
13343
- if (from2 == 0 && to == this.length) {
13344
- return this;
13345
- }
13346
- return new Leaf2(this.values.slice(from2, to));
13347
- };
13348
- Leaf2.prototype.getInner = function getInner(i) {
13349
- return this.values[i];
13350
- };
13351
- Leaf2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
13352
- for (var i = from2; i < to; i++) {
13353
- if (f(this.values[i], start + i) === false) {
13354
- return false;
13355
- }
13356
- }
13357
- };
13358
- Leaf2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
13359
- for (var i = from2 - 1; i >= to; i--) {
13360
- if (f(this.values[i], start + i) === false) {
13361
- return false;
13362
- }
13363
- }
13364
- };
13365
- Leaf2.prototype.leafAppend = function leafAppend(other) {
13366
- if (this.length + other.length <= GOOD_LEAF_SIZE) {
13367
- return new Leaf2(this.values.concat(other.flatten()));
13368
- }
13369
- };
13370
- Leaf2.prototype.leafPrepend = function leafPrepend(other) {
13371
- if (this.length + other.length <= GOOD_LEAF_SIZE) {
13372
- return new Leaf2(other.flatten().concat(this.values));
13373
- }
13374
- };
13375
- prototypeAccessors.length.get = function() {
13376
- return this.values.length;
13377
- };
13378
- prototypeAccessors.depth.get = function() {
13379
- return 0;
13380
- };
13381
- Object.defineProperties(Leaf2.prototype, prototypeAccessors);
13382
- return Leaf2;
13383
- }(RopeSequence);
13384
- RopeSequence.empty = new Leaf([]);
13385
- var Append = /* @__PURE__ */ function(RopeSequence3) {
13386
- function Append2(left, right) {
13387
- RopeSequence3.call(this);
13388
- this.left = left;
13389
- this.right = right;
13390
- this.length = left.length + right.length;
13391
- this.depth = Math.max(left.depth, right.depth) + 1;
13392
- }
13393
- if (RopeSequence3)
13394
- Append2.__proto__ = RopeSequence3;
13395
- Append2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype);
13396
- Append2.prototype.constructor = Append2;
13397
- Append2.prototype.flatten = function flatten() {
13398
- return this.left.flatten().concat(this.right.flatten());
13399
- };
13400
- Append2.prototype.getInner = function getInner(i) {
13401
- return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length);
13402
- };
13403
- Append2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
13404
- var leftLen = this.left.length;
13405
- if (from2 < leftLen && this.left.forEachInner(f, from2, Math.min(to, leftLen), start) === false) {
13406
- return false;
13407
- }
13408
- if (to > leftLen && this.right.forEachInner(f, Math.max(from2 - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) {
13409
- return false;
13410
- }
13411
- };
13412
- Append2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
13413
- var leftLen = this.left.length;
13414
- if (from2 > leftLen && this.right.forEachInvertedInner(f, from2 - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) {
13415
- return false;
13416
- }
13417
- if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from2, leftLen), to, start) === false) {
13418
- return false;
13419
- }
13420
- };
13421
- Append2.prototype.sliceInner = function sliceInner(from2, to) {
13422
- if (from2 == 0 && to == this.length) {
13423
- return this;
13424
- }
13425
- var leftLen = this.left.length;
13426
- if (to <= leftLen) {
13427
- return this.left.slice(from2, to);
13428
- }
13429
- if (from2 >= leftLen) {
13430
- return this.right.slice(from2 - leftLen, to - leftLen);
13431
- }
13432
- return this.left.slice(from2, leftLen).append(this.right.slice(0, to - leftLen));
13433
- };
13434
- Append2.prototype.leafAppend = function leafAppend(other) {
13435
- var inner = this.right.leafAppend(other);
13436
- if (inner) {
13437
- return new Append2(this.left, inner);
13438
- }
13439
- };
13440
- Append2.prototype.leafPrepend = function leafPrepend(other) {
13441
- var inner = this.left.leafPrepend(other);
13442
- if (inner) {
13443
- return new Append2(inner, this.right);
13444
- }
13445
- };
13446
- Append2.prototype.appendInner = function appendInner2(other) {
13447
- if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) {
13448
- return new Append2(this.left, new Append2(this.right, other));
13449
- }
13450
- return new Append2(this, other);
13451
- };
13452
- return Append2;
13453
- }(RopeSequence);
13454
- var ropeSequence = RopeSequence;
13455
- const max_empty_items = 500;
13456
- class Branch {
13457
- constructor(items, eventCount) {
13458
- this.items = items;
13459
- this.eventCount = eventCount;
13830
+ const Document = Document$1.extend({
13831
+ marks: MarkGroups.SETTINGS
13832
+ });
13833
+ const Paragraph$1 = Node.create({
13834
+ name: "paragraph",
13835
+ priority: 1e3,
13836
+ addOptions() {
13837
+ return {
13838
+ HTMLAttributes: {}
13839
+ };
13840
+ },
13841
+ group: "block",
13842
+ content: "inline*",
13843
+ parseHTML() {
13844
+ return [
13845
+ { tag: "p" }
13846
+ ];
13847
+ },
13848
+ renderHTML({ HTMLAttributes }) {
13849
+ return ["p", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
13850
+ },
13851
+ addCommands() {
13852
+ return {
13853
+ setParagraph: () => ({ commands: commands2 }) => {
13854
+ return commands2.setNode(this.name);
13855
+ }
13856
+ };
13857
+ },
13858
+ addKeyboardShortcuts() {
13859
+ return {
13860
+ "Mod-Alt-0": () => this.editor.commands.setParagraph()
13861
+ };
13460
13862
  }
13461
- popEvent(state, preserveItems) {
13462
- if (this.eventCount == 0)
13463
- return null;
13464
- let end = this.items.length;
13465
- for (; ; end--) {
13466
- let next2 = this.items.get(end - 1);
13467
- if (next2.selection) {
13468
- --end;
13469
- break;
13863
+ });
13864
+ const Paragraph = Paragraph$1.extend({
13865
+ marks: MarkGroups.ALL,
13866
+ addOptions: () => ({
13867
+ HTMLAttributes: { class: "zw-style" }
13868
+ })
13869
+ });
13870
+ const Heading$1 = Node.create({
13871
+ name: "heading",
13872
+ addOptions() {
13873
+ return {
13874
+ levels: [1, 2, 3, 4, 5, 6],
13875
+ HTMLAttributes: {}
13876
+ };
13877
+ },
13878
+ content: "inline*",
13879
+ group: "block",
13880
+ defining: true,
13881
+ addAttributes() {
13882
+ return {
13883
+ level: {
13884
+ default: 1,
13885
+ rendered: false
13470
13886
  }
13471
- }
13472
- let remap, mapFrom;
13473
- if (preserveItems) {
13474
- remap = this.remapping(end, this.items.length);
13475
- mapFrom = remap.maps.length;
13476
- }
13477
- let transform = state.tr;
13478
- let selection, remaining;
13479
- let addAfter = [], addBefore = [];
13480
- this.items.forEach((item, i) => {
13481
- if (!item.step) {
13482
- if (!remap) {
13483
- remap = this.remapping(end, i + 1);
13484
- mapFrom = remap.maps.length;
13887
+ };
13888
+ },
13889
+ parseHTML() {
13890
+ return this.options.levels.map((level) => ({
13891
+ tag: `h${level}`,
13892
+ attrs: { level }
13893
+ }));
13894
+ },
13895
+ renderHTML({ node, HTMLAttributes }) {
13896
+ const hasLevel = this.options.levels.includes(node.attrs.level);
13897
+ const level = hasLevel ? node.attrs.level : this.options.levels[0];
13898
+ return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
13899
+ },
13900
+ addCommands() {
13901
+ return {
13902
+ setHeading: (attributes) => ({ commands: commands2 }) => {
13903
+ if (!this.options.levels.includes(attributes.level)) {
13904
+ return false;
13485
13905
  }
13486
- mapFrom--;
13487
- addBefore.push(item);
13488
- return;
13489
- }
13490
- if (remap) {
13491
- addBefore.push(new Item(item.map));
13492
- let step = item.step.map(remap.slice(mapFrom)), map2;
13493
- if (step && transform.maybeStep(step).doc) {
13494
- map2 = transform.mapping.maps[transform.mapping.maps.length - 1];
13495
- addAfter.push(new Item(map2, void 0, void 0, addAfter.length + addBefore.length));
13906
+ return commands2.setNode(this.name, attributes);
13907
+ },
13908
+ toggleHeading: (attributes) => ({ commands: commands2 }) => {
13909
+ if (!this.options.levels.includes(attributes.level)) {
13910
+ return false;
13496
13911
  }
13497
- mapFrom--;
13498
- if (map2)
13499
- remap.appendMap(map2, mapFrom);
13500
- } else {
13501
- transform.maybeStep(item.step);
13502
- }
13503
- if (item.selection) {
13504
- selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
13505
- remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
13506
- return false;
13507
- }
13508
- }, this.items.length, 0);
13509
- return { remaining, transform, selection };
13510
- }
13511
- addTransform(transform, selection, histOptions, preserveItems) {
13512
- let newItems = [], eventCount = this.eventCount;
13513
- let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
13514
- for (let i = 0; i < transform.steps.length; i++) {
13515
- let step = transform.steps[i].invert(transform.docs[i]);
13516
- let item = new Item(transform.mapping.maps[i], step, selection), merged;
13517
- if (merged = lastItem && lastItem.merge(item)) {
13518
- item = merged;
13519
- if (i)
13520
- newItems.pop();
13521
- else
13522
- oldItems = oldItems.slice(0, oldItems.length - 1);
13523
- }
13524
- newItems.push(item);
13525
- if (selection) {
13526
- eventCount++;
13527
- selection = void 0;
13912
+ return commands2.toggleNode(this.name, "paragraph", attributes);
13528
13913
  }
13529
- if (!preserveItems)
13530
- lastItem = item;
13531
- }
13532
- let overflow = eventCount - histOptions.depth;
13533
- if (overflow > DEPTH_OVERFLOW) {
13534
- oldItems = cutOffEvents(oldItems, overflow);
13535
- eventCount -= overflow;
13536
- }
13537
- return new Branch(oldItems.append(newItems), eventCount);
13538
- }
13539
- remapping(from2, to) {
13540
- let maps = new Mapping();
13541
- this.items.forEach((item, i) => {
13542
- let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from2 ? maps.maps.length - item.mirrorOffset : void 0;
13543
- maps.appendMap(item.map, mirrorPos);
13544
- }, from2, to);
13545
- return maps;
13546
- }
13547
- addMaps(array) {
13548
- if (this.eventCount == 0)
13549
- return this;
13550
- return new Branch(this.items.append(array.map((map2) => new Item(map2))), this.eventCount);
13551
- }
13552
- rebased(rebasedTransform, rebasedCount) {
13553
- if (!this.eventCount)
13554
- return this;
13555
- let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount);
13556
- let mapping = rebasedTransform.mapping;
13557
- let newUntil = rebasedTransform.steps.length;
13558
- let eventCount = this.eventCount;
13559
- this.items.forEach((item) => {
13560
- if (item.selection)
13561
- eventCount--;
13562
- }, start);
13563
- let iRebased = rebasedCount;
13564
- this.items.forEach((item) => {
13565
- let pos = mapping.getMirror(--iRebased);
13566
- if (pos == null)
13567
- return;
13568
- newUntil = Math.min(newUntil, pos);
13569
- let map2 = mapping.maps[pos];
13570
- if (item.step) {
13571
- let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
13572
- let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
13573
- if (selection)
13574
- eventCount++;
13575
- rebasedItems.push(new Item(map2, step, selection));
13576
- } else {
13577
- rebasedItems.push(new Item(map2));
13914
+ };
13915
+ },
13916
+ addKeyboardShortcuts() {
13917
+ return this.options.levels.reduce((items, level) => ({
13918
+ ...items,
13919
+ ...{
13920
+ [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level })
13578
13921
  }
13579
- }, start);
13580
- let newMaps = [];
13581
- for (let i = rebasedCount; i < newUntil; i++)
13582
- newMaps.push(new Item(mapping.maps[i]));
13583
- let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
13584
- let branch = new Branch(items, eventCount);
13585
- if (branch.emptyItemCount() > max_empty_items)
13586
- branch = branch.compress(this.items.length - rebasedItems.length);
13587
- return branch;
13922
+ }), {});
13923
+ },
13924
+ addInputRules() {
13925
+ return this.options.levels.map((level) => {
13926
+ return textblockTypeInputRule({
13927
+ find: new RegExp(`^(#{1,${level}})\\s$`),
13928
+ type: this.type,
13929
+ getAttributes: {
13930
+ level
13931
+ }
13932
+ });
13933
+ });
13588
13934
  }
13589
- emptyItemCount() {
13590
- let count = 0;
13591
- this.items.forEach((item) => {
13592
- if (!item.step)
13593
- count++;
13935
+ });
13936
+ const Heading = Heading$1.extend({
13937
+ marks: MarkGroups.ALL,
13938
+ addOptions: () => ({
13939
+ levels: [1, 2, 3, 4],
13940
+ HTMLAttributes: { class: "zw-style" }
13941
+ })
13942
+ });
13943
+ class ProseMirrorPlugin {
13944
+ static create(editor, options) {
13945
+ const plugin = new this(editor, options || {});
13946
+ return new Plugin({
13947
+ key: new PluginKey(this.name),
13948
+ props: plugin.buildProps()
13594
13949
  });
13595
- return count;
13596
13950
  }
13597
- compress(upto = this.items.length) {
13598
- let remap = this.remapping(0, upto), mapFrom = remap.maps.length;
13599
- let items = [], events2 = 0;
13600
- this.items.forEach((item, i) => {
13601
- if (i >= upto) {
13602
- items.push(item);
13603
- if (item.selection)
13604
- events2++;
13605
- } else if (item.step) {
13606
- let step = item.step.map(remap.slice(mapFrom)), map2 = step && step.getMap();
13607
- mapFrom--;
13608
- if (map2)
13609
- remap.appendMap(map2, mapFrom);
13610
- if (step) {
13611
- let selection = item.selection && item.selection.map(remap.slice(mapFrom));
13612
- if (selection)
13613
- events2++;
13614
- let newItem = new Item(map2.invert(), step, selection), merged, last = items.length - 1;
13615
- if (merged = items.length && items[last].merge(newItem))
13616
- items[last] = merged;
13617
- else
13618
- items.push(newItem);
13619
- }
13620
- } else if (item.map) {
13621
- mapFrom--;
13622
- }
13623
- }, this.items.length, 0);
13624
- return new Branch(ropeSequence.from(items.reverse()), events2);
13951
+ constructor(editor, options) {
13952
+ this.options = options;
13953
+ this.editor = editor;
13954
+ }
13955
+ buildProps() {
13956
+ return {};
13625
13957
  }
13626
13958
  }
13627
- Branch.empty = new Branch(ropeSequence.empty, 0);
13628
- function cutOffEvents(items, n) {
13629
- let cutPoint;
13630
- items.forEach((item, i) => {
13631
- if (item.selection && n-- == 0) {
13632
- cutPoint = i;
13633
- return false;
13959
+ class PastePlugin extends ProseMirrorPlugin {
13960
+ buildProps() {
13961
+ return {
13962
+ transformPastedHTML: this._transformPastedHTML.bind(this),
13963
+ handlePaste: this._handlePaste.bind(this)
13964
+ };
13965
+ }
13966
+ _transformPastedHTML(html2) {
13967
+ if (html2.includes("data-pm-slice") && html2.includes("zw-style")) {
13968
+ return html2;
13634
13969
  }
13635
- });
13636
- return items.slice(cutPoint);
13637
- }
13638
- class Item {
13639
- constructor(map2, step, selection, mirrorOffset) {
13640
- this.map = map2;
13641
- this.step = step;
13642
- this.selection = selection;
13643
- this.mirrorOffset = mirrorOffset;
13970
+ const normalizer = ContentNormalizer.build(html2);
13971
+ normalizer.normalizeHTML();
13972
+ this._removeDeprecatedStyles(normalizer);
13973
+ return normalizer.normalizedHTML;
13644
13974
  }
13645
- merge(other) {
13646
- if (this.step && other.step && !other.selection) {
13647
- let step = other.step.merge(this.step);
13648
- if (step)
13649
- return new Item(step.getMap().invert(), step, this.selection);
13975
+ _removeDeprecatedStyles(normalizer) {
13976
+ const elements = normalizer.dom.querySelectorAll('[style*="margin"]');
13977
+ for (const element of Array.from(elements)) {
13978
+ element.style.removeProperty("margin");
13979
+ element.style.removeProperty("margin-top");
13980
+ element.style.removeProperty("margin-right");
13981
+ element.style.removeProperty("margin-bottom");
13982
+ element.style.removeProperty("margin-left");
13650
13983
  }
13651
13984
  }
13652
- }
13653
- class HistoryState {
13654
- constructor(done, undone, prevRanges, prevTime) {
13655
- this.done = done;
13656
- this.undone = undone;
13657
- this.prevRanges = prevRanges;
13658
- this.prevTime = prevTime;
13985
+ _handlePaste(view, _, slice2) {
13986
+ const transaction = this._insertPastedContent(view, slice2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
13987
+ view.dispatch(transaction);
13988
+ return true;
13659
13989
  }
13660
- }
13661
- const DEPTH_OVERFLOW = 20;
13662
- function applyTransaction(history2, state, tr, options) {
13663
- let historyTr = tr.getMeta(historyKey), rebased;
13664
- if (historyTr)
13665
- return historyTr.historyState;
13666
- if (tr.getMeta(closeHistoryKey))
13667
- history2 = new HistoryState(history2.done, history2.undone, null, 0);
13668
- let appended = tr.getMeta("appendedTransaction");
13669
- if (tr.steps.length == 0) {
13670
- return history2;
13671
- } else if (appended && appended.getMeta(historyKey)) {
13672
- if (appended.getMeta(historyKey).redo)
13673
- return new HistoryState(history2.done.addTransform(tr, void 0, options, mustPreserveItems(state)), history2.undone, rangesFor(tr.mapping.maps[tr.steps.length - 1]), history2.prevTime);
13674
- else
13675
- return new HistoryState(history2.done, history2.undone.addTransform(tr, void 0, options, mustPreserveItems(state)), null, history2.prevTime);
13676
- } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
13677
- let newGroup = history2.prevTime == 0 || !appended && (history2.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history2.prevRanges));
13678
- let prevRanges = appended ? mapRanges(history2.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps[tr.steps.length - 1]);
13679
- return new HistoryState(history2.done.addTransform(tr, newGroup ? state.selection.getBookmark() : void 0, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time);
13680
- } else if (rebased = tr.getMeta("rebased")) {
13681
- return new HistoryState(history2.done.rebased(tr, rebased), history2.undone.rebased(tr, rebased), mapRanges(history2.prevRanges, tr.mapping), history2.prevTime);
13682
- } else {
13683
- return new HistoryState(history2.done.addMaps(tr.mapping.maps), history2.undone.addMaps(tr.mapping.maps), mapRanges(history2.prevRanges, tr.mapping), history2.prevTime);
13990
+ _insertPastedContent({ state, input }, slice2) {
13991
+ if (!this._isFullBlockSelected(state)) {
13992
+ return state.tr.replaceSelection(slice2);
13993
+ }
13994
+ return state.tr.replaceSelectionWith(slice2.content, input.shiftKey);
13684
13995
  }
13685
- }
13686
- function isAdjacentTo(transform, prevRanges) {
13687
- if (!prevRanges)
13688
- return false;
13689
- if (!transform.docChanged)
13690
- return true;
13691
- let adjacent = false;
13692
- transform.mapping.maps[0].forEach((start, end) => {
13693
- for (let i = 0; i < prevRanges.length; i += 2)
13694
- if (start <= prevRanges[i + 1] && end >= prevRanges[i])
13695
- adjacent = true;
13696
- });
13697
- return adjacent;
13698
- }
13699
- function rangesFor(map2) {
13700
- let result = [];
13701
- map2.forEach((_from, _to, from2, to) => result.push(from2, to));
13702
- return result;
13703
- }
13704
- function mapRanges(ranges, mapping) {
13705
- if (!ranges)
13706
- return null;
13707
- let result = [];
13708
- for (let i = 0; i < ranges.length; i += 2) {
13709
- let from2 = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);
13710
- if (from2 <= to)
13711
- result.push(from2, to);
13996
+ _isFullBlockSelected(state) {
13997
+ const blocksSelection = this._expandSelectionToBlocks(state);
13998
+ const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
13999
+ const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
14000
+ return isFromMatch && isToMatch;
14001
+ }
14002
+ _expandSelectionToBlocks({ selection, doc: doc2 }) {
14003
+ let from2 = selection.from;
14004
+ let to = selection.to;
14005
+ doc2.nodesBetween(from2, to, (node, position, parent) => {
14006
+ if (parent.type.name !== NodeTypes.DOCUMENT)
14007
+ return;
14008
+ from2 = Math.min(from2, position + 1);
14009
+ to = Math.max(to, position + node.nodeSize - 1);
14010
+ });
14011
+ return { from: from2, to };
14012
+ }
14013
+ _isMatchPosition(position1, position2) {
14014
+ return Math.abs(position1 - position2) < 5;
13712
14015
  }
13713
- return result;
13714
- }
13715
- function histTransaction(history2, state, dispatch, redo2) {
13716
- let preserveItems = mustPreserveItems(state);
13717
- let histOptions = historyKey.get(state).spec.config;
13718
- let pop = (redo2 ? history2.undone : history2.done).popEvent(state, preserveItems);
13719
- if (!pop)
13720
- return;
13721
- let selection = pop.selection.resolve(pop.transform.doc);
13722
- let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
13723
- let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0);
13724
- dispatch(pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist }).scrollIntoView());
13725
14016
  }
13726
- let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
13727
- function mustPreserveItems(state) {
13728
- let plugins = state.plugins;
13729
- if (cachedPreserveItemsPlugins != plugins) {
13730
- cachedPreserveItems = false;
13731
- cachedPreserveItemsPlugins = plugins;
13732
- for (let i = 0; i < plugins.length; i++)
13733
- if (plugins[i].spec.historyPreserveItems) {
13734
- cachedPreserveItems = true;
13735
- break;
13736
- }
14017
+ class PlaceholderPlugin extends ProseMirrorPlugin {
14018
+ constructor() {
14019
+ super(...arguments);
14020
+ __privateAdd(this, _buildDecorations);
14021
+ }
14022
+ buildProps() {
14023
+ return { decorations: __privateMethod(this, _buildDecorations, buildDecorations_fn).bind(this) };
13737
14024
  }
13738
- return cachedPreserveItems;
13739
14025
  }
13740
- const historyKey = new PluginKey("history");
13741
- const closeHistoryKey = new PluginKey("closeHistory");
13742
- function history(config = {}) {
13743
- config = {
13744
- depth: config.depth || 100,
13745
- newGroupDelay: config.newGroupDelay || 500
13746
- };
13747
- return new Plugin({
13748
- key: historyKey,
13749
- state: {
13750
- init() {
13751
- return new HistoryState(Branch.empty, Branch.empty, null, 0);
13752
- },
13753
- apply(tr, hist, state) {
13754
- return applyTransaction(hist, state, tr, config);
13755
- }
13756
- },
13757
- config,
13758
- props: {
13759
- handleDOMEvents: {
13760
- beforeinput(view, e) {
13761
- let inputType = e.inputType;
13762
- let command2 = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
13763
- if (!command2)
13764
- return false;
13765
- e.preventDefault();
13766
- return command2(view.state, view.dispatch);
13767
- }
13768
- }
14026
+ _buildDecorations = new WeakSet();
14027
+ buildDecorations_fn = function({ doc: doc2 }) {
14028
+ const decorations = [];
14029
+ if (!this.editor.isEditable)
14030
+ return null;
14031
+ if (doc2.childCount > 1)
14032
+ return;
14033
+ doc2.descendants((node, pos) => {
14034
+ if (!node.childCount) {
14035
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
14036
+ class: "zw-wysiwyg__placeholder",
14037
+ "data-placeholder": "Type your text here..."
14038
+ });
14039
+ decorations.push(decoration);
13769
14040
  }
13770
- });
13771
- }
13772
- const undo = (state, dispatch) => {
13773
- let hist = historyKey.getState(state);
13774
- if (!hist || hist.done.eventCount == 0)
13775
- return false;
13776
- if (dispatch)
13777
- histTransaction(hist, state, dispatch, false);
13778
- return true;
13779
- };
13780
- const redo = (state, dispatch) => {
13781
- let hist = historyKey.getState(state);
13782
- if (!hist || hist.undone.eventCount == 0)
13783
14041
  return false;
13784
- if (dispatch)
13785
- histTransaction(hist, state, dispatch, true);
13786
- return true;
14042
+ });
14043
+ return DecorationSet.create(doc2, decorations);
13787
14044
  };
13788
- const History = Extension.create({
13789
- name: "history",
13790
- addOptions() {
13791
- return {
13792
- depth: 100,
13793
- newGroupDelay: 500
13794
- };
13795
- },
14045
+ const ProseMirrorPlugins = Extension.create({
14046
+ name: "prose_mirror_plugins",
14047
+ addProseMirrorPlugins() {
14048
+ return [
14049
+ PastePlugin.create(this.editor),
14050
+ PlaceholderPlugin.create(this.editor)
14051
+ ];
14052
+ }
14053
+ });
14054
+ const buildCoreExtensions = () => [
14055
+ Document,
14056
+ Paragraph,
14057
+ Heading,
14058
+ Text$1,
14059
+ History,
14060
+ NodeProcessor,
14061
+ TextProcessor,
14062
+ SelectionProcessor,
14063
+ ProseMirrorPlugins
14064
+ ];
14065
+ const FontFamily = Mark.create({
14066
+ name: TextSettings.FONT_FAMILY,
14067
+ group: MarkGroups.SETTINGS,
14068
+ addOptions: () => ({
14069
+ fonts: []
14070
+ }),
14071
+ addAttributes: () => ({
14072
+ value: { required: true }
14073
+ }),
13796
14074
  addCommands() {
13797
14075
  return {
13798
- undo: () => ({ state, dispatch }) => {
13799
- return undo(state, dispatch);
13800
- },
13801
- redo: () => ({ state, dispatch }) => {
13802
- return redo(state, dispatch);
13803
- }
14076
+ applyFontFamily: createCommand(({ commands: commands2 }, value) => {
14077
+ commands2.applyMark(this.name, { value });
14078
+ const font = commands2.findFontByName(value);
14079
+ let fontWeight = unref(commands2.getFontWeight());
14080
+ if (!font.isWeightSupported(fontWeight)) {
14081
+ fontWeight = font.findClosestWeight(fontWeight);
14082
+ commands2.applyFontWeight(fontWeight);
14083
+ }
14084
+ if (!font.isItalicSupported(fontWeight)) {
14085
+ commands2.removeItalic();
14086
+ }
14087
+ }),
14088
+ getFont: createCommand(({ commands: commands2 }) => {
14089
+ const defaultPreset = unref(this.options.defaultPreset);
14090
+ const defaultFont = commands2.findFontByName(defaultPreset.common.font_family);
14091
+ const fontFamily = commands2.getFontFamily();
14092
+ return computed(() => commands2.findFontByName(unref(fontFamily)) || defaultFont);
14093
+ }),
14094
+ findFontByName: createCommand((_, name) => {
14095
+ return this.options.fonts.find((font) => font.name === name);
14096
+ }),
14097
+ getFontFamily: createCommand(({ commands: commands2 }) => {
14098
+ return commands2.getCommonSettingMark(this.name, commands2.getDefaultFontFamily());
14099
+ }),
14100
+ getDefaultFontFamily: createCommand(({ commands: commands2 }) => {
14101
+ const preset = commands2.getPreset();
14102
+ return computed(() => unref(preset).common.font_family);
14103
+ })
13804
14104
  };
13805
14105
  },
13806
- addProseMirrorPlugins() {
14106
+ parseHTML() {
14107
+ const getAttrs = (input) => ({ value: input.replace(/["']/g, "") });
13807
14108
  return [
13808
- history(this.options)
14109
+ {
14110
+ style: "--zw-font-family",
14111
+ getAttrs
14112
+ },
14113
+ {
14114
+ style: "font-family",
14115
+ getAttrs
14116
+ }
13809
14117
  ];
13810
14118
  },
13811
- addKeyboardShortcuts() {
13812
- return {
13813
- "Mod-z": () => this.editor.commands.undo(),
13814
- "Mod-y": () => this.editor.commands.redo(),
13815
- "Shift-Mod-z": () => this.editor.commands.redo(),
13816
- "Mod-\u044F": () => this.editor.commands.undo(),
13817
- "Shift-Mod-\u044F": () => this.editor.commands.redo()
13818
- };
14119
+ renderHTML({ HTMLAttributes: attrs }) {
14120
+ const font_family = attrs.value ? `"${attrs.value}"` : null;
14121
+ return renderMark({ font_family });
13819
14122
  }
13820
14123
  });
13821
- class RemoveNodeMarkStep extends Step {
13822
- static fromJSON(schema, json) {
13823
- if (typeof json.pos != "number") {
13824
- throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
13825
- }
13826
- return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
13827
- }
13828
- constructor(pos, mark) {
13829
- super();
13830
- this.pos = pos;
13831
- this.mark = mark;
13832
- }
13833
- apply(doc2) {
13834
- const node = doc2.nodeAt(this.pos);
13835
- if (!node)
13836
- return StepResult.fail("No node at mark step's position");
13837
- const updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
13838
- const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13839
- return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13840
- }
13841
- invert(doc2) {
13842
- const node = doc2.nodeAt(this.pos);
13843
- if (!node || !this.mark.isInSet(node.marks))
13844
- return this;
13845
- return new AddNodeMarkStep(this.pos, this.mark);
13846
- }
13847
- map(mapping) {
13848
- const pos = mapping.mapResult(this.pos, 1);
13849
- return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
13850
- }
13851
- toJSON() {
13852
- return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
13853
- }
13854
- }
13855
- Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
13856
- class AddNodeMarkStep extends Step {
13857
- static fromJSON(schema, json) {
13858
- if (typeof json.pos != "number") {
13859
- throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
13860
- }
13861
- return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
13862
- }
13863
- constructor(pos, mark) {
13864
- super();
13865
- this.pos = pos;
13866
- this.mark = mark;
13867
- }
13868
- apply(doc2) {
13869
- const node = doc2.nodeAt(this.pos);
13870
- if (!node)
13871
- return StepResult.fail("No node at mark step's position");
13872
- const updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
13873
- const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13874
- return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13875
- }
13876
- invert(doc2) {
13877
- const node = doc2.nodeAt(this.pos);
13878
- if (node) {
13879
- const newSet = this.mark.addToSet(node.marks);
13880
- if (newSet.length === node.marks.length) {
13881
- for (const mark of node.marks) {
13882
- if (!mark.isInSet(newSet)) {
13883
- return new AddNodeMarkStep(this.pos, mark);
14124
+ const StylePreset = Extension.create({
14125
+ name: TextSettings.STYLE_PRESET,
14126
+ addGlobalAttributes() {
14127
+ return [
14128
+ {
14129
+ types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
14130
+ attributes: {
14131
+ preset: {
14132
+ isRequired: false,
14133
+ default: { id: this.options.defaultId },
14134
+ parseHTML: (element) => {
14135
+ const presets = unref(this.options.presets);
14136
+ if (element.parentElement.tagName === "LI")
14137
+ return null;
14138
+ for (const { id: id2, node, fallbackClass } of presets) {
14139
+ if (fallbackClass && element.classList.contains(fallbackClass)) {
14140
+ return { id: id2 };
14141
+ }
14142
+ const presetSelector = this.options.styleRenderer.makePresetCssClass({ id: id2 });
14143
+ if (element.matches(presetSelector))
14144
+ return { id: id2 };
14145
+ if (element.tagName === `H${node == null ? void 0 : node.level}`)
14146
+ return { id: id2 };
14147
+ }
14148
+ return element.tagName === "P" ? { id: this.options.defaultId } : null;
14149
+ },
14150
+ renderHTML: (attrs) => {
14151
+ if (!attrs.preset)
14152
+ return null;
14153
+ return { class: this.options.styleRenderer.makePresetHtmlClass(attrs.preset) };
14154
+ }
13884
14155
  }
13885
14156
  }
13886
- return new AddNodeMarkStep(this.pos, this.mark);
13887
14157
  }
14158
+ ];
14159
+ },
14160
+ addCommands() {
14161
+ function findPresetById(presets, id2) {
14162
+ return presets.find((preset) => id2 === preset.id);
13888
14163
  }
13889
- return new RemoveNodeMarkStep(this.pos, this.mark);
13890
- }
13891
- map(mapping) {
13892
- const pos = mapping.mapResult(this.pos, 1);
13893
- return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
13894
- }
13895
- toJSON() {
13896
- return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
13897
- }
13898
- }
13899
- Step.jsonID("addNodeMark", AddNodeMarkStep);
13900
- class AttrStep extends Step {
13901
- static fromJSON(schema, json) {
13902
- if (typeof json.pos != "number" || typeof json.attr != "string") {
13903
- throw new RangeError("Invalid input for AttrStep.fromJSON");
14164
+ function mergeSettings(source, target) {
14165
+ const settings = {};
14166
+ for (const name of Object.keys(source)) {
14167
+ const sourceValue = source[name];
14168
+ const targetValue = target[name];
14169
+ const isInherit = !targetValue || targetValue.toLowerCase() === "inherit";
14170
+ settings[name] = isInherit ? sourceValue : targetValue;
14171
+ }
14172
+ return settings;
13904
14173
  }
13905
- return new AttrStep(json.pos, json.attr, json.value);
13906
- }
13907
- constructor(pos, attr, value) {
13908
- super();
13909
- this.pos = pos;
13910
- this.attr = attr;
13911
- this.value = value;
13912
- }
13913
- apply(doc2) {
13914
- const node = doc2.nodeAt(this.pos);
13915
- if (!node)
13916
- return StepResult.fail("No node at attribute step's position");
13917
- const attrs = /* @__PURE__ */ Object.create(null);
13918
- for (let name in node.attrs)
13919
- attrs[name] = node.attrs[name];
13920
- attrs[this.attr] = this.value;
13921
- const updated = node.type.create(attrs, null, node.marks);
13922
- const slice2 = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
13923
- return StepResult.fromReplace(doc2, this.pos, this.pos + 1, slice2);
13924
- }
13925
- getMap() {
13926
- return StepMap.empty;
13927
- }
13928
- invert(doc2) {
13929
- return new AttrStep(this.pos, this.attr, doc2.nodeAt(this.pos).attrs[this.attr]);
13930
- }
13931
- map(mapping) {
13932
- let pos = mapping.mapResult(this.pos, 1);
13933
- return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
13934
- }
13935
- toJSON() {
13936
- return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
13937
- }
13938
- }
13939
- Step.jsonID("attr", AttrStep);
13940
- const NodeProcessor = Extension.create({
13941
- name: "node_processor",
13942
- addCommands() {
13943
14174
  return {
13944
- setBlockAttributes: createCommand(({ commands: commands2, state }, name, attrs, defaults2 = {}) => {
13945
- var _a;
13946
- const current = (_a = unref(commands2.getBlockAttributes(name))) != null ? _a : {};
13947
- const { doc: doc2, tr } = state;
13948
- const { from: from2, to } = tr.selection;
13949
- doc2.nodesBetween(from2, to, (node, position) => {
13950
- if (!NodeTypes.blocks.includes(node.type.name))
13951
- return;
13952
- tr.step(new AttrStep(position, name, { ...defaults2, ...current, ...attrs }));
14175
+ getPresetList: createCommand(() => computed(() => {
14176
+ return this.options.presets.filter((preset) => !preset.hidden);
14177
+ })),
14178
+ getPreset: createCommand(({ commands: commands2 }) => {
14179
+ const selectionRef = commands2.getBlockAttributes("preset", { id: this.options.defaultId });
14180
+ const presetsRef = commands2.getPresetList();
14181
+ const isLinkRef = commands2.isLink();
14182
+ const linkPresetRef = commands2.getLinkPreset();
14183
+ return computed(() => {
14184
+ const preset = findPresetById(unref(presetsRef), unref(selectionRef).id);
14185
+ if (!unref(isLinkRef))
14186
+ return preset;
14187
+ const linkPreset = unref(linkPresetRef);
14188
+ return {
14189
+ id: preset.id,
14190
+ common: mergeSettings(preset.common, linkPreset.common),
14191
+ mobile: mergeSettings(preset.mobile, linkPreset.mobile),
14192
+ tablet: mergeSettings(preset.tablet, linkPreset.tablet),
14193
+ desktop: mergeSettings(preset.desktop, linkPreset.desktop)
14194
+ };
13953
14195
  });
13954
14196
  }),
13955
- getBlockAttributes: createCommand(({ editor }, name, defaults2) => computed(() => {
13956
- var _a;
13957
- let attrs = Object.assign({}, defaults2 || {});
13958
- for (const type of NodeTypes.blocks) {
13959
- Object.assign(attrs, ((_a = editor.getAttributes(type)) == null ? void 0 : _a[name]) || {});
14197
+ applyPreset: createCommand(({ commands: commands2, chain }, presetId) => {
14198
+ var _a, _b;
14199
+ const presets = unref(commands2.getPresetList());
14200
+ const preset = findPresetById(presets, presetId);
14201
+ const nodeType = (_b = (_a = preset.node) == null ? void 0 : _a.type) != null ? _b : NodeTypes.PARAGRAPH;
14202
+ const attrs = {
14203
+ preset: { id: presetId }
14204
+ };
14205
+ if (preset.node) {
14206
+ attrs.level = preset.node.level;
13960
14207
  }
13961
- return Object.keys(attrs).length ? attrs : null;
13962
- })),
13963
- removeBlockAttributes: createCommand(({ commands: commands2 }, names) => {
13964
- for (const type of NodeTypes.blocks) {
13965
- commands2.resetAttributes(type, names);
14208
+ for (const textAttribute of TextSettings.attributes) {
14209
+ attrs[textAttribute] = unref(commands2.getBlockAttributes(textAttribute));
13966
14210
  }
14211
+ chain().removeList().setNode(nodeType, attrs).run();
13967
14212
  }),
13968
- applyMark: createCommand(({ state, commands: commands2 }, name, value, customizer = {}) => {
13969
- const { tr, doc: doc2, schema } = state;
13970
- const { $from, $to } = tr.selection;
13971
- const markType = getMarkType(name, schema);
13972
- const markGroup = markType.spec.group || "";
13973
- if (!markGroup.includes(MarkGroups.SETTINGS)) {
13974
- return commands2.setMark(name, value);
13975
- }
13976
- if ($from.pos === $to.pos)
13977
- return;
13978
- const onAppliedToParent = (context) => {
13979
- if (!customizer.onAppliedToParent || customizer.onAppliedToParent(context) === false) {
13980
- const { tr: tr2, node, position, mark } = context;
13981
- commands2._removeNodeMark({ tr: tr2, node, position, mark: mark.type });
13982
- }
13983
- };
13984
- doc2.nodesBetween($from.pos, $to.pos, (node, position) => {
13985
- if (node.type.name === NodeTypes.LIST)
13986
- return;
13987
- const initialMark = findMarkByType(node.marks, name);
13988
- const applyingMark = markType.create({ ...(initialMark == null ? void 0 : initialMark.attrs) || {}, ...value });
13989
- const textPosition = resolveTextPosition($from, $to, node, position);
13990
- if (isMarkAppliedToParent(tr.doc, position, applyingMark, customizer.isAppliedToParent)) {
13991
- return onAppliedToParent({ tr, node, position, mark: applyingMark });
13992
- }
13993
- if (node.isText) {
13994
- tr.addMark(textPosition.from, textPosition.to, applyingMark);
13995
- return;
13996
- }
13997
- if (isNodeFullySelected(tr.doc, tr.selection, node, position)) {
13998
- tr.step(new AddNodeMarkStep(position, applyingMark));
13999
- }
14000
- });
14213
+ applyDefaultPreset: createCommand(({ commands: commands2 }) => {
14214
+ commands2.applyPreset(this.options.defaultId);
14001
14215
  }),
14002
- getMarks: createCommand(({ editor }, name) => {
14003
- const stateRef = toRef(editor, "state");
14004
- return computed(() => {
14005
- const { selection, doc: doc2 } = unref(stateRef);
14006
- const { from: from2, to } = unref(selection);
14007
- const marks = [];
14008
- doc2.nodesBetween(from2, to, (node) => {
14009
- for (const mark of node.marks) {
14010
- if (mark.type.name === name)
14011
- marks.unshift(mark.attrs);
14012
- }
14013
- });
14014
- return marks;
14015
- });
14216
+ removePreset: createCommand(({ commands: commands2 }) => {
14217
+ commands2.setNode(NodeTypes.PARAGRAPH, { preset: null });
14016
14218
  }),
14017
- getMark: createCommand(({ commands: commands2 }, name) => {
14018
- const marksRef = commands2.getMarks(name);
14219
+ getPresetCustomization: createCommand(({ editor, commands: commands2 }) => {
14220
+ const state = toRef(editor, "state");
14019
14221
  return computed(() => {
14020
- var _a;
14021
- return (_a = unref(marksRef)[0]) != null ? _a : null;
14222
+ const { selection, doc: doc2 } = unref(state);
14223
+ const { from: from2, to } = selection;
14224
+ return commands2._getSettingCustomization(doc2, from2, to);
14022
14225
  });
14023
14226
  }),
14024
- hasMark: createCommand(({ commands: commands2 }, name) => {
14025
- const mark = commands2.getMark(name);
14026
- return computed(() => !!unref(mark));
14027
- }),
14028
- getCommonSettingMark: createCommand(({ commands: commands2 }, name, defaultRef) => {
14029
- const selectionRef = commands2.getMark(name);
14227
+ isSettingCustomized: createCommand(({ commands: commands2 }, name) => {
14228
+ const customization = commands2.getPresetCustomization();
14229
+ const group = TextSettings.attributes.includes(name) ? "attributes" : "marks";
14030
14230
  return computed(() => {
14031
14231
  var _a, _b;
14032
- return (_b = (_a = unref(selectionRef)) == null ? void 0 : _a.value) != null ? _b : unref(defaultRef);
14232
+ return (_b = (_a = unref(customization)[group]) == null ? void 0 : _a.includes(name)) != null ? _b : false;
14033
14233
  });
14034
14234
  }),
14035
- getDeviceSettingMark: createCommand(({ commands: commands2 }, name, defaultRef) => {
14036
- const selectionRef = commands2.getMarks(name);
14037
- const deviceRef = commands2.getDevice();
14235
+ getContentCustomization: createCommand(({ editor, commands: commands2 }) => {
14236
+ const state = toRef(editor, "state");
14038
14237
  return computed(() => {
14039
- for (const attrs of unref(selectionRef)) {
14040
- const value = attrs[unref(deviceRef)];
14041
- if (value)
14042
- return value;
14043
- }
14044
- return unref(defaultRef);
14045
- });
14046
- }),
14047
- removeAllMarks: createCommand(({ state, commands: commands2 }) => {
14048
- const { tr, doc: doc2 } = state;
14049
- const { from: from2, to } = tr.selection;
14050
- doc2.nodesBetween(from2, to, (node, position) => {
14051
- for (const mark of node.marks) {
14052
- commands2._removeNodeMark({ tr, node, position, mark });
14053
- }
14238
+ const { doc: doc2 } = unref(state);
14239
+ return commands2._getSettingCustomization(doc2, 0, doc2.content.size);
14054
14240
  });
14055
14241
  }),
14056
- removeMarks: createCommand(({ state, commands: commands2 }, marks) => {
14057
- const { tr, doc: doc2 } = state;
14058
- const { from: from2, to } = tr.selection;
14059
- doc2.nodesBetween(from2, to, (node, position) => {
14060
- const removingMarks = node.marks.filter((mark) => marks.includes(mark.type.name));
14061
- for (const mark of removingMarks) {
14062
- commands2._removeNodeMark({ tr, node, position, mark });
14242
+ _getSettingCustomization: createCommand((_, doc2, from2, to) => {
14243
+ const marks = /* @__PURE__ */ new Set();
14244
+ const attributes = /* @__PURE__ */ new Set();
14245
+ doc2.nodesBetween(from2, to, (node) => {
14246
+ for (const [name, value] of Object.entries(node.attrs)) {
14247
+ const isSetting = TextSettings.attributes.includes(name);
14248
+ if (isSetting && value)
14249
+ attributes.add(name);
14063
14250
  }
14064
- });
14065
- }),
14066
- _removeNodeMark: createCommand((context, { tr, node, position, mark }) => {
14067
- return node.isText ? tr.removeMark(position, position + node.nodeSize, mark) : tr.step(new RemoveNodeMarkStep(position, mark));
14068
- })
14069
- };
14070
- }
14071
- });
14072
- const TextProcessor = Extension.create({
14073
- name: "text_processor",
14074
- addCommands() {
14075
- return {
14076
- getSelectedText: createCommand(({ state }) => {
14077
- const { from: from2, to } = state.selection;
14078
- return state.doc.textBetween(from2, to, " ");
14079
- }),
14080
- transformText: createCommand(({ state }, transform) => {
14081
- const { $from, $to } = state.tr.selection;
14082
- if ($from.pos === $to.pos)
14083
- return;
14084
- state.doc.nodesBetween($from.pos, $to.pos, (node, position) => {
14085
- if (!node.isText)
14086
- return;
14087
- const textPosition = resolveTextPosition($from, $to, node, position);
14088
- const substringFrom = Math.max(0, $from.pos - position);
14089
- const substringTo = Math.max(0, $to.pos - position);
14090
- const updatedText = transform({
14091
- text: node.textContent.substring(substringFrom, substringTo)
14092
- });
14093
- const updatedNode = state.schema.text(updatedText, node.marks);
14094
- state.tr.replaceWith(textPosition.from, textPosition.to, updatedNode);
14095
- });
14096
- })
14097
- };
14098
- }
14099
- });
14100
- const SelectionProcessor = Extension.create({
14101
- name: "selection_processor",
14102
- addStorage: () => ({
14103
- selection: null
14104
- }),
14105
- addCommands() {
14106
- return {
14107
- storeSelection: createCommand(({ state }) => {
14108
- this.storage.selection = state.selection;
14109
- }),
14110
- restoreSelection: createCommand(({ commands: commands2 }) => {
14111
- this.storage.selection && commands2.setTextSelection(this.storage.selection);
14112
- }),
14113
- expandSelection: createCommand(({ tr, commands: commands2 }, predicate) => {
14114
- let from2 = tr.selection.from;
14115
- let to = tr.selection.to;
14116
- tr.doc.nodesBetween(from2, to, (node, position, parent) => {
14117
- if (predicate({ node, parent })) {
14118
- const offset2 = node.isText ? 0 : resolvePositionOffset(tr.doc, position);
14119
- from2 = Math.min(from2, position + offset2);
14120
- to = Math.max(to, position + node.nodeSize - offset2);
14251
+ for (const { type } of node.marks) {
14252
+ if (TextSettings.marks.includes(type.name)) {
14253
+ marks.add(type.name);
14254
+ }
14121
14255
  }
14122
14256
  });
14123
- commands2.setTextSelection({ from: from2, to });
14124
- }),
14125
- expandSelectionToBlock: createCommand(({ commands: commands2 }) => {
14126
- commands2.expandSelection(({ parent }) => parent.type.name === NodeTypes.DOCUMENT);
14127
- })
14128
- };
14129
- }
14130
- });
14131
- const Document$1 = Node.create({
14132
- name: "doc",
14133
- topNode: true,
14134
- content: "block+"
14135
- });
14136
- const Document = Document$1.extend({
14137
- marks: MarkGroups.SETTINGS
14138
- });
14139
- const Paragraph$1 = Node.create({
14140
- name: "paragraph",
14141
- priority: 1e3,
14142
- addOptions() {
14143
- return {
14144
- HTMLAttributes: {}
14145
- };
14146
- },
14147
- group: "block",
14148
- content: "inline*",
14149
- parseHTML() {
14150
- return [
14151
- { tag: "p" }
14152
- ];
14153
- },
14154
- renderHTML({ HTMLAttributes }) {
14155
- return ["p", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
14156
- },
14157
- addCommands() {
14158
- return {
14159
- setParagraph: () => ({ commands: commands2 }) => {
14160
- return commands2.setNode(this.name);
14161
- }
14162
- };
14163
- },
14164
- addKeyboardShortcuts() {
14165
- return {
14166
- "Mod-Alt-0": () => this.editor.commands.setParagraph()
14167
- };
14168
- }
14169
- });
14170
- const Paragraph = Paragraph$1.extend({
14171
- marks: MarkGroups.ALL,
14172
- addOptions: () => ({
14173
- HTMLAttributes: { class: "zw-style" }
14174
- })
14175
- });
14176
- const Heading$1 = Node.create({
14177
- name: "heading",
14178
- addOptions() {
14179
- return {
14180
- levels: [1, 2, 3, 4, 5, 6],
14181
- HTMLAttributes: {}
14182
- };
14183
- },
14184
- content: "inline*",
14185
- group: "block",
14186
- defining: true,
14187
- addAttributes() {
14188
- return {
14189
- level: {
14190
- default: 1,
14191
- rendered: false
14192
- }
14257
+ return {
14258
+ attributes: Array.from(attributes),
14259
+ marks: Array.from(marks)
14260
+ };
14261
+ }),
14262
+ removePresetCustomization: createCommand(({ chain }) => {
14263
+ chain().storeSelection().expandSelectionToBlock().removeMarks(TextSettings.marks).resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes).resetAttributes(NodeTypes.HEADING, TextSettings.attributes).restoreSelection().run();
14264
+ }),
14265
+ removeFormat: createCommand(({ chain }) => {
14266
+ chain().storeSelection().expandSelectionToBlock().removeAllMarks().applyDefaultPreset().restoreSelection().run();
14267
+ })
14193
14268
  };
14194
14269
  },
14195
- parseHTML() {
14196
- return this.options.levels.map((level) => ({
14197
- tag: `h${level}`,
14198
- attrs: { level }
14199
- }));
14200
- },
14201
- renderHTML({ node, HTMLAttributes }) {
14202
- const hasLevel = this.options.levels.includes(node.attrs.level);
14203
- const level = hasLevel ? node.attrs.level : this.options.levels[0];
14204
- return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
14205
- },
14270
+ onCreate() {
14271
+ this.options.styleRenderer.inject(ContextWindow.head, this.options.presets);
14272
+ }
14273
+ });
14274
+ const FontWeight = Mark.create({
14275
+ name: TextSettings.FONT_WEIGHT,
14276
+ group: MarkGroups.SETTINGS,
14277
+ addAttributes: () => ({
14278
+ value: { required: true }
14279
+ }),
14206
14280
  addCommands() {
14207
14281
  return {
14208
- setHeading: (attributes) => ({ commands: commands2 }) => {
14209
- if (!this.options.levels.includes(attributes.level)) {
14210
- return false;
14211
- }
14212
- return commands2.setNode(this.name, attributes);
14213
- },
14214
- toggleHeading: (attributes) => ({ commands: commands2 }) => {
14215
- if (!this.options.levels.includes(attributes.level)) {
14216
- return false;
14282
+ applyFontWeight: createCommand(({ commands: commands2 }, value) => {
14283
+ commands2.applyMark(this.name, { value });
14284
+ const font = unref(commands2.getFont());
14285
+ if (!font.isItalicSupported(value)) {
14286
+ commands2.removeItalic();
14217
14287
  }
14218
- return commands2.toggleNode(this.name, "paragraph", attributes);
14219
- }
14288
+ }),
14289
+ toggleBold: createCommand(({ commands: commands2 }) => {
14290
+ const currentWeight = unref(commands2.getFontWeight());
14291
+ const currentFont = unref(commands2.getFont());
14292
+ const isBold = Number(currentWeight) >= 600;
14293
+ const wantedWeight = isBold ? "400" : "700";
14294
+ const nextWeight = currentFont.findClosestWeight(wantedWeight);
14295
+ commands2.applyFontWeight(nextWeight);
14296
+ }),
14297
+ getFontWeight: createCommand(({ commands: commands2 }) => {
14298
+ const selectionRef = commands2.getCommonSettingMark(this.name, commands2.getDefaultFontWeight());
14299
+ const fontRef = commands2.getFont();
14300
+ return computed(() => {
14301
+ const weight = unref(selectionRef);
14302
+ const font = unref(fontRef);
14303
+ return font.isWeightSupported(weight) ? weight : font.findClosestWeight(weight);
14304
+ });
14305
+ }),
14306
+ getDefaultFontWeight: createCommand(({ commands: commands2 }) => {
14307
+ const preset = commands2.getPreset();
14308
+ return computed(() => unref(preset).common.font_weight);
14309
+ })
14220
14310
  };
14221
14311
  },
14222
- addKeyboardShortcuts() {
14223
- return this.options.levels.reduce((items, level) => ({
14224
- ...items,
14225
- ...{
14226
- [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level })
14227
- }
14228
- }), {});
14229
- },
14230
- addInputRules() {
14231
- return this.options.levels.map((level) => {
14232
- return textblockTypeInputRule({
14233
- find: new RegExp(`^(#{1,${level}})\\s$`),
14234
- type: this.type,
14235
- getAttributes: {
14236
- level
14237
- }
14238
- });
14239
- });
14240
- }
14241
- });
14242
- const Heading = Heading$1.extend({
14243
- marks: MarkGroups.ALL,
14244
- addOptions: () => ({
14245
- levels: [1, 2, 3, 4],
14246
- HTMLAttributes: { class: "zw-style" }
14247
- })
14248
- });
14249
- class ProseMirrorPlugin {
14250
- static create(editor, options) {
14251
- const plugin = new this(editor, options || {});
14252
- return new Plugin({
14253
- key: new PluginKey(this.name),
14254
- props: plugin.buildProps()
14255
- });
14256
- }
14257
- constructor(editor, options) {
14258
- this.options = options;
14259
- this.editor = editor;
14260
- }
14261
- buildProps() {
14262
- return {};
14263
- }
14264
- }
14265
- class PastePlugin extends ProseMirrorPlugin {
14266
- buildProps() {
14267
- return {
14268
- transformPastedHTML: this._transformPastedHTML.bind(this),
14269
- handlePaste: this._handlePaste.bind(this)
14312
+ addKeyboardShortcuts: () => ({
14313
+ "Mod-b": createKeyboardShortcut("toggleBold"),
14314
+ "Mod-B": createKeyboardShortcut("toggleBold")
14315
+ }),
14316
+ parseHTML() {
14317
+ const getAttrs = (value) => {
14318
+ if (value === "bold")
14319
+ return { value: "700" };
14320
+ return Number(value) ? { value } : false;
14270
14321
  };
14271
- }
14272
- _transformPastedHTML(html2) {
14273
- if (html2.includes("data-pm-slice") && html2.includes("zw-style")) {
14274
- return html2;
14275
- }
14276
- const normalizer = ContentNormalizer.build(html2);
14277
- normalizer.normalizeHTML();
14278
- this._removeDeprecatedStyles(normalizer);
14279
- return normalizer.normalizedHTML;
14280
- }
14281
- _removeDeprecatedStyles(normalizer) {
14282
- const elements = normalizer.dom.querySelectorAll('[style*="margin"]');
14283
- for (const element of Array.from(elements)) {
14284
- element.style.removeProperty("margin");
14285
- element.style.removeProperty("margin-top");
14286
- element.style.removeProperty("margin-right");
14287
- element.style.removeProperty("margin-bottom");
14288
- element.style.removeProperty("margin-left");
14289
- }
14290
- }
14291
- _handlePaste(view, _, slice2) {
14292
- const transaction = this._insertPastedContent(view, slice2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste");
14293
- view.dispatch(transaction);
14294
- return true;
14295
- }
14296
- _insertPastedContent({ state, input }, slice2) {
14297
- if (!this._isFullBlockSelected(state)) {
14298
- return state.tr.replaceSelection(slice2);
14299
- }
14300
- return state.tr.replaceSelectionWith(slice2.content, input.shiftKey);
14301
- }
14302
- _isFullBlockSelected(state) {
14303
- const blocksSelection = this._expandSelectionToBlocks(state);
14304
- const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
14305
- const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
14306
- return isFromMatch && isToMatch;
14307
- }
14308
- _expandSelectionToBlocks({ selection, doc: doc2 }) {
14309
- let from2 = selection.from;
14310
- let to = selection.to;
14311
- doc2.nodesBetween(from2, to, (node, position, parent) => {
14312
- if (parent.type.name !== NodeTypes.DOCUMENT)
14313
- return;
14314
- from2 = Math.min(from2, position + 1);
14315
- to = Math.max(to, position + node.nodeSize - 1);
14316
- });
14317
- return { from: from2, to };
14318
- }
14319
- _isMatchPosition(position1, position2) {
14320
- return Math.abs(position1 - position2) < 5;
14321
- }
14322
- }
14323
- class PlaceholderPlugin extends ProseMirrorPlugin {
14324
- constructor() {
14325
- super(...arguments);
14326
- __privateAdd(this, _buildDecorations);
14327
- }
14328
- buildProps() {
14329
- return { decorations: __privateMethod(this, _buildDecorations, buildDecorations_fn).bind(this) };
14330
- }
14331
- }
14332
- _buildDecorations = new WeakSet();
14333
- buildDecorations_fn = function({ doc: doc2 }) {
14334
- const decorations = [];
14335
- if (!this.editor.isEditable)
14336
- return null;
14337
- if (doc2.childCount > 1)
14338
- return;
14339
- doc2.descendants((node, pos) => {
14340
- if (!node.childCount) {
14341
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
14342
- class: "zw-wysiwyg__placeholder",
14343
- "data-placeholder": "Type your text here..."
14344
- });
14345
- decorations.push(decoration);
14346
- }
14347
- return false;
14348
- });
14349
- return DecorationSet.create(doc2, decorations);
14350
- };
14351
- const ProseMirrorPlugins = Extension.create({
14352
- name: "prose_mirror_plugins",
14353
- addProseMirrorPlugins() {
14354
14322
  return [
14355
- PastePlugin.create(this.editor),
14356
- PlaceholderPlugin.create(this.editor)
14323
+ {
14324
+ style: "--zw-font-weight",
14325
+ getAttrs
14326
+ },
14327
+ {
14328
+ style: "font-weight",
14329
+ getAttrs
14330
+ },
14331
+ {
14332
+ tag: "b",
14333
+ attrs: { value: "700" }
14334
+ },
14335
+ {
14336
+ tag: "strong",
14337
+ attrs: { value: "700" }
14338
+ }
14357
14339
  ];
14340
+ },
14341
+ renderHTML({ HTMLAttributes: attrs }) {
14342
+ return renderMark({ font_weight: attrs.value });
14358
14343
  }
14359
14344
  });
14360
- const buildCoreExtensions = () => [
14361
- Document,
14362
- Paragraph,
14363
- Heading,
14364
- Text$1,
14365
- History,
14366
- NodeProcessor,
14367
- TextProcessor,
14368
- SelectionProcessor,
14369
- ProseMirrorPlugins
14370
- ];
14371
14345
  const FontSize = Mark.create({
14372
14346
  name: TextSettings.FONT_SIZE,
14373
14347
  group: MarkGroups.SETTINGS,
@@ -14774,9 +14748,9 @@ const Alignment = Extension.create({
14774
14748
  if (textAlign) {
14775
14749
  return { desktop: textAlign, tablet: textAlign, mobile: textAlign };
14776
14750
  }
14777
- const mobile = style2.getPropertyValue("--zw-text-align-mobile") || null;
14778
- const tablet = style2.getPropertyValue("--zw-text-align-tablet") || null;
14779
- const desktop = style2.getPropertyValue("--zw-text-align-desktop") || null;
14751
+ const mobile = style2.getPropertyValue("--zw-alignment-mobile") || null;
14752
+ const tablet = style2.getPropertyValue("--zw-alignment-tablet") || null;
14753
+ const desktop = style2.getPropertyValue("--zw-alignment-desktop") || null;
14780
14754
  if (!mobile && !tablet && !desktop)
14781
14755
  return null;
14782
14756
  return { desktop, tablet, mobile };
@@ -14785,9 +14759,9 @@ const Alignment = Extension.create({
14785
14759
  if (!attrs.alignment)
14786
14760
  return null;
14787
14761
  return renderInlineSetting({
14788
- text_align_mobile: attrs.alignment.mobile,
14789
- text_align_tablet: attrs.alignment.tablet,
14790
- text_align_desktop: attrs.alignment.desktop
14762
+ alignment_mobile: attrs.alignment.mobile,
14763
+ alignment_tablet: attrs.alignment.tablet,
14764
+ alignment_desktop: attrs.alignment.desktop
14791
14765
  });
14792
14766
  }
14793
14767
  }
@@ -16218,8 +16192,11 @@ function buildExtensions(options) {
16218
16192
  StylePreset.configure({
16219
16193
  presets: options.presetsRef,
16220
16194
  defaultId: options.defaultPresetId,
16221
- baseClass: options.basePresetClass,
16222
- makeVariable: options.makePresetVariable
16195
+ styleRenderer: new StylePresetRenderer({
16196
+ baseClass: options.basePresetClass,
16197
+ makeVariable: options.makePresetVariable,
16198
+ linkPresetId: options.linkPresetId
16199
+ })
16223
16200
  }),
16224
16201
  List.configure({
16225
16202
  baseClass: options.baseListClass,
@@ -17705,6 +17682,62 @@ const _HtmlToJsonParser = class {
17705
17682
  };
17706
17683
  let HtmlToJsonParser = _HtmlToJsonParser;
17707
17684
  _contentSerializer = new WeakMap();
17685
+ class StylePresetRenderer {
17686
+ constructor({ baseClass, makeVariable, linkPresetId }) {
17687
+ __privateAdd(this, _makeInternalVariableName);
17688
+ __privateAdd(this, _baseClass, void 0);
17689
+ __privateAdd(this, _makeVariable, void 0);
17690
+ __privateAdd(this, _linkPresetId, void 0);
17691
+ __privateSet(this, _baseClass, baseClass);
17692
+ __privateSet(this, _makeVariable, makeVariable);
17693
+ __privateSet(this, _linkPresetId, linkPresetId);
17694
+ }
17695
+ inject(hostEl, presets) {
17696
+ let styleEl = hostEl.querySelector("[data-zw-styles]");
17697
+ if (styleEl)
17698
+ return;
17699
+ styleEl = ContextWindow.document.createElement("style");
17700
+ styleEl.dataset.zwStyles = "";
17701
+ styleEl.innerHTML = this.render(presets);
17702
+ hostEl.append(styleEl);
17703
+ }
17704
+ render(presets) {
17705
+ let css = "";
17706
+ for (const preset of presets) {
17707
+ const isLink = preset.id === __privateGet(this, _linkPresetId);
17708
+ const className = this.makePresetCssClass(preset);
17709
+ css += ` ${className} {`;
17710
+ for (const device of Devices.values) {
17711
+ for (const setting of Object.keys(preset[device])) {
17712
+ const variable = __privateGet(this, _makeVariable).call(this, { device, preset, property: setting });
17713
+ const internalVariable = __privateMethod(this, _makeInternalVariableName, makeInternalVariableName_fn).call(this, setting, device);
17714
+ css += `${internalVariable}: var(${variable}, inherit);`;
17715
+ if (isLink) {
17716
+ const overrideVariable = internalVariable.replace("preset-", "");
17717
+ css += `${overrideVariable}: var(${internalVariable});`;
17718
+ }
17719
+ }
17720
+ }
17721
+ css += "}";
17722
+ }
17723
+ return css;
17724
+ }
17725
+ makePresetHtmlClass(preset) {
17726
+ return __privateGet(this, _baseClass) + preset.id;
17727
+ }
17728
+ makePresetCssClass(preset) {
17729
+ return this.makePresetHtmlClass(preset).split(" ").map((part) => `.${part}`).join("");
17730
+ }
17731
+ }
17732
+ _baseClass = new WeakMap();
17733
+ _makeVariable = new WeakMap();
17734
+ _linkPresetId = new WeakMap();
17735
+ _makeInternalVariableName = new WeakSet();
17736
+ makeInternalVariableName_fn = function(setting, device) {
17737
+ const property = setting === "color" ? "font-color" : setting.replace(/_/i, "-");
17738
+ const prefix = device === Devices.COMMON ? "" : `-${device}`;
17739
+ return `--zw-preset-${property}${prefix}`;
17740
+ };
17708
17741
  function convertFontSize(value, wrapperEl) {
17709
17742
  if (!value.includes("em"))
17710
17743
  return parseInt(value);
@@ -23656,6 +23689,8 @@ function useModalToggler({ onBeforeOpened, onClosed, wrapperRef, modalRef } = {}
23656
23689
  });
23657
23690
  }
23658
23691
  async function open() {
23692
+ if (isOpened.value)
23693
+ return;
23659
23694
  onBeforeOpened == null ? void 0 : onBeforeOpened();
23660
23695
  editor.commands.storeSelection();
23661
23696
  isOpened.value = true;
@@ -24453,7 +24488,7 @@ var __component__$v = /* @__PURE__ */ normalizeComponent(
24453
24488
  staticRenderFns$v,
24454
24489
  false,
24455
24490
  __vue2_injectStyles$v,
24456
- "eeca926a",
24491
+ "bb5c4efe",
24457
24492
  null,
24458
24493
  null
24459
24494
  );
@@ -25087,7 +25122,7 @@ var __component__$o = /* @__PURE__ */ normalizeComponent(
25087
25122
  staticRenderFns$o,
25088
25123
  false,
25089
25124
  __vue2_injectStyles$o,
25090
- "3739e310",
25125
+ "1f333e30",
25091
25126
  null,
25092
25127
  null
25093
25128
  );