Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

docs-content.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* eslint-disable */
  2. // HEY! DO NOT MODIFY THIS FILE. THE CONTENTS OF THIS FILE
  3. // ARE AUTO-GENERATED BY A SCRIPT AT: /scripts/docs-gen.js
  4. // ANY CHANGES WILL BE LOST WHEN THE SCRIPT RUNS AGAIN!
  5. export default {
  6. name: 'docs-content.ts',
  7. content: `
  8. Welcome to the documentation for tldraw's code editor. You can use the code editor to create shapes using JavaScript or TypeScript code.
  9. \`\`\`ts
  10. const rect = new Rectangle({
  11. point: [100, 100],
  12. size: [200, 200],
  13. style: {
  14. color: ColorStyle.Blue,
  15. },
  16. })
  17. rect.x = 300
  18. \`\`\`
  19. To run your code, press **Command + S**.
  20. Your new shapes will appear on the canvas. You can interact with code-created shapes just like any other shape: you can move the shape, change its style, delete it, etc.
  21. Each time you run your code, any existing code-created shapes will be replaced by your new code-created shapes. If you want to keep your code-created shapes, select the shapes that you want to keep, press **Command + D** to duplicate them, and move them off to the side.
  22. ## Shapes
  23. You can use the code editor to create any of the regular shapes:
  24. - Draw
  25. - Rectangle
  26. - Ellipse
  27. - Arrow
  28. - Text
  29. You can also create shapes that can _only_ be created with code:
  30. - Dot
  31. - Ray
  32. - Line
  33. - Polyline
  34. Each of these shapes is a \`class\`. To create the shape, use the following syntax:
  35. \`\`\`ts
  36. const myShape = new Rectangle()
  37. \`\`\`
  38. You can also create a shape with custom properties like this:
  39. \`\`\`ts
  40. const myShape = new Rectangle({
  41. point: [100, 100],
  42. size: [200, 200],
  43. style: {
  44. color: ColorStyle.Blue,
  45. size: SizeStyle.Large,
  46. dash: DashStyle.Dotted,
  47. },
  48. })
  49. \`\`\`
  50. Once you've created a shape, you can set its properties like this:
  51. \`\`\`ts
  52. const myShape = new Rectangle()
  53. myShape.x = 100
  54. myShape.color = ColorStyle.Red
  55. \`\`\`
  56. You can find more information on each shape class by clicking its name in the list above.
  57. ## Controls
  58. In addition to shapes, you can also use code to create controls.
  59. \`\`\`ts
  60. new NumberControl({
  61. label: 'x',
  62. value: 0,
  63. })
  64. const myShape = new Rectangle({
  65. point: [controls.x, 0],
  66. })
  67. \`\`\`
  68. Once you've created a control, the app's will display a panel where you can edit the control's value. As you edit the value, your code will run again with the control's new value.
  69. There are two kinds of controls:
  70. - NumberControl
  71. - VectorControl
  72. - TextControl
  73. Each of these controls is a \`class\`. To create the control, use the following syntax:
  74. \`\`\`ts
  75. const control = new TextControl({
  76. label: 'myLabel',
  77. value: 'my value',
  78. })
  79. \`\`\`
  80. Once you've created a control, you can use its value in your code like this:
  81. \`\`\`ts
  82. const myShape = new Text({
  83. text: controls.myLabel,
  84. })
  85. \`\`\`
  86. You can find more information on each control class by clicking its name in the list above.
  87. ## Shape Classes
  88. ...
  89. ## Control Classes
  90. ...
  91. `,
  92. }