@salla.sa/twilight-bundles 0.1.30 ā 0.1.32
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/bin/tw-init.js +82 -46
- package/dist/twilight-bundles.cjs +2 -2
- package/dist/twilight-bundles.js +8 -8
- package/package.json +1 -1
package/bin/tw-init.js
CHANGED
|
@@ -44,7 +44,7 @@ function installStarterKit(projectRoot) {
|
|
|
44
44
|
return new Promise((resolve) => {
|
|
45
45
|
try {
|
|
46
46
|
console.log('š¦ Installing @salla.sa/twilight-bundles-starter-kit...');
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
// Check if pnpm exists on the system
|
|
49
49
|
try {
|
|
50
50
|
execSync('pnpm --version', { stdio: 'ignore' });
|
|
@@ -55,10 +55,10 @@ function installStarterKit(projectRoot) {
|
|
|
55
55
|
resolve(false);
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
// Install the package using pnpm
|
|
60
60
|
const installCommand = 'pnpm add @salla.sa/twilight-bundles-starter-kit@latest';
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
console.log(`š¦ Running: ${installCommand}`);
|
|
63
63
|
console.log('ā ļø This may take a moment...');
|
|
64
64
|
try {
|
|
@@ -84,10 +84,10 @@ function installStarterKit(projectRoot) {
|
|
|
84
84
|
function copyStarterKitFiles(projectRoot) {
|
|
85
85
|
try {
|
|
86
86
|
console.log('š Copying starter-kit files to your project...');
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
// Get the path to the starter-kit package
|
|
89
89
|
const starterKitPath = path.join(projectRoot, 'node_modules', '@salla.sa', 'twilight-bundles-starter-kit');
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
// Files and directories to copy
|
|
92
92
|
const itemsToCopy = [
|
|
93
93
|
'src',
|
|
@@ -96,18 +96,25 @@ function copyStarterKitFiles(projectRoot) {
|
|
|
96
96
|
'vite.config.ts',
|
|
97
97
|
'README.md'
|
|
98
98
|
];
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
// Copy each item
|
|
101
101
|
for (const item of itemsToCopy) {
|
|
102
102
|
const sourcePath = path.join(starterKitPath, item);
|
|
103
103
|
const targetPath = path.join(projectRoot, item);
|
|
104
|
-
|
|
104
|
+
const isExist = fs.existsSync(targetPath);
|
|
105
|
+
|
|
106
|
+
if (isExist && item === 'twilight-bundle.json') {
|
|
107
|
+
console.log(`ā ļø ${item} already exists, merging...`);
|
|
108
|
+
mergeTwilightBundleJson(sourcePath, targetPath);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
105
112
|
// Skip if target already exists
|
|
106
|
-
if (
|
|
113
|
+
if (isExist) {
|
|
107
114
|
console.log(`ā ļø ${item} already exists, skipping...`);
|
|
108
115
|
continue;
|
|
109
116
|
}
|
|
110
|
-
|
|
117
|
+
|
|
111
118
|
// Copy directory recursively
|
|
112
119
|
if (fs.statSync(sourcePath).isDirectory()) {
|
|
113
120
|
copyDirectoryRecursive(sourcePath, targetPath);
|
|
@@ -115,10 +122,10 @@ function copyStarterKitFiles(projectRoot) {
|
|
|
115
122
|
// Copy file
|
|
116
123
|
fs.copyFileSync(sourcePath, targetPath);
|
|
117
124
|
}
|
|
118
|
-
|
|
125
|
+
|
|
119
126
|
console.log(`ā
Copied ${item}`);
|
|
120
127
|
}
|
|
121
|
-
|
|
128
|
+
|
|
122
129
|
return true;
|
|
123
130
|
} catch (error) {
|
|
124
131
|
console.error('ā Failed to copy starter-kit files:', error.message);
|
|
@@ -136,15 +143,15 @@ function copyDirectoryRecursive(source, target) {
|
|
|
136
143
|
if (!fs.existsSync(target)) {
|
|
137
144
|
fs.mkdirSync(target, { recursive: true });
|
|
138
145
|
}
|
|
139
|
-
|
|
146
|
+
|
|
140
147
|
// Get all items in the source directory
|
|
141
148
|
const items = fs.readdirSync(source);
|
|
142
|
-
|
|
149
|
+
|
|
143
150
|
// Copy each item
|
|
144
151
|
for (const item of items) {
|
|
145
152
|
const sourcePath = path.join(source, item);
|
|
146
153
|
const targetPath = path.join(target, item);
|
|
147
|
-
|
|
154
|
+
|
|
148
155
|
// Copy directory recursively or file directly
|
|
149
156
|
if (fs.statSync(sourcePath).isDirectory()) {
|
|
150
157
|
copyDirectoryRecursive(sourcePath, targetPath);
|
|
@@ -162,23 +169,23 @@ function copyDirectoryRecursive(source, target) {
|
|
|
162
169
|
function mergePackageJson(projectRoot) {
|
|
163
170
|
try {
|
|
164
171
|
console.log('š Merging package.json...');
|
|
165
|
-
|
|
172
|
+
|
|
166
173
|
// Get the path to the starter-kit package.json
|
|
167
174
|
const starterKitPackageJsonPath = path.join(
|
|
168
|
-
projectRoot,
|
|
169
|
-
'node_modules',
|
|
170
|
-
'@salla.sa',
|
|
171
|
-
'twilight-bundles-starter-kit',
|
|
175
|
+
projectRoot,
|
|
176
|
+
'node_modules',
|
|
177
|
+
'@salla.sa',
|
|
178
|
+
'twilight-bundles-starter-kit',
|
|
172
179
|
'package.json'
|
|
173
180
|
);
|
|
174
|
-
|
|
181
|
+
|
|
175
182
|
// Get the path to the current package.json
|
|
176
183
|
const currentPackageJsonPath = path.join(projectRoot, 'package.json');
|
|
177
|
-
|
|
184
|
+
|
|
178
185
|
// Read the package.json files
|
|
179
186
|
const starterKitPackageJson = JSON.parse(fs.readFileSync(starterKitPackageJsonPath, 'utf8'));
|
|
180
187
|
const currentPackageJson = JSON.parse(fs.readFileSync(currentPackageJsonPath, 'utf8'));
|
|
181
|
-
|
|
188
|
+
|
|
182
189
|
// Merge the package.json files
|
|
183
190
|
const mergedPackageJson = {
|
|
184
191
|
...currentPackageJson,
|
|
@@ -196,13 +203,13 @@ function mergePackageJson(projectRoot) {
|
|
|
196
203
|
...currentPackageJson.devDependencies
|
|
197
204
|
}
|
|
198
205
|
};
|
|
199
|
-
|
|
206
|
+
|
|
200
207
|
// Write the merged package.json
|
|
201
208
|
fs.writeFileSync(
|
|
202
|
-
currentPackageJsonPath,
|
|
209
|
+
currentPackageJsonPath,
|
|
203
210
|
JSON.stringify(mergedPackageJson, null, 2)
|
|
204
211
|
);
|
|
205
|
-
|
|
212
|
+
|
|
206
213
|
console.log('ā
package.json merged successfully');
|
|
207
214
|
return true;
|
|
208
215
|
} catch (error) {
|
|
@@ -211,6 +218,35 @@ function mergePackageJson(projectRoot) {
|
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
220
|
|
|
221
|
+
function mergeTwilightBundleJson(sourcePath, targetPath) {
|
|
222
|
+
try {
|
|
223
|
+
console.log('š Merging twilight-bundle.json...');
|
|
224
|
+
|
|
225
|
+
// Read the twilight-bundle.json files
|
|
226
|
+
const currentTwilightBundleJson = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
|
|
227
|
+
const starterKitTwilightBundleComponents = JSON.parse(fs.readFileSync(sourcePath, 'utf8')).components||[];
|
|
228
|
+
const currentComponents = currentTwilightBundleJson.components?.map((component) => component.name)||[];
|
|
229
|
+
|
|
230
|
+
starterKitTwilightBundleComponents.forEach((component) => {
|
|
231
|
+
if (!currentComponents.includes(component.name)) {
|
|
232
|
+
currentTwilightBundleJson.components.push(component);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Write the merged twilight-bundle.json
|
|
237
|
+
fs.writeFileSync(
|
|
238
|
+
targetPath,
|
|
239
|
+
JSON.stringify(currentTwilightBundleJson, null, 2)
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
console.log('ā
twilight-bundle.json merged successfully');
|
|
243
|
+
return true;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error('ā Failed to merge twilight-bundle.json:', error.message);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
214
250
|
/**
|
|
215
251
|
* Initialize a new Twilight Bundles project
|
|
216
252
|
* @param {string} [projectRootArg] - Optional project root directory
|
|
@@ -218,19 +254,19 @@ function mergePackageJson(projectRoot) {
|
|
|
218
254
|
async function initTwilightBundles(projectRootArg) {
|
|
219
255
|
// Get project root from arguments or default to current directory
|
|
220
256
|
const projectRoot = projectRootArg || process.cwd();
|
|
221
|
-
|
|
257
|
+
|
|
222
258
|
console.log('š Initializing Salla Twilight Bundles Project š\n');
|
|
223
|
-
|
|
259
|
+
|
|
224
260
|
// Check if twilight-bundle.json already exists
|
|
225
261
|
if (twilightBundlesExists(projectRoot)) {
|
|
226
262
|
console.log('ā ļø This directory already contains a Twilight Bundles project (twilight-bundle.json exists)');
|
|
227
|
-
console.log('If you want to start a new project, please create a new directory and run this command again, or if want new component run `pnpm tw-component`.');
|
|
228
|
-
return false;
|
|
263
|
+
//console.log('If you want to start a new project, please create a new directory and run this command again, or if want new component run `pnpm tw-component`.');
|
|
264
|
+
//return false;
|
|
229
265
|
}
|
|
230
|
-
|
|
266
|
+
|
|
231
267
|
// Check if starter-kit is installed
|
|
232
268
|
let starterKitReady = starterKitInstalled(projectRoot);
|
|
233
|
-
|
|
269
|
+
|
|
234
270
|
// Install starter-kit if not installed
|
|
235
271
|
if (!starterKitReady) {
|
|
236
272
|
starterKitReady = await installStarterKit(projectRoot);
|
|
@@ -238,71 +274,71 @@ async function initTwilightBundles(projectRootArg) {
|
|
|
238
274
|
return false;
|
|
239
275
|
}
|
|
240
276
|
}
|
|
241
|
-
|
|
277
|
+
|
|
242
278
|
// Copy starter-kit files
|
|
243
279
|
if (!copyStarterKitFiles(projectRoot)) {
|
|
244
280
|
return false;
|
|
245
281
|
}
|
|
246
|
-
|
|
282
|
+
|
|
247
283
|
// Merge package.json
|
|
248
284
|
if (!mergePackageJson(projectRoot)) {
|
|
249
285
|
return false;
|
|
250
286
|
}
|
|
251
|
-
|
|
287
|
+
|
|
252
288
|
console.log('\nš Twilight Bundles project initialized successfully!\n');
|
|
253
|
-
|
|
289
|
+
|
|
254
290
|
console.log('Installing dependencies...');
|
|
255
|
-
execSync('pnpm install',
|
|
291
|
+
execSync('pnpm install', { stdio: 'inherit' });
|
|
256
292
|
|
|
257
293
|
console.log('\nStarting development server...\n');
|
|
258
|
-
|
|
294
|
+
|
|
259
295
|
// Start dev server asynchronously so it doesn't block
|
|
260
296
|
const devServer = spawn('pnpm', ['run', 'dev'], {
|
|
261
297
|
stdio: 'inherit',
|
|
262
298
|
cwd: projectRoot,
|
|
263
299
|
shell: true
|
|
264
300
|
});
|
|
265
|
-
|
|
301
|
+
|
|
266
302
|
// Wait a moment for the server to start outputting
|
|
267
303
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
268
|
-
|
|
304
|
+
|
|
269
305
|
// Show the helpful message while the server is running
|
|
270
306
|
console.log('\n' + '='.repeat(60));
|
|
271
307
|
console.log('šÆ Next Steps & Quick Tips');
|
|
272
308
|
console.log('='.repeat(60) + '\n');
|
|
273
|
-
|
|
309
|
+
|
|
274
310
|
console.log('š§ Development Commands:');
|
|
275
311
|
console.log(' ⢠pnpm dev - Start development server with hot reload');
|
|
276
312
|
console.log(' ⢠pnpm build - Build bundles for production');
|
|
277
|
-
|
|
313
|
+
|
|
278
314
|
console.log('š Documentation:');
|
|
279
315
|
console.log(' ⢠README.md - Project overview and setup');
|
|
280
316
|
console.log(' ⢠src/ - Your bundle components');
|
|
281
317
|
console.log(' ⢠twilight-bundle.json - Bundle configuration\n');
|
|
282
|
-
|
|
318
|
+
|
|
283
319
|
console.log('š” Pro Tips:');
|
|
284
320
|
console.log(' ⢠Edit files in src/ to see changes instantly');
|
|
285
321
|
console.log(' ⢠Check twilight-bundle.json for bundle settings');
|
|
286
322
|
console.log(' ⢠Use TypeScript for better type safety\n');
|
|
287
|
-
|
|
323
|
+
|
|
288
324
|
console.log('š Keyboard Shortcuts (in dev mode):');
|
|
289
325
|
console.log(' ⢠q + Enter - Quit the dev server safely');
|
|
290
326
|
console.log(' ⢠r + Enter - Restart the dev server');
|
|
291
327
|
console.log(' ⢠o + Enter - Open in browser');
|
|
292
328
|
console.log(' ⢠Ctrl+C - Force Stop the development server\n');
|
|
293
|
-
|
|
329
|
+
|
|
294
330
|
console.log('š¦ Component Management:');
|
|
295
331
|
console.log(' pnpm tw-create-component <component-name> - Create a new component');
|
|
296
332
|
console.log(' pnpm tw-delete-component <component-name> - Delete a component');
|
|
297
333
|
console.log(' Example: pnpm tw-create-component tw-my-button\n');
|
|
298
|
-
|
|
334
|
+
|
|
299
335
|
// Handle server exit
|
|
300
336
|
devServer.on('exit', (code) => {
|
|
301
337
|
if (code !== 0 && code !== null) {
|
|
302
338
|
//console.log(`\nā ļø Development server exited with code ${code}`);
|
|
303
339
|
}
|
|
304
340
|
});
|
|
305
|
-
|
|
341
|
+
|
|
306
342
|
return true;
|
|
307
343
|
}
|
|
308
344
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const{is:$t,defineProperty:ft,getOwnPropertyDescriptor:gt,getOwnPropertyNames:_t,getOwnPropertySymbols:yt,getPrototypeOf:At}=Object,f=globalThis,X=f.trustedTypes,St=X?X.emptyScript:"",
|
|
9
|
+
*/const{is:$t,defineProperty:ft,getOwnPropertyDescriptor:gt,getOwnPropertyNames:_t,getOwnPropertySymbols:yt,getPrototypeOf:At}=Object,f=globalThis,X=f.trustedTypes,St=X?X.emptyScript:"",I=f.reactiveElementPolyfillSupport,P=(n,t)=>n,k={toAttribute(n,t){switch(t){case Boolean:n=n?St:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},K=(n,t)=>!$t(n,t),Y={attribute:!0,type:String,converter:k,reflect:!1,useDefault:!1,hasChanged:K};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),f.litPropertyMetadata??(f.litPropertyMetadata=new WeakMap);class w extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=Y){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&ft(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:r}=gt(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o}};return{get:i,set(o){const l=i==null?void 0:i.call(this);r==null||r.call(this,o),this.requestUpdate(t,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Y}static _$Ei(){if(this.hasOwnProperty(P("elementProperties")))return;const t=At(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(P("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(P("properties"))){const e=this.properties,s=[..._t(e),...yt(e)];for(const i of s)this.createProperty(i,e[i])}const t=this[Symbol.metadata];if(t!==null){const e=litPropertyMetadata.get(t);if(e!==void 0)for(const[s,i]of e)this.elementProperties.set(s,i)}this._$Eh=new Map;for(const[e,s]of this.elementProperties){const i=this._$Eu(e,s);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const i of s)e.unshift(Q(i))}else t!==void 0&&e.push(Q(t));return e}static _$Eu(t,e){const s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$ES=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach((e=>e(this)))}addController(t){var e;(this._$EO??(this._$EO=new Set)).add(t),this.renderRoot!==void 0&&this.isConnected&&((e=t.hostConnected)==null||e.call(t))}removeController(t){var e;(e=this._$EO)==null||e.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return mt(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$EO)==null||t.forEach((e=>{var s;return(s=e.hostConnected)==null?void 0:s.call(e)}))}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$EO)==null||t.forEach((e=>{var s;return(s=e.hostDisconnected)==null?void 0:s.call(e)}))}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$ET(t,e){var r;const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(i!==void 0&&s.reflect===!0){const o=(((r=s.converter)==null?void 0:r.toAttribute)!==void 0?s.converter:k).toAttribute(e,s.type);this._$Em=t,o==null?this.removeAttribute(i):this.setAttribute(i,o),this._$Em=null}}_$AK(t,e){var r,o;const s=this.constructor,i=s._$Eh.get(t);if(i!==void 0&&this._$Em!==i){const l=s.getPropertyOptions(i),a=typeof l.converter=="function"?{fromAttribute:l.converter}:((r=l.converter)==null?void 0:r.fromAttribute)!==void 0?l.converter:k;this._$Em=i;const c=a.fromAttribute(e,l.type);this[i]=c??((o=this._$Ej)==null?void 0:o.get(i))??c,this._$Em=null}}requestUpdate(t,e,s){var i;if(t!==void 0){const r=this.constructor,o=this[t];if(s??(s=r.getPropertyOptions(t)),!((s.hasChanged??K)(o,e)||s.useDefault&&s.reflect&&o===((i=this._$Ej)==null?void 0:i.get(t))&&!this.hasAttribute(r._$Eu(t,s))))return;this.C(t,e,s)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:i,wrapped:r},o){s&&!(this._$Ej??(this._$Ej=new Map)).has(t)&&(this._$Ej.set(t,o??e??this[t]),r!==!0||o!==void 0)||(this._$AL.has(t)||(this.hasUpdated||s||(e=void 0),this._$AL.set(t,e)),i===!0&&this._$Em!==t&&(this._$Eq??(this._$Eq=new Set)).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}const i=this.constructor.elementProperties;if(i.size>0)for(const[r,o]of i){const{wrapped:l}=o,a=this[r];l!==!0||this._$AL.has(r)||a===void 0||this.C(r,void 0,o,a)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),(s=this._$EO)==null||s.forEach((i=>{var r;return(r=i.hostUpdate)==null?void 0:r.call(i)})),this.update(e)):this._$EM()}catch(i){throw t=!1,this._$EM(),i}t&&this._$AE(e)}willUpdate(t){}_$AE(t){var e;(e=this._$EO)==null||e.forEach((s=>{var i;return(i=s.hostUpdated)==null?void 0:i.call(s)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&(this._$Eq=this._$Eq.forEach((e=>this._$ET(e,this[e])))),this._$EM()}updated(t){}firstUpdated(t){}}w.elementStyles=[],w.shadowRootOptions={mode:"open"},w[P("elementProperties")]=new Map,w[P("finalized")]=new Map,I==null||I({ReactiveElement:w}),(f.reactiveElementVersions??(f.reactiveElementVersions=[])).push("2.1.1");/**
|
|
10
10
|
* @license
|
|
11
11
|
* Copyright 2017 Google LLC
|
|
12
12
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -20,4 +20,4 @@
|
|
|
20
20
|
* @license
|
|
21
21
|
* Copyright 2017 Google LLC
|
|
22
22
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
23
|
-
*/const Ut={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:K},Ot=(n=Ut,t,e)=>{const{kind:s,metadata:i}=e;let r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),s==="setter"&&((n=Object.create(n)).wrapped=!0),r.set(e.name,n),s==="accessor"){const{name:o}=e;return{set(l){const a=t.get.call(this);t.set.call(this,l),this.requestUpdate(o,a,n)},init(l){return l!==void 0&&this.C(o,void 0,n,l),l}}}if(s==="setter"){const{name:o}=e;return function(l){const a=this[o];t.call(this,l),this.requestUpdate(o,a,n)}}throw Error("Unsupported decorator location: "+s)};function z(n){return(t,e)=>typeof e=="object"?Ot(n,t,e):((s,i,r)=>{const o=i.hasOwnProperty(r);return i.constructor.createProperty(r,s),o?Object.getOwnPropertyDescriptor(i,r):void 0})(n,t,e)}class y{static onBundlesReady(){return y.makeSureSallaIsReady().then(()=>Salla.event.onlyWhen("twilight-bundles::initiated"))}static async initializeSalla(){if(Salla.status==="ready"){salla.log("Salla is ready");return}const t=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),e=t==null?void 0:t.hasAttribute("demo-mode");let s=t==null?void 0:t.getAttribute("store-id"),i=JSON.parse((t==null?void 0:t.getAttribute("config"))||"false");return e||i||s?(s=s||"1510890315",i=i||await y.getStoreSettings(s),Salla.init(i||{debug:!0,store:{id:s}})):Salla.onReady()}static async getStoreSettings(t){let e=Salla.storage.session.get(`store-settings-${t}`);return e||(e=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":t}}).then(s=>s.json())).data,Salla.storage.session.set(`store-settings-${t}`,e),e)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(y.initializeSalla()):new Promise((t,e)=>{let s;const i=setTimeout(()=>{window.clearInterval(s),e(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);s=window.setInterval(()=>{window.Salla&&(window.clearInterval(s),clearTimeout(i),t(y.initializeSalla()))},50)})}}var Rt=Object.defineProperty,
|
|
23
|
+
*/const Ut={attribute:!0,type:String,converter:k,reflect:!1,hasChanged:K},Ot=(n=Ut,t,e)=>{const{kind:s,metadata:i}=e;let r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),s==="setter"&&((n=Object.create(n)).wrapped=!0),r.set(e.name,n),s==="accessor"){const{name:o}=e;return{set(l){const a=t.get.call(this);t.set.call(this,l),this.requestUpdate(o,a,n)},init(l){return l!==void 0&&this.C(o,void 0,n,l),l}}}if(s==="setter"){const{name:o}=e;return function(l){const a=this[o];t.call(this,l),this.requestUpdate(o,a,n)}}throw Error("Unsupported decorator location: "+s)};function z(n){return(t,e)=>typeof e=="object"?Ot(n,t,e):((s,i,r)=>{const o=i.hasOwnProperty(r);return i.constructor.createProperty(r,s),o?Object.getOwnPropertyDescriptor(i,r):void 0})(n,t,e)}class y{static onBundlesReady(){return y.makeSureSallaIsReady().then(()=>Salla.event.onlyWhen("twilight-bundles::initiated")).then(()=>Salla.lang.onLoaded())}static async initializeSalla(){if(Salla.status==="ready"){salla.log("Salla is ready");return}const t=document.currentScript||document.querySelector('script[src*="twilight-bundles.js"]'),e=t==null?void 0:t.hasAttribute("demo-mode");let s=t==null?void 0:t.getAttribute("store-id"),i=JSON.parse((t==null?void 0:t.getAttribute("config"))||"false");return e||i||s?(s=s||"1510890315",i=i||await y.getStoreSettings(s),Salla.init(i||{debug:!0,store:{id:s}})):Salla.onReady()}static async getStoreSettings(t){let e=Salla.storage.session.get(`store-settings-${t}`);return e||(e=(await fetch("https://api.salla.dev/store/v1/store/settings",{headers:{"store-identifier":t}}).then(s=>s.json())).data,Salla.storage.session.set(`store-settings-${t}`,e),e)}static makeSureSallaIsReady(){return window.Salla?Promise.resolve(y.initializeSalla()):new Promise((t,e)=>{let s;const i=setTimeout(()=>{window.clearInterval(s),e(new Error("Timeout: Salla object not found after 10 seconds"))},1e4);s=window.setInterval(()=>{window.Salla&&(window.clearInterval(s),clearTimeout(i),t(y.initializeSalla()))},50)})}}var Rt=Object.defineProperty,L=(n,t,e,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(t,e,i)||i);return i&&Rt(t,e,i),i};const F=class F extends M{constructor(){super(...arguments),this.key="",this.data={},this.imports={},this.shadowRootMode="open"}createRenderRoot(){return this.shadowRootMode!==!1?this.attachShadow({mode:this.shadowRootMode||"closed"}):this}static register(t){const e={component:this,dynamicTagName:`${t}-${Math.random().toString(36).substring(2,8)}`};return y.onBundlesReady().then(()=>Salla.bundles.registerComponent(t,e))}};F.styles=pt`:host { display: block; }`;let v=F;L([z()],v.prototype,"key");L([z()],v.prototype,"data");L([z()],v.prototype,"imports");L([z()],v.prototype,"shadowRootMode");class Ht extends HTMLElement{connectedCallback(){var e;let t=(e=this.getAttribute("component-name"))==null?void 0:e.replace(/^salla-/,"");if(!t)return Salla.error("Component name is required",this),Promise.resolve();this.innerHTML=`<!-- Loading ${t} -->`,this.removeAttribute("component-name"),Salla.bundles.renderCustomComponentDom(`salla-${t}`,this)}}class Nt{constructor(){this.components=new Map,this.pendingComponents=[],this.initialized=!1,Salla.onReady().then(()=>{if(Salla.bundles){Salla.log("TwilightBundles is already initialized");return}this.init(),Salla.bundles=this,Salla.event.emit("twilight-bundles::initiated"),this.registerCustomComponents()})}async init(){this.initialized||(this.initialized=!0)}registerCustomComponents(){var t;HTMLElement.registerSallaComponent=function(e){Salla.bundles.registerComponent(e,{component:this,dynamicTagName:`${e}-${Math.random().toString(36).substring(2,8)}`})},(t=window.customComponents)==null||t.forEach(e=>{const s=document.createElement("script");s.type="module",s.src=e,document.head.appendChild(s)})}renderCustomComponentDom(t,e){salla.log("Rendering custom component",t),e.getAttribute("component-name");const s=this.components.get(t);return s?this.renderDynamicCustomComponentDom(s.dynamicTagName,e):this.pendingComponents.push({tagName:t,component:e})}renderDynamicCustomComponentDom(t,e){const s=document.createElement(t);Array.from(e.attributes).forEach(i=>s.setAttribute(i.name,i.value||"")),e.before(s),e.remove()}registerComponent(t,e){if(this.components.has(t))return console.warn(`Component ${t} is already registered into the this.components map. Skipping.`);if(!e.dynamicTagName)return console.warn(`Component ${t} is missing dynamicTagName. Skipping.`);if(!e.component)return console.warn(`Component ${t} is missing component. Skipping.`);if(window.customElements.get(e.dynamicTagName))return console.warn(`Component ${e.dynamicTagName} is already registered into the window custom elements. Skipping.`);window.customElements.define(e.dynamicTagName,e.component),this.components.set(t,e),Salla.log("Component registered:",e.dynamicTagName);const s=this.pendingComponents.filter(i=>i.tagName===t);s.length&&(s.forEach(i=>{this.renderDynamicCustomComponentDom(e.dynamicTagName,i.component)}),this.pendingComponents=this.pendingComponents.filter(i=>i.tagName!==t),Salla.log("Pending Components rendered:",t,e.dynamicTagName))}renderSharedAssests(...t){const e={sallaicons:`<link rel="stylesheet" href="${Salla.url.cdn("fonts/sallaicons.css")}">`};return t.map(s=>e[s]||"").join("")}}y.makeSureSallaIsReady().then(()=>new Nt).then(()=>window.customElements.get("salla-custom-component")||window.customElements.define("salla-custom-component",Ht));exports.SallaComponent=v;
|
package/dist/twilight-bundles.js
CHANGED
|
@@ -45,7 +45,7 @@ const ut = (n) => new at(typeof n == "string" ? n : n + "", void 0, J), pt = (n,
|
|
|
45
45
|
* Copyright 2017 Google LLC
|
|
46
46
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
47
47
|
*/
|
|
48
|
-
const { is: $t, defineProperty: ft, getOwnPropertyDescriptor: gt, getOwnPropertyNames: _t, getOwnPropertySymbols: yt, getPrototypeOf: At } = Object, f = globalThis, X = f.trustedTypes, St = X ? X.emptyScript : "",
|
|
48
|
+
const { is: $t, defineProperty: ft, getOwnPropertyDescriptor: gt, getOwnPropertyNames: _t, getOwnPropertySymbols: yt, getPrototypeOf: At } = Object, f = globalThis, X = f.trustedTypes, St = X ? X.emptyScript : "", I = f.reactiveElementPolyfillSupport, P = (n, t) => n, k = { toAttribute(n, t) {
|
|
49
49
|
switch (t) {
|
|
50
50
|
case Boolean:
|
|
51
51
|
n = n ? St : null;
|
|
@@ -278,7 +278,7 @@ class v extends HTMLElement {
|
|
|
278
278
|
firstUpdated(t) {
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
v.elementStyles = [], v.shadowRootOptions = { mode: "open" }, v[P("elementProperties")] = /* @__PURE__ */ new Map(), v[P("finalized")] = /* @__PURE__ */ new Map(),
|
|
281
|
+
v.elementStyles = [], v.shadowRootOptions = { mode: "open" }, v[P("elementProperties")] = /* @__PURE__ */ new Map(), v[P("finalized")] = /* @__PURE__ */ new Map(), I == null || I({ ReactiveElement: v }), (f.reactiveElementVersions ?? (f.reactiveElementVersions = [])).push("2.1.1");
|
|
282
282
|
/**
|
|
283
283
|
* @license
|
|
284
284
|
* Copyright 2017 Google LLC
|
|
@@ -585,7 +585,7 @@ function j(n) {
|
|
|
585
585
|
}
|
|
586
586
|
class y {
|
|
587
587
|
static onBundlesReady() {
|
|
588
|
-
return y.makeSureSallaIsReady().then(() => Salla.event.onlyWhen("twilight-bundles::initiated"));
|
|
588
|
+
return y.makeSureSallaIsReady().then(() => Salla.event.onlyWhen("twilight-bundles::initiated")).then(() => Salla.lang.onLoaded());
|
|
589
589
|
}
|
|
590
590
|
static async initializeSalla() {
|
|
591
591
|
if (Salla.status === "ready") {
|
|
@@ -615,7 +615,7 @@ class y {
|
|
|
615
615
|
});
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
|
-
var Ot = Object.defineProperty,
|
|
618
|
+
var Ot = Object.defineProperty, L = (n, t, e, s) => {
|
|
619
619
|
for (var i = void 0, r = n.length - 1, o; r >= 0; r--)
|
|
620
620
|
(o = n[r]) && (i = o(t, e, i) || i);
|
|
621
621
|
return i && Ot(t, e, i), i;
|
|
@@ -637,16 +637,16 @@ const F = class F extends M {
|
|
|
637
637
|
};
|
|
638
638
|
F.styles = pt`:host { display: block; }`;
|
|
639
639
|
let E = F;
|
|
640
|
-
|
|
640
|
+
L([
|
|
641
641
|
j()
|
|
642
642
|
], E.prototype, "key");
|
|
643
|
-
|
|
643
|
+
L([
|
|
644
644
|
j()
|
|
645
645
|
], E.prototype, "data");
|
|
646
|
-
|
|
646
|
+
L([
|
|
647
647
|
j()
|
|
648
648
|
], E.prototype, "imports");
|
|
649
|
-
|
|
649
|
+
L([
|
|
650
650
|
j()
|
|
651
651
|
], E.prototype, "shadowRootMode");
|
|
652
652
|
class Ht extends HTMLElement {
|
package/package.json
CHANGED