@tldraw/editor 3.11.0-canary.f529c521e249 → 3.11.0
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 +93 -2
- package/dist-cjs/index.d.ts +23 -9
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +4 -4
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +34 -26
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
- package/dist-cjs/lib/config/TLUserPreferences.js.map +1 -1
- package/dist-cjs/lib/config/createTLStore.js +2 -1
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/constants.js +1 -1
- package/dist-cjs/lib/constants.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +18 -14
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager.js +15 -0
- package/dist-cjs/lib/editor/managers/FocusManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager.js +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/exports/StyleEmbedder.js +16 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/exportToSvg.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/exports/parseCss.js +27 -2
- package/dist-cjs/lib/exports/parseCss.js.map +2 -2
- package/dist-cjs/lib/hooks/useLocalStore.js +3 -0
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +7 -1
- package/dist-cjs/lib/license/Watermark.js.map +2 -2
- package/dist-cjs/lib/options.js +2 -1
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +8 -0
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +23 -9
- package/dist-esm/index.mjs +4 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +4 -4
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +34 -26
- package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +1 -1
- package/dist-esm/lib/config/createTLStore.mjs +2 -1
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/constants.mjs +1 -1
- package/dist-esm/lib/constants.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +18 -14
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager.mjs +15 -0
- package/dist-esm/lib/editor/managers/FocusManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +22 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/exportToSvg.mjs.map +1 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs +1 -1
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/exports/parseCss.mjs +27 -2
- package/dist-esm/lib/exports/parseCss.mjs.map +2 -2
- package/dist-esm/lib/hooks/useLocalStore.mjs +3 -0
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +7 -1
- package/dist-esm/lib/license/Watermark.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +2 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +8 -0
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +11 -1
- package/package.json +10 -7
- package/src/index.ts +4 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +4 -4
- package/src/lib/components/default-components/DefaultShapeIndicators.tsx +52 -31
- package/src/lib/config/TLUserPreferences.ts +1 -1
- package/src/lib/config/createTLStore.ts +1 -0
- package/src/lib/constants.ts +1 -1
- package/src/lib/editor/Editor.ts +20 -17
- package/src/lib/editor/managers/FocusManager.ts +18 -0
- package/src/lib/editor/managers/UserPreferencesManager.ts +1 -1
- package/src/lib/exports/StyleEmbedder.ts +23 -4
- package/src/lib/exports/exportToSvg.tsx +1 -1
- package/src/lib/exports/getSvgJsx.tsx +1 -1
- package/src/lib/exports/parseCss.ts +36 -2
- package/src/lib/hooks/useLocalStore.ts +3 -0
- package/src/lib/license/Watermark.tsx +7 -1
- package/src/lib/options.ts +6 -0
- package/src/lib/utils/sync/LocalIndexedDb.ts +9 -0
- package/src/version.ts +3 -3
|
@@ -7,7 +7,12 @@ import {
|
|
|
7
7
|
getRenderedChildren,
|
|
8
8
|
} from './domUtils'
|
|
9
9
|
import { resourceToDataUrl } from './fetchCache'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
isPropertyCoveredByCurrentColor,
|
|
12
|
+
isPropertyInherited,
|
|
13
|
+
parseCssValueUrls,
|
|
14
|
+
shouldIncludeCssProperty,
|
|
15
|
+
} from './parseCss'
|
|
11
16
|
|
|
12
17
|
type Styles = { [K in string]?: string }
|
|
13
18
|
type ReadonlyStyles = { readonly [K in string]?: string }
|
|
@@ -53,9 +58,20 @@ export class StyleEmbedder {
|
|
|
53
58
|
? getDefaultStylesForTagName(element.tagName.toLowerCase())
|
|
54
59
|
: NO_STYLES
|
|
55
60
|
|
|
56
|
-
const parentStyles =
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
const parentStyles = Object.assign({}, NO_STYLES) as Styles
|
|
62
|
+
if (shouldSkipInheritedParentStyles) {
|
|
63
|
+
let el = element.parentElement
|
|
64
|
+
// Keep going up the tree to find all the relevant styles
|
|
65
|
+
while (el) {
|
|
66
|
+
const currentStyles = this.styles.get(el)?.self
|
|
67
|
+
for (const style in currentStyles) {
|
|
68
|
+
if (!parentStyles[style]) {
|
|
69
|
+
parentStyles[style] = currentStyles[style]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
el = el.parentElement
|
|
73
|
+
}
|
|
74
|
+
}
|
|
59
75
|
|
|
60
76
|
const info: ElementStyleInfo = {
|
|
61
77
|
self: styleFromElement(element, { defaultStyles, parentStyles }),
|
|
@@ -230,6 +246,8 @@ function styleFromComputedStyleMap(
|
|
|
230
246
|
|
|
231
247
|
if (defaultStyles[property] === value) continue
|
|
232
248
|
if (parentStyles[property] === value && isPropertyInherited(property)) continue
|
|
249
|
+
if (isPropertyCoveredByCurrentColor(style.get('color')?.toString() || '', property, value))
|
|
250
|
+
continue
|
|
233
251
|
|
|
234
252
|
styles[property] = value
|
|
235
253
|
}
|
|
@@ -249,6 +267,7 @@ function styleFromComputedStyle(
|
|
|
249
267
|
|
|
250
268
|
if (defaultStyles[property] === value) continue
|
|
251
269
|
if (parentStyles[property] === value && isPropertyInherited(property)) continue
|
|
270
|
+
if (isPropertyCoveredByCurrentColor(style.color, property, value)) continue
|
|
252
271
|
|
|
253
272
|
styles[property] = value
|
|
254
273
|
}
|
|
@@ -62,7 +62,7 @@ export async function exportToSvg(
|
|
|
62
62
|
const svg = renderTarget.firstElementChild
|
|
63
63
|
assert(svg instanceof SVGSVGElement, 'Expected an SVG element')
|
|
64
64
|
|
|
65
|
-
// And apply any changes to <foreignObject> elements that we need to make.
|
|
65
|
+
// And apply any changes to <foreignObject> elements that we need to make. while we're in
|
|
66
66
|
// the document, these elements work exactly as we'd expect from other dom elements - they
|
|
67
67
|
// can load external resources, and any stylesheets in the document apply to them as we
|
|
68
68
|
// would expect them to. But when we pull the SVG into its own file or draw it to a canvas
|
|
@@ -354,7 +354,7 @@ function SvgExport({
|
|
|
354
354
|
key: uniqueId(),
|
|
355
355
|
getElement: async () => {
|
|
356
356
|
const declaration = await editor.fonts.toEmbeddedCssDeclaration(font)
|
|
357
|
-
return <style>{declaration}</style>
|
|
357
|
+
return <style nonce={editor.options.nonce}>{declaration}</style>
|
|
358
358
|
},
|
|
359
359
|
})
|
|
360
360
|
}
|
|
@@ -111,11 +111,43 @@ export function parseCssValueUrls(value: string) {
|
|
|
111
111
|
}))
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
const currentColorProperties = new Set([
|
|
115
|
+
'border-block-end-color',
|
|
116
|
+
'border-block-start-color',
|
|
117
|
+
'border-bottom-color',
|
|
118
|
+
'border-inline-end-color',
|
|
119
|
+
'border-inline-start-color',
|
|
120
|
+
'border-left-color',
|
|
121
|
+
'border-right-color',
|
|
122
|
+
'border-top-color',
|
|
123
|
+
'caret-color',
|
|
124
|
+
'column-rule-color',
|
|
125
|
+
'outline-color',
|
|
126
|
+
'text-decoration',
|
|
127
|
+
'text-decoration-color',
|
|
128
|
+
'text-emphasis-color',
|
|
129
|
+
])
|
|
130
|
+
|
|
131
|
+
export function isPropertyCoveredByCurrentColor(
|
|
132
|
+
currentColor: string,
|
|
133
|
+
property: string,
|
|
134
|
+
value: string
|
|
135
|
+
) {
|
|
136
|
+
if (currentColorProperties.has(property)) {
|
|
137
|
+
return (
|
|
138
|
+
value === 'currentColor' ||
|
|
139
|
+
value === currentColor ||
|
|
140
|
+
(property === 'text-decoration' && value === `none solid ${currentColor}`)
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
114
145
|
const inheritedProperties = new Set([
|
|
115
146
|
'border-collapse',
|
|
116
147
|
'border-spacing',
|
|
117
148
|
'caption-side',
|
|
118
|
-
'color',
|
|
149
|
+
// N.B. We shouldn't inherit 'color' because there's some UA styling, e.g. `mark` elements
|
|
150
|
+
// 'color',
|
|
119
151
|
'cursor',
|
|
120
152
|
'direction',
|
|
121
153
|
'empty-cells',
|
|
@@ -136,16 +168,18 @@ const inheritedProperties = new Set([
|
|
|
136
168
|
'orphans',
|
|
137
169
|
'overflow-wrap',
|
|
138
170
|
'quotes',
|
|
171
|
+
'stroke-linecap',
|
|
172
|
+
'stroke-linejoin',
|
|
139
173
|
'tab-size',
|
|
140
174
|
'text-align',
|
|
141
175
|
'text-align-last',
|
|
142
|
-
'text-decoration-color',
|
|
143
176
|
'text-indent',
|
|
144
177
|
'text-justify',
|
|
145
178
|
'text-shadow',
|
|
146
179
|
'text-transform',
|
|
147
180
|
'visibility',
|
|
148
181
|
'white-space',
|
|
182
|
+
'white-space-collapse',
|
|
149
183
|
'widows',
|
|
150
184
|
'word-break',
|
|
151
185
|
'word-spacing',
|
|
@@ -85,6 +85,7 @@ const WatermarkInner = memo(function WatermarkInner({ src }: { src: string }) {
|
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
const LicenseStyles = memo(function LicenseStyles() {
|
|
88
|
+
const editor = useEditor()
|
|
88
89
|
const className = LicenseManager.className
|
|
89
90
|
|
|
90
91
|
const CSS = `/* ------------------- SEE LICENSE -------------------
|
|
@@ -156,8 +157,13 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
156
157
|
animation: delayed_link 0.2s forwards ease-in-out;
|
|
157
158
|
animation-delay: 0.32s;
|
|
158
159
|
}
|
|
160
|
+
|
|
161
|
+
.${className} > a:focus-visible {
|
|
162
|
+
opacity: 1;
|
|
163
|
+
}
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
|
|
161
167
|
@keyframes delayed_link {
|
|
162
168
|
0% {
|
|
163
169
|
cursor: inherit;
|
|
@@ -171,5 +177,5 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
171
177
|
}
|
|
172
178
|
}`
|
|
173
179
|
|
|
174
|
-
return <style>{CSS}</style>
|
|
180
|
+
return <style nonce={editor.options.nonce}>{CSS}</style>
|
|
175
181
|
})
|
package/src/lib/options.ts
CHANGED
|
@@ -75,6 +75,11 @@ export interface TldrawOptions {
|
|
|
75
75
|
* away and let the fonts load in in the background.
|
|
76
76
|
*/
|
|
77
77
|
readonly maxFontsToLoadBeforeRender: number
|
|
78
|
+
/**
|
|
79
|
+
* If you have a CSP policy that blocks inline styles, you can use this prop to provide a
|
|
80
|
+
* nonce to use in the editor's styles.
|
|
81
|
+
*/
|
|
82
|
+
readonly nonce: string | undefined
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/** @public */
|
|
@@ -121,4 +126,5 @@ export const defaultTldrawOptions = {
|
|
|
121
126
|
exportProvider: Fragment,
|
|
122
127
|
enableToolbarKeyboardShortcuts: true,
|
|
123
128
|
maxFontsToLoadBeforeRender: Infinity,
|
|
129
|
+
nonce: undefined,
|
|
124
130
|
} as const satisfies TldrawOptions
|
|
@@ -303,6 +303,15 @@ export class LocalIndexedDb {
|
|
|
303
303
|
await assetsStore.put(blob, assetId)
|
|
304
304
|
})
|
|
305
305
|
}
|
|
306
|
+
|
|
307
|
+
async removeAssets(assetId: string[]) {
|
|
308
|
+
await this.tx('readwrite', [Table.Assets], async (tx) => {
|
|
309
|
+
const assetsStore = tx.objectStore(Table.Assets)
|
|
310
|
+
for (const id of assetId) {
|
|
311
|
+
await assetsStore.delete(id)
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
}
|
|
306
315
|
}
|
|
307
316
|
|
|
308
317
|
/** @internal */
|
package/src/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '3.11.0
|
|
4
|
+
export const version = '3.11.0'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-03-
|
|
8
|
-
patch: '2025-03-
|
|
7
|
+
minor: '2025-03-20T14:45:59.625Z',
|
|
8
|
+
patch: '2025-03-20T14:45:59.625Z',
|
|
9
9
|
}
|