playroom 0.44.3 → 0.44.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # playroom
2
2
 
3
+ ## 0.44.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#450](https://github.com/seek-oss/playroom/pull/450) [`2dfefd8`](https://github.com/seek-oss/playroom/commit/2dfefd810b2c161f9028f5fc52c575b1aac8d1f6) Thanks [@felixhabib](https://github.com/felixhabib)! - Ensure "Toggle comment" command works correctly when there is no other code in the editor.
8
+
9
+ - [#451](https://github.com/seek-oss/playroom/pull/451) [`4a515dc`](https://github.com/seek-oss/playroom/commit/4a515dc5171661c9b68f5013eb6db2111ad95505) Thanks [@felixhabib](https://github.com/felixhabib)! - Ensure "Format code" command works correctly when there is no code other than JSX comments in the editor.
10
+
3
11
  ## 0.44.3
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playroom",
3
- "version": "0.44.3",
3
+ "version": "0.44.4",
4
4
  "description": "Design with code, powered by your own component library",
5
5
  "bin": {
6
6
  "playroom": "bin/cli.cjs"
@@ -225,6 +225,12 @@ const determineCommentType = (
225
225
  from: CodeMirror.Position,
226
226
  to: CodeMirror.Position
227
227
  ): CommentType => {
228
+ const lineContent = cm.getLine(from.line);
229
+
230
+ if (lineContent.trim() === '' && from.line === to.line) {
231
+ return 'block';
232
+ }
233
+
228
234
  const lineTokens = cm.getLineTokens(from.line);
229
235
 
230
236
  const containsTag = lineTokens.some((token) => token.type === 'tag');
@@ -62,8 +62,15 @@ export const cursorOffsetToPosition = (
62
62
  export const wrapJsx = (code: string) => `<>\n${code}\n</>`;
63
63
 
64
64
  // Removes `<>\n` and `\n</>` and unindents the two spaces due to the wrapping
65
- export const unwrapJsx = (code: string) =>
66
- code.replace(/\n {2}/g, '\n').slice(3, -5);
65
+ export const unwrapJsx = (code: string) => {
66
+ if (code.startsWith('<>\n')) {
67
+ // Multi-line: remove indentation, then unwrap
68
+ return code.replace(/\n {2}/g, '\n').slice(3, -5);
69
+ }
70
+
71
+ // Single-line: just remove wrapper tags
72
+ return code.slice(2).replace(/<\/>;?\n?$/, '');
73
+ };
67
74
 
68
75
  // Handles running prettier, ensuring multiple root level JSX values are valid
69
76
  // by wrapping the code in <>{code}</> then finally removing the layer of indentation
@@ -104,10 +111,12 @@ export const formatCode = ({
104
111
  formatResult.cursorOffset
105
112
  );
106
113
 
114
+ const isMultiLine = formatResult.formatted.startsWith('<>\n');
115
+
107
116
  return {
108
117
  code: formattedCode,
109
118
  cursor: {
110
- line: position.line - WRAPPED_LINE_OFFSET,
119
+ line: position.line - (isMultiLine ? WRAPPED_LINE_OFFSET : 0),
111
120
  ch: position.ch === 0 ? 0 : position.ch - WRAPPED_INDENT_OFFSET,
112
121
  },
113
122
  };