@bigbluebutton/tlschema 2.0.0-alpha.19

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 (261) hide show
  1. package/LICENSE +190 -0
  2. package/dist-cjs/TLStore.js +133 -0
  3. package/dist-cjs/TLStore.js.map +7 -0
  4. package/dist-cjs/assets/TLBaseAsset.js +37 -0
  5. package/dist-cjs/assets/TLBaseAsset.js.map +7 -0
  6. package/dist-cjs/assets/TLBookmarkAsset.js +38 -0
  7. package/dist-cjs/assets/TLBookmarkAsset.js.map +7 -0
  8. package/dist-cjs/assets/TLImageAsset.js +76 -0
  9. package/dist-cjs/assets/TLImageAsset.js.map +7 -0
  10. package/dist-cjs/assets/TLVideoAsset.js +76 -0
  11. package/dist-cjs/assets/TLVideoAsset.js.map +7 -0
  12. package/dist-cjs/createPresenceStateDerivation.js +68 -0
  13. package/dist-cjs/createPresenceStateDerivation.js.map +7 -0
  14. package/dist-cjs/createTLSchema.js +68 -0
  15. package/dist-cjs/createTLSchema.js.map +7 -0
  16. package/dist-cjs/index.d.ts +1414 -0
  17. package/dist-cjs/index.js +142 -0
  18. package/dist-cjs/index.js.map +7 -0
  19. package/dist-cjs/misc/TLColor.js +36 -0
  20. package/dist-cjs/misc/TLColor.js.map +7 -0
  21. package/dist-cjs/misc/TLCursor.js +55 -0
  22. package/dist-cjs/misc/TLCursor.js.map +7 -0
  23. package/dist-cjs/misc/TLHandle.js +36 -0
  24. package/dist-cjs/misc/TLHandle.js.map +7 -0
  25. package/dist-cjs/misc/TLOpacity.js +30 -0
  26. package/dist-cjs/misc/TLOpacity.js.map +7 -0
  27. package/dist-cjs/misc/TLScribble.js +40 -0
  28. package/dist-cjs/misc/TLScribble.js.map +7 -0
  29. package/dist-cjs/misc/geometry-types.js +37 -0
  30. package/dist-cjs/misc/geometry-types.js.map +7 -0
  31. package/dist-cjs/misc/id-validator.js +33 -0
  32. package/dist-cjs/misc/id-validator.js.map +7 -0
  33. package/dist-cjs/records/TLAsset.js +74 -0
  34. package/dist-cjs/records/TLAsset.js.map +7 -0
  35. package/dist-cjs/records/TLCamera.js +74 -0
  36. package/dist-cjs/records/TLCamera.js.map +7 -0
  37. package/dist-cjs/records/TLDocument.js +82 -0
  38. package/dist-cjs/records/TLDocument.js.map +7 -0
  39. package/dist-cjs/records/TLInstance.js +452 -0
  40. package/dist-cjs/records/TLInstance.js.map +7 -0
  41. package/dist-cjs/records/TLPage.js +74 -0
  42. package/dist-cjs/records/TLPage.js.map +7 -0
  43. package/dist-cjs/records/TLPageState.js +209 -0
  44. package/dist-cjs/records/TLPageState.js.map +7 -0
  45. package/dist-cjs/records/TLPointer.js +76 -0
  46. package/dist-cjs/records/TLPointer.js.map +7 -0
  47. package/dist-cjs/records/TLPresence.js +170 -0
  48. package/dist-cjs/records/TLPresence.js.map +7 -0
  49. package/dist-cjs/records/TLRecord.js +17 -0
  50. package/dist-cjs/records/TLRecord.js.map +7 -0
  51. package/dist-cjs/records/TLShape.js +147 -0
  52. package/dist-cjs/records/TLShape.js.map +7 -0
  53. package/dist-cjs/shapes/TLArrowShape.js +156 -0
  54. package/dist-cjs/shapes/TLArrowShape.js.map +7 -0
  55. package/dist-cjs/shapes/TLBaseShape.js +52 -0
  56. package/dist-cjs/shapes/TLBaseShape.js.map +7 -0
  57. package/dist-cjs/shapes/TLBookmarkShape.js +57 -0
  58. package/dist-cjs/shapes/TLBookmarkShape.js.map +7 -0
  59. package/dist-cjs/shapes/TLDrawShape.js +89 -0
  60. package/dist-cjs/shapes/TLDrawShape.js.map +7 -0
  61. package/dist-cjs/shapes/TLEmbedShape.js +709 -0
  62. package/dist-cjs/shapes/TLEmbedShape.js.map +7 -0
  63. package/dist-cjs/shapes/TLFrameShape.js +33 -0
  64. package/dist-cjs/shapes/TLFrameShape.js.map +7 -0
  65. package/dist-cjs/shapes/TLGeoShape.js +230 -0
  66. package/dist-cjs/shapes/TLGeoShape.js.map +7 -0
  67. package/dist-cjs/shapes/TLGroupShape.js +28 -0
  68. package/dist-cjs/shapes/TLGroupShape.js.map +7 -0
  69. package/dist-cjs/shapes/TLHighlightShape.js +38 -0
  70. package/dist-cjs/shapes/TLHighlightShape.js.map +7 -0
  71. package/dist-cjs/shapes/TLImageShape.js +69 -0
  72. package/dist-cjs/shapes/TLImageShape.js.map +7 -0
  73. package/dist-cjs/shapes/TLLineShape.js +70 -0
  74. package/dist-cjs/shapes/TLLineShape.js.map +7 -0
  75. package/dist-cjs/shapes/TLNoteShape.js +144 -0
  76. package/dist-cjs/shapes/TLNoteShape.js.map +7 -0
  77. package/dist-cjs/shapes/TLTextShape.js +67 -0
  78. package/dist-cjs/shapes/TLTextShape.js.map +7 -0
  79. package/dist-cjs/shapes/TLVideoShape.js +53 -0
  80. package/dist-cjs/shapes/TLVideoShape.js.map +7 -0
  81. package/dist-cjs/store-migrations.js +81 -0
  82. package/dist-cjs/store-migrations.js.map +7 -0
  83. package/dist-cjs/styles/StyleProp.js +94 -0
  84. package/dist-cjs/styles/StyleProp.js.map +7 -0
  85. package/dist-cjs/styles/TLColorStyle.js +283 -0
  86. package/dist-cjs/styles/TLColorStyle.js.map +7 -0
  87. package/dist-cjs/styles/TLDashStyle.js +29 -0
  88. package/dist-cjs/styles/TLDashStyle.js.map +7 -0
  89. package/dist-cjs/styles/TLFillStyle.js +29 -0
  90. package/dist-cjs/styles/TLFillStyle.js.map +7 -0
  91. package/dist-cjs/styles/TLFontStyle.js +36 -0
  92. package/dist-cjs/styles/TLFontStyle.js.map +7 -0
  93. package/dist-cjs/styles/TLHorizontalAlignStyle.js +29 -0
  94. package/dist-cjs/styles/TLHorizontalAlignStyle.js.map +7 -0
  95. package/dist-cjs/styles/TLSizeStyle.js +29 -0
  96. package/dist-cjs/styles/TLSizeStyle.js.map +7 -0
  97. package/dist-cjs/styles/TLVerticalAlignStyle.js +29 -0
  98. package/dist-cjs/styles/TLVerticalAlignStyle.js.map +7 -0
  99. package/dist-cjs/translations/languages.js +59 -0
  100. package/dist-cjs/translations/languages.js.map +7 -0
  101. package/dist-cjs/translations/translations.js +63 -0
  102. package/dist-cjs/translations/translations.js.map +7 -0
  103. package/dist-cjs/util-types.js +17 -0
  104. package/dist-cjs/util-types.js.map +7 -0
  105. package/dist-esm/TLStore.mjs +113 -0
  106. package/dist-esm/TLStore.mjs.map +7 -0
  107. package/dist-esm/assets/TLBaseAsset.mjs +17 -0
  108. package/dist-esm/assets/TLBaseAsset.mjs.map +7 -0
  109. package/dist-esm/assets/TLBookmarkAsset.mjs +18 -0
  110. package/dist-esm/assets/TLBookmarkAsset.mjs.map +7 -0
  111. package/dist-esm/assets/TLImageAsset.mjs +56 -0
  112. package/dist-esm/assets/TLImageAsset.mjs.map +7 -0
  113. package/dist-esm/assets/TLVideoAsset.mjs +56 -0
  114. package/dist-esm/assets/TLVideoAsset.mjs.map +7 -0
  115. package/dist-esm/createPresenceStateDerivation.mjs +48 -0
  116. package/dist-esm/createPresenceStateDerivation.mjs.map +7 -0
  117. package/dist-esm/createTLSchema.mjs +48 -0
  118. package/dist-esm/createTLSchema.mjs.map +7 -0
  119. package/dist-esm/index.d.mts +1414 -0
  120. package/dist-esm/index.mjs +193 -0
  121. package/dist-esm/index.mjs.map +7 -0
  122. package/dist-esm/misc/TLColor.mjs +16 -0
  123. package/dist-esm/misc/TLColor.mjs.map +7 -0
  124. package/dist-esm/misc/TLCursor.mjs +35 -0
  125. package/dist-esm/misc/TLCursor.mjs.map +7 -0
  126. package/dist-esm/misc/TLHandle.mjs +16 -0
  127. package/dist-esm/misc/TLHandle.mjs.map +7 -0
  128. package/dist-esm/misc/TLOpacity.mjs +10 -0
  129. package/dist-esm/misc/TLOpacity.mjs.map +7 -0
  130. package/dist-esm/misc/TLScribble.mjs +20 -0
  131. package/dist-esm/misc/TLScribble.mjs.map +7 -0
  132. package/dist-esm/misc/geometry-types.mjs +17 -0
  133. package/dist-esm/misc/geometry-types.mjs.map +7 -0
  134. package/dist-esm/misc/id-validator.mjs +13 -0
  135. package/dist-esm/misc/id-validator.mjs.map +7 -0
  136. package/dist-esm/records/TLAsset.mjs +57 -0
  137. package/dist-esm/records/TLAsset.mjs.map +7 -0
  138. package/dist-esm/records/TLCamera.mjs +54 -0
  139. package/dist-esm/records/TLCamera.mjs.map +7 -0
  140. package/dist-esm/records/TLDocument.mjs +62 -0
  141. package/dist-esm/records/TLDocument.mjs.map +7 -0
  142. package/dist-esm/records/TLInstance.mjs +432 -0
  143. package/dist-esm/records/TLInstance.mjs.map +7 -0
  144. package/dist-esm/records/TLPage.mjs +54 -0
  145. package/dist-esm/records/TLPage.mjs.map +7 -0
  146. package/dist-esm/records/TLPageState.mjs +189 -0
  147. package/dist-esm/records/TLPageState.mjs.map +7 -0
  148. package/dist-esm/records/TLPointer.mjs +56 -0
  149. package/dist-esm/records/TLPointer.mjs.map +7 -0
  150. package/dist-esm/records/TLPresence.mjs +150 -0
  151. package/dist-esm/records/TLPresence.mjs.map +7 -0
  152. package/dist-esm/records/TLRecord.mjs +1 -0
  153. package/dist-esm/records/TLRecord.mjs.map +7 -0
  154. package/dist-esm/records/TLShape.mjs +127 -0
  155. package/dist-esm/records/TLShape.mjs.map +7 -0
  156. package/dist-esm/shapes/TLArrowShape.mjs +136 -0
  157. package/dist-esm/shapes/TLArrowShape.mjs.map +7 -0
  158. package/dist-esm/shapes/TLBaseShape.mjs +32 -0
  159. package/dist-esm/shapes/TLBaseShape.mjs.map +7 -0
  160. package/dist-esm/shapes/TLBookmarkShape.mjs +37 -0
  161. package/dist-esm/shapes/TLBookmarkShape.mjs.map +7 -0
  162. package/dist-esm/shapes/TLDrawShape.mjs +69 -0
  163. package/dist-esm/shapes/TLDrawShape.mjs.map +7 -0
  164. package/dist-esm/shapes/TLEmbedShape.mjs +689 -0
  165. package/dist-esm/shapes/TLEmbedShape.mjs.map +7 -0
  166. package/dist-esm/shapes/TLFrameShape.mjs +13 -0
  167. package/dist-esm/shapes/TLFrameShape.mjs.map +7 -0
  168. package/dist-esm/shapes/TLGeoShape.mjs +212 -0
  169. package/dist-esm/shapes/TLGeoShape.mjs.map +7 -0
  170. package/dist-esm/shapes/TLGroupShape.mjs +8 -0
  171. package/dist-esm/shapes/TLGroupShape.mjs.map +7 -0
  172. package/dist-esm/shapes/TLHighlightShape.mjs +18 -0
  173. package/dist-esm/shapes/TLHighlightShape.mjs.map +7 -0
  174. package/dist-esm/shapes/TLImageShape.mjs +49 -0
  175. package/dist-esm/shapes/TLImageShape.mjs.map +7 -0
  176. package/dist-esm/shapes/TLLineShape.mjs +50 -0
  177. package/dist-esm/shapes/TLLineShape.mjs.map +7 -0
  178. package/dist-esm/shapes/TLNoteShape.mjs +126 -0
  179. package/dist-esm/shapes/TLNoteShape.mjs.map +7 -0
  180. package/dist-esm/shapes/TLTextShape.mjs +47 -0
  181. package/dist-esm/shapes/TLTextShape.mjs.map +7 -0
  182. package/dist-esm/shapes/TLVideoShape.mjs +33 -0
  183. package/dist-esm/shapes/TLVideoShape.mjs.map +7 -0
  184. package/dist-esm/store-migrations.mjs +61 -0
  185. package/dist-esm/store-migrations.mjs.map +7 -0
  186. package/dist-esm/styles/StyleProp.mjs +74 -0
  187. package/dist-esm/styles/StyleProp.mjs.map +7 -0
  188. package/dist-esm/styles/TLColorStyle.mjs +263 -0
  189. package/dist-esm/styles/TLColorStyle.mjs.map +7 -0
  190. package/dist-esm/styles/TLDashStyle.mjs +9 -0
  191. package/dist-esm/styles/TLDashStyle.mjs.map +7 -0
  192. package/dist-esm/styles/TLFillStyle.mjs +9 -0
  193. package/dist-esm/styles/TLFillStyle.mjs.map +7 -0
  194. package/dist-esm/styles/TLFontStyle.mjs +16 -0
  195. package/dist-esm/styles/TLFontStyle.mjs.map +7 -0
  196. package/dist-esm/styles/TLHorizontalAlignStyle.mjs +9 -0
  197. package/dist-esm/styles/TLHorizontalAlignStyle.mjs.map +7 -0
  198. package/dist-esm/styles/TLSizeStyle.mjs +9 -0
  199. package/dist-esm/styles/TLSizeStyle.mjs.map +7 -0
  200. package/dist-esm/styles/TLVerticalAlignStyle.mjs +9 -0
  201. package/dist-esm/styles/TLVerticalAlignStyle.mjs.map +7 -0
  202. package/dist-esm/translations/languages.mjs +39 -0
  203. package/dist-esm/translations/languages.mjs.map +7 -0
  204. package/dist-esm/translations/translations.mjs +43 -0
  205. package/dist-esm/translations/translations.mjs.map +7 -0
  206. package/dist-esm/util-types.mjs +1 -0
  207. package/dist-esm/util-types.mjs.map +7 -0
  208. package/package.json +64 -0
  209. package/src/TLStore.ts +160 -0
  210. package/src/assets/TLBaseAsset.ts +44 -0
  211. package/src/assets/TLBookmarkAsset.ts +31 -0
  212. package/src/assets/TLImageAsset.ts +73 -0
  213. package/src/assets/TLVideoAsset.ts +73 -0
  214. package/src/createPresenceStateDerivation.ts +53 -0
  215. package/src/createTLSchema.ts +65 -0
  216. package/src/index.ts +168 -0
  217. package/src/migrations.test.ts +1768 -0
  218. package/src/misc/TLColor.ts +28 -0
  219. package/src/misc/TLCursor.ts +54 -0
  220. package/src/misc/TLHandle.ts +41 -0
  221. package/src/misc/TLOpacity.ts +11 -0
  222. package/src/misc/TLScribble.ts +39 -0
  223. package/src/misc/geometry-types.ts +37 -0
  224. package/src/misc/id-validator.ts +14 -0
  225. package/src/records/TLAsset.ts +80 -0
  226. package/src/records/TLCamera.ts +74 -0
  227. package/src/records/TLDocument.ts +77 -0
  228. package/src/records/TLInstance.ts +493 -0
  229. package/src/records/TLPage.ts +72 -0
  230. package/src/records/TLPageState.ts +216 -0
  231. package/src/records/TLPointer.ts +74 -0
  232. package/src/records/TLPresence.ts +179 -0
  233. package/src/records/TLRecord.ts +21 -0
  234. package/src/records/TLShape.ts +214 -0
  235. package/src/shapes/TLArrowShape.ts +160 -0
  236. package/src/shapes/TLBaseShape.ts +67 -0
  237. package/src/shapes/TLBookmarkShape.ts +44 -0
  238. package/src/shapes/TLDrawShape.ts +89 -0
  239. package/src/shapes/TLEmbedShape.ts +754 -0
  240. package/src/shapes/TLFrameShape.ts +18 -0
  241. package/src/shapes/TLGeoShape.ts +226 -0
  242. package/src/shapes/TLGroupShape.ts +14 -0
  243. package/src/shapes/TLHighlightShape.ts +24 -0
  244. package/src/shapes/TLImageShape.ts +59 -0
  245. package/src/shapes/TLLineShape.ts +61 -0
  246. package/src/shapes/TLNoteShape.ts +137 -0
  247. package/src/shapes/TLTextShape.ts +55 -0
  248. package/src/shapes/TLVideoShape.ts +40 -0
  249. package/src/store-migrations.ts +63 -0
  250. package/src/styles/StyleProp.ts +105 -0
  251. package/src/styles/TLColorStyle.ts +296 -0
  252. package/src/styles/TLDashStyle.ts +11 -0
  253. package/src/styles/TLFillStyle.ts +11 -0
  254. package/src/styles/TLFontStyle.ts +19 -0
  255. package/src/styles/TLHorizontalAlignStyle.ts +11 -0
  256. package/src/styles/TLSizeStyle.ts +11 -0
  257. package/src/styles/TLVerticalAlignStyle.ts +11 -0
  258. package/src/translations/languages.ts +39 -0
  259. package/src/translations/translations.test.ts +43 -0
  260. package/src/translations/translations.ts +73 -0
  261. package/src/util-types.ts +2 -0
@@ -0,0 +1,216 @@
1
+ import { BaseRecord, createRecordType, defineMigrations, RecordId } from '@bigbluebutton/store'
2
+ import { JsonObject } from '@bigbluebutton/utils'
3
+ import { T } from '@bigbluebutton/validate'
4
+ import { idValidator } from '../misc/id-validator'
5
+ import { shapeIdValidator } from '../shapes/TLBaseShape'
6
+ import { CameraRecordType } from './TLCamera'
7
+ import { TLINSTANCE_ID } from './TLInstance'
8
+ import { pageIdValidator, TLPage } from './TLPage'
9
+ import { TLShapeId } from './TLShape'
10
+
11
+ /**
12
+ * TLInstancePageState
13
+ *
14
+ * State that is unique to a particular page of the document in a particular browser tab
15
+ *
16
+ * @public
17
+ */
18
+ export interface TLInstancePageState
19
+ extends BaseRecord<'instance_page_state', TLInstancePageStateId> {
20
+ pageId: RecordId<TLPage>
21
+ selectedShapeIds: TLShapeId[]
22
+ hintingShapeIds: TLShapeId[]
23
+ erasingShapeIds: TLShapeId[]
24
+ hoveredShapeId: TLShapeId | null
25
+ editingShapeId: TLShapeId | null
26
+ croppingShapeId: TLShapeId | null
27
+ focusedGroupId: TLShapeId | null
28
+ meta: JsonObject
29
+ }
30
+
31
+ /** @internal */
32
+ export const instancePageStateValidator: T.Validator<TLInstancePageState> = T.model(
33
+ 'instance_page_state',
34
+ T.object({
35
+ typeName: T.literal('instance_page_state'),
36
+ id: idValidator<TLInstancePageStateId>('instance_page_state'),
37
+ pageId: pageIdValidator,
38
+ selectedShapeIds: T.arrayOf(shapeIdValidator),
39
+ hintingShapeIds: T.arrayOf(shapeIdValidator),
40
+ erasingShapeIds: T.arrayOf(shapeIdValidator),
41
+ hoveredShapeId: shapeIdValidator.nullable(),
42
+ editingShapeId: shapeIdValidator.nullable(),
43
+ croppingShapeId: shapeIdValidator.nullable(),
44
+ focusedGroupId: shapeIdValidator.nullable(),
45
+ meta: T.jsonValue as T.ObjectValidator<JsonObject>,
46
+ })
47
+ )
48
+
49
+ /** @internal */
50
+ export const instancePageStateVersions = {
51
+ AddCroppingId: 1,
52
+ RemoveInstanceIdAndCameraId: 2,
53
+ AddMeta: 3,
54
+ RenameProperties: 4,
55
+ RenamePropertiesAgain: 5,
56
+ } as const
57
+
58
+ /** @public */
59
+ export const instancePageStateMigrations = defineMigrations({
60
+ currentVersion: instancePageStateVersions.RenamePropertiesAgain,
61
+ migrators: {
62
+ [instancePageStateVersions.AddCroppingId]: {
63
+ up(instance) {
64
+ return { ...instance, croppingShapeId: null }
65
+ },
66
+ down({ croppingShapeId: _croppingShapeId, ...instance }) {
67
+ return instance
68
+ },
69
+ },
70
+ [instancePageStateVersions.RemoveInstanceIdAndCameraId]: {
71
+ up({ instanceId: _, cameraId: __, ...instance }) {
72
+ return instance
73
+ },
74
+ down(instance) {
75
+ // this should never be called since we bump the schema version
76
+ return {
77
+ ...instance,
78
+ instanceId: TLINSTANCE_ID,
79
+ cameraId: CameraRecordType.createId('void'),
80
+ }
81
+ },
82
+ },
83
+ [instancePageStateVersions.AddMeta]: {
84
+ up: (record) => {
85
+ return {
86
+ ...record,
87
+ meta: {},
88
+ }
89
+ },
90
+ down: ({ meta: _, ...record }) => {
91
+ return {
92
+ ...record,
93
+ }
94
+ },
95
+ },
96
+ [instancePageStateVersions.RenameProperties]: {
97
+ // this migration is cursed: it was written wrong and doesn't do anything.
98
+ // rather than replace it, I've added another migration below that fixes it.
99
+ up: (record) => {
100
+ const {
101
+ selectedShapeIds,
102
+ hintingShapeIds,
103
+ erasingShapeIds,
104
+ hoveredShapeId,
105
+ editingShapeId,
106
+ croppingShapeId,
107
+ focusedGroupId,
108
+ ...rest
109
+ } = record
110
+ return {
111
+ selectedShapeIds: selectedShapeIds,
112
+ hintingShapeIds: hintingShapeIds,
113
+ erasingShapeIds: erasingShapeIds,
114
+ hoveredShapeId: hoveredShapeId,
115
+ editingShapeId: editingShapeId,
116
+ croppingShapeId: croppingShapeId,
117
+ focusedGroupId: focusedGroupId,
118
+ ...rest,
119
+ }
120
+ },
121
+ down: (record) => {
122
+ const {
123
+ selectedShapeIds,
124
+ hintingShapeIds,
125
+ erasingShapeIds,
126
+ hoveredShapeId,
127
+ editingShapeId,
128
+ croppingShapeId,
129
+ focusedGroupId,
130
+ ...rest
131
+ } = record
132
+ return {
133
+ selectedShapeIds: selectedShapeIds,
134
+ hintingShapeIds: hintingShapeIds,
135
+ erasingShapeIds: erasingShapeIds,
136
+ hoveredShapeId: hoveredShapeId,
137
+ editingShapeId: editingShapeId,
138
+ croppingShapeId: croppingShapeId,
139
+ focusedGroupId: focusedGroupId,
140
+ ...rest,
141
+ }
142
+ },
143
+ },
144
+ [instancePageStateVersions.RenamePropertiesAgain]: {
145
+ up: (record) => {
146
+ const {
147
+ selectedIds,
148
+ hintingIds,
149
+ erasingIds,
150
+ hoveredId,
151
+ editingId,
152
+ croppingShapeId,
153
+ croppingId,
154
+ focusLayerId,
155
+ ...rest
156
+ } = record
157
+ return {
158
+ ...rest,
159
+ selectedShapeIds: selectedIds,
160
+ hintingShapeIds: hintingIds,
161
+ erasingShapeIds: erasingIds,
162
+ hoveredShapeId: hoveredId,
163
+ editingShapeId: editingId,
164
+ croppingShapeId: croppingShapeId ?? croppingId ?? null,
165
+ focusedGroupId: focusLayerId,
166
+ }
167
+ },
168
+ down: (record) => {
169
+ const {
170
+ selectedShapeIds,
171
+ hintingShapeIds,
172
+ erasingShapeIds,
173
+ hoveredShapeId,
174
+ editingShapeId,
175
+ croppingShapeId,
176
+ focusedGroupId,
177
+ ...rest
178
+ } = record
179
+ return {
180
+ ...rest,
181
+ selectedIds: selectedShapeIds,
182
+ hintingIds: hintingShapeIds,
183
+ erasingIds: erasingShapeIds,
184
+ hoveredId: hoveredShapeId,
185
+ editingId: editingShapeId,
186
+ croppingId: croppingShapeId,
187
+ focusLayerId: focusedGroupId,
188
+ }
189
+ },
190
+ },
191
+ },
192
+ })
193
+
194
+ /** @public */
195
+ export const InstancePageStateRecordType = createRecordType<TLInstancePageState>(
196
+ 'instance_page_state',
197
+ {
198
+ migrations: instancePageStateMigrations,
199
+ validator: instancePageStateValidator,
200
+ scope: 'session',
201
+ }
202
+ ).withDefaultProperties(
203
+ (): Omit<TLInstancePageState, 'id' | 'typeName' | 'pageId'> => ({
204
+ editingShapeId: null,
205
+ croppingShapeId: null,
206
+ selectedShapeIds: [],
207
+ hoveredShapeId: null,
208
+ erasingShapeIds: [],
209
+ hintingShapeIds: [],
210
+ focusedGroupId: null,
211
+ meta: {},
212
+ })
213
+ )
214
+
215
+ /** @public */
216
+ export type TLInstancePageStateId = RecordId<TLInstancePageState>
@@ -0,0 +1,74 @@
1
+ import { BaseRecord, createRecordType, defineMigrations, RecordId } from '@bigbluebutton/store'
2
+ import { JsonObject } from '@bigbluebutton/utils'
3
+ import { T } from '@bigbluebutton/validate'
4
+ import { idValidator } from '../misc/id-validator'
5
+
6
+ /**
7
+ * TLPointer
8
+ *
9
+ * @public
10
+ */
11
+ export interface TLPointer extends BaseRecord<'pointer', TLPointerId> {
12
+ x: number
13
+ y: number
14
+ lastActivityTimestamp: number
15
+ meta: JsonObject
16
+ }
17
+
18
+ /** @public */
19
+ export type TLPointerId = RecordId<TLPointer>
20
+
21
+ /** @internal */
22
+ export const pointerValidator: T.Validator<TLPointer> = T.model(
23
+ 'pointer',
24
+ T.object({
25
+ typeName: T.literal('pointer'),
26
+ id: idValidator<TLPointerId>('pointer'),
27
+ x: T.number,
28
+ y: T.number,
29
+ lastActivityTimestamp: T.number,
30
+ meta: T.jsonValue as T.ObjectValidator<JsonObject>,
31
+ })
32
+ )
33
+
34
+ /** @internal */
35
+ export const pointerVersions = {
36
+ AddMeta: 1,
37
+ }
38
+
39
+ /** @internal */
40
+ export const pointerMigrations = defineMigrations({
41
+ currentVersion: pointerVersions.AddMeta,
42
+ migrators: {
43
+ [pointerVersions.AddMeta]: {
44
+ up: (record) => {
45
+ return {
46
+ ...record,
47
+ meta: {},
48
+ }
49
+ },
50
+ down: ({ meta: _, ...record }) => {
51
+ return {
52
+ ...record,
53
+ }
54
+ },
55
+ },
56
+ },
57
+ })
58
+
59
+ /** @public */
60
+ export const PointerRecordType = createRecordType<TLPointer>('pointer', {
61
+ validator: pointerValidator,
62
+ migrations: pointerMigrations,
63
+ scope: 'session',
64
+ }).withDefaultProperties(
65
+ (): Omit<TLPointer, 'id' | 'typeName'> => ({
66
+ x: 0,
67
+ y: 0,
68
+ lastActivityTimestamp: 0,
69
+ meta: {},
70
+ })
71
+ )
72
+
73
+ /** @public */
74
+ export const TLPOINTER_ID = PointerRecordType.createId('pointer')
@@ -0,0 +1,179 @@
1
+ import { BaseRecord, createRecordType, defineMigrations, RecordId } from '@bigbluebutton/store'
2
+ import { JsonObject } from '@bigbluebutton/utils'
3
+ import { T } from '@bigbluebutton/validate'
4
+ import { Box2dModel, box2dModelValidator } from '../misc/geometry-types'
5
+ import { idValidator } from '../misc/id-validator'
6
+ import { cursorTypeValidator, TLCursor } from '../misc/TLCursor'
7
+ import { scribbleValidator, TLScribble } from '../misc/TLScribble'
8
+ import { TLINSTANCE_ID } from './TLInstance'
9
+ import { TLPageId } from './TLPage'
10
+ import { TLShapeId } from './TLShape'
11
+
12
+ /** @public */
13
+ export interface TLInstancePresence extends BaseRecord<'instance_presence', TLInstancePresenceID> {
14
+ userId: string
15
+ userName: string
16
+ lastActivityTimestamp: number
17
+ color: string // can be any hex color
18
+ camera: { x: number; y: number; z: number }
19
+ selectedShapeIds: TLShapeId[]
20
+ currentPageId: TLPageId
21
+ brush: Box2dModel | null
22
+ scribbles: TLScribble[]
23
+ screenBounds: Box2dModel
24
+ followingUserId: string | null
25
+ cursor: {
26
+ x: number
27
+ y: number
28
+ type: TLCursor['type']
29
+ rotation: number
30
+ }
31
+ chatMessage: string
32
+ meta: JsonObject
33
+ }
34
+
35
+ /** @public */
36
+ export type TLInstancePresenceID = RecordId<TLInstancePresence>
37
+
38
+ /** @internal */
39
+ export const instancePresenceValidator: T.Validator<TLInstancePresence> = T.model(
40
+ 'instance_presence',
41
+ T.object({
42
+ typeName: T.literal('instance_presence'),
43
+ id: idValidator<TLInstancePresenceID>('instance_presence'),
44
+ userId: T.string,
45
+ userName: T.string,
46
+ lastActivityTimestamp: T.number,
47
+ followingUserId: T.string.nullable(),
48
+ cursor: T.object({
49
+ x: T.number,
50
+ y: T.number,
51
+ type: cursorTypeValidator,
52
+ rotation: T.number,
53
+ }),
54
+ color: T.string,
55
+ camera: T.object({
56
+ x: T.number,
57
+ y: T.number,
58
+ z: T.number,
59
+ }),
60
+ screenBounds: box2dModelValidator,
61
+ selectedShapeIds: T.arrayOf(idValidator<TLShapeId>('shape')),
62
+ currentPageId: idValidator<TLPageId>('page'),
63
+ brush: box2dModelValidator.nullable(),
64
+ scribbles: T.arrayOf(scribbleValidator),
65
+ chatMessage: T.string,
66
+ meta: T.jsonValue as T.ObjectValidator<JsonObject>,
67
+ })
68
+ )
69
+
70
+ /** @internal */
71
+ export const instancePresenceVersions = {
72
+ AddScribbleDelay: 1,
73
+ RemoveInstanceId: 2,
74
+ AddChatMessage: 3,
75
+ AddMeta: 4,
76
+ RenameSelectedShapeIds: 5,
77
+ } as const
78
+
79
+ export const instancePresenceMigrations = defineMigrations({
80
+ currentVersion: instancePresenceVersions.RenameSelectedShapeIds,
81
+ migrators: {
82
+ [instancePresenceVersions.AddScribbleDelay]: {
83
+ up: (instance) => {
84
+ if (instance.scribble !== null) {
85
+ return { ...instance, scribble: { ...instance.scribble, delay: 0 } }
86
+ }
87
+ return { ...instance }
88
+ },
89
+ down: (instance) => {
90
+ if (instance.scribble !== null) {
91
+ const { delay: _delay, ...rest } = instance.scribble
92
+ return { ...instance, scribble: rest }
93
+ }
94
+ return { ...instance }
95
+ },
96
+ },
97
+ [instancePresenceVersions.RemoveInstanceId]: {
98
+ up: ({ instanceId: _, ...instance }) => {
99
+ return instance
100
+ },
101
+ down: (instance) => {
102
+ return { ...instance, instanceId: TLINSTANCE_ID }
103
+ },
104
+ },
105
+ [instancePresenceVersions.AddChatMessage]: {
106
+ up: (instance) => {
107
+ return { ...instance, chatMessage: '' }
108
+ },
109
+ down: ({ chatMessage: _, ...instance }) => {
110
+ return instance
111
+ },
112
+ },
113
+ [instancePresenceVersions.AddMeta]: {
114
+ up: (record) => {
115
+ return {
116
+ ...record,
117
+ meta: {},
118
+ }
119
+ },
120
+ down: ({ meta: _, ...record }) => {
121
+ return {
122
+ ...record,
123
+ }
124
+ },
125
+ },
126
+ [instancePresenceVersions.RenameSelectedShapeIds]: {
127
+ up: (record) => {
128
+ const { selectedShapeIds, ...rest } = record
129
+ return {
130
+ selectedShapeIds: selectedShapeIds,
131
+ ...rest,
132
+ }
133
+ },
134
+ down: (record) => {
135
+ const { selectedShapeIds, ...rest } = record
136
+ return {
137
+ selectedShapeIds: selectedShapeIds,
138
+ ...rest,
139
+ }
140
+ },
141
+ },
142
+ },
143
+ })
144
+
145
+ /** @public */
146
+ export const InstancePresenceRecordType = createRecordType<TLInstancePresence>(
147
+ 'instance_presence',
148
+ {
149
+ migrations: instancePresenceMigrations,
150
+ validator: instancePresenceValidator,
151
+ scope: 'presence',
152
+ }
153
+ ).withDefaultProperties(() => ({
154
+ lastActivityTimestamp: 0,
155
+ followingUserId: null,
156
+ color: '#FF0000',
157
+ camera: {
158
+ x: 0,
159
+ y: 0,
160
+ z: 1,
161
+ },
162
+ cursor: {
163
+ x: 0,
164
+ y: 0,
165
+ type: 'default',
166
+ rotation: 0,
167
+ },
168
+ screenBounds: {
169
+ x: 0,
170
+ y: 0,
171
+ w: 1,
172
+ h: 1,
173
+ },
174
+ selectedShapeIds: [],
175
+ brush: null,
176
+ scribbles: [],
177
+ chatMessage: '',
178
+ meta: {},
179
+ }))
@@ -0,0 +1,21 @@
1
+ import { TLAsset } from './TLAsset'
2
+ import { TLCamera } from './TLCamera'
3
+ import { TLDocument } from './TLDocument'
4
+ import { TLInstance } from './TLInstance'
5
+ import { TLPage } from './TLPage'
6
+ import { TLInstancePageState } from './TLPageState'
7
+ import { TLPointer } from './TLPointer'
8
+ import { TLInstancePresence } from './TLPresence'
9
+ import { TLShape } from './TLShape'
10
+
11
+ /** @public */
12
+ export type TLRecord =
13
+ | TLAsset
14
+ | TLCamera
15
+ | TLDocument
16
+ | TLInstance
17
+ | TLInstancePageState
18
+ | TLPage
19
+ | TLShape
20
+ | TLInstancePresence
21
+ | TLPointer
@@ -0,0 +1,214 @@
1
+ import { createRecordType, defineMigrations, RecordId, UnknownRecord } from '@bigbluebutton/store'
2
+ import { mapObjectMapValues } from '@bigbluebutton/utils'
3
+ import { T } from '@bigbluebutton/validate'
4
+ import { nanoid } from 'nanoid'
5
+ import { SchemaShapeInfo } from '../createTLSchema'
6
+ import { TLArrowShape } from '../shapes/TLArrowShape'
7
+ import { createShapeValidator, TLBaseShape } from '../shapes/TLBaseShape'
8
+ import { TLBookmarkShape } from '../shapes/TLBookmarkShape'
9
+ import { TLDrawShape } from '../shapes/TLDrawShape'
10
+ import { TLEmbedShape } from '../shapes/TLEmbedShape'
11
+ import { TLFrameShape } from '../shapes/TLFrameShape'
12
+ import { TLGeoShape } from '../shapes/TLGeoShape'
13
+ import { TLGroupShape } from '../shapes/TLGroupShape'
14
+ import { TLHighlightShape } from '../shapes/TLHighlightShape'
15
+ import { TLImageShape } from '../shapes/TLImageShape'
16
+ import { TLLineShape } from '../shapes/TLLineShape'
17
+ import { TLNoteShape } from '../shapes/TLNoteShape'
18
+ import { TLTextShape } from '../shapes/TLTextShape'
19
+ import { TLVideoShape } from '../shapes/TLVideoShape'
20
+ import { StyleProp } from '../styles/StyleProp'
21
+ import { TLPageId } from './TLPage'
22
+
23
+ /**
24
+ * The default set of shapes that are available in the editor.
25
+ *
26
+ * @public */
27
+ export type TLDefaultShape =
28
+ | TLArrowShape
29
+ | TLBookmarkShape
30
+ | TLDrawShape
31
+ | TLEmbedShape
32
+ | TLFrameShape
33
+ | TLGeoShape
34
+ | TLGroupShape
35
+ | TLImageShape
36
+ | TLLineShape
37
+ | TLNoteShape
38
+ | TLTextShape
39
+ | TLVideoShape
40
+ | TLHighlightShape
41
+
42
+ /**
43
+ * A type for a shape that is available in the editor but whose type is
44
+ * unknown—either one of the editor's default shapes or else a custom shape.
45
+ *
46
+ * @public */
47
+ export type TLUnknownShape = TLBaseShape<string, object>
48
+
49
+ /**
50
+ * The set of all shapes that are available in the editor, including unknown shapes.
51
+ *
52
+ * @public
53
+ */
54
+ export type TLShape = TLDefaultShape | TLUnknownShape
55
+
56
+ /** @public */
57
+ export type TLShapePartial<T extends TLShape = TLShape> = T extends T
58
+ ? {
59
+ id: TLShapeId
60
+ type: T['type']
61
+ props?: Partial<T['props']>
62
+ meta?: Partial<T['meta']>
63
+ } & Partial<Omit<T, 'type' | 'id' | 'props' | 'meta'>>
64
+ : never
65
+
66
+ /** @public */
67
+ export type TLShapeId = RecordId<TLUnknownShape>
68
+
69
+ // evil type shit that will get deleted in the next PR
70
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
71
+ ? I
72
+ : never
73
+
74
+ type Identity<T> = { [K in keyof T]: T[K] }
75
+
76
+ /** @public */
77
+ export type TLShapeProps = Identity<UnionToIntersection<TLDefaultShape['props']>>
78
+
79
+ /** @public */
80
+ export type TLShapeProp = keyof TLShapeProps
81
+
82
+ /** @public */
83
+ export type TLParentId = TLPageId | TLShapeId
84
+
85
+ /** @internal */
86
+ export const rootShapeVersions = {
87
+ AddIsLocked: 1,
88
+ HoistOpacity: 2,
89
+ AddMeta: 3,
90
+ } as const
91
+
92
+ /** @internal */
93
+ export const rootShapeMigrations = defineMigrations({
94
+ currentVersion: rootShapeVersions.AddMeta,
95
+ migrators: {
96
+ [rootShapeVersions.AddIsLocked]: {
97
+ up: (record) => {
98
+ return {
99
+ ...record,
100
+ isLocked: false,
101
+ }
102
+ },
103
+ down: (record) => {
104
+ const { isLocked: _, ...rest } = record
105
+ return {
106
+ ...rest,
107
+ }
108
+ },
109
+ },
110
+ [rootShapeVersions.HoistOpacity]: {
111
+ up: ({ props: { opacity, ...props }, ...record }) => {
112
+ return {
113
+ ...record,
114
+ opacity: Number(opacity ?? '1'),
115
+ props,
116
+ }
117
+ },
118
+ down: ({ opacity, ...record }) => {
119
+ return {
120
+ ...record,
121
+ props: {
122
+ ...record.props,
123
+ opacity:
124
+ opacity < 0.175
125
+ ? '0.1'
126
+ : opacity < 0.375
127
+ ? '0.25'
128
+ : opacity < 0.625
129
+ ? '0.5'
130
+ : opacity < 0.875
131
+ ? '0.75'
132
+ : '1',
133
+ },
134
+ }
135
+ },
136
+ },
137
+ [rootShapeVersions.AddMeta]: {
138
+ up: (record) => {
139
+ return {
140
+ ...record,
141
+ meta: {},
142
+ }
143
+ },
144
+ down: ({ meta: _, ...record }) => {
145
+ return {
146
+ ...record,
147
+ }
148
+ },
149
+ },
150
+ },
151
+ })
152
+
153
+ /** @public */
154
+ export function isShape(record?: UnknownRecord): record is TLShape {
155
+ if (!record) return false
156
+ return record.typeName === 'shape'
157
+ }
158
+
159
+ /** @public */
160
+ export function isShapeId(id?: string): id is TLShapeId {
161
+ if (!id) return false
162
+ return id.startsWith('shape:')
163
+ }
164
+
165
+ /** @public */
166
+ export function createShapeId(id?: string): TLShapeId {
167
+ return `shape:${id ?? nanoid()}` as TLShapeId
168
+ }
169
+
170
+ /** @internal */
171
+ export function getShapePropKeysByStyle(props: Record<string, T.Validatable<any>>) {
172
+ const propKeysByStyle = new Map<StyleProp<unknown>, string>()
173
+ for (const [key, prop] of Object.entries(props)) {
174
+ if (prop instanceof StyleProp) {
175
+ if (propKeysByStyle.has(prop)) {
176
+ throw new Error(
177
+ `Duplicate style prop ${prop.id}. Each style prop can only be used once within a shape.`
178
+ )
179
+ }
180
+ propKeysByStyle.set(prop, key)
181
+ }
182
+ }
183
+ return propKeysByStyle
184
+ }
185
+
186
+ /** @internal */
187
+ export function createShapeRecordType(shapes: Record<string, SchemaShapeInfo>) {
188
+ return createRecordType<TLShape>('shape', {
189
+ migrations: defineMigrations({
190
+ currentVersion: rootShapeMigrations.currentVersion,
191
+ firstVersion: rootShapeMigrations.firstVersion,
192
+ migrators: rootShapeMigrations.migrators,
193
+ subTypeKey: 'type',
194
+ subTypeMigrations: mapObjectMapValues(shapes, (_, v) => v.migrations ?? defineMigrations({})),
195
+ }),
196
+ scope: 'document',
197
+ validator: T.model(
198
+ 'shape',
199
+ T.union(
200
+ 'type',
201
+ mapObjectMapValues(shapes, (type, { props, meta }) =>
202
+ createShapeValidator(type, props, meta)
203
+ )
204
+ )
205
+ ),
206
+ }).withDefaultProperties(() => ({
207
+ x: 0,
208
+ y: 0,
209
+ rotation: 0,
210
+ isLocked: false,
211
+ opacity: 1,
212
+ meta: {},
213
+ }))
214
+ }