@inkandswitch/patchwork-pkg-base 0.0.44 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkandswitch/patchwork-pkg-base",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "description": "Base packages for the Patchwork system",
6
6
  "repository": {
@@ -3068,6 +3068,62 @@ var searchExtensions = [
3068
3068
  // src/extensions/markdown.ts
3069
3069
  import { EditorView as EditorView4, keymap } from "@codemirror/view";
3070
3070
 
3071
+ // src/extensions/formatting.ts
3072
+ import { EditorSelection as EditorSelection3 } from "@codemirror/state";
3073
+ var toggleWrap = (mark) => ({ state, dispatch }) => {
3074
+ const selection = state.changeByRange((range) => {
3075
+ const before = state.sliceDoc(range.from - mark.length, range.from);
3076
+ const after = state.sliceDoc(range.to, range.to + mark.length);
3077
+ const inside = state.sliceDoc(range.from, range.from + mark.length) === mark && state.sliceDoc(range.to - mark.length, range.to) === mark && range.to - range.from >= mark.length * 2;
3078
+ if (before === mark && after === mark) {
3079
+ return {
3080
+ changes: [
3081
+ { from: range.from - mark.length, to: range.from },
3082
+ { from: range.to, to: range.to + mark.length }
3083
+ ],
3084
+ range: EditorSelection3.range(
3085
+ range.from - mark.length,
3086
+ range.to - mark.length
3087
+ )
3088
+ };
3089
+ }
3090
+ if (inside) {
3091
+ return {
3092
+ changes: [
3093
+ { from: range.from, to: range.from + mark.length },
3094
+ { from: range.to - mark.length, to: range.to }
3095
+ ],
3096
+ range: EditorSelection3.range(
3097
+ range.from,
3098
+ range.to - mark.length * 2
3099
+ )
3100
+ };
3101
+ }
3102
+ return {
3103
+ changes: [
3104
+ { from: range.from, insert: mark },
3105
+ { from: range.to, insert: mark }
3106
+ ],
3107
+ range: EditorSelection3.range(
3108
+ range.from + mark.length,
3109
+ range.to + mark.length
3110
+ )
3111
+ };
3112
+ });
3113
+ dispatch(state.update(selection, { scrollIntoView: true, userEvent: "input" }));
3114
+ return true;
3115
+ };
3116
+ var toggleBold = toggleWrap("**");
3117
+ var toggleItalic = toggleWrap("_");
3118
+ var toggleStrikethrough = toggleWrap("~~");
3119
+ var toggleCode = toggleWrap("`");
3120
+ var markdownFormattingKeymap = [
3121
+ { key: "Mod-b", run: toggleBold, preventDefault: true },
3122
+ { key: "Mod-i", run: toggleItalic, preventDefault: true },
3123
+ { key: "Mod-Shift-x", run: toggleStrikethrough, preventDefault: true },
3124
+ { key: "Mod-e", run: toggleCode, preventDefault: true }
3125
+ ];
3126
+
3071
3127
  // src/themes/markdown.ts
3072
3128
  import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
3073
3129
  import {
@@ -3076,7 +3132,8 @@ import {
3076
3132
  ViewPlugin as ViewPlugin2,
3077
3133
  WidgetType
3078
3134
  } from "@codemirror/view";
3079
- var MARKDOWN_STYLES = {
3135
+ var bodyFont = (style) => style == "serif" ? 'var(--text-editor-family-serif, "Merriweather", serif)' : "var(--text-editor-family-sans)";
3136
+ var markdownStyles = (style) => ({
3080
3137
  "&": {},
3081
3138
  "&.cm-editor.cm-focused": {
3082
3139
  outline: "none"
@@ -3099,6 +3156,7 @@ var MARKDOWN_STYLES = {
3099
3156
  // but doesn't feel right for most documents.
3100
3157
  // textAlign: "justify",
3101
3158
  textWrap: "pretty",
3159
+ fontFamily: bodyFont(style),
3102
3160
  lineHeight: "1.5rem",
3103
3161
  color: "var(--text-editor-line)",
3104
3162
  caretColor: "var(--text-editor-cursor-fill)",
@@ -3120,7 +3178,7 @@ var MARKDOWN_STYLES = {
3120
3178
  },
3121
3179
  ".frontmatter, .frontmatter *": {
3122
3180
  fontSize: "14px",
3123
- fontFamily: "var(--studio-family-code, monospace)",
3181
+ fontFamily: "var(--text-editor-family-code)",
3124
3182
  color: "var(--syntax-comment, #666)",
3125
3183
  textDecoration: "none",
3126
3184
  fontWeight: "normal",
@@ -3152,21 +3210,21 @@ var MARKDOWN_STYLES = {
3152
3210
  ".codeblock": {
3153
3211
  background: "orange"
3154
3212
  }
3155
- };
3213
+ });
3156
3214
  var baseHeadingStyles = {
3157
- fontFamily: '"Merriweather Sans", sans-serif',
3215
+ fontFamily: "var(--text-editor-family-sans)",
3158
3216
  fontWeight: 400,
3159
3217
  textDecoration: "none"
3160
3218
  };
3161
3219
  var baseCodeStyles = {
3162
- fontFamily: "var(--studio-family-code, monospace)",
3220
+ fontFamily: "var(--text-editor-family-code)",
3163
3221
  fontSize: "1em"
3164
3222
  };
3165
3223
  var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
3166
3224
  // this is how you ensure that codeblocks are still monospace
3167
3225
  {
3168
3226
  tag: tags.content,
3169
- fontFamily: style == "serif" ? '"Merriweather", serif' : '"Merriweather Sans", sans-serif'
3227
+ fontFamily: bodyFont(style)
3170
3228
  },
3171
3229
  {
3172
3230
  tag: tags.heading1,
@@ -3199,10 +3257,14 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
3199
3257
  marginBottom: "1rem",
3200
3258
  marginTop: "2rem"
3201
3259
  },
3260
+ {
3261
+ tag: tags.processingInstruction,
3262
+ color: "var(--text-editor-line-offset-40)"
3263
+ },
3202
3264
  {
3203
3265
  tag: tags.comment,
3204
3266
  color: "var(--syntax-comment, #555)",
3205
- fontFamily: "var(--studio-family-code, monospace)"
3267
+ fontFamily: "var(--text-editor-family-code)"
3206
3268
  },
3207
3269
  { tag: tags.quote, fontStyle: "var(--syntax-style-quote, italic)" },
3208
3270
  {
@@ -3221,7 +3283,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
3221
3283
  tag: [tags.meta],
3222
3284
  fontWeight: 300,
3223
3285
  color: "var(--syntax-meta, #999)",
3224
- fontFamily: '"Merriweather Sans", sans-serif'
3286
+ fontFamily: "var(--text-editor-family-sans)"
3225
3287
  },
3226
3288
  { tag: tags.keyword, ...baseCodeStyles, color: "var(--syntax-keyword, #708)" },
3227
3289
  {
@@ -3263,7 +3325,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
3263
3325
  { tag: tags.monospace, ...baseCodeStyles }
3264
3326
  ]);
3265
3327
  var theme = (style) => [
3266
- EditorView3.theme(MARKDOWN_STYLES),
3328
+ EditorView3.theme(markdownStyles(style)),
3267
3329
  syntaxHighlighting(markdownSyntaxHighlighting(style)),
3268
3330
  bullets,
3269
3331
  codeblocks
@@ -3346,6 +3408,7 @@ function markdownExtensions() {
3346
3408
  ...theme("sans"),
3347
3409
  indentOnInput(),
3348
3410
  keymap.of([
3411
+ ...markdownFormattingKeymap,
3349
3412
  ...defaultKeymap,
3350
3413
  ...searchKeymap,
3351
3414
  ...foldKeymap,