js-draw 0.9.1 → 0.9.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 (59) hide show
  1. package/.github/ISSUE_TEMPLATE/translation.yml +742 -0
  2. package/CHANGELOG.md +3 -0
  3. package/build_tools/buildTranslationTemplate.ts +119 -0
  4. package/dist/build_tools/buildTranslationTemplate.d.ts +1 -0
  5. package/dist/build_tools/buildTranslationTemplate.js +93 -0
  6. package/dist/bundle.js +1 -1
  7. package/dist/src/Editor.d.ts +0 -1
  8. package/dist/src/Editor.js +7 -15
  9. package/dist/src/SVGLoader.js +1 -1
  10. package/dist/src/Viewport.js +1 -3
  11. package/dist/src/commands/Command.d.ts +2 -2
  12. package/dist/src/commands/uniteCommands.js +19 -10
  13. package/dist/src/components/{Text.d.ts → TextComponent.d.ts} +0 -0
  14. package/dist/src/components/{Text.js → TextComponent.js} +0 -0
  15. package/dist/src/components/lib.d.ts +1 -1
  16. package/dist/src/components/lib.js +1 -1
  17. package/dist/src/rendering/renderers/AbstractRenderer.d.ts +1 -1
  18. package/dist/src/rendering/renderers/CanvasRenderer.d.ts +1 -1
  19. package/dist/src/rendering/renderers/CanvasRenderer.js +1 -1
  20. package/dist/src/rendering/renderers/DummyRenderer.d.ts +1 -1
  21. package/dist/src/rendering/renderers/SVGRenderer.d.ts +1 -1
  22. package/dist/src/rendering/renderers/TextOnlyRenderer.d.ts +1 -1
  23. package/dist/src/rendering/renderers/TextOnlyRenderer.js +2 -2
  24. package/dist/src/toolbar/IconProvider.d.ts +1 -1
  25. package/dist/src/tools/FindTool.d.ts +21 -0
  26. package/dist/src/tools/FindTool.js +113 -0
  27. package/dist/src/tools/SelectionTool/Selection.js +42 -11
  28. package/dist/src/tools/SelectionTool/SelectionTool.js +1 -1
  29. package/dist/src/tools/TextTool.d.ts +1 -1
  30. package/dist/src/tools/TextTool.js +1 -1
  31. package/dist/src/tools/ToolController.js +2 -0
  32. package/dist/src/tools/localization.d.ts +6 -0
  33. package/dist/src/tools/localization.js +6 -0
  34. package/package.json +2 -1
  35. package/src/Editor.css +1 -0
  36. package/src/Editor.toSVG.test.ts +1 -1
  37. package/src/Editor.ts +12 -22
  38. package/src/SVGLoader.ts +1 -1
  39. package/src/Viewport.ts +1 -3
  40. package/src/commands/Command.ts +2 -2
  41. package/src/commands/uniteCommands.ts +21 -10
  42. package/src/components/{Text.test.ts → TextComponent.test.ts} +1 -1
  43. package/src/components/{Text.ts → TextComponent.ts} +0 -0
  44. package/src/components/lib.ts +1 -1
  45. package/src/rendering/renderers/AbstractRenderer.ts +1 -1
  46. package/src/rendering/renderers/CanvasRenderer.ts +1 -1
  47. package/src/rendering/renderers/DummyRenderer.ts +1 -1
  48. package/src/rendering/renderers/SVGRenderer.ts +1 -1
  49. package/src/rendering/renderers/TextOnlyRenderer.ts +3 -3
  50. package/src/toolbar/IconProvider.ts +1 -1
  51. package/src/tools/FindTool.css +7 -0
  52. package/src/tools/FindTool.ts +151 -0
  53. package/src/tools/PasteHandler.ts +1 -1
  54. package/src/tools/SelectionTool/Selection.ts +51 -10
  55. package/src/tools/SelectionTool/SelectionTool.ts +1 -1
  56. package/src/tools/TextTool.ts +1 -1
  57. package/src/tools/ToolController.ts +2 -0
  58. package/src/tools/localization.ts +14 -0
  59. package/.github/ISSUE_TEMPLATE/translation.md +0 -100
package/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
 
2
+ # 0.9.2
3
+ * Added a find dialog that can be opened with `ctrl+f`
4
+
2
5
  # 0.9.1
3
6
  * Bug fixes:
4
7
  * Fix line tool producing an open shape. This caused issues with erasing and zooming in on these shapes.
@@ -0,0 +1,119 @@
1
+
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+
5
+ import { defaultEditorLocalization } from '../src/localization';
6
+
7
+ // Adds markdown formatting to format text like code.
8
+ const codeFormat = (text: string) => {
9
+ let maxConsecutiveBackticks = 0;
10
+
11
+ // Find the longest number of consecutive backticks — we need to have more
12
+ // than that for the delimiters.
13
+ const backtickRuns = text.matchAll(/[`]+/g);
14
+ for (const backticks of backtickRuns) {
15
+ if (backticks.length > maxConsecutiveBackticks) {
16
+ maxConsecutiveBackticks = backticks.length;
17
+ }
18
+ }
19
+
20
+ let codeStartEnd = '';
21
+ for (let i = 0; i < maxConsecutiveBackticks + 1; i++) {
22
+ codeStartEnd += '`';
23
+ }
24
+
25
+ // If the text already starts with a `, add a space to prevent the
26
+ // markdown parser from treating it as part of the delimiter.
27
+ if (text.startsWith('`')) {
28
+ text = ' ' + text;
29
+ }
30
+
31
+ if (text.endsWith('`')) {
32
+ text = text + ' ';
33
+ }
34
+
35
+ return `${codeStartEnd}${text}${codeStartEnd}`;
36
+ };
37
+
38
+ const generateTranslationTemplate = () => {
39
+ const bodyContentLines: string[] = [];
40
+
41
+ const addInput = (
42
+ type: string, id: string, attrs: Record<string, string>, required: boolean = false
43
+ ) => {
44
+ const lines: string[] = [];
45
+ lines.push(` - type: ${type}`);
46
+ lines.push(` id: ${id}`);
47
+ lines.push(' attributes:');
48
+
49
+ for (const key in attrs) {
50
+ const value = `${attrs[key]}`;
51
+
52
+ const escapedValue = value.replace(/[\\]/g, '\\\\').replace(/"/g, '\\"');
53
+ lines.push(` ${key}: "${escapedValue}"`);
54
+ }
55
+
56
+ lines.push(' validations:');
57
+ lines.push(` required: ${required}`);
58
+
59
+ bodyContentLines.push(...lines);
60
+ };
61
+
62
+ const addLabel = (text: string) => {
63
+ bodyContentLines.push(' - type: markdown');
64
+ bodyContentLines.push(' attributes:');
65
+ bodyContentLines.push(' value: |');
66
+ bodyContentLines.push(' ' + text);
67
+ };
68
+
69
+ addLabel(`
70
+ Thank you for taking the time to translate \`js-draw\`! If you don't have time to translate
71
+ all of the strings below, feel free to submit an incomplete translation and edit it later.
72
+ Use this template to update an existing translation or to create a new translation.
73
+ `.replace(/\s+/g, ' '));
74
+
75
+ addLabel(`
76
+ (Optional) If you would like to submit a pull request that applies this translation,
77
+ note that existing translations are present in
78
+ [src/localizations/](https://github.com/personalizedrefrigerator/js-draw/tree/main/src/localizations).
79
+ `.replace(/\s+/g, ''));
80
+
81
+ addInput('input', 'language-name', {
82
+ label: 'Language',
83
+ description: 'The name of the language to translate to in English (e.g. Spanish)',
84
+ }, true);
85
+
86
+ for (const key in defaultEditorLocalization) {
87
+ const englishTranslation = `${(defaultEditorLocalization as any)[key]}`;
88
+ addInput('input', `translation-${key}`, {
89
+ label: `${key}`,
90
+ description: `Translate ${codeFormat(englishTranslation)}.`,
91
+ placeholder: englishTranslation,
92
+ });
93
+ }
94
+
95
+ addInput('textarea', 'additional-comments', {
96
+ label: 'Additional information',
97
+ placeholder: 'Any additional information/comments on the translation can go here.',
98
+ });
99
+
100
+ return `name: Translation
101
+ # This template is auto-generated by build_tools/buildTranslationTemplate.ts
102
+ # Do not modify it directly.
103
+ description: Translate the editor to a new language!
104
+ title: "[Translation]: <language>"
105
+ labels: [localization]
106
+ assignees: []
107
+ body:
108
+ ${bodyContentLines.join('\n')}`;
109
+ };
110
+
111
+ const template = generateTranslationTemplate();
112
+
113
+ // According to https://stackoverflow.com/a/13650454, fs should
114
+ // be able to handle forward and back slashes (both) on Windows (so extra
115
+ // path logic shouldn't be needed here.)
116
+ const rootDir = path.dirname(__dirname);
117
+ const translationTempaltePath = path.join(rootDir, '.github/ISSUE_TEMPLATE/translation.yml');
118
+
119
+ fs.writeFileSync(translationTempaltePath, template);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { defaultEditorLocalization } from '../src/localization';
4
+ // Adds markdown formatting to format text like code.
5
+ const codeFormat = (text) => {
6
+ let maxConsecutiveBackticks = 0;
7
+ // Find the longest number of consecutive backticks — we need to have more
8
+ // than that for the delimiters.
9
+ const backtickRuns = text.matchAll(/[`]+/g);
10
+ for (const backticks of backtickRuns) {
11
+ if (backticks.length > maxConsecutiveBackticks) {
12
+ maxConsecutiveBackticks = backticks.length;
13
+ }
14
+ }
15
+ let codeStartEnd = '';
16
+ for (let i = 0; i < maxConsecutiveBackticks + 1; i++) {
17
+ codeStartEnd += '`';
18
+ }
19
+ // If the text already starts with a `, add a space to prevent the
20
+ // markdown parser from treating it as part of the delimiter.
21
+ if (text.startsWith('`')) {
22
+ text = ' ' + text;
23
+ }
24
+ if (text.endsWith('`')) {
25
+ text = text + ' ';
26
+ }
27
+ return `${codeStartEnd}${text}${codeStartEnd}`;
28
+ };
29
+ const generateTranslationTemplate = () => {
30
+ const bodyContentLines = [];
31
+ const addInput = (type, id, attrs, required = false) => {
32
+ const lines = [];
33
+ lines.push(` - type: ${type}`);
34
+ lines.push(` id: ${id}`);
35
+ lines.push(' attributes:');
36
+ for (const key in attrs) {
37
+ const value = `${attrs[key]}`;
38
+ const escapedValue = value.replace(/[\\]/g, '\\\\').replace(/"/g, '\\"');
39
+ lines.push(` ${key}: "${escapedValue}"`);
40
+ }
41
+ lines.push(' validations:');
42
+ lines.push(` required: ${required}`);
43
+ bodyContentLines.push(...lines);
44
+ };
45
+ const addLabel = (text) => {
46
+ bodyContentLines.push(' - type: markdown');
47
+ bodyContentLines.push(' attributes:');
48
+ bodyContentLines.push(' value: |');
49
+ bodyContentLines.push(' ' + text);
50
+ };
51
+ addLabel(`
52
+ Thank you for taking the time to translate \`js-draw\`! If you don't have time to translate
53
+ all of the strings below, feel free to submit an incomplete translation and edit it later.
54
+ Use this template to update an existing translation or to create a new translation.
55
+ `.replace(/\s+/g, ' '));
56
+ addLabel(`
57
+ (Optional) If you would like to submit a pull request that applies this translation,
58
+ note that existing translations are present in
59
+ [src/localizations/](https://github.com/personalizedrefrigerator/js-draw/tree/main/src/localizations).
60
+ `.replace(/\s+/g, ''));
61
+ addInput('input', 'language-name', {
62
+ label: 'Language',
63
+ description: 'The name of the language to translate to in English (e.g. Spanish)',
64
+ }, true);
65
+ for (const key in defaultEditorLocalization) {
66
+ const englishTranslation = `${defaultEditorLocalization[key]}`;
67
+ addInput('input', `translation-${key}`, {
68
+ label: `${key}`,
69
+ description: `Translate ${codeFormat(englishTranslation)}.`,
70
+ placeholder: englishTranslation,
71
+ });
72
+ }
73
+ addInput('textarea', 'additional-comments', {
74
+ label: 'Additional information',
75
+ placeholder: 'Any additional information/comments on the translation can go here.',
76
+ });
77
+ return `name: Translation
78
+ # This template is auto-generated by build_tools/buildTranslationTemplate.ts
79
+ # Do not modify it directly.
80
+ description: Translate the editor to a new language!
81
+ title: "[Translation]: <language>"
82
+ labels: [localization]
83
+ assignees: []
84
+ body:
85
+ ${bodyContentLines.join('\n')}`;
86
+ };
87
+ const template = generateTranslationTemplate();
88
+ // According to https://stackoverflow.com/a/13650454, fs should
89
+ // be able to handle forward and back slashes (both) on Windows (so extra
90
+ // path logic shouldn't be needed here.)
91
+ const rootDir = path.dirname(__dirname);
92
+ const translationTempaltePath = path.join(rootDir, '.github/ISSUE_TEMPLATE/translation.yml');
93
+ fs.writeFileSync(translationTempaltePath, template);